#Yul

1 messages ยท Page 1 of 1 (latest)

bronze wraithBOT
modern bridge
#

My system is built on PHP

stable kite
modern bridge
#

Well, yeah, I believe it, but I'm lazy. Can't get to the point..

#

๐Ÿ˜ฆ

stable kite
#

for subscription docs? yes
You can also just look at the sidebar

modern bridge
#

Is it mandatory to create a customer for each subscription payment?

stable kite
#

Yeah without a customer the subscription can't exist as such

modern bridge
#

On the webhook part (callback): how do I distinguish to whom of my customers I should update the subscription?

#

"You should provision the subscription and save the customer ID to your database." - what customer ID? From your side or from mine?

stable kite
#

From Stripe

modern bridge
#

Okay and how do I know who is this on my system?

stable kite
#

Your code creates the customer on Stripe so you should be able to add a reference to your local user ID in a field such as metadata

modern bridge
#

this stripe customer ID is different for each payment?

#

Even if the user is reccuring? For example, he just renews the subscription..

stable kite
#

It shouldn't be different, no.

modern bridge
#

The technique is:

user init payment: I create stripe customer, update reference on my side, redirect to payment
->
The I receive the callback with this reference and in this way I can distinguish who it is...

stable kite
#

hold on, let's take a step back.
What's the end goal here? What problem are you trying to solve?
Is it just keeping Stripe customer and your local customer in-sync OR something else?

modern bridge
#

yes

#

exactly

#

To update his subscription on my end if he paid..

#

He's a customer, he's already already in my mysql db and he goes to pay for the subscription, he's logged in ... To be precise

stable kite
#

In that case here's how I would handle it,

1/ Create a customer before creating the subscription and store their customer ID in local database
2/ Listen for subscription related webhook events
3/ When I receive invoice.paid , I'll look at the associated customer ID and look for the same in my local database
4/ Once I find them, I'll provision access.

#

Above handles provision asynchronously

modern bridge
#

Yeah.. If the customer wants to upgrade the subscription... I created subscriptions as products. Would I have to create a new customer?

stable kite
modern bridge
#

So, before \Stripe\Checkout\Session::create I need to $stripe->customers->create() ?

stable kite
#

Yeah

modern bridge
#

And how do I pass this customer to checkout session ?

stable kite
modern bridge
stable kite
#

Yes, more like 'customer' => 'cus_xxx'

#

since customer objects on Stripe have cus_ prefix ๐Ÿ™‚

modern bridge
#

Do I have to check if customer already have in my db cus_xxx? Do I have to check it before each payment attempt?

stable kite
#

It depends on your usecase, but I guess yes? So that you don't have two customers with the same cus_xxx in your local db

modern bridge
#

Well, no, I will simply rewrite the cus_xxx if it already exists for some customer

#

If I'm not going to check it

#

Is it possible stripe to create a duplicate cus_xxx ?

#

usually all the customer ID's are unique..

vapid barn
#

Hello! I'm taking over and catching up...

modern bridge
#

Hi hi

vapid barn
#

Customer IDs in Stripe are unique across your account. You won't see the same cus_ ID more than once across your account's Customers.

modern bridge
#

Ok, the technique is clear for me I think:

  1. I check if the customer in my local db already has the cus_ID
  2. I not then I create stripe customer. Get the cus_ID.
  3. Then I
    $session = \Stripe\Checkout\Session::create([
    'customer' => 'cus_ID',
    'success_url' => 'https://example.com/success.html?session_id={CHECKOUT_SESSION_ID}',
    'cancel_url' => 'https://example.com/canceled.html',
    'mode' => 'subscription',
    'line_items' => [[
    'price' => $priceId,
    // For metered billing, do not pass quantity
    'quantity' => 1,
    ]],
    ]);
  4. Then he pays, I receive the callback and by this cus_
#
  1. Then he pays, I receive the callback and by this cusID I know who he is and able to update the subscription...
#

Oh and 2.1. I update the cus_ID for this customer on my local db

#

But how do I know which subscription did he bought? Will I have lookup_key in the callback?

vapid barn
modern bridge
#

Ok!