当前位置: 首页>>代码示例>>Golang>>正文


Golang plan.Del函数代码示例

本文整理汇总了Golang中github.com/stripe/stripe-go/plan.Del函数的典型用法代码示例。如果您正苦于以下问题:Golang Del函数的具体用法?Golang Del怎么用?Golang Del使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Del函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: createSubItem

func createSubItem(t *testing.T) (*stripe.Sub, *stripe.SubItem, func()) {
	customerParams := &stripe.CustomerParams{
		Source: &stripe.SourceParams{
			Card: &stripe.CardParams{
				Number: "378282246310005",
				Month:  "06",
				Year:   "20",
			},
		},
	}

	cust, err := customer.New(customerParams)
	if err != nil {
		t.Fatalf("customer creation: %s", err)
	}

	planID := fmt.Sprintf("test-%d", rand.Int63())
	planParams := &stripe.PlanParams{
		ID:       planID,
		Name:     "Test Plan",
		Amount:   99,
		Currency: currency.USD,
		Interval: plan.Month,
	}

	p, err := plan.New(planParams)
	if err != nil {
		t.Fatalf("plan creation: %s", err)
	}

	subParams := &stripe.SubParams{
		Customer: cust.ID,
		Items: []*stripe.SubItemsParams{
			{
				Plan:     p.ID,
				Quantity: 1,
			},
		},
	}

	target, err := sub.New(subParams)
	if err != nil {
		t.Fatalf("subscription creation: %s", err)
	}
	if target.Items == nil {
		t.Fatalf("no items for sub %s", target.ID)
	}
	if len(target.Items.Values) != 1 {
		t.Fatalf("missing items: %#v", target)
	}
	return target, target.Items.Values[0], func() {
		sub.Cancel(target.ID, nil)
		plan.Del(p.ID)
		customer.Del(cust.ID)
	}
}
开发者ID:captain401,项目名称:stripe-go,代码行数:56,代码来源:client_test.go

示例2: TestSubscriptionNew

func TestSubscriptionNew(t *testing.T) {
	customerParams := &stripe.CustomerParams{
		Source: &stripe.SourceParams{
			Card: &stripe.CardParams{
				Number: "378282246310005",
				Month:  "06",
				Year:   "20",
			},
		},
	}

	cust, _ := customer.New(customerParams)

	planParams := &stripe.PlanParams{
		ID:       "test",
		Name:     "Test Plan",
		Amount:   99,
		Currency: currency.USD,
		Interval: plan.Month,
	}

	plan.New(planParams)

	subParams := &stripe.SubParams{
		Customer:           cust.ID,
		Plan:               "test",
		Quantity:           10,
		TaxPercent:         20.0,
		BillingCycleAnchor: time.Now().AddDate(0, 0, 12).Unix(),
	}

	target, err := New(subParams)

	if err != nil {
		t.Error(err)
	}

	if target.Plan.ID != subParams.Plan {
		t.Errorf("Plan %v does not match expected plan %v\n", target.Plan, subParams.Plan)
	}

	if target.Quantity != subParams.Quantity {
		t.Errorf("Quantity %v does not match expected quantity %v\n", target.Quantity, subParams.Quantity)
	}

	if target.TaxPercent != subParams.TaxPercent {
		t.Errorf("TaxPercent %f does not match expected TaxPercent %f\n", target.TaxPercent, subParams.TaxPercent)
	}

	if target.PeriodEnd != subParams.BillingCycleAnchor {
		t.Errorf("PeriodEnd %v does not match expected BillingCycleAnchor %v\n", target.PeriodEnd, subParams.BillingCycleAnchor)
	}

	customer.Del(cust.ID)
	plan.Del("test")
}
开发者ID:captain401,项目名称:stripe-go,代码行数:56,代码来源:client_test.go

示例3: TestSubscriptionUpdate

func TestSubscriptionUpdate(t *testing.T) {
	customerParams := &stripe.CustomerParams{
		Source: &stripe.SourceParams{
			Card: &stripe.CardParams{
				Number: "378282246310005",
				Month:  "06",
				Year:   "20",
			},
		},
	}

	cust, _ := customer.New(customerParams)

	planParams := &stripe.PlanParams{
		ID:       "test",
		Name:     "Test Plan",
		Amount:   99,
		Currency: currency.USD,
		Interval: plan.Month,
	}

	plan.New(planParams)

	subParams := &stripe.SubParams{
		Customer:    cust.ID,
		Plan:        "test",
		Quantity:    10,
		TrialEndNow: true,
	}

	subscription, _ := New(subParams)
	updatedSub := &stripe.SubParams{
		Customer:   cust.ID,
		NoProrate:  true,
		Quantity:   13,
		TaxPercent: 20.0,
	}

	target, err := Update(subscription.ID, updatedSub)

	if err != nil {
		t.Error(err)
	}

	if target.Quantity != updatedSub.Quantity {
		t.Errorf("Quantity %v does not match expected quantity %v\n", target.Quantity, updatedSub.Quantity)
	}

	if target.TaxPercent != updatedSub.TaxPercent {
		t.Errorf("TaxPercent %f does not match expected tax_percent %f\n", target.TaxPercent, updatedSub.TaxPercent)
	}

	customer.Del(cust.ID)
	plan.Del("test")
}
开发者ID:zkirill,项目名称:stripe-go,代码行数:55,代码来源:client_test.go

示例4: TestSubscriptionCancel

func TestSubscriptionCancel(t *testing.T) {
	customerParams := &stripe.CustomerParams{
		Source: &stripe.SourceParams{
			Card: &stripe.CardParams{
				Number: "378282246310005",
				Month:  "06",
				Year:   "20",
			},
		},
	}

	cust, _ := customer.New(customerParams)

	planParams := &stripe.PlanParams{
		ID:       "test",
		Name:     "Test Plan",
		Amount:   99,
		Currency: currency.USD,
		Interval: plan.Month,
	}

	plan.New(planParams)

	subParams := &stripe.SubParams{
		Customer: cust.ID,
		Plan:     "test",
		Quantity: 10,
	}

	subscription, _ := New(subParams)
	s, err := Cancel(subscription.ID, nil)

	if err != nil {
		t.Error(err)
	}

	if s.Canceled == 0 {
		t.Errorf("Subscription.Canceled %v expected to be non 0\n", s.Canceled)
	}

	subscription, _ = New(subParams)
	s, err = Cancel(subscription.ID, &stripe.SubParams{Customer: cust.ID})

	if err != nil {
		t.Error(err)
	}

	if s.Canceled == 0 {
		t.Errorf("Subscription.Canceled %v expected to be non 0\n", s.Canceled)
	}

	customer.Del(cust.ID)
	plan.Del("test")
}
开发者ID:captain401,项目名称:stripe-go,代码行数:54,代码来源:client_test.go

示例5: TestSubscriptionGet

func TestSubscriptionGet(t *testing.T) {
	customerParams := &stripe.CustomerParams{
		Source: &stripe.SourceParams{
			Card: &stripe.CardParams{
				Number: "378282246310005",
				Month:  "06",
				Year:   "20",
			},
		},
	}

	cust, _ := customer.New(customerParams)

	planParams := &stripe.PlanParams{
		ID:       "test",
		Name:     "Test Plan",
		Amount:   99,
		Currency: currency.USD,
		Interval: plan.Month,
	}

	plan.New(planParams)

	subParams := &stripe.SubParams{
		Customer: cust.ID,
		Plan:     "test",
		Quantity: 10,
	}

	subscription, _ := New(subParams)
	target, err := Get(subscription.ID, nil)

	if err != nil {
		t.Error(err)
	}

	if target.ID != subscription.ID {
		t.Errorf("Subscription id %q does not match expected id %q\n", target.ID, subscription.ID)
	}

	target, err = Get(subscription.ID, &stripe.SubParams{Customer: cust.ID})

	if err != nil {
		t.Error(err)
	}

	if target.ID != subscription.ID {
		t.Errorf("Subscription id %q does not match expected id %q\n", target.ID, subscription.ID)
	}

	customer.Del(cust.ID)
	plan.Del("test")
}
开发者ID:captain401,项目名称:stripe-go,代码行数:53,代码来源:client_test.go

示例6: TestSubscriptionZeroQuantity

func TestSubscriptionZeroQuantity(t *testing.T) {
	customerParams := &stripe.CustomerParams{
		Source: &stripe.SourceParams{
			Card: &stripe.CardParams{
				Number: "378282246310005",
				Month:  "06",
				Year:   "20",
			},
		},
	}

	cust, _ := customer.New(customerParams)

	planParams := &stripe.PlanParams{
		ID:       "test",
		Name:     "Test Plan",
		Amount:   99,
		Currency: currency.USD,
		Interval: plan.Month,
	}

	plan.New(planParams)

	subParams := &stripe.SubParams{
		Customer:       cust.ID,
		Plan:           "test",
		QuantityZero:   true,
		TaxPercentZero: true,
	}

	target, err := New(subParams)

	if err != nil {
		t.Error(err)
	}

	if target.Plan.ID != subParams.Plan {
		t.Errorf("Plan %v does not match expected plan %v\n", target.Plan, subParams.Plan)
	}

	if target.Quantity != 0 {
		t.Errorf("Quantity %v does not match expected quantity %v\n", target.Quantity, 0)
	}

	if target.TaxPercent != 0 {
		t.Errorf("Tax percent %v does not match expected tax percent %v\n", target.TaxPercent, 0)
	}

	customer.Del(cust.ID)
	plan.Del("test")
}
开发者ID:captain401,项目名称:stripe-go,代码行数:51,代码来源:client_test.go

示例7: TestSubscriptionList

func TestSubscriptionList(t *testing.T) {
	customerParams := &stripe.CustomerParams{
		Source: &stripe.SourceParams{
			Card: &stripe.CardParams{
				Number: "378282246310005",
				Month:  "06",
				Year:   "20",
			},
		},
	}

	cust, _ := customer.New(customerParams)

	planParams := &stripe.PlanParams{
		ID:       "test",
		Name:     "Test Plan",
		Amount:   99,
		Currency: currency.USD,
		Interval: plan.Month,
	}

	plan.New(planParams)

	subParams := &stripe.SubParams{
		Customer: cust.ID,
		Plan:     "test",
		Quantity: 10,
	}

	for i := 0; i < 5; i++ {
		New(subParams)
	}

	i := List(&stripe.SubListParams{Customer: cust.ID})
	for i.Next() {
		if i.Sub() == nil {
			t.Error("No nil values expected")
		}

		if i.Meta() == nil {
			t.Error("No metadata returned")
		}
	}
	if err := i.Err(); err != nil {
		t.Error(err)
	}

	customer.Del(cust.ID)
	plan.Del("test")
}
开发者ID:zkirill,项目名称:stripe-go,代码行数:50,代码来源:client_test.go

示例8: TestListItems

func TestListItems(t *testing.T) {
	sub, _, cleanup := createSubItem(t)
	defer cleanup()

	// Create a new plan
	planID := fmt.Sprintf("test-%d", rand.Int63())
	planParams := &stripe.PlanParams{
		ID:       planID,
		Name:     "Expensive plan",
		Amount:   1000,
		Currency: currency.USD,
		Interval: plan.Month,
	}
	p, err := plan.New(planParams)
	if err != nil {
		t.Fatal(err)
	}
	defer plan.Del(p.ID)

	item, err := New(&stripe.SubItemParams{
		Sub:      sub.ID,
		Plan:     p.ID,
		Quantity: 2,
	})
	if err != nil {
		t.Errorf("new err: %s", err)
	}
	if item.Quantity != 2 {
		t.Errorf("quantity should be 2 after update, not %d", item.Quantity)
	}

	if item.ID != "" {
		item, err := Del(item.ID, nil)
		if err != nil {
			t.Errorf("del err: %s", err)
		}
		if !item.Deleted {
			t.Errorf("item should be deleted %#v", item)
		}
	}
}
开发者ID:captain401,项目名称:stripe-go,代码行数:41,代码来源:client_test.go

示例9: TestCustomerNewWithPlan

func TestCustomerNewWithPlan(t *testing.T) {
	planParams := &stripe.PlanParams{
		ID:       "test",
		Name:     "Test Plan",
		Amount:   99,
		Currency: currency.USD,
		Interval: plan.Month,
	}

	_, err := plan.New(planParams)
	if err != nil {
		t.Error(err)
	}

	customerParams := &stripe.CustomerParams{
		Plan:       planParams.ID,
		TaxPercent: 10.0,
	}
	customerParams.SetSource(&stripe.CardParams{
		Name:   "Test Card",
		Number: "378282246310005",
		Month:  "06",
		Year:   "20",
	})

	target, err := New(customerParams)

	if err != nil {
		t.Error(err)
	}

	_, err = Del(target.ID)
	if err != nil {
		t.Error(err)
	}

	_, err = plan.Del(planParams.ID)
	if err != nil {
		t.Error(err)
	}
}
开发者ID:captain401,项目名称:stripe-go,代码行数:41,代码来源:client_test.go

示例10: TestSubscriptionDiscount

func TestSubscriptionDiscount(t *testing.T) {
	couponParams := &stripe.CouponParams{
		Duration: coupon.Forever,
		ID:       "sub_coupon",
		Percent:  99,
	}

	coupon.New(couponParams)

	customerParams := &stripe.CustomerParams{
		Source: &stripe.SourceParams{
			Card: &stripe.CardParams{
				Number: "378282246310005",
				Month:  "06",
				Year:   "20",
			},
		},
	}

	cust, _ := customer.New(customerParams)

	planParams := &stripe.PlanParams{
		ID:       "test",
		Name:     "Test Plan",
		Amount:   99,
		Currency: currency.USD,
		Interval: plan.Month,
	}

	plan.New(planParams)

	subParams := &stripe.SubParams{
		Customer: cust.ID,
		Plan:     "test",
		Quantity: 10,
		Coupon:   "sub_coupon",
	}

	target, err := New(subParams)

	if err != nil {
		t.Error(err)
	}

	if target.Discount == nil {
		t.Errorf("Discount not found, but one was expected\n")
	}

	if target.Discount.Coupon == nil {
		t.Errorf("Coupon not found, but one was expected\n")
	}

	if target.Discount.Coupon.ID != subParams.Coupon {
		t.Errorf("Coupon id %q does not match expected id %q\n", target.Discount.Coupon.ID, subParams.Coupon)
	}

	_, err = discount.DelSub(target.ID)

	if err != nil {
		t.Error(err)
	}

	target, err = Get(target.ID, nil)

	if err != nil {
		t.Error(err)
	}

	if target.Discount != nil {
		t.Errorf("A discount %v was found, but was expected to have been deleted\n", target.Discount)
	}

	customer.Del(cust.ID)
	plan.Del("test")
	coupon.Del("sub_coupon")
}
开发者ID:captain401,项目名称:stripe-go,代码行数:76,代码来源:client_test.go

示例11: TestAllInvoicesScenarios


//.........这里部分代码省略.........
	}
	if err := ii.Err(); err != nil {
		t.Error(err)
	}

	i := List(&stripe.InvoiceListParams{Customer: cust.ID})
	for i.Next() {
		if i.Invoice() == nil {
			t.Error("No nil values expected")
		}

		if i.Meta() == nil {
			t.Error("No metadata returned")
		}
	}
	if err := i.Err(); err != nil {
		t.Error(err)
	}

	il := ListLines(&stripe.InvoiceLineListParams{ID: targetInvoice.ID, Customer: cust.ID})
	for il.Next() {
		if il.InvoiceLine() == nil {
			t.Error("No nil values expected")
		}

		if il.Meta() == nil {
			t.Error("No metadata returned")
		}
	}
	if err := il.Err(); err != nil {
		t.Error(err)
	}

	iiDel, err := invoiceitem.Del(targetItem.ID)

	if err != nil {
		t.Error(err)
	}

	if !iiDel.Deleted {
		t.Errorf("Invoice Item id %q expected to be marked as deleted on the returned resource\n", iiDel.ID)
	}

	_, err = Get(targetInvoice.ID, nil)

	if err != nil {
		t.Error(err)
	}

	planParams := &stripe.PlanParams{
		ID:       "test",
		Name:     "Test Plan",
		Amount:   99,
		Currency: currency.USD,
		Interval: plan.Month,
	}

	_, err = plan.New(planParams)
	if err != nil {
		t.Error(err)
	}

	subParams := &stripe.SubParams{
		Customer:    cust.ID,
		Plan:        planParams.ID,
		Quantity:    10,
开发者ID:captain401,项目名称:stripe-go,代码行数:67,代码来源:client_test.go


注:本文中的github.com/stripe/stripe-go/plan.Del函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。