本文整理汇总了Golang中github.com/stripe/stripe-go/plan.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的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)
}
}
示例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")
}
示例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")
}
示例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")
}
示例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")
}
示例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")
}
示例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")
}
示例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)
}
}
}
示例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)
}
}
示例10: TestAllInvoicesScenarios
// Invoices are somewhat painful to test since you need
// to first have some items, so test everything together to
// avoid unnecessary duplication
func TestAllInvoicesScenarios(t *testing.T) {
customerParams := &stripe.CustomerParams{
Source: &stripe.SourceParams{
Card: &stripe.CardParams{
Number: "378282246310005",
Month: "06",
Year: "20",
},
},
}
cust, _ := customer.New(customerParams)
item := &stripe.InvoiceItemParams{
Customer: cust.ID,
Amount: 100,
Currency: currency.USD,
Desc: "Test Item",
}
targetItem, err := invoiceitem.New(item)
if err != nil {
t.Error(err)
}
if targetItem.Customer.ID != item.Customer {
t.Errorf("Item customer %q does not match expected customer %q\n", targetItem.Customer.ID, item.Customer)
}
if targetItem.Desc != item.Desc {
t.Errorf("Item description %q does not match expected description %q\n", targetItem.Desc, item.Desc)
}
if targetItem.Amount != item.Amount {
t.Errorf("Item amount %v does not match expected amount %v\n", targetItem.Amount, item.Amount)
}
if targetItem.Currency != item.Currency {
t.Errorf("Item currency %q does not match expected currency %q\n", targetItem.Currency, item.Currency)
}
if targetItem.Date == 0 {
t.Errorf("Item date is not set\n")
}
invoiceParams := &stripe.InvoiceParams{
Customer: cust.ID,
Desc: "Desc",
Statement: "Statement",
TaxPercent: 20.0,
}
targetInvoice, err := New(invoiceParams)
if err != nil {
t.Error(err)
}
if targetInvoice.Customer.ID != invoiceParams.Customer {
t.Errorf("Invoice customer %q does not match expected customer %q\n", targetInvoice.Customer.ID, invoiceParams.Customer)
}
if targetInvoice.TaxPercent != invoiceParams.TaxPercent {
t.Errorf("Invoice tax percent %f does not match expected tax percent %f\n", targetInvoice.TaxPercent, invoiceParams.TaxPercent)
}
if targetInvoice.Tax != 20 {
t.Errorf("Invoice tax %v does not match expected tax 20\n", targetInvoice.Tax)
}
if targetInvoice.Amount != targetItem.Amount+targetInvoice.Tax {
t.Errorf("Invoice amount %v does not match expected amount %v + tax %v\n", targetInvoice.Amount, targetItem.Amount, targetInvoice.Tax)
}
if targetInvoice.Currency != targetItem.Currency {
t.Errorf("Invoice currency %q does not match expected currency %q\n", targetInvoice.Currency, targetItem.Currency)
}
if targetInvoice.Date == 0 {
t.Errorf("Invoice date is not set\n")
}
if targetInvoice.Start == 0 {
t.Errorf("Invoice start is not set\n")
}
if targetInvoice.End == 0 {
t.Errorf("Invoice end is not set\n")
}
if targetInvoice.Total != targetInvoice.Amount || targetInvoice.Subtotal != targetInvoice.Amount-targetInvoice.Tax {
t.Errorf("Invoice total %v and subtotal %v do not match expected amount %v\n", targetInvoice.Total, targetInvoice.Subtotal, targetInvoice.Amount)
}
if targetInvoice.Desc != invoiceParams.Desc {
t.Errorf("Invoice description %q does not match expected description %q\n", targetInvoice.Desc, invoiceParams.Desc)
//.........这里部分代码省略.........
示例11: 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")
}