Stripe with rails

Umeriqbal
2 min readDec 4, 2023

--

stripe integration with ruby on rails

add

gem 'stripe'

in your gem file and the ruby “bundle install” command

crate stripe.rb file in initializers
config/initializers/stripe. rb and the secret key init

Stripe.api_key = 'sk_test_51OC....'

you will get that secret key form your stripe account in developer tab under api key and then reveal secret key

to hide it form public you can add that secret key in rails credentials file here is how you can do that.
run the following command in you terminal

EDITOR=nano rails credentials:edit

then add the public and secret key in that file like this.

stripe:
secret_key: sk_test_51OCcup....
public_key: pk_test_51OCcup...

after that press Ctrl+x, then enter “y” and then press enter key

here is how you can access that encoded keys in stripe.rb file that we create earlier or at any place in the application

Stripe.api_key = Rails.application.credentials[:stripe][:secret_key]

if you already open the rails console than close it and and again open it and check the already created customer on the stripe account like below

3.2.2 :001 > Stripe::Customer.list
=>
#<Stripe::ListObject:0x7648> JSON: {
"object": "list",
"data": [

if you get this type of response then its means you success fully configure the stripe.

related stripe with rails articles

  1. Buy local products (product save on our on server) through stripe with rails
  2. Add customer and payment method on Stripe with ruby on rails
  3. Create product and price on stripe using ruby on rails
  4. How to buy products through stripe using ruby on rails

--

--

Umeriqbal

I am a full stack software engineer specializing in Ruby on Rails, I have extensive experience in developing and deploying web applications.