#sk-zehad_code
1 messages ¡ Page 1 of 1 (latest)
đ Welcome to your new thread!
â˛ď¸ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
âąď¸ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
đ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1328952314928824330
đ Have more to share? Add more details, code, screenshots, videos, etc. below.
Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
- sk-zehad_code, 17 hours ago, 9 messages
Yes, when the payment is paid on Checkout
are you there?
Yes
in my application when user signup, then create a initial subscription using this code:
public function createInitialSubscription(string $customerId): string
{
// Create the subscription with then trial price ID and 7 days trial period
$stripeSubscription = StripeSubscription::create([
'customer' => $customerId,
'items' => [
[
'price' => env('STRIPE_TRIAL_PRICE_ID'),
],
],
'trial_period_days' => 7, // Set the trial period to 7 days
]);
return $stripeSubscription->id;
}
then user choose a plan and subcribe, this time create checkout using this code:
public function pay(array $data): array
{
$session = Session::create([
'payment_method_types' => ['card'],
'mode' => 'subscription',
'customer' => $data['customerId'], // Pass the customer ID here
'line_items' => [
[
'price' => $data['priceId'], // The price_id from frontend
'quantity' => $data['quantity'],
]
],
'success_url' => $data['successUrl'],
'cancel_url' => $data['successUrl'],
]);
return [
'id' => $session->id,
'url' => $session->url,
];
i want when user subscribe a plan, autometic enable proration.
then when upgrade with new plan, stripe autometic adjust bill
i can upgrade using this code
public function upgrade(string $subscriptionId, string $newPlanId): array
{
try {
// Retrieve the existing subscription
$existingSubscription = StripeSubscription::retrieve($subscriptionId);
// Get the current subscription item ID
$subscriptionItemId = $existingSubscription->items->data[0]->id;
// Update the subscription with the new plan and enable proration
$updatedSubscription = StripeSubscription::update($subscriptionId, [
'items' => [
[
'id' => $subscriptionItemId,
'price' => $newPlanId, // New plan price ID
],
],
'proration_behavior' => 'create_prorations', // Enable proration, its by default
]);
Log::info('Subscription updated', ['subscription' => $updatedSubscription]);
return [
'id' => $updatedSubscription->id,
'status' => $updatedSubscription->status,
];
} catch (\Stripe\Exception\ApiErrorException $e) {
throw new \Exception('Failed to update subscription: ' . $e->getMessage());
}
}
But I can't take payment with maintaining proration,
help me how to develop it?
Looking...
Hmm why you are creating Subscription before creating a Checkout Session? The Checkout Session will create another Checkout Session under the hood
Cause When the user signs up, he gets a free trial plan, so there is no need to checkout on the free plan, so the subscription is created before checking out.
You can create a Checkout Session with a trial option on Subscription