satellite/payments/stripecoinpayments: add ctx to Stripe method calls

This commit ensures that all invocations of Stripe library methods
include a context. This allows us to control the timeout and
cancellation of the underlying HTTP requests made by the Stripe
library.

References #5156

Change-Id: I8ddb317f3f2cbb06cfab869fbebdaf2ad78b7999
This commit is contained in:
Jeremy Wharton 2023-03-13 21:59:24 -05:00 committed by Storj Robot
parent c3d5965ef2
commit b95ef36541
9 changed files with 125 additions and 52 deletions

View File

@ -50,6 +50,7 @@ func TestAutoFreezeChore(t *testing.T) {
t.Run("No freeze event for paid invoice", func(t *testing.T) {
item, err := stripeClient.InvoiceItems().New(&stripe.InvoiceItemParams{
Params: stripe.Params{Context: ctx},
Amount: &amount,
Currency: &curr,
Customer: &cus1,
@ -63,12 +64,15 @@ func TestAutoFreezeChore(t *testing.T) {
Currency: &curr,
})
inv, err := stripeClient.Invoices().New(&stripe.InvoiceParams{
Params: stripe.Params{Context: ctx},
Customer: &cus1,
InvoiceItems: items,
})
require.NoError(t, err)
inv, err = stripeClient.Invoices().Pay(inv.ID, &stripe.InvoicePayParams{})
inv, err = stripeClient.Invoices().Pay(inv.ID, &stripe.InvoicePayParams{
Params: stripe.Params{Context: ctx},
})
require.NoError(t, err)
require.Equal(t, stripe.InvoiceStatusPaid, inv.Status)
@ -102,6 +106,7 @@ func TestAutoFreezeChore(t *testing.T) {
chore.TestSetNow(time.Now)
item, err := stripeClient.InvoiceItems().New(&stripe.InvoiceItemParams{
Params: stripe.Params{Context: ctx},
Amount: &amount,
Currency: &curr,
Customer: &cus1,
@ -115,6 +120,7 @@ func TestAutoFreezeChore(t *testing.T) {
Currency: &curr,
})
inv, err := stripeClient.Invoices().New(&stripe.InvoiceParams{
Params: stripe.Params{Context: ctx},
Customer: &cus1,
InvoiceItems: items,
})
@ -122,6 +128,7 @@ func TestAutoFreezeChore(t *testing.T) {
paymentMethod := stripecoinpayments.MockInvoicesPayFailure
inv, err = stripeClient.Invoices().Pay(inv.ID, &stripe.InvoicePayParams{
Params: stripe.Params{Context: ctx},
PaymentMethod: &paymentMethod,
})
require.Error(t, err)

View File

@ -49,7 +49,8 @@ func (accounts *accounts) Setup(ctx context.Context, userID uuid.UUID, email str
}
params := &stripe.CustomerParams{
Email: stripe.String(email),
Params: stripe.Params{Context: ctx},
Email: stripe.String(email),
}
if signupPromoCode == "" {
@ -66,7 +67,8 @@ func (accounts *accounts) Setup(ctx context.Context, userID uuid.UUID, email str
}
promoCodeIter := accounts.service.stripeClient.PromoCodes().List(&stripe.PromotionCodeListParams{
Code: stripe.String(signupPromoCode),
ListParams: stripe.ListParams{Context: ctx},
Code: stripe.String(signupPromoCode),
})
var promoCode *stripe.PromotionCode
@ -109,7 +111,8 @@ func (accounts *accounts) Balance(ctx context.Context, userID uuid.UUID) (_ paym
return payments.Balance{}, Error.Wrap(err)
}
customer, err := accounts.service.stripeClient.Customers().Get(customerID, nil)
params := &stripe.CustomerParams{Params: stripe.Params{Context: ctx}}
customer, err := accounts.service.stripeClient.Customers().Get(customerID, params)
if err != nil {
return payments.Balance{}, Error.Wrap(err)
}
@ -250,7 +253,8 @@ func (accounts *accounts) Charges(ctx context.Context, userID uuid.UUID) (_ []pa
}
params := &stripe.ChargeListParams{
Customer: stripe.String(customerID),
ListParams: stripe.ListParams{Context: ctx},
Customer: stripe.String(customerID),
}
params.Filters.AddFilter("limit", "", "100")

View File

@ -33,6 +33,7 @@ func (coupons *coupons) ApplyFreeTierCoupon(ctx context.Context, userID uuid.UUI
}
customer, err := coupons.service.stripeClient.Customers().Update(customerID, &stripe.CustomerParams{
Params: stripe.Params{Context: ctx},
Coupon: stripe.String(coupons.service.StripeFreeTierCouponID),
})
if err != nil {
@ -51,7 +52,10 @@ func (coupons *coupons) ApplyCoupon(ctx context.Context, userID uuid.UUID, coupo
return nil, Error.Wrap(err)
}
customer, err := coupons.service.stripeClient.Customers().Update(customerID, &stripe.CustomerParams{Coupon: stripe.String(couponID)})
customer, err := coupons.service.stripeClient.Customers().Update(customerID, &stripe.CustomerParams{
Params: stripe.Params{Context: ctx},
Coupon: stripe.String(couponID),
})
if err != nil {
return nil, Error.Wrap(err)
}
@ -81,7 +85,8 @@ func (coupons *coupons) ApplyCouponCode(ctx context.Context, userID uuid.UUID, c
}
promoCodeIter := coupons.service.stripeClient.PromoCodes().List(&stripe.PromotionCodeListParams{
Code: stripe.String(couponCode),
ListParams: stripe.ListParams{Context: ctx},
Code: stripe.String(couponCode),
})
if !promoCodeIter.Next() {
return nil, payments.ErrInvalidCoupon.New("Invalid coupon code")
@ -94,6 +99,7 @@ func (coupons *coupons) ApplyCouponCode(ctx context.Context, userID uuid.UUID, c
}
params := &stripe.CustomerParams{
Params: stripe.Params{Context: ctx},
PromotionCode: stripe.String(promoCode.ID),
}
params.AddExpand("discount.promotion_code")
@ -119,7 +125,7 @@ func (coupons *coupons) GetByUserID(ctx context.Context, userID uuid.UUID) (_ *p
return nil, Error.Wrap(err)
}
params := &stripe.CustomerParams{}
params := &stripe.CustomerParams{Params: stripe.Params{Context: ctx}}
params.AddExpand("discount.promotion_code")
customer, err := coupons.service.stripeClient.Customers().Get(customerID, params)

View File

@ -29,17 +29,19 @@ func (creditCards *creditCards) List(ctx context.Context, userID uuid.UUID) (car
return nil, Error.Wrap(err)
}
customer, err := creditCards.service.stripeClient.Customers().Get(customerID, nil)
cusParams := &stripe.CustomerParams{Params: stripe.Params{Context: ctx}}
customer, err := creditCards.service.stripeClient.Customers().Get(customerID, cusParams)
if err != nil {
return nil, Error.Wrap(err)
}
params := &stripe.PaymentMethodListParams{
Customer: &customerID,
Type: stripe.String(string(stripe.PaymentMethodTypeCard)),
cardParams := &stripe.PaymentMethodListParams{
ListParams: stripe.ListParams{Context: ctx},
Customer: &customerID,
Type: stripe.String(string(stripe.PaymentMethodTypeCard)),
}
paymentMethodsIterator := creditCards.service.stripeClient.PaymentMethods().List(params)
paymentMethodsIterator := creditCards.service.stripeClient.PaymentMethods().List(cardParams)
for paymentMethodsIterator.Next() {
stripeCard := paymentMethodsIterator.PaymentMethod()
@ -75,8 +77,9 @@ func (creditCards *creditCards) Add(ctx context.Context, userID uuid.UUID, cardT
}
cardParams := &stripe.PaymentMethodParams{
Type: stripe.String(string(stripe.PaymentMethodTypeCard)),
Card: &stripe.PaymentMethodCardParams{Token: &cardToken},
Params: stripe.Params{Context: ctx},
Type: stripe.String(string(stripe.PaymentMethodTypeCard)),
Card: &stripe.PaymentMethodCardParams{Token: &cardToken},
}
card, err := creditCards.service.stripeClient.PaymentMethods().New(cardParams)
@ -85,6 +88,7 @@ func (creditCards *creditCards) Add(ctx context.Context, userID uuid.UUID, cardT
}
attachParams := &stripe.PaymentMethodAttachParams{
Params: stripe.Params{Context: ctx},
Customer: &customerID,
}
@ -94,6 +98,7 @@ func (creditCards *creditCards) Add(ctx context.Context, userID uuid.UUID, cardT
}
params := &stripe.CustomerParams{
Params: stripe.Params{Context: ctx},
InvoiceSettings: &stripe.CustomerInvoiceSettingsParams{
DefaultPaymentMethod: stripe.String(card.ID),
},
@ -123,6 +128,7 @@ func (creditCards *creditCards) MakeDefault(ctx context.Context, userID uuid.UUI
}
params := &stripe.CustomerParams{
Params: stripe.Params{Context: ctx},
InvoiceSettings: &stripe.CustomerInvoiceSettingsParams{
DefaultPaymentMethod: stripe.String(cardID),
},
@ -142,7 +148,8 @@ func (creditCards *creditCards) Remove(ctx context.Context, userID uuid.UUID, ca
return payments.ErrAccountNotSetup.Wrap(err)
}
customer, err := creditCards.service.stripeClient.Customers().Get(customerID, nil)
cusParams := &stripe.CustomerParams{Params: stripe.Params{Context: ctx}}
customer, err := creditCards.service.stripeClient.Customers().Get(customerID, cusParams)
if err != nil {
return Error.Wrap(err)
}
@ -152,7 +159,8 @@ func (creditCards *creditCards) Remove(ctx context.Context, userID uuid.UUID, ca
return Error.Wrap(errs.New("can not detach default payment method."))
}
_, err = creditCards.service.stripeClient.PaymentMethods().Detach(cardID, nil)
cardParams := &stripe.PaymentMethodDetachParams{Params: stripe.Params{Context: ctx}}
_, err = creditCards.service.stripeClient.PaymentMethods().Detach(cardID, cardParams)
return Error.Wrap(err)
}
@ -166,8 +174,10 @@ func (creditCards *creditCards) RemoveAll(ctx context.Context, userID uuid.UUID)
if err != nil {
return Error.Wrap(err)
}
params := &stripe.PaymentMethodDetachParams{Params: stripe.Params{Context: ctx}}
for _, cc := range ccList {
_, err = creditCards.service.stripeClient.PaymentMethods().Detach(cc.ID, nil)
_, err = creditCards.service.stripeClient.PaymentMethods().Detach(cc.ID, params)
if err != nil {
return Error.Wrap(err)
}

View File

@ -29,6 +29,7 @@ func (invoices *invoices) Create(ctx context.Context, userID uuid.UUID, price in
}
inv, err := invoices.service.stripeClient.Invoices().New(&stripe.InvoiceParams{
Params: stripe.Params{Context: ctx},
Customer: stripe.String(customerID),
Discounts: []*stripe.InvoiceDiscountParams{},
Description: stripe.String(desc),
@ -39,6 +40,7 @@ func (invoices *invoices) Create(ctx context.Context, userID uuid.UUID, price in
}
item, err := invoices.service.stripeClient.InvoiceItems().New(&stripe.InvoiceItemParams{
Params: stripe.Params{Context: ctx},
Customer: stripe.String(customerID),
Amount: stripe.Int64(price),
Description: stripe.String(desc),
@ -59,6 +61,7 @@ func (invoices *invoices) Create(ctx context.Context, userID uuid.UUID, price in
func (invoices *invoices) Pay(ctx context.Context, invoiceID, paymentMethodID string) (*payments.Invoice, error) {
inv, err := invoices.service.stripeClient.Invoices().Pay(invoiceID, &stripe.InvoicePayParams{
Params: stripe.Params{Context: ctx},
PaymentMethod: stripe.String(paymentMethodID),
})
if err != nil {
@ -80,6 +83,7 @@ func (invoices *invoices) AttemptPayOverdueInvoices(ctx context.Context, userID
}
params := &stripe.InvoiceListParams{
ListParams: stripe.ListParams{Context: ctx},
Customer: &customerID,
Status: stripe.String(string(stripe.InvoiceStatusOpen)),
DueDateRange: &stripe.RangeQueryParams{LesserThan: time.Now().Unix()},
@ -91,7 +95,7 @@ func (invoices *invoices) AttemptPayOverdueInvoices(ctx context.Context, userID
for invoicesIterator.Next() {
stripeInvoice := invoicesIterator.Invoice()
params := &stripe.InvoicePayParams{}
params := &stripe.InvoicePayParams{Params: stripe.Params{Context: ctx}}
invResponse, err := invoices.service.stripeClient.Invoices().Pay(stripeInvoice.ID, params)
if err != nil {
errGrp.Add(Error.New("unable to pay invoice %s: %w", stripeInvoice.ID, err))
@ -121,7 +125,8 @@ func (invoices *invoices) List(ctx context.Context, userID uuid.UUID) (invoicesL
}
params := &stripe.InvoiceListParams{
Customer: &customerID,
ListParams: stripe.ListParams{Context: ctx},
Customer: &customerID,
}
invoicesIterator := invoices.service.stripeClient.Invoices().List(params)
@ -162,7 +167,8 @@ func (invoices *invoices) ListFailed(ctx context.Context) (invoicesList []paymen
status := string(stripe.InvoiceStatusOpen)
params := &stripe.InvoiceListParams{
Status: &status,
ListParams: stripe.ListParams{Context: ctx},
Status: &status,
}
invoicesIterator := invoices.service.stripeClient.Invoices().List(params)
@ -208,7 +214,8 @@ func (invoices *invoices) ListWithDiscounts(ctx context.Context, userID uuid.UUI
}
params := &stripe.InvoiceListParams{
Customer: &customerID,
ListParams: stripe.ListParams{Context: ctx},
Customer: &customerID,
}
params.AddExpand("data.total_discount_amounts.discount")
@ -279,8 +286,9 @@ func (invoices *invoices) CheckPendingItems(ctx context.Context, userID uuid.UUI
}
params := &stripe.InvoiceItemListParams{
Customer: &customerID,
Pending: stripe.Bool(true),
ListParams: stripe.ListParams{Context: ctx},
Customer: &customerID,
Pending: stripe.Bool(true),
}
itemIterator := invoices.service.stripeClient.InvoiceItems().List(params)
@ -302,7 +310,8 @@ func (invoices *invoices) CheckPendingItems(ctx context.Context, userID uuid.UUI
func (invoices *invoices) Delete(ctx context.Context, id string) (_ *payments.Invoice, err error) {
defer mon.Task()(&ctx)(&err)
stripeInvoice, err := invoices.service.stripeClient.Invoices().Del(id, &stripe.InvoiceParams{})
params := &stripe.InvoiceParams{Params: stripe.Params{Context: ctx}}
stripeInvoice, err := invoices.service.stripeClient.Invoices().Del(id, params)
if err != nil {
return nil, Error.Wrap(err)
}

View File

@ -367,8 +367,9 @@ func (service *Service) getInvoices(ctx context.Context, cusID string, createdOn
defer mon.Task()(&ctx)(&err)
params := &stripe.InvoiceListParams{
Customer: stripe.String(cusID),
Status: stripe.String(string(stripe.InvoiceStatusOpen)),
ListParams: stripe.ListParams{Context: ctx},
Customer: stripe.String(cusID),
Status: stripe.String(string(stripe.InvoiceStatusOpen)),
}
params.Filters.AddFilter("created", "gte", strconv.FormatInt(createdOnAfter.Unix(), 10))
invoicesIterator := service.stripeClient.Invoices().List(params)
@ -398,6 +399,7 @@ func (service *Service) addCreditNoteToInvoice(ctx context.Context, invoiceID, c
lineParams = append(lineParams, &lineParam)
params := &stripe.CreditNoteParams{
Params: stripe.Params{Context: ctx},
Invoice: stripe.String(invoiceID),
Lines: lineParams,
Memo: stripe.String("Storjscan Token Payment - Wallet: 0x" + wallet),
@ -494,6 +496,7 @@ func (service *Service) createInvoiceItems(ctx context.Context, cusID, projName
items := service.InvoiceItemsFromProjectUsage(projName, usages)
for _, item := range items {
item.Params = stripe.Params{Context: ctx}
item.Currency = stripe.String(string(stripe.CurrencyUSD))
item.Customer = stripe.String(cusID)
item.AddMetadata("projectID", record.ProjectID.String())
@ -579,7 +582,8 @@ func (service *Service) ApplyFreeTierCoupons(ctx context.Context) (err error) {
nextOffset = customersPage.NextOffset
for _, c := range customersPage.Customers {
stripeCust, err := service.stripeClient.Customers().Get(c.ID, nil)
params := &stripe.CustomerParams{Params: stripe.Params{Context: ctx}}
stripeCust, err := service.stripeClient.Customers().Get(c.ID, params)
if err != nil {
service.log.Error("Failed to get customer", zap.Error(err))
failedUsers = append(failedUsers, c.ID)
@ -588,6 +592,7 @@ func (service *Service) ApplyFreeTierCoupons(ctx context.Context) (err error) {
// if customer does not have a coupon, apply the free tier coupon
if stripeCust.Discount == nil || stripeCust.Discount.Coupon == nil {
params := &stripe.CustomerParams{
Params: stripe.Params{Context: ctx},
Coupon: stripe.String(service.StripeFreeTierCouponID),
}
_, err := service.stripeClient.Customers().Update(c.ID, params)
@ -669,6 +674,7 @@ func (service *Service) createInvoice(ctx context.Context, cusID string, period
stripeInvoice, err = service.stripeClient.Invoices().New(
&stripe.InvoiceParams{
Params: stripe.Params{Context: ctx},
Customer: stripe.String(cusID),
AutoAdvance: stripe.Bool(service.AutoAdvance),
Description: stripe.String(description),
@ -687,10 +693,11 @@ func (service *Service) createInvoice(ctx context.Context, cusID string, period
// auto advance the invoice if nothing is due from the customer
if !stripeInvoice.AutoAdvance && stripeInvoice.AmountDue == 0 {
stripeInvoice, err = service.stripeClient.Invoices().Update(
stripeInvoice.ID,
&stripe.InvoiceParams{AutoAdvance: stripe.Bool(true)},
)
params := &stripe.InvoiceParams{
Params: stripe.Params{Context: ctx},
AutoAdvance: stripe.Bool(true),
}
stripeInvoice, err = service.stripeClient.Invoices().Update(stripeInvoice.ID, params)
if err != nil {
return nil, err
}
@ -730,7 +737,8 @@ func (service *Service) FinalizeInvoices(ctx context.Context) (err error) {
defer mon.Task()(&ctx)(&err)
params := &stripe.InvoiceListParams{
Status: stripe.String("draft"),
ListParams: stripe.ListParams{Context: ctx},
Status: stripe.String("draft"),
}
invoicesIterator := service.stripeClient.Invoices().List(params)
@ -752,7 +760,10 @@ func (service *Service) FinalizeInvoices(ctx context.Context) (err error) {
func (service *Service) finalizeInvoice(ctx context.Context, invoiceID string) (err error) {
defer mon.Task()(&ctx)(&err)
params := &stripe.InvoiceFinalizeParams{AutoAdvance: stripe.Bool(false)}
params := &stripe.InvoiceFinalizeParams{
Params: stripe.Params{Context: ctx},
AutoAdvance: stripe.Bool(false),
}
_, err = service.stripeClient.Invoices().FinalizeInvoice(invoiceID, params)
return err
}
@ -763,7 +774,8 @@ func (service *Service) PayInvoices(ctx context.Context, createdOnAfter time.Tim
defer mon.Task()(&ctx)(&err)
params := &stripe.InvoiceListParams{
Status: stripe.String("open"),
ListParams: stripe.ListParams{Context: ctx},
Status: stripe.String("open"),
}
params.Filters.AddFilter("created", "gte", strconv.FormatInt(createdOnAfter.Unix(), 10))
@ -780,7 +792,7 @@ func (service *Service) PayInvoices(ctx context.Context, createdOnAfter time.Tim
continue
}
params := &stripe.InvoicePayParams{}
params := &stripe.InvoicePayParams{Params: stripe.Params{Context: ctx}}
_, err = service.stripeClient.Invoices().Pay(stripeInvoice.ID, params)
if err != nil {
errGrp.Add(Error.New("unable to pay invoice %s", stripeInvoice.ID))

View File

@ -455,7 +455,8 @@ func TestService_GenerateInvoice(t *testing.T) {
cusID, err := satellite.DB.StripeCoinPayments().Customers().GetCustomerID(ctx, user.ID)
require.NoError(t, err)
stripeUser, err := payments.StripeClient.Customers().Get(cusID, nil)
params := &stripe.CustomerParams{Params: stripe.Params{Context: ctx}}
stripeUser, err := payments.StripeClient.Customers().Get(cusID, params)
require.NoError(t, err)
require.NotNil(t, stripeUser.Discount)
require.NotNil(t, stripeUser.Discount.Coupon)
@ -469,8 +470,8 @@ func TestService_GenerateInvoice(t *testing.T) {
require.NotNil(t, rec)
require.NoError(t, err)
invoice, hasInvoice := getCustomerInvoice(payments.StripeClient, cusID)
invoiceItems := getCustomerInvoiceItems(payments.StripeClient, cusID)
invoice, hasInvoice := getCustomerInvoice(ctx, payments.StripeClient, cusID)
invoiceItems := getCustomerInvoiceItems(ctx, payments.StripeClient, cusID)
// If invoicing empty usage invoices was skipped, then we don't
// expect an invoice or invoice items.
@ -495,16 +496,22 @@ func TestService_GenerateInvoice(t *testing.T) {
}
}
func getCustomerInvoice(stripeClient stripecoinpayments.StripeClient, cusID string) (*stripe.Invoice, bool) {
iter := stripeClient.Invoices().List(&stripe.InvoiceListParams{Customer: &cusID})
func getCustomerInvoice(ctx context.Context, stripeClient stripecoinpayments.StripeClient, cusID string) (*stripe.Invoice, bool) {
iter := stripeClient.Invoices().List(&stripe.InvoiceListParams{
ListParams: stripe.ListParams{Context: ctx},
Customer: &cusID,
})
if iter.Next() {
return iter.Invoice(), true
}
return nil, false
}
func getCustomerInvoiceItems(stripeClient stripecoinpayments.StripeClient, cusID string) (items []*stripe.InvoiceItem) {
iter := stripeClient.InvoiceItems().List(&stripe.InvoiceItemListParams{Customer: &cusID})
func getCustomerInvoiceItems(ctx context.Context, stripeClient stripecoinpayments.StripeClient, cusID string) (items []*stripe.InvoiceItem) {
iter := stripeClient.InvoiceItems().List(&stripe.InvoiceItemListParams{
ListParams: stripe.ListParams{Context: ctx},
Customer: &cusID,
})
for iter.Next() {
items = append(items, iter.InvoiceItem())
}
@ -616,7 +623,7 @@ func TestProjectUsagePrice(t *testing.T) {
cusID, err := sat.DB.StripeCoinPayments().Customers().GetCustomerID(ctx, user.ID)
require.NoError(t, err)
items := getCustomerInvoiceItems(sat.API.Payments.StripeClient, cusID)
items := getCustomerInvoiceItems(ctx, sat.API.Payments.StripeClient, cusID)
require.Len(t, items, 3)
storage, _ := tt.expectedPrice.StorageMBMonthCents.Float64()
require.Equal(t, storage, items[0].UnitAmountDecimal)
@ -642,12 +649,14 @@ func TestPayInvoicesSkipDue(t *testing.T) {
due := time.Now().Add(14 * 24 * time.Hour).Unix()
_, err := satellite.API.Payments.StripeClient.InvoiceItems().New(&stripe.InvoiceItemParams{
Params: stripe.Params{Context: ctx},
Amount: &amount,
Currency: &curr,
Customer: &cus1,
})
require.NoError(t, err)
_, err = satellite.API.Payments.StripeClient.InvoiceItems().New(&stripe.InvoiceItemParams{
Params: stripe.Params{Context: ctx},
Amount: &amount,
Currency: &curr,
Customer: &cus2,
@ -655,28 +664,34 @@ func TestPayInvoicesSkipDue(t *testing.T) {
require.NoError(t, err)
inv, err := satellite.API.Payments.StripeClient.Invoices().New(&stripe.InvoiceParams{
Params: stripe.Params{Context: ctx},
Customer: &cus1,
})
require.NoError(t, err)
inv, err = satellite.API.Payments.StripeClient.Invoices().FinalizeInvoice(inv.ID, &stripe.InvoiceFinalizeParams{})
finalizeParams := &stripe.InvoiceFinalizeParams{Params: stripe.Params{Context: ctx}}
inv, err = satellite.API.Payments.StripeClient.Invoices().FinalizeInvoice(inv.ID, finalizeParams)
require.NoError(t, err)
require.Equal(t, stripe.InvoiceStatusOpen, inv.Status)
invWithDue, err := satellite.API.Payments.StripeClient.Invoices().New(&stripe.InvoiceParams{
Params: stripe.Params{Context: ctx},
Customer: &cus2,
DueDate: &due,
})
require.NoError(t, err)
invWithDue, err = satellite.API.Payments.StripeClient.Invoices().FinalizeInvoice(invWithDue.ID, &stripe.InvoiceFinalizeParams{})
invWithDue, err = satellite.API.Payments.StripeClient.Invoices().FinalizeInvoice(invWithDue.ID, finalizeParams)
require.NoError(t, err)
require.Equal(t, stripe.InvoiceStatusOpen, invWithDue.Status)
err = satellite.API.Payments.StripeService.PayInvoices(ctx, time.Time{})
require.NoError(t, err)
iter := satellite.API.Payments.StripeClient.Invoices().List(&stripe.InvoiceListParams{})
iter := satellite.API.Payments.StripeClient.Invoices().List(&stripe.InvoiceListParams{
ListParams: stripe.ListParams{Context: ctx},
})
for iter.Next() {
i := iter.Invoice()
if i.ID == inv.ID {

View File

@ -99,7 +99,8 @@ func (tokens *storjTokens) ListDepositBonuses(ctx context.Context, userID uuid.U
var bonuses []payments.DepositBonus
customer, err := tokens.service.stripeClient.Customers().Get(cusID, nil)
params := &stripe.CustomerParams{Params: stripe.Params{Context: ctx}}
customer, err := tokens.service.stripeClient.Customers().Get(cusID, params)
if err != nil {
return nil, err
}
@ -131,7 +132,10 @@ func (tokens *storjTokens) ListDepositBonuses(ctx context.Context, userID uuid.U
)
}
it := tokens.service.stripeClient.CustomerBalanceTransactions().List(&stripe.CustomerBalanceTransactionListParams{Customer: stripe.String(cusID)})
it := tokens.service.stripeClient.CustomerBalanceTransactions().List(&stripe.CustomerBalanceTransactionListParams{
ListParams: stripe.ListParams{Context: ctx},
Customer: stripe.String(cusID),
})
for it.Next() {
tx := it.CustomerBalanceTransaction()

View File

@ -40,6 +40,7 @@ func TestTokens_ListDepositBonuses(t *testing.T) {
// Credit the Stripe balance with a STORJ deposit of $10
txParams := stripe.CustomerBalanceTransactionParams{
Params: stripe.Params{Context: ctx},
Customer: stripe.String(customerID),
Amount: stripe.Int64(-1000),
Description: stripe.String(stripecoinpayments.StripeDepositTransactionDescription),
@ -50,6 +51,7 @@ func TestTokens_ListDepositBonuses(t *testing.T) {
// Credit the Stripe balance with a 13% bonus - $1.30
txParams = stripe.CustomerBalanceTransactionParams{
Params: stripe.Params{Context: ctx},
Customer: stripe.String(customerID),
Amount: stripe.Int64(-130),
Description: stripe.String(stripecoinpayments.StripeDepositBonusTransactionDescription),
@ -68,9 +70,13 @@ func TestTokens_ListDepositBonuses(t *testing.T) {
}
b, err := json.Marshal(credit)
require.NoError(t, err)
customerParams := stripe.CustomerParams{}
customerParams.Metadata = map[string]string{
"credit_" + credit.TransactionID.String(): string(b),
customerParams := stripe.CustomerParams{
Params: stripe.Params{
Context: ctx,
Metadata: map[string]string{
"credit_" + credit.TransactionID.String(): string(b),
},
},
}
_, err = satellite.API.Payments.StripeClient.Customers().Update(customerID, &customerParams)
require.NoError(t, err)