#BarrelRider
1 messages · Page 1 of 1 (latest)
Hi there
Can you provide me an example of a Subscription that you have tested with so I can see how you are cancelling here?
Hi Bismarck, sure, this is the subscription ID: sub_1MqLKiEgkYGsrIK1hXtefvQ1
I am subscribing and canceling only via stripe hosted pages.
This is the general flow of what is happening:
-
User subscribes and pays the required amount via stripe hosted page.
-
E.g. 15 days passes and then the user decides to cancel via stripe hosted subscription management page.
-
They cancel via stripe hosted cancelation page and the credit automatically goes into their credit balance. I can see that credit amount in customer dashboard, so user now has a credit in credit balance that normally would be deducted from the next invoice if I didn't refund it.
-
Now upon subscription deletion event I am retrieving the prorated amount of that credit in users balance. That amount comes from the latest invoice that has been created when subscription was cancelled. So now I have cancellation invoice with prorated amount and invoice with the original full payment. Original full payment - prorated amount = used time.
-
I am issuing the actual money refund to original payment method. That amount comes from prorated cancellation amount from the cancellation invoice.
-
Once I have the confirmation that refund has been created sucessfully I am putting a debit for that amount from cancellation invoice on user credit balance so effectively i am 0ing it out because I am debiting the amount that they got in credit for cancelation. I do this manually because this is not automated in stripe.
It is all in regards to the prorated subscription.
currently I am rewriting this a bit in my code to listen for events, I want to be sure user has balance before I issue the refund.
Thanks for the details, let me take a look
Hmm there should not be a 1 hour delay on the Invoice creation from cancellation. That invoice should be cut immediately.
I see this example uses a test clock so you can't really see this timing here any way
Where are you seeing the 1 hour delay exactly?
So when I cancelled the subscription and opened the draft invoice, before I moved the clock to 20:41 it said something like "This invoice will be finalised at 20:40".
But weirdly enough one time I moved time by I think couple of minutes by accident and it still finalised the invoice.
Yeah test clocks aren't really going to be perfect with that minutiae. Overall, this new invoice will be created and finalized immediately on cancellation.
That said, if you really want to make sure the Customer has a credit before actioning, you can check their Customer Balance via listing their customer balance transactions: https://stripe.com/docs/api/customer_balance_transactions/list
You can also then debit that balance via the API as well
hmm so I guess I will just listen for invoice.payment_succeeded event, because I would like to avoid randomly just checking the balance so I don't hit any throttling.
Is that acceptable idea?
Well you are going to receive other invoice.payment_succeeded events, right?
So you can't really rely on that
true I was hoping I could just figure out by metadata how to tell which customer needs refunding
I would listen for customer.subscription.deleted in this case
Then you can retrieve the Subscription and expand the latest_invoice
Then you can get the necessary details you need
I am doing that in Laravel by default but I branched out to further events because of that discrepancy, when I check the balance upon that event it says 0 because of the draft, but on live system it will be fine?
I am doing literally what you just said, getting the latest invocie and refund amount and all that, I am just worried that balance comes up as 0 upon that deletion event
What says 0 exactly? Can you drop the payload that you see for the latest_invoice?
I really don't think it should be in draft at this point...
But would love to double check on that
when I make API to get users balance that says 0.00 and that happens upon cancellation event, as for the payload plase allow me two minutes
So this is the payload
sub id sub_1MqM99EgkYGsrIK13MQyjyeH
That is PHP code servicing that event (Laravel Cashier)
now if it that provided code I would check if the balance is there it would say that balance is 0.
Hi @steady totem hope you are well, let me know if you need any more info
@slate drum ah, sorry we missed this thread! Do you mind sharing a quick summary of where you're currently blocked? I'm not a PHP expert so may need to pull in a teammate for help
no problem
so the issue I am having is not PHP realated
the problem is that Stipe upon cancellation of prorated subscription is supposed to credit user credit account with prorated amount straight away.
What happens though is cancellation invoice is created as a draft and it takes about an hour for it to be finalised.
This bugs me because I wanted to check user balance upon sub cancelation event and I can't do that because if cancellation invoice is not finalised the blanace is not credited with prorated amount
what you see on the screenshots shows cancellation invoice in draft state which should never happen
payload file is cancellation event payload
and my code is simply to provide clearer picture
that invoice is about to be finalised in less than a minute
I think
not sure if something is not broken because
Subscription
invoice will be finalized and charged 3/27/23, 9:55 PM is updated every minute to another minute
something is broken on Stripe side
Each time I refresh the draft page it says the draft will be resolved in the next minute and one minute after the clock updates to say it will be resolved next minute.
The invoice to my understanding should not be in draft state to begin with,
got it, give me a few minutes to catch up
no problem at all lemme know if you need more info
Okay, I'm following. let me pull up details about sub_1MqLKiEgkYGsrIK1hXtefvQ1
Hm, I think my teammate mentioned above that test clocks might not handle this very well
I think he did, but does that mean i can just assume balance will always be available in real life scenario?
Does the invoice change at all if you advance the test clock 1hr?
yeah it does pop back into place, as it should it becomes paid
also if I skip checking balance (because it is 0 with that broken invoice) because refunds are immediate I am adjusting balance and it all works out to 0
but I am just a bit worried that I will go live and I will just have major problem with refunds and things
Got it, okay. Yep, I think what you're seeing is just part of test clocks.