#funk101
1 messages · Page 1 of 1 (latest)
It seems the mode should be kept at payment because the customer is purchasing a "product" which "is a subscription", correct?
Hi, for subscriptions, you'd want "mode" => "subscription" in this case, https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-mode
but why would I create the subscription product in stripe dashboard then?
it seems if I create a subscription product in the Stripe dashboard, then the user is actually PURCHASING a "subscription product". Which the Stripe would recur that payment every billing cycle, no?
When you create a Subscription, https://stripe.com/docs/api/checkout/sessions/create it's required that you specify the mode for the Checkout Session.
ok, so when I follow that doc and set "mode" => "subscription" it has failed
The product/price that you've created on the Dashboard can be used, https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-line_items-price.
Can you share the request id for when the request fails? Here's how you can find a request ID: https://support.stripe.com/questions/finding-the-id-for-an-api-request
don't have it
I guess I'll try switching the mode again
see if it fails again and get request
this is my code:
require_once('vendor/autoload.php');
require_once('include/Common.inc.php');
extract($_POST);
/*
echo '<pre>'.var_dump($_POST).'</pre>';
exit;
*/
\Stripe\Stripe::setApiKey(STRIPE_SECRET_KEY);
header('Content-Type: application/json');
$checkout_session = \Stripe\Checkout\Session::create([
'payment_method_types' => ['card'],
'line_items' => [[
'price_data' => [
'product_data' => [
'name' => $subscription_name
],
'currency' => 'usd',
'unit_amount' => $subscription_price
],
'quantity' => 1
]],
'mode' => 'subscription',
'success_url' => BASE_URL.'/checkout-complete.php',
'cancel_url' => BASE_URL.'/checkout-cancelled.php'
]);
header("HTTP/1.1 303 See Other");
header("Location: " . $checkout_session->url);
You can share any object id that is failing so I can further review this on my end
yes it fails again
What is the error?
This page isn’t workingstaging.lacgroup.com is currently unable to handle this request.
HTTP ERROR 500```
Can you share the checkout session id?
hmm, no
must be something wrong in script, like a typo, does that script look right?
this script works fine with mode => payment
it needs a price_id
"mode" => "subscription" needs a "price_id" parameter
Yes, this is the documentation you'd be looking at: https://stripe.com/docs/billing/subscriptions/build-subscriptions
thanks