Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 45 additions & 45 deletions billing/checkout/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,8 @@ func (s *Service) Create(ctx context.Context, ch Checkout) (Checkout, error) {
quantity = userCount
}
itemParams := &stripe.CheckoutSessionLineItemParams{
Price: stripe.String(productPrice.ProviderID),
Quantity: stripe.Int64(quantity),
Price: new(productPrice.ProviderID),
Quantity: new(quantity),
}
subsItems = append(subsItems, itemParams)
}
Expand All @@ -302,7 +302,7 @@ func (s *Service) Create(ctx context.Context, ch Checkout) (Checkout, error) {
return Checkout{}, err
}
if plan.TrialDays > 0 && !ch.SkipTrial && !userHasTrialedBefore {
trialDays = stripe.Int64(plan.TrialDays)
trialDays = new(plan.TrialDays)
}

// create subscription checkout link
Expand All @@ -311,10 +311,10 @@ func (s *Service) Create(ctx context.Context, ch Checkout) (Checkout, error) {
Context: ctx,
},
AutomaticTax: &stripe.CheckoutSessionAutomaticTaxParams{
Enabled: stripe.Bool(s.stripeAutoTax),
Enabled: new(s.stripeAutoTax),
},
Currency: stripe.String(billingCustomer.Currency),
Customer: stripe.String(billingCustomer.ProviderID),
Currency: new(billingCustomer.Currency),
Customer: new(billingCustomer.ProviderID),
LineItems: subsItems,
Metadata: map[string]string{
"org_id": billingCustomer.OrgID,
Expand All @@ -324,11 +324,11 @@ func (s *Service) Create(ctx context.Context, ch Checkout) (Checkout, error) {
"managed_by": "frontier",
},
CustomerUpdate: &stripe.CheckoutSessionCustomerUpdateParams{
Address: stripe.String(addressCollectionParam),
Address: new(addressCollectionParam),
},
Mode: stripe.String(string(stripe.CheckoutSessionModeSubscription)),
Mode: new(string(stripe.CheckoutSessionModeSubscription)),
SubscriptionData: &stripe.CheckoutSessionSubscriptionDataParams{
Description: stripe.String(fmt.Sprintf("Checkout for %s", plan.Name)),
Description: new(fmt.Sprintf("Checkout for %s", plan.Name)),
Metadata: map[string]string{
"org_id": billingCustomer.OrgID,
CheckoutIDMetadataKey: checkoutID,
Expand All @@ -342,11 +342,11 @@ func (s *Service) Create(ctx context.Context, ch Checkout) (Checkout, error) {
},
},
},
AllowPromotionCodes: stripe.Bool(true),
CancelURL: stripe.String(ch.CancelUrl),
SuccessURL: stripe.String(ch.SuccessUrl),
ExpiresAt: stripe.Int64(time.Now().Add(SessionValidity).Unix()),
PaymentMethodCollection: stripe.String(string(stripe.PaymentLinkPaymentMethodCollectionIfRequired)),
AllowPromotionCodes: new(true),
CancelURL: new(ch.CancelUrl),
SuccessURL: new(ch.SuccessUrl),
ExpiresAt: new(time.Now().Add(SessionValidity).Unix()),
PaymentMethodCollection: new(string(stripe.PaymentLinkPaymentMethodCollectionIfRequired)),
})
if err != nil {
return Checkout{}, fmt.Errorf("failed to create subscription at billing provider: %w", err)
Expand Down Expand Up @@ -408,17 +408,17 @@ func (s *Service) Create(ctx context.Context, ch Checkout) (Checkout, error) {
continue
}
itemParams := &stripe.CheckoutSessionLineItemParams{
Price: stripe.String(productPrice.ProviderID),
Price: new(productPrice.ProviderID),
AdjustableQuantity: &stripe.CheckoutSessionLineItemAdjustableQuantityParams{
Enabled: stripe.Bool(adjustableQuantity),
Enabled: new(adjustableQuantity),
},
}
if adjustableQuantity {
itemParams.AdjustableQuantity.Minimum = stripe.Int64(minQ)
itemParams.AdjustableQuantity.Maximum = stripe.Int64(maxQ)
itemParams.AdjustableQuantity.Minimum = new(minQ)
itemParams.AdjustableQuantity.Maximum = new(maxQ)
}
if productPrice.UsageType == product.PriceUsageTypeLicensed {
itemParams.Quantity = stripe.Int64(defaultQ)
itemParams.Quantity = new(defaultQ)
}

if productPrice.Currency == s.defaultCurrency {
Expand All @@ -435,7 +435,7 @@ func (s *Service) Create(ctx context.Context, ch Checkout) (Checkout, error) {
var paymentMethodTypes []*string
for _, paymentMethodConfig := range s.paymentMethodConfig {
if paymentMethodConfig.IsAllowedForAmount(amountSubtotal) {
paymentMethodTypes = append(paymentMethodTypes, stripe.String(paymentMethodConfig.Type))
paymentMethodTypes = append(paymentMethodTypes, new(paymentMethodConfig.Type))
}
}

Expand All @@ -445,12 +445,12 @@ func (s *Service) Create(ctx context.Context, ch Checkout) (Checkout, error) {
Context: ctx,
},
AutomaticTax: &stripe.CheckoutSessionAutomaticTaxParams{
Enabled: stripe.Bool(s.stripeAutoTax),
Enabled: new(s.stripeAutoTax),
},
Currency: stripe.String(s.defaultCurrency),
Customer: stripe.String(billingCustomer.ProviderID),
Currency: new(s.defaultCurrency),
Customer: new(billingCustomer.ProviderID),
InvoiceCreation: &stripe.CheckoutSessionInvoiceCreationParams{
Enabled: stripe.Bool(true),
Enabled: new(true),
},
LineItems: subsItems,
Mode: stripe.String(string(stripe.CheckoutSessionModePayment)),
Expand All @@ -463,12 +463,12 @@ func (s *Service) Create(ctx context.Context, ch Checkout) (Checkout, error) {
"managed_by": "frontier",
},
CustomerUpdate: &stripe.CheckoutSessionCustomerUpdateParams{
Address: stripe.String(addressCollectionParam),
Address: new(addressCollectionParam),
},
AllowPromotionCodes: stripe.Bool(true),
CancelURL: stripe.String(ch.CancelUrl),
SuccessURL: stripe.String(ch.SuccessUrl),
ExpiresAt: stripe.Int64(time.Now().Add(SessionValidity).Unix()),
AllowPromotionCodes: new(true),
CancelURL: new(ch.CancelUrl),
SuccessURL: new(ch.SuccessUrl),
ExpiresAt: new(time.Now().Add(SessionValidity).Unix()),
PaymentMethodTypes: paymentMethodTypes,
PaymentMethodOptions: &stripe.CheckoutSessionPaymentMethodOptionsParams{
CustomerBalance: &stripe.CheckoutSessionPaymentMethodOptionsCustomerBalanceParams{
Expand Down Expand Up @@ -554,7 +554,7 @@ func (s *Service) SyncWithProvider(ctx context.Context, customerID string) error
Context: ctx,
},
Expand: []*string{
stripe.String("line_items.data.price.product"),
new("line_items.data.price.product"),
},
})
if err != nil {
Expand Down Expand Up @@ -782,12 +782,12 @@ func (s *Service) CreateSessionForPaymentMethod(ctx context.Context, ch Checkout
Params: stripe.Params{
Context: ctx,
},
Customer: stripe.String(billingCustomer.ProviderID),
Currency: stripe.String(billingCustomer.Currency),
Customer: new(billingCustomer.ProviderID),
Currency: new(billingCustomer.Currency),
Mode: stripe.String(string(stripe.CheckoutSessionModeSetup)),
CancelURL: stripe.String(ch.CancelUrl),
SuccessURL: stripe.String(ch.SuccessUrl),
ExpiresAt: stripe.Int64(time.Now().Add(SessionValidity).Unix()),
CancelURL: new(ch.CancelUrl),
SuccessURL: new(ch.SuccessUrl),
ExpiresAt: new(time.Now().Add(SessionValidity).Unix()),
Metadata: map[string]string{
"org_id": billingCustomer.OrgID,
"checkout_id": checkoutID,
Expand Down Expand Up @@ -827,11 +827,11 @@ func (s *Service) CreateSessionForCustomerPortal(ctx context.Context, ch Checkou
Params: stripe.Params{
Context: ctx,
},
Customer: stripe.String(billingCustomer.ProviderID),
Customer: new(billingCustomer.ProviderID),
}

if ch.CancelUrl != "" {
sessionParams.ReturnURL = stripe.String(ch.CancelUrl)
sessionParams.ReturnURL = new(ch.CancelUrl)
}

session, err := s.stripeClient.BillingPortalSessions.New(sessionParams)
Expand Down Expand Up @@ -870,7 +870,7 @@ func (s *Service) Apply(ctx context.Context, ch Checkout) (*subscription.Subscri
}

autoTaxParams := &stripe.SubscriptionAutomaticTaxParams{
Enabled: stripe.Bool(s.stripeAutoTax),
Enabled: new(s.stripeAutoTax),
}

// checkout could be for a plan or a product
Expand Down Expand Up @@ -929,8 +929,8 @@ func (s *Service) Apply(ctx context.Context, ch Checkout) (*subscription.Subscri
}

itemParams := &stripe.SubscriptionItemsParams{
Price: stripe.String(productPrice.ProviderID),
Quantity: stripe.Int64(quantity),
Price: new(productPrice.ProviderID),
Quantity: new(quantity),
Metadata: map[string]string{
"org_id": billingCustomer.OrgID,
"product_id": planProduct.ID,
Expand All @@ -946,28 +946,28 @@ func (s *Service) Apply(ctx context.Context, ch Checkout) (*subscription.Subscri

var trialDays *int64 = nil
if plan.TrialDays > 0 && !ch.SkipTrial {
trialDays = stripe.Int64(plan.TrialDays)
trialDays = new(plan.TrialDays)
}

if totalExpectedPrice == 0 {
// if total price is 0, disable auto tax. This ensures that when the subscription is created without
// user billing details while onboarding, creating 0 amount invoice doesn't fail
// This will be toggled back on when the user changes it's plan to a paid one
autoTaxParams.Enabled = stripe.Bool(false)
autoTaxParams.Enabled = new(false)
}

var couponID *string
if ch.ProviderCouponID != "" {
couponID = stripe.String(ch.ProviderCouponID)
couponID = new(ch.ProviderCouponID)
}
// create subscription directly
stripeSubscription, err := s.stripeClient.Subscriptions.New(&stripe.SubscriptionParams{
Params: stripe.Params{
Context: ctx,
},
AutomaticTax: autoTaxParams,
Customer: stripe.String(billingCustomer.ProviderID),
Currency: stripe.String(billingCustomer.Currency),
Customer: new(billingCustomer.ProviderID),
Currency: new(billingCustomer.Currency),
Items: subsItems,
Metadata: map[string]string{
"org_id": billingCustomer.OrgID,
Expand Down
8 changes: 3 additions & 5 deletions billing/checkout/service_concurrent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ func TestService_InitClose_Concurrent(t *testing.T) {
}

var wg sync.WaitGroup
for i := 0; i < 2; i++ {
wg.Add(1)
go func() {
defer wg.Done()
for range 2 {
wg.Go(func() {
if err := s.Init(context.Background()); err != nil {
t.Errorf("Init: %v", err)
}
}()
})
}
wg.Wait()

Expand Down
2 changes: 1 addition & 1 deletion billing/credit/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func (s Service) createAuditRecord(ctx context.Context, customerID string, event
Target: &auditrecord.Target{
ID: txID,
Type: pkgAuditRecord.BillingTransactionType,
Metadata: map[string]interface{}{
Metadata: map[string]any{
"amount": txEntry.Amount,
"source": txEntry.Source,
"description": txEntry.Description,
Expand Down
8 changes: 4 additions & 4 deletions billing/customer/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ func (s *Service) RegisterToProvider(ctx context.Context, customer Customer) (*s
var customerTaxes []*stripe.CustomerTaxIDDataParams = nil
for _, tax := range customer.TaxData {
customerTaxes = append(customerTaxes, &stripe.CustomerTaxIDDataParams{
Type: stripe.String(tax.Type),
Value: stripe.String(tax.ID),
Type: new(tax.Type),
Value: new(tax.ID),
})
}
// create a new customer in stripe
Expand Down Expand Up @@ -318,12 +318,12 @@ func (s *Service) ListPaymentMethods(ctx context.Context, id string) ([]PaymentM
}

stripePaymentMethodItr := s.stripeClient.PaymentMethods.List(&stripe.PaymentMethodListParams{
Customer: stripe.String(customer.ProviderID),
Customer: new(customer.ProviderID),
ListParams: stripe.ListParams{
Context: ctx,
},
Expand: []*string{
stripe.String("data.customer"),
new("data.customer"),
},
})

Expand Down
8 changes: 3 additions & 5 deletions billing/customer/service_concurrent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ func TestService_InitClose_Concurrent(t *testing.T) {
}

var wg sync.WaitGroup
for i := 0; i < 2; i++ {
wg.Add(1)
go func() {
defer wg.Done()
for range 2 {
wg.Go(func() {
if err := s.Init(context.Background()); err != nil {
t.Errorf("Init: %v", err)
}
}()
})
}
wg.Wait()

Expand Down
54 changes: 27 additions & 27 deletions billing/customer/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,16 @@ func TestService_Create(t *testing.T) {
Context: ctx,
},
Address: &stripe.AddressParams{
City: stripe.String(""),
Country: stripe.String(""),
Line1: stripe.String(""),
Line2: stripe.String(""),
PostalCode: stripe.String(""),
State: stripe.String(""),
City: new(""),
Country: new(""),
Line1: new(""),
Line2: new(""),
PostalCode: new(""),
State: new(""),
},
Email: stripe.String(""),
Name: stripe.String("customer1"),
Phone: stripe.String(""),
Email: new(""),
Name: new("customer1"),
Phone: new(""),
TaxIDData: nil,
Metadata: map[string]string{
"managed_by": "frontier",
Expand Down Expand Up @@ -232,16 +232,16 @@ func TestService_Update(t *testing.T) {
Context: ctx,
},
Address: &stripe.AddressParams{
City: stripe.String(""),
Country: stripe.String(""),
Line1: stripe.String(""),
Line2: stripe.String(""),
PostalCode: stripe.String(""),
State: stripe.String(""),
City: new(""),
Country: new(""),
Line1: new(""),
Line2: new(""),
PostalCode: new(""),
State: new(""),
},
Email: stripe.String(""),
Name: stripe.String("customer1"),
Phone: stripe.String(""),
Email: new(""),
Name: new("customer1"),
Phone: new(""),
TaxIDData: nil,
Metadata: map[string]string{
"managed_by": "frontier",
Expand Down Expand Up @@ -314,16 +314,16 @@ func TestService_Update(t *testing.T) {
Context: ctx,
},
Address: &stripe.AddressParams{
City: stripe.String(""),
Country: stripe.String(""),
Line1: stripe.String(""),
Line2: stripe.String(""),
PostalCode: stripe.String(""),
State: stripe.String(""),
City: new(""),
Country: new(""),
Line1: new(""),
Line2: new(""),
PostalCode: new(""),
State: new(""),
},
Email: stripe.String(""),
Name: stripe.String("customer1"),
Phone: stripe.String(""),
Email: new(""),
Name: new("customer1"),
Phone: new(""),
TaxIDData: nil,
Metadata: map[string]string{
"managed_by": "frontier",
Expand Down
Loading
Loading