#icurrytheteam

1 messages · Page 1 of 1 (latest)

chrome yachtBOT
surreal sparrow
old pebble
#

So could I just check if there exists a default saved payment and if there is, then just charge that? Otherwise, I would return the clientSecret of the payment intent so that they may enter their information?

surreal sparrow
old pebble
#

May I read this for a second?

surreal sparrow
#

Sure

old pebble
#

Ok, so what happens if no saved payment methods exist and I try to process a subscription? Will it throw an error?

surreal sparrow
#

What do you mean by 'process a subscription'?

old pebble
#

Sorry, purchase

#

I meant to type purchase, it autocorrected.

surreal sparrow
#

Yeah, but what exactly does that mean? Make the API call to create the Subscription?

old pebble
#

Yes

surreal sparrow
#

It'll likely be in an incomplete state until you confirm the Payment Intent on the initial Invoice

old pebble
#
    customer="{{CUSTOMER ID}}",
    items=[{"price": "{{PRICE ID}}"}],
    transfer_data={'destination': '{{ACCOUNT ID}}'},
    expand=['latest_invoice.payment_intent'],
    application_fee_percent=30,
)```
#

I just tested the above code and I was thrown an InvalidRequest error.

#

It says the customer has no attached payment methods, I see.

surreal sparrow
old pebble
#

Let me take a look.

#

I see and if I pass the clientSecret to the client-side and fill out the form with the payment details, would that complete the transaction?

surreal sparrow
#

Yep! Once you call confirmPayment we'd attempt payment with the details collected and carry out 3DS/auth if required

#

Will set the payment details you collect as the default for the subscription automatically, so that recurring payment aren't interrupted

old pebble
#

Ok, so it saves the payment details for the subscription. I'm understanding that correctly?

grim raven
#

it automatically saves the PaymentMethod used for that first payment to the Customer object involved, and sets the ID of that PaymentMethod to be the default that we charge for recurring payments on that Subscription

old pebble
#

Exactly what I need it to do.

#

As for the case when the user has already saved their payment method, I can just create the subscription "normally" right? I think this would work because subscriptions automatically charge the default payment method should it already be there.

grim raven
#

no, you should make sure to pass explicitly the payment method you want it to use

#

what's the context exactly where you'd be creating a subscription like that? is the customer present on your website at the time you create the subscription or not?

old pebble
#

yes

#

I want my subscription flow to cover two case: one where the user has not entered their payment information and another where they have.

#

So for example, if a user would like to subscribe and they have already saved a default payment method, then I would want to charge that payment method

grim raven
#

probably the best way to do that then is create the subscription in the same way, but on the frontend instead of using an instance of Elements to collect cards details, pass the ID of their existing PaymentMethod via https://stripe.com/docs/js/payment_intents/confirm_card_payment#stripe_confirm_card_payment-existing ; which will charge that card for the first invoice of that new subscription and also make it the default for that subscription if you used the save_default_payment_method option when creating the subscription

old pebble
#

I'll be accepting transactions using cards and bank accounts. Is there something like this but that'll handle both?

grim raven
old pebble
#

Oh, so could I just check the payment method so the frontend knows which function to call?

grim raven
#

yes

old pebble
#

Alright, so to sum up, I can create the subscription on the backend the same way and on the frontend, I would just check to see what function to call, then call that.

#

Did this make sense?

#

If so, then I think I'm done here.

grim raven
#

yep sounds good