Doc Improvement for Create Intent And Capture later
See original GitHub issueDescribe the bug When I read the doc everywhere here, expo, stripe.dev (front/api) and other platforms, I can’t find anything that make a pre payment that’s not billed directly and we are able to capture payment later even will strongest 3D secure (2 authenticate at every step).
To Reproduce Steps to reproduce the behavior:
- Go to doc, sample or readme
- Take a example and copy paste
- Test your code
- Add payment type error, need authenticate error…
Expected behavior We should have a clear working example with last versions and react-native.
Screenshots
Setup intent option capture or charge will not work with strong cards
Desktop (please complete the following information):
- OS: OSX
- Browser Brave
Smartphone (please complete the following information):
- Device: Emulator
- OS: Android 12
Here it’s what works Front
/**
* When we create setup intent (save card and pay later)
* We need to create separately a payment method and send it to Stripe API for confirm
* Should be Called at clicking Validate Card button
*/
const createPaymentMethodForCapture = async (): Promise<unknown> => {
console.info("[PaymentCard] Init payment method");
const result = await createPaymentMethod({
paymentMethodType: "Card",
card: refCardElement,
billing_details: {
name: user?.last_name,
email: user?.email,
},
});
// Handle payment method error while creation
if (result.error) {
console.error("[PaymentCard] Create payment method Error", result.error);
return null;
}
// Handle payment method created success
console.debug(
"[PaymentCard] Create payment method: ",
result.paymentMethod
);
//Create intent on serveur
const intent = await apiCreatePaymentNew(result.paymentMethod?.id);
if (intent.error) {
console.info("[BikeSelection] Error creating intent", intent);
return null;
}
console.log("[BikeSelection] Intent created with capture manual:", intent);
const confirmPaymentIntent = await confirmPayment(intent.client_secret, {
paymentMethodType: "Card",
type: "Card",
card: refCardElement,
});
console.log("[BikeSelection] Intent confirmed:", confirmPaymentIntent);
setPaymentIntentId(confirmPaymentIntent.paymentIntent?.id);
setPaymentSecret(confirmPaymentIntent.paymentIntent?.clientSecret);
return intent;
};
BACK
# Initiate the payment
# When a user tries to unlock a vehicle
# Start/Beginning of the tour
def create_intent_new
payment_method_id = params[:payment_method_id]
Rails.logger.info("[Payment] Create a payment intent for this transaction NEW: #{payment_method_id}")
# head :unprocessable_entity unless current_user.stripe_customer_id && current_user.default_stripe_payment_source
begin
intent = Stripe::PaymentIntent.create({
amount: rental_max_cents,
currency: 'eur',
customer: current_user.stripe_customer_id,
capture_method: 'manual',
payment_method: payment_method_id,
confirm: true
})
rescue Stripe::CardError => e
# Error code will be authentication_required if authentication is needed
Rails.logger.info "[Payment] Error is: #{e.error.code}"
payment_intent_id = e.error.payment_intent.id
payment_intent = Stripe::PaymentIntent.retrieve(payment_intent_id)
intent = payment_intent
Rails.logger.info "[Payment] Retrieve #{payment_intent.id}"
end
Rails.logger.info "[Payment] Intent created #{intent}"
render status: 200, json: intent
end
# Capture full amount
def capture_intent_new
payment_intent_id = params[:payment_intent_id]
Rails.logger.info "[Payment] Capture payment #{payment_intent_id}"
begin
intent = Stripe::PaymentIntent.capture(
payment_intent_id, { amount_to_capture: rental_max_cents, }
)
rescue => e
Rails.logger.warn "[Payment] Error while capturing the payment #{e.message}"
end
Rails.logger.info "[Payment] Finish to capture payment #{intent}" if intent
intent
end
```
Issue Analytics
- State:
- Created a year ago
- Reactions:2
- Comments:5
Top Results From Across the Web
Intents and Intent Filters - Android Developers
An intent filter is an expression in an app's manifest file that specifies the type of intents that the component would like to...
Read more >Stripe API reference – PaymentIntents – curl
You can reference the PaymentIntent later to see the history of payment ... When using manual capture, a future timestamp after which the...
Read more >Creating intents - IBM Cloud Docs
If the input is unrelated to any of the intents in your application, you can teach your assistant that by selecting the displayed...
Read more >Authorize and Capture - PayPal Developer
Before you authorize funds, you must create an order with the intent field set ... After a successful authorization, PayPal recommends that you...
Read more >Does a Stripe payment intent place a hold before or after ...
The creation, confirmation, and capture of a payment intent are three distinct steps that happen in that order over time. I have read...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yes, in that case you’ll need to manually bring the customer back on-session for them to complete the SCA flow
the setup intent will allow the card to be used in off-session transactions, but issuers can still decline those transactions with
authentication_required
if they choose, so it’s best to implement a process for bringing payments back on-session when requiredgonna go ahead and close this since we haven’t heard back from @73k05 on whether or not those docs were what they were looking for, but happy to keep answering questions!