func deleteSubscription(subscriptionID, customerID string) (*stripe.Sub, error) { sub, err := sub.Cancel(subscriptionID, &stripe.SubParams{Customer: customerID}) if sub != nil && sub.Status == "canceled" { return sub, nil } return sub, err }
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) } }