08-19 Stripe Checkout Migration
2019-08-19
Spent the weekend migrating the payment processing system to use Stripe's new Checkout portal.
Problem
Stripe's modal Checkout window which is being depricated. AVWX uses this for credit card entry and storage when upgrading to a paid account.
Solution
Migrate to the full-page Checkout which will continue being supported and provides additional payment options.
Process
Stripe offers a Checkout migration guide to start with. I determined that I was using the dynamic subscription method which requires both frontend and backend changes. This would replace the plans.new_subscription
and "Subscribe" button calls with some additional handling.
After making the new "Subcribe" button, the page sends a Checkout Session object and redirects the user to the payment page. On success or cancel, Stripe redirects the user to a success or failure endpoint back in the app. They warn not to use the success page to fulfill the request since it doesn't guarentee that the payment went through.
They offer a few ways to verify a completed Checkout Session. I opted to register a webhook that would be triggered after a completed session. It first verifies the session in the POST with Stripe to stop any fraudulent calls. It then applies the new customer ID, subscription ID, and plan ID to the user.
The user is tracked through this process by passing the user ID to the Check Session object. I tried to use email and existing customer IDs, but these did not guarentee the same user would be found during fulfillment. Stripe sometimes changed the customer ID, and supplying just the email for existing users would create duplicates. I still pass Stripe the email for new customers so I can associate accounts in the Stripe dashboard during support requests.
During this process, I also found a bug that prevented free tier users from generating their first token. This was a remnant check when users needed paid accounts to generate a token. This check logic has been fixed and moved into the User class instead of the token view.
Result
The payment system now redirects users to Stripe to enter their credit card information. Users can now also use Apple Pay with more options available as Stripe adds them with no code changes needed on my part. This upgrade does not affect paid-to-paid and paid-to-free changes. I also fixed a nasty bug for new users.
Next Steps
A user mentioned that there is no method to update their credit card information without affecting their current plan. That is the next feature I need to address.