#arundev47
1 messages · Page 1 of 1 (latest)
hi! https://stripe.com/docs/billing/subscriptions/cancel are the docs for how to cancel a customer's exisiting subscription.
Yes I saw it but I want to prorate adjust when I am creating a new checkout session with new price id. How I can generate a prorate checkout session ?
you can't, Checkout is only for creating new Subscriptions, it can't edit existing ones.
How I can do any other way ? I want to redirect to stripe whenever user want to change plan
the Customer Portal https://stripe.com/docs/no-code/customer-portal is likely a good fit then!
No I can't go with that. I am also using stripe sdk in flutter app. In app what I did
- First create a setup intent for new user and create a subscription with 7 days free trial in webhook when setup intent succeeded.
- If user want to choose another subscription plan then I create a subscription intent with these params
'payment_behavior' => 'default_incomplete',
'expand' => ['latest_invoice.payment_intent'], - When it succeeded then I cancel previous plan in customer.subscription.updated webhook.
So I was thinking the same way in website. But there I am not able to create subscription intent so that I can redriect to stripe portal like checkcout session. I wanted to cancel previous subscription plan whenever customer.subscription.updated webhook run.
May be there can be a better way.
Well you can use the same flow on the web too, I don't understand what you mean by " I am not able to create subscription intent", you totally can.
it's https://stripe.com/docs/billing/subscriptions/build-subscriptions?ui=elements , and is pretty much identical to the process you're describing for Flutter.
I mean I am creating subscription intent for mobile api like this
$ephemeralKey = $this->stripe->ephemeralKeys->create([
'customer' => $stripe_customer_id,
], [
'stripe_version' => '2023-08-16',
]);
$subscription_params = [
'customer' => $stripe_customer_id,
'items' => [
[
'price' => $plan->stripe_price_id,
],
],
'metadata' => [
'plan_id' => $plan->id,
'subscription'=> 'active',
'action' => 'cancel_old_subscription',
],
'payment_behavior' => 'default_incomplete',
'expand' => ['latest_invoice.payment_intent'],
];
$tax_rates = StripeTaxRate::pluck('stripe_tax_id');
if($tax_rates->count()) {
$subscription_params['default_tax_rates'] = $tax_rates->toArray();
}
$stripe_subscription = $this->stripe->subscriptions->create($subscription_params);
if(is_string($stripe_subscription->pending_setup_intent)) {
$setupIntent = $this->stripe->setupIntents->retrieve($stripe_subscription->pending_setup_intent);
return [
'client_secret'=> $setupIntent->client_secret,
'ephemeral_key'=> $ephemeralKey->secret,
'customer'=> $stripe_customer_id,
'public_key'=> env('STRIPE_KEY'),
];
}
else {
return [
'client_secret'=> $stripe_subscription->latest_invoice->payment_intent->client_secret,
'ephemeral_key'=> $ephemeralKey->secret,
'customer'=> $stripe_customer_id,
'public_key'=> env('STRIPE_KEY'),
];
}
But for web I am not able to create like this. I want to redirect to stripe after creating a subscription intent so that user can check summary of plan and pay with any payment method again.
But for web I am not able to create like this.
hmm that exact code will work on the web though.
It is not giving any redirect url
on the frontend you can use that client_secret that your backend is returning, in order to present the PaymentElment , per the guide I linked earlier
it won't show the details like "summary of plan" , but neither does your mobile SDK 🙂 either way it's functionality you'd have to build. It sounds like you already solved that in your app.
I think you think Checkout and redirecting to a hosted page is the only way to integrate on the web, but that is not true.