Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to accept on-session payments with saved payment method. #318

Closed
benipuri opened this issue Jun 8, 2021 · 4 comments
Closed

How to accept on-session payments with saved payment method. #318

benipuri opened this issue Jun 8, 2021 · 4 comments
Labels
question Further information is requested

Comments

@benipuri
Copy link

benipuri commented Jun 8, 2021

Hi, I am migrating my App from Charges API to PaymentIntents and I think I am missing something very basic here but Is there any documentation about how to accept on-session payments with saved cards/payment methods. I checked Stripe's documentation about saving and reusing a payment method but it only explains about off-session payments and steps one should follow to start a recovery flow in case the off-session payment gets declined.

In my use case, and I think this is a very common use case, customer adds a card and pay for their order. I am saving this card for future use with setup_future_usage : on-session. Everything working perfectly fine when I try to add a new card and pay. The payment is processed perfectly, the authentication screen pops up wherever required, the payment method gets saved to the customer and so on.. But I can't understand how should I use this saved payment method later.

Any help will be highly appreciated.

@thorsten-stripe
Copy link
Contributor

You can simply call confirmPayment with the saved payment method's id:

const { error, paymentIntent } = await confirmPayment(clientSecret, {
    type: 'Card',      
    paymentMethodId,    
});

You can see an example of this here: https://github.com/stripe/stripe-react-native/blob/master/example/src/screens/CVCReCollectionScreen.tsx#L74-L80

Note that if you're not recollecting the cvc, you can just leave out the cvc param as shown above.

@thorsten-stripe thorsten-stripe added the question Further information is requested label Jun 8, 2021
@benipuri
Copy link
Author

benipuri commented Jun 8, 2021

Thank you so much for the prompt reply.

Actually I already tried using confirmPayment in the exact same way as mentioned by you but I think I am not importing confirmPayment correctly.

My import statement.

import { initPaymentSheet, presentPaymentSheet, confirmPayment } from '@stripe/stripe-react-native';

initPaymentSheet and presentPaymentSheet are working perfectly but confirmPayment is giving the error Undefined is not a function..

Please advice how should we import the confirmPayment function.

@thorsten-stripe
Copy link
Contributor

@benipuri it looks like for a direct function export we've named the method confirmPaymentMethod (https://github.com/stripe/stripe-react-native/blob/master/src/functions.ts#L112), so you'd have to use that instead. Sorry about the discrepancy here! If you use the useConfirmPayment hooks, it would be called confirmPayment. I'll see that we fix that.

@benipuri
Copy link
Author

benipuri commented Jun 8, 2021

Thank you for the quick clarification. confirmPaymentMethod did the work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants