如何通过单次API调用完成Stripe订单的创建与支付?
Great question—let’s break down what’s possible and the best alternatives to fit your workflow.
Feasibility of Combining Order Create + Pay in One Request
First, the straight answer: Stripe’s native Order API requires two separate requests for create and pay by design. The create endpoint generates the order object (with line items, customer info, etc.), while the pay endpoint requires the existing order ID and additional details like the payment method to trigger the transaction. There’s no built-in way to merge these two actions into a single HTTP call directly via the Order API.
Recommended Alternatives for Single-Call Creation + Payment
If you want to streamline this into a single backend trigger (to boost efficiency and improve user experience), here are the best approaches:
1. Use Stripe Checkout Sessions (Most Recommended)
Stripe Checkout is built to handle the entire payment flow in one go, and you can tie it to order creation seamlessly:
- Make a single
POST /v1/checkout/sessionsrequest from your backend, including all order details (line items, amount, customer email, success/cancel URLs). - Redirect the user to the returned Checkout URL—they’ll complete payment directly with Stripe.
- Once payment succeeds, Stripe sends a
checkout.session.completedwebhook to your backend. Use this webhook to create your internal order record and link it to the Checkout Session ID for tracking.
This approach means your backend only makes one initial request, and the rest of the flow is handled by Stripe—perfect for keeping things efficient and user-friendly.
2. Use Payment Intents + Backend Order Creation
If you prefer a custom frontend instead of Stripe Checkout, use Payment Intents (Stripe’s modern replacement for the older Charge API):
- Make a single backend call that does two things:
- Sends a
POST /v1/payment_intentsrequest to Stripe, specifying the amount, currency, and any required payment method details. - Immediately creates your internal order record, linking it to the new Payment Intent ID.
- Sends a
- Use Stripe’s webhooks (like
payment_intent.succeeded) to update your order’s status to "paid" once the transaction goes through.
This keeps your workflow to one backend trigger while leveraging Stripe’s robust payment handling (including support for 3D Secure, delayed capture, and modern payment methods).
Your Proposed Approach: Create Charge First, Then Order
Your idea of creating a Charge first and linking it to an order later is technically possible, but note that the Charge API is legacy—Stripe strongly recommends using Payment Intents instead for better support of modern payment flows and compliance. If you do go this route, be sure to handle failure cases (e.g., if the Charge fails, you’ll need to clean up any partial order records and notify the user).
Final Takeaway
While you can’t merge the Order API’s create and pay into one request, the alternatives above let you achieve the same goal of a single backend trigger for order creation + payment, while also taking advantage of Stripe’s most reliable, up-to-date tools.
内容的提问来源于stack exchange,提问作者Tom Lehman




