When I was using charges, this was easy, just create a charge without capturing funds, and funds were authorized (if there is enough money, of course).
But after switching to the PaymentIntent, no charges were created on creation of PaymentIntent, so no funds were auhtorized. When I call paymentIntent.confirm()
the charge is created and captured at once, if there is enough funds on the card. If not, the CardException was thrown.
I need a way to authorize funds, or other way to check if there is enough funds on the card but BEFORE I call confirm.
Is there any way to do this?
I managed to do this by setting capture_method
of paymentIntent to manual. Default is automatic, so on confirm, related charge will be both created and captured. But if this is set on manual, on confirm charge will be created (if balance is ok), and we need to call paymentIntent.capture() to do the actual payment.
So the flow is
capture_method
set to manual paymentIntent.confirm()
to authorize funds paymentIntent.capture()
to pay when you are ready to pay If there is no sufficient funds on the card, on 2nd step the CardException will be thrown.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.