#oleg.moseiko

1 messages ยท Page 1 of 1 (latest)

scarlet loomBOT
silk cargo
#

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?

fossil peak
#

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

silk cargo
fossil peak
#

when do i need to do it?

silk cargo
#

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.

fossil peak
#

so which is my steps must be to switch user from Free to Starter plane?

#
  1. create session to subscribe to Starter
  2. listening webhook
  3. if user subscribed to new plan (event from webhook) i need to remove old plan
#

correct?

silk cargo
#

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.

fossil peak
#

when i need apply new Plan and remove old plan

silk cargo
#

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.

fossil peak
#

๐Ÿ˜ฉ

#

USER CAN HAVE ONLY ONE SUBSCRIPTION

#

user try to subscribe to new subscription

#

how can to do it

#

2

#

3

#

????

#

step by step

silk cargo
#

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

fossil peak
#

algorithm

#

fuck

#

thanks

#

big help

#

๐Ÿ’ฉ

silk cargo
#

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.

fossil peak
#

help me understand how to use our API

#

how to switch user from one plane to new plane

#

step by step

silk cargo
# fossil peak how to switch user from one plane to new plane

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?

fossil peak
#

have existing Subscriptions
so, want to update the existing Subscription to change the Price object

silk cargo
#

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

Learn how to upgrade and downgrade subscriptions by changing the price.

fossil peak
#

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

silk cargo
#

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?

fossil peak
#

no Customer has no payment method

silk cargo
#

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?

fossil peak
#

when the Subscription upgrade

silk cargo
#

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?

fossil peak
#

i don't have

silk cargo
#

So you want to use a hosted page for that, or are you planning to build your own page for collecting payment method details?

fossil peak
#

use a hosted page for that - what is it?

silk cargo
#

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

fossil peak
#

ok i would like to use hosted page

silk cargo
#

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.

#

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)

fossil peak
silk cargo
#

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.

fossil peak
#

You will need to check if the Customer or the Subscription has a default payment method. --- how can to do it?

silk cargo
fossil peak
#

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?

silk cargo
#

You should provide the Customer's ID in the customer parameter there as well, since you already have the Customer created.

fossil peak
#

$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,
]);

silk cargo
#

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.

fossil peak
#

ok but how can i run request to update the existing Subscription?

fossil peak
#

it must be my 'success_url' => $referer,?

#

or i need to use webhook

silk cargo
#

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.

fossil peak
#

OMG))

#
  1. check if user have default pyament
  2. if yes subscriptons->update
  3. if no Session::create -> 'mode' => 'setup',
    3.1 webhook to start subscriptons->update
#

correct?

silk cargo
#

That seems reasonable.

fossil peak
#

thanks a lot

#

the last question

silk cargo
#

Sure?

fossil peak
#

3.1 webhook to start subscriptons->update

#

which event will be sent?

silk cargo
#

You'll want to listen for checkout.session.completed

fossil peak
#

ok

#

thanks

silk cargo
#

Happy to help!