djaodjin / djaodjin-saas

Django application for software-as-service and subscription businesses
Other
564 stars 124 forks source link

Investigate to merge Charge.payment_successful on checkout request in RazorPay setup #101

Open smirolo opened 8 years ago

smirolo commented 8 years ago

The flow to subscribe and pay for a plan is as follow:

  1. POST to /api/cart/
  2. GET /api/billing/:organization/checkout/
  3. compute the total amount to charge from the list of invoicables.
  4. POST to RazorPay
  5. POST /api/billing/:organization/checkout/ with {“processor_token”: token-returned-by-razorpay} This will call RazorpayBackend.create_charge_on_card to capture the total amount of invoicables.
  6. GET /api/billing/charges/:charge (:charge being return by the previous call as "processor_key") This will call Charge.payment_successful and create the Transaction in the database as well as switch Charge.state from "created" to “done".

RazorPay works somewhat differently from Stripe. The processor_token passed back by RazorPay is an actual charge id. The processor_token passed back by Stripe is a card id. It is quite possible that payment_successful could be called after razorpay.capture and make step #6 optional in RazorPay setup.