#Yul
1 messages ยท Page 1 of 1 (latest)
Hello again ๐
The ideal solution here would be listen to webhook events
Can you specify what exactly are you trying to keep in sync?
You again! I'm doubting your approach. The thing is that I can't see anywhere in the docs that you should create customer before checkout session.
Your approach was:
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.
You were asking about a subscription, a subscription needs a customer.
You never mentioned that some of them won't have a subscription!
yeah
Everyone must first create an account and only after creating account they can choose to add a subscription or not...
Theres also some other params beside "customer" in the checkout create:
"customer_creation": null,
"customer_details": {
"address": null,
"email": "example@example.com",
"name": null,
"phone": null,
"tax_exempt": "none",
"tax_ids": null
},
"customer_email": null,
if I don't add any myself I kinda let everything to handle about customer to stripe.... And if I add only customer then I kinda mess up with the customer info.
Also, what about subscription renewal? Ican handle it with 'invoice.paid' too?
Me, personally, I would've passed my local customer id in the session crete metadata and upon receiving webhook, bim bam boom bam! I have my local customer ID and price_ID ... I can upgrade subscription
But will I have this metadata on subscription renew?
Customer information doesn't change on renewal right?
I believe you're confusing two things together. Are you trying to keep the customer in sync OR the subscription?
Think of these as separate objects
Customer information doesn't change on renewal, subscription's status might (if let's say the payment fails)
nah
In that case, all you have to do is listen for customer.* webhook events.
When anything about a customer changes on Stripe, we will send out webhook events for that.
subscription too..
for subscriptions we have customer.subscription.* events
I actually see another approach which a like the most... For all the customers on my website create a stripe customer............... And give every customer in my local DB a cus_xxx ...
This way I will be able to make checkout like in docs. But.. why do I need all these customer in my stripe account which aren't going to pay anything anytime? ... Like, maybe 2% of them are going to pay something
Your docs are meant like all the customers on my app are going to pay for subscription! But thats not the case..
It goes back to your app design
Everyone must first create an account and only after creating account they can choose to add a subscription or not...
I can create a 0 eur/year subscription and add these customers to this subscription, but isn't it just dum ?
yeah, that is my app design
Everyone must first create an account in my local db*
I can create a 0 eur/year subscription and add these customers to this subscription, but isn't it just dum ?
You can choose to not create a sub but then you won't be able to upgrade to the paid plans without creating a subscription and you'll have to maintain your own history of the subscription up until the time you create a subscription
I understood your thought
Can I create a 0 eur/year subscription?
Without any card details and so on?
You think that this would be the best approach for me?
I'll be using subscription: new, renew, downgrade, upgrade, unsub events.
Yes you can create a 0 eur/year subscription as long as you create a 0 eur product
While creating a Checkout Session, you can set payment_method_collection to if_required which will avoid collecting a PaymentMethod if the invoice is 0 eur
https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-payment_method_collection
You think that this would be the best approach for me?
Only you can decide that honestly ๐ Its your app
If I pass the cus_ID in the "customer" param in the checkout create - new customer is not goind to be create right?
Stripe will use the customer provided in the customer field, right?
And if I'm not passing anything in this field, customer is going to be created, right?
Yes, that's correct
And if I'm not passing anything in this field, customer is going to be created, right?
In subscription mode, yes.
Does your cus_ID have a static length? Of 18 characters?
At the moment they aren't specified to have a specific length, they might be that length now but could be expanded in future
All fields on customer->create are optional. Does it mean I can create customer with no data?
I'm using php
Correct, you can create a customer without providing any data and then fill out whatever you need later
How the subscription downgrading/unsub handled? I will get some money back if I downgrade/unsub?
If you use proration by default it will credit the customer for the time left on the subscription https://stripe.com/docs/billing/subscriptions/prorations
I am checking but I think you can partially refund the user if you want
It looks like there isn't an argument for that. You would have to create your own refunds separately for that
Yeah, so by default if user cancels or downgrades subscription he will not receive any money back and he will just use it until expiry....
Separate question: can I receive a chargeback on my subscription? For example, if I simply don't want to use it anymore?
Actually, it's much more easier for me to cancel immediately or downgrade his subscription if he unsubs or downgrades.... Is it an ok way?
You can cancel immediately or set the subscription to cancel at the end of the cycle, either are valid
Chargebacks are possible on any transaction. Those come from the user reporting charges to their bank
It also seems not so easy to get the price_id from the event object on webhook...
event->data->object->lines->data[0]->price->id
... Is it a legit way? Maybe there's a better way?
So, it's going to be
// Handle the event
switch ($event->type) {
case 'checkout.session.completed':
$subscription = $event->data->object; // contains a \Stripe\Subscription
$priceId = $subscription->lines->data[0]->price->id;
for me. On the webhook part
oh, actually case 'invoice.paid':
Hi there ๐ jumping in as the server is a bit busy today. Yes, that is the correct way to get to the Price ID from an Event containing an Invoice.
\Stripe\Checkout\Session::create([ is the same as $stripe->checkout->sessions->create([?
Hi
The structure dont lie
Was the only outstanding question, or is there something else you're looking for assistance with currently?
I don't think so