#Naveed | Web3Auth
1 messages · Page 1 of 1 (latest)
Hi there, yes you can attach an existing payment method to a paymentIntent.
Or I'd just set the payment method as the default_payment_method when creating the subsription.
Hmm so basically I use PaymentElement on the frontend for a customer to subscribe to a monthly recurring plan.
I'm assuming that I can first fetch customer's default credit card to see if they have one on file, and if so instead of showing them the UI to add the credit card I can show them some basic card details e.g. use existing card,
I assume also my create subscription intent endpoint can handle the scenario where they have a card vs without one
subscriptionParams := &stripe.SubscriptionParams{
Customer: stripe.String(customerID),
Items: priceItems,
PaymentBehavior: stripe.String("default_incomplete"),
PaymentSettings: &stripe.SubscriptionPaymentSettingsParams{
SaveDefaultPaymentMethod: stripe.String(string(stripe.SubscriptionPaymentSettingsSaveDefaultPaymentMethodOnSubscription)),
},
CollectionMethod: stripe.String(string(stripe.SubscriptionCollectionMethodChargeAutomatically)),
BillingCycleAnchor: stripe.Int64(currentMonthEnd.Unix()),
}
subscriptionParams.AddExpand("latest_invoice.payment_intent")
subscription, err := sub.New(subscriptionParams)
if err != nil {
log.WithField("customer_id", customerID).WithField("error", err).Error("Failed to create stripe subscription")
return nil, utils.NewUnexpectedError("Failed to create subscription intent", nil)
}
this is how im setting up subscriptionParams
its doing save default payment
Hey! Taking over for my colleague. Let me catch up.
Yes that's a good option
Are you facing any particular issue with this integration so ?
im going to try it out, but im just wondering whats the behaviour of payment element on the frontend if i were to feed it the payment intent with default payment method attached
and btw im kind of confused about which card gets used if there are a bunch of non-default cards set up on customer account
in the above example where customer inputs their card details it will save it to their account
but i think it wont set it also as their default account
previously in our app we had customers simply set up their card (using setup intents api)
after setting up, i would set up the card to be default
with another api call
You simply don't need to show the PaymentElement as you have the PaymentMethod already
That's up to you/your customer to choose
right what i was assuming though that maybe itd prefill card details
Why you want to prefill card details ? if the customer has already PaymentMethod registered you can simply reuse it, without asking the merchant to reauthenticate their card agains
But in all cases, the card prefill can be managed by the customer browser and not Stripe Elements
oh right...
ok and basically after that ill need to also be able to handle changing of subscriptions
e.g. changing from basic -> growth -> scale etc. etc.
I guess i can simply modify subscription items in the backend
update might require payment method though
if its prorated
how does it look from customer perspective if theyve paid for growth
then want to change to scale?
at this point card has been added
im not sure if i should use create subscription intent endpoint again since itd create a new subscription
yes just do an api call udpate
the default payment method in the subscription will be used
https://stripe.com/docs/api/subscriptions/object#subscription_object-default_payment_method
No need for another Payment Method unless there is problem with the previous Payment Method
They can update, for the next billing cycle they will observe an increase in the invoice amount.
hmm ok a simple api endpoint to update sub items
yes, try using Stripe test clock and do some simulation :
https://stripe.com/docs/billing/testing/test-clocks
oh thatll help a lot
One more thing though, are subscriptions by default configured to charge default credit card
e.g. as id mentioned before i had a setup intent flow where users would set up their credit card
but not sure whatever subscriptions i create would make use of that credit card or not
e.g. if i created sub like this
// create subscription on Stripe
subscriptionParams := &stripe.SubscriptionParams{
Customer: stripe.String(cus.StripeID),
Items: []*stripe.SubscriptionItemsParams{
{
Price: stripe.String(priceID),
},
},
BillingCycleAnchor: stripe.Int64(nextMonthStart.Unix()),
CollectionMethod: stripe.String(string(stripe.SubscriptionCollectionMethodChargeAutomatically)),
ProrationBehavior: stripe.String(string(stripe.SubscriptionProrationBehaviorNone)),
}
Add the default_payment_method too when creating the subscription:
https://stripe.com/docs/api/subscriptions/create#create_subscription-default_payment_method