#anndonnelly
1 messages · Page 1 of 1 (latest)
Hey apologies for the delay. Looking in to what you can do here. Can you send me the snippet of code that you are currently using that starts the free trial like that?
Or do you have the ID of a subscription (sub_123) that you saw this with in test mode?
Sure
$domain_url = getenv('FRONTEND_URL') . '/subscriptions';
$priceId = "price_1LD75yLdiofqj2pGx7wP8qcA"; // test-tourist productId
$success_url = getenv('FRONTEND_URL') . "/profile/settings?session_id={CHECKOUT_SESSION_ID}";
if ($product === "cadet"){
$priceId = getenv('STRIPE_CADET_PRICE_ID');
} elseif ($product === "tourist"){
$priceId = getenv('STRIPE_TOURIST_PRICE_ID');
} elseif ($product === "explorer"){
$priceId = getenv('STRIPE_EXPLORER_PRICE_ID');
}
try {
$checkout_session = \Stripe\Checkout\Session::create([
'success_url' => $success_url,
'cancel_url' => $domain_url,
'mode' => 'subscription',
'line_items' => [[
'price' => $priceId,
'quantity' => 1,
]],
'subscription_data' => [
'trial_settings' => ['end_behavior' => ['missing_payment_method' => 'cancel']],
'trial_period_days' => 14,
],
'payment_method_collection' => 'if_required',
]);
header("HTTP/1.1 303 See Other");
header("Location: " . $checkout_session->url);
return $checkout_session->url;
} catch (Exception $e) {
http_response_code(500);
echo json_encode(['error' => $e->getMessage()]);
}
}
```
Hi there 👋 taking over, as my colleague needs to step away
I gave an answer to this yesterday. Have you tried what I recommended?
Ah, okay so you would need to create a free Price alongside Subscription Schedules, which would allow you to create a Phase for the trial where your customer is charged nothing: https://stripe.com/docs/billing/subscriptions/subscription-schedules
Where can I find Subscription Schedules?