Worklog: the ‘Pay’ Gem and Stripe Integration Rails 6
A couple helpful things I learned while integrating Stripe on a Ruby on Rails 6 application.
Stripe has made it really simple to integrate with their system, and with the help of the ‘Pay’ Gem from Chris Oliver and the crew at Jumpstart and pay-rails it is seamless.
This is not a walkthrough on how to use the gem or Stripe, but just some errors and configuration issues I worked through that might help you as well.
If you need a guide, read the docs and watch these videos.
Video Guide on Pay Gem:
Pay Gem Docs:
Stripe API Docs:
Error: Stripe Needs API key
I thought I had my credentials set up the way I needed them to but it wasn’t saving when I opened the credentials to edit them.
Solution:
Was missing the Editor mode-
EDITOR=”code — wait” rails credentials:edit --environment=development
Error: Configuring Custom Line Items
The guides use products configured on Stripe, they have a product Id you send in as the line item. If you have dynamic products in your database you can inline create line items but they are more of a stickler.
Solution:
Read over the creating a session object on the Stripe API.
Errors encountered in creating the custom line_item object:
- The product_data is a property of the price_data.
- Configuring what property goes where is something you can find on the API docs. They have the docs nested in the manner you are to nest them.
- Not a Valid URL — I thought it was because of the session success or cancel urls, but it was actually because the images in the images array need to be valid URLs.
Example if you had a cart with line_items and each of those are associated with a product in your database