Best approach for Laravel Cashier "top up" purchase flow #45451
Unanswered
sts-ryan-holton
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I'm building a web application where users can purchase "SMS credits". Each credit can be used to send an SMS. So users will need to purchase credits which are then stored as a
CreditTransaction
entry with adelta
column in my database, this way, each transaction can have a negative or positive delta value and thesum
of all of these is the user's credit balance.My initial approach here, is to have a Laravel job called
ProcessCreditTransaction
which is triggered on the checkout, I believe this is fine for customers that enter mytry
block, but for customers that enter thecatch
, and where additional payment action is required, how can I only trigger my Job if successful?Right now, for example, if the
$e->payment->requiresPaymentMethod()
block is triggered, then so is my job to add credits to their account, but if they didn't complete the purchase, then they've now got a positive amount of credits in their account?How's best to handle this, here's my current checkout purchase flow:
The TODO comments are the parts I need some advice on.
Beta Was this translation helpful? Give feedback.
All reactions