#lucasemanuel
1 messages · Page 1 of 1 (latest)
Hi 👋 can you elaborate on what you're trying to accomplish? You cannot complete payment for a Checkout Session via the API, as Checkout Sessions are a hosted surface for your customers to provide the necessary payment method details and complete the payment.
allright,
already working with subscription
is there any alternative via api for buys one time?
Sorry, I'm a little unclear what you're asking, can you include more context to ensure we're aligned? For instance, what is already working for with subscriptions, and is there an API flow that is an alternative to what?
Okay, im use only api, already have payment_method and need buy products one time, but all flow must via api
$checkout = $stripe->checkout->sessions->create([
'customer' => $user->stripe_id,
'success_url' => 'https://example.com/success',
'line_items' => [
[
'price' => 'price_1Mj4RwKoGRirOu8OBs1hy2EN',
'quantity' => 1,
],
],
'payment_intent_data' => [
'setup_future_usage' => 'off_session'
],
'invoice_creation' => [
'enabled' => true
],
'mode' => 'payment',
]);
$stripe->paymentIntents->confirm(
$checkout->payment_intent,
[
'payment_method' => $paymentMethod->stripe_id
]
);
You cannot perform this action on PaymentIntents created by Checkout.
Yeah, that won't work, if you want to confirm the Payment Intent directly then you should create the Payment Intent yourself.
When you're creating the Payment Methods that you want to use later, are you setting them up for future usage, and if so are you setting them up for on_session or off_session payments?
Gotcha, then it seems like you're likely trying to process an off_session payment, in which case you would create and confirm the Payment Intent directly.
You can see examples of how to do that in our guides for setting up payment methods to be charged later:
https://stripe.com/docs/payments/save-during-payment?platform=web#charge-saved-payment-method
Let me know if anything there is unclear or if you run into errors.