rootstrap/blog

How to work with Stripe

fedeagripa opened this issue ยท 2 comments

How to work with stripe

Motivation:

As stripe is one of the most common options to implement payments (also the first one we propose here at rootstrap) I find it useful to explain a bit how it works and how you data structures and flows should be (for advanced usage it may be a second post)


๐Ÿ“Œ Notes:

					HOW TO WORK WITH STRIPE

WHY STRIPE?
	Pros
		Easy to implement and use
		Fast to implement
		Solves most of your usual payment problems, so you don't lose life
	Cons
		Expensive (high % fee)
	
INSTALLATION
	RAILS
	REACT

START USING IT
	CREDIT CARDS
		REACT
                        DO YOURSELF A FAVOR AND USE THE EXISTING COMPONENT
		RAILS
			DONT TRY TO STORE ALL INFO (ITS ILEGAL)
	SUBSCRIPTIONS
		CREATING THEM
		RENEWALS
			DONT OVERTHINK IT, THERE IS JUST A WEBHOOK FOR MOST OF YOUR CASES
	SUBSCRIPTION ITEMS
	DISCOUNTS

	WEBHOOKS
		There is a lot of them, they will solve most of your problems, the only downcase, is a mess trying to understand when exactly to use which one

SPECIAL RECOMMENDATIONS
Try not to use old versions or take too much 

๐Ÿ” Keywords:

Stripe
Ruby
React
Payment


@sebaherrera07 When some time take a look at my initial schema and comment on it ๐Ÿ‘Š

I suggest including the following things:

1. Differences between Charge and Payment Intent. Personally used Charges, but I know you can also use Payment Intent.
https://stripe.com/docs/payments/payment-intents/migration/charges
https://stripe.com/docs/api/charges/object
https://stripe.com/docs/api/payment_intents

2. Option to capture Charge immediately or not. Explain the differences, and how to work with both of them.
https://stripe.com/docs/api/charges/create#create_charge-capture
https://stripe.com/docs/api/charges/capture

3. Good practices regarding payments consistency. The implementation should consider the following practices:
a. Use the charge metadata to be able to associate the Stripe charges, with your database records (user_id / user_email, order_id / order_number, payment_id)
https://stripe.com/docs/api/charges/create#create_charge-metadata
b. For payments consistency, save the payment record in your database with pending status, before actually calling Stripe API, and update its status to success or fail after Stripe response. This may require a background job checking and resolving for inconsistent payments.
https://blogs.dropbox.com/tech/2017/09/handling-system-failures-during-payment-communication/
c. For payments consistency, you may also use idempotency keys. This is another strategy different form (b), you may choose one or the other.
https://stripe.com/docs/api/idempotent_requests