#Naveed | Web3Auth

1 messages · Page 1 of 1 (latest)

rapid tangleBOT
heavy token
#

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.

random glade
#

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

fallow patio
#

Hey! Taking over for my colleague. Let me catch up.

fallow patio
#

Are you facing any particular issue with this integration so ?

random glade
#

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

fallow patio
fallow patio
random glade
fallow patio
#

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

random glade
#

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

fallow patio
fallow patio
fallow patio
random glade
#

hmm ok a simple api endpoint to update sub items

fallow patio
random glade
#

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)),
    }
fallow patio