DEV Community

Cover image for Integrate Stripe in your Ruby on Rails app

Integrate Stripe in your Ruby on Rails app

Oksana Ivanchenko on March 20, 2019

Creating a workspace We will start by creating a Ruby on Rails application $ rails new tuto $ cd tuto $ bundle install Enter f...
Collapse
 
yverbytskyi profile image
Yurii Verbytskyi

Hi, what's the point of defining instance variable in BillingController

  @user=current_user.email
Enter fullscreen mode Exit fullscreen mode

if you can use

current_user.email
Enter fullscreen mode Exit fullscreen mode

directly in views using Rails?
P.S. It's strange to see this part of code in turorials:

  subscriptions.each do |subscription|
    subscription.delete
  end
Enter fullscreen mode Exit fullscreen mode

Instead of this one:

  subscriptions.each(&:delete)
Enter fullscreen mode Exit fullscreen mode
Collapse
 
wbouvier profile image
Wbouvier

[gestionstock]$rails server
=> Booting WEBrick
=> Rails 4.1.16 application starting in development on 0.0.0.0:3000
=> Run rails server -h for more startup options
=> Notice: server is listening on all interfaces (0.0.0.0). Consider using 127.0.0.1 (--binding option)
=> Ctrl-C to shutdown server
Exiting
/Users/wbouvier/Sites/Rails/gestionstock/config/environments/development.rb:33:in block in <top (required)>': undefined methodcredentials' for #Gestionstock::Application:0x007fb2... (NoMethodError)

Collapse
 
daneb profile image
Dane Balia • Edited

@ksushiva - thank you so much for this article. Was very valuable in a project I was working on.

PS. There is a small typo (as per below) and an extra "end" for the subscribe method:

In config/root.rb:
Collapse
 
wbouvier profile image
Wbouvier

Bonjour,
Je dois intégrer Stripe à un site déjà existant. En suivant les étapes, après le 1er lancement du rails s (After that in terminal we run 'rails s' and after clicking on our button we should have something like this: )
j'ai me message d'erreur en pièce jointe.
Pourriez-vous me donner un coup de main ?
Merci.
Wilfried.

Collapse
 
ksushiva profile image
Oksana Ivanchenko

Hello, votre version de rails est 4.1.1. Les "encrypted credentials" de rails ne sont disponibles qu'avec rails 5.2+. Vous pouvez utiliser des variables d'environnement à la place pour enregistrer vos informations d'identification stripe.

Hi, Your rails version is 4.1.1. The rails encrypted credentials are only available with rails 5.2+. You can use environment variables instead to save your stripe credentials.

Collapse
 
wbouvier profile image
Wbouvier

Hi,

cela fonctionne.
Merci beaucoup, je continue les étapes.

Bon week-end.
Wilfried

Collapse
 
jalovatt profile image
Adam Lovatt

Great tutorial. One problem - this line in "Linking a card to a user" didn't work for me:

<%= form_tag create_payment_method_path, id: "billing-create-payment-method" do %>

It ended up creating a form with action=/id.... :( This worked:

<%= form_tag create_payment_method_path, :id => "billing-create-payment-method" do %>

Collapse
 
ammar299 profile image
ammar299

i want to get subscription please help.. here is my code
module BillingHelper
def check_if_user_already_subscribe(plan_id)
customer = Stripe::Customer.new current_user.stripe_id
subscriptions = Stripe::Subscription.list(customer: customer.id)
plan_ids = get_from_subcriptions
if plan_ids.include?(plan_id)
true
else
false
end
end
end

Collapse
 
francelwebdev profile image
Francel

Bonsoir Oksana Ivanchenko,
Merci baucoup pour ton tutoriel. Merci encore, je suis africain pasionné par le développement web. j'ai appris ruby et rails par moi même et j'ai seulement les bases de rails. pourrai tu m'epprendre les techniques avancés de rails ? SVP, apprenez moi quelques technique avancés sur rails afin que je puisse acquérir plus de connaissance et me perfectionner.
Merci encore Oksana Ivanchenko,
Francel

Collapse
 
david_j_eddy profile image
David J Eddy

Excellent article Oksana. I will actually have to do this exact thing very soon.

Collapse
 
booz profile image
bo-oz

Any thoughts on if/how to store transactions in a local Rails model? Or do you totally depend on those objects/records living in Stripe?

Collapse
 
aonomike profile image
Mike Aono

Thanks so much for this tutorial, really great @ksushiva ! Could you know of a step to step implementation to have this implemented for the current SCA improvements. Apologies for my english

Collapse
 
eugenedm profile image
eugenedm

Hi Oksana! What happens if the person cancels the payment / card for the upcoming month? How do you handle that?

Thanks for your article! :) Good work.