#binayak-payment
1 messages · Page 1 of 1 (latest)
here's the code snippet, please check if it is correct.
const stripe = require('stripe')('sk_test_51J7k95Cd3LRlmO28v32DBPeCbJpjoe2b8YLeayKF1bHmh1nHPOdcTSWPT6q5lOve1uTNfXm8g0Ku0Qu1zxDKH3in007t6jQqsQ');
const paymentIntent = await stripe.paymentIntents.create({
amount: amount,
currency: currency,
payment_method_types: ['card'],
capture_method: 'manual',
type: 'card',
card: {
number: '4242424242424242',
exp_month: 9,
exp_year: 2023,
cvc: '314',
},
automatic_payment_methods: {enabled: true}
});
we are trying to create hold.
well you're passing a raw card number in backend code which is never recommended and puts you in PCI compliance scope (https://stripe.com/docs/security/guide#validating-pci-compliance, "API Direct")
It's also not valid syntax for the API no.
this is a sandbox code
we will refactor
please guide
the problem is we are getting error while capturing the fund.
yep because you didn't "confirm" the PaymentIntent first.
but we will create first, then confirm na?
yes. I highly recommend you build https://stripe.com/docs/payments/accept-a-payment first. Once you have a working payment integration, it's extremely easy to change it to be a hold instead.
sir we already have the entire setup done, we just required to hold instead of capture funds immediately.
just let me know if any problem is there in the code snippet I shared
const stripe = require('stripe')('sk_test_51J7k95Cd3LRlmO28v32DBPeCbJpjoe2b8YLeayKF1bHmh1nHPOdcTSWPT6q5lOve1uTNfXm8g0Ku0Qu1zxDKH3in007t6jQqsQ');
const paymentIntent = await stripe.paymentIntents.create({
amount: amount,
currency: currency,
payment_method_types: ['card'],
capture_method: 'manual',
automatic_payment_methods: {enabled: true}
});
there's nothing wrong with it. It creates a PaymentIntent.
but while capturing funds, we are getting error message as:
"message": "This PaymentIntent could not be captured because it has a status of requires_payment_method. Only a PaymentIntent with one of the following statuses may be captured: requires_capture.",
so any change we need to do?
you need to confirm the PaymentIntent to actually charge the customer
after that charge succeeds, you can capture. So like I said, it's the same existing payment integration where you make a PaymentIntent, confirm it on the frontend, handle webhooks etc. The capture is just one extra thing you do at the very end
okay, confirm has to done at front end?
yes.
you said "we already have the entire setup done," so it's the same as that. https://stripe.com/docs/payments/accept-a-payment
cant we schedule it?
you can do payments on saved cards from the backend yes. https://stripe.com/docs/payments/save-and-reuse?platform=web#charge-saved-payment-method for example.
like, if customer orders today, we will create a hold tomorrow and charge after the item gets dispatched.