nodejs - how to handle payment

Viewed 149

Background:
I am working on making nodejs function for payment using stripe.

My clients would have their own reward point, which can turn into cash dollar for payment

Current Design
Customer Table(mySQL)

-id: string(primary key)
-rewardPoints: int

Therefore I am working on 2 api seperately.

/transaction/debit-points 
   -this api is used to debit the reward point of clients when they want to turn it into cash dollar(debit the rewardPoints in Customer table)

/payment
   -this api will use stripe api to handle some credit card payment etc

Example
Let's say 100 reward points can turn into $1 cash dollar

Customer A is going to settle payment which is $200.
Customer A have 1000 reward points and want to turn all of it into cash dollar in this payment.

At first, I will use /transaction/debit-points to debit all 1000 reward points for the customer, and then use /payment to settle the payment.

1. /transaction/debit-points
2. /payment (run if /transaction/debit-points is successful)

If /payment fails, I want to reverse the effect of /transaction/debit-points, is it possible to do it in nodejs?

Or is there any better way?

0 Answers
Related