#oleg.moseiko
1 messages ยท Page 1 of 1 (latest)
Hi ๐ I'm going to need more context. Is the FreePlan you referenced something on your end, or do you have a Subscription object in Stripe representing that?
by default for all customer i create FreePlan subscription
and user try subscribe to new subscription but i need to remove old FreePlan
so i need to understand when do i need to remove FreePlan
so really i need switch user from Free Plan to Starter Plane
If you need to cancel an existing Subscription, then you use this endpoint/function to do so:
https://stripe.com/docs/api/subscriptions/cancel
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
when do i need to do it?
When you need to cancel the Subscription, I don't know when in your business flow that makes sense to do, that is something that you would need to determine.
so which is my steps must be to switch user from Free to Starter plane?
- create session to subscribe to Starter
- listening webhook
- if user subscribed to new plan (event from webhook) i need to remove old plan
correct?
Is that the steps you want?
It seems reasonable to me, but it's your business flow so you should decide on what works best for your needs.
just want to be sure i correctly understand stripe business flow
when i need apply new Plan and remove old plan
Sorry, what are you trying to show with that video? I won't know when you should cancel an existing free Subscription, but if you know when that should happen, then I can help answer questions about how to do that.
๐ฉ
USER CAN HAVE ONLY ONE SUBSCRIPTION
user try to subscribe to new subscription
how can to do it
2
3
????
step by step
Check for existing Subscriptions for the Customer:
https://stripe.com/docs/api/subscriptions/list
Cancel any you don't want to stay active:
https://stripe.com/docs/api/subscriptions/cancel
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
What are you trying to ask?
I clearly don't understand your question, but you keep saying the same thing. We aren't here to design your business flows for you, we're here to help you understand how to use our API to build the flows you've designed.
help me understand how to use our API
how to switch user from one plane to new plane
step by step
Can you elaborate on this, there are multiple ways this can be handled and its hard to provide guidance without understanding what you're trying to accomplish.
Do your Customers already have existing Subscriptions? If so, do you want to update the existing Subscription to change the Price object that it is referencing? Or do you want to cancel the existing Subscription(s) and create a new one?
have existing Subscriptions
so, want to update the existing Subscription to change the Price object
Okay, then you would use this endpoint to update the Subscription:
https://stripe.com/docs/api/subscriptions/update
An example code snippet of how to do this is shown here:
https://stripe.com/docs/billing/subscriptions/upgrade-downgrade#changing
try this way
$stripe->subscriptions->update(
$subscription->id,
[
'cancel_at_period_end' => false,
'proration_behavior' => 'create_prorations',
'items' => [
[
'id' => $subscription->items->data[0]->id,
'price' => 'price_CBb6IXqvTLXp3f',
],
],
]
);
but have error
This customer has no attached payment source or default payment method. Please consider adding a default payment method. For more information, visit https://stripe.com/docs/billing/subscriptions/payment-methods-setting#payment-method-priority.
That error indicates that there is currently no default payment method specified at either the Subscription or Customer level, so the Subscription change fails because we don't know where to collect payment from.
Have you previously collected payment method details at this point? Do your Customers already have a set up Payment Method?
no Customer has no payment method
Okay, then you will need to introduce a flow to collect payment method details and create a Payment Method. When in your process do you want to collect payment method details, when your customers first sign up for the free trial, or when the Subscription upgrade is triggered?
when the Subscription upgrade
Alright, then before you upgrade the Subscription, you will need to first handle collection of Payment Method details.
Do you have your own page where you would like to embed the collection of payment method details?
i don't have
So you want to use a hosted page for that, or are you planning to build your own page for collecting payment method details?
use a hosted page for that - what is it?
A prebuilt page that we provide, that you would direct your customers to.
This page walks through how to use our Checkout Sessions (our hosted page) to collect payment method details and prepare a Payment Method for future usage:
https://stripe.com/docs/payments/save-and-reuse
ok i would like to use hosted page
In Step 5, where it says to use the Payment Method for Payment Intents, you will ignore that part. Instead you'll then update either the Subscription or the Customer object to set the newly created Payment Method as the default.
If setting that at the Customer level, you'll want to update this field:
https://stripe.com/docs/api/customers/update#update_customer-invoice_settings-default_payment_method
Or this one if you're updating the Subscription:
https://stripe.com/docs/api/subscriptions/update#update_subscription-default_payment_method
Then you can proceed with changing the Price of the Subscription. (If you're setting the default_payment_method on the Subscription object, then you should be able to set that and change the Price in one request)
so i need to check if user have payment method
and if no i need to start
$session = \Stripe\Checkout\Session::create([
'payment_method_types' => ['card'],
'mode' => 'setup',
'customer' => '{{CUSTOMER_ID}}',
'success_url' => 'https://example.com/success?session_id={CHECKOUT_SESSION_ID}',
'cancel_url' => 'https://example.com/cancel',
]);
You will need to check if the Customer or the Subscription has a default payment method. The Customer can have Payment Methods, but not one set as their default payment method for Invoices.
You will need to check if the Customer or the Subscription has a default payment method. --- how can to do it?
You will check the fields that I referenced in this message, to see if they have a value already set for them.
ok i checked user and he has no default payment method
need to start
$session = \Stripe\Checkout\Session::create([
'payment_method_types' => ['card'],
'mode' => 'setup',
correct?
You should provide the Customer's ID in the customer parameter there as well, since you already have the Customer created.
$session = \Stripe\Checkout\Session::create([
'payment_method_types' => ['card'],
'mode' => 'setup',
'customer' => '{{CUSTOMER_ID}}',
ok user will add payment method
only after that i need to start subscribe update ?
$session = \Stripe\Checkout\Session::create([
'customer' => $stripeCustomer->id,
'line_items' => [
[
'price' => $priceId,
'quantity' => 1,
]
],
'mode' => 'subscription',
'success_url' => $referer,
'cancel_url' => $referer_cancel,
]);
Yes, you will want to trigger the update after collecting payment method details, and setting the created Payment Method as the default at either the Customer or Subscription level.
You won't create a Checkout Session for the Subscription, that will create a Subscription which isn't what you want to do since you already have a Subscription that you want to update.
Instead you will make a request to update the existing Subscription as you tried before that previously ran into an error because there was no default payment method to charge.
ok but how can i run request to update the existing Subscription?
Like this
success_url specifies the URL that the customer should be redirected to upon completion of their Checkout Session.
Oh, are you asking how to trigger the request to update the Subscription after the Checkout Session's flow has been completed? If so, then using a webhook endpoint is the recommended way to do that.
OMG))
- check if user have default pyament
- if yes subscriptons->update
- if no Session::create -> 'mode' => 'setup',
3.1 webhook to start subscriptons->update
correct?
That seems reasonable.
Sure?
You'll want to listen for checkout.session.completed
Happy to help!