All threads / Stripe integration on Ruby On Rails

Ask A Question

Notifications

You’re not receiving notifications from this thread.

Stripe integration on Ruby On Rails

raphael asked in Rails

Hi Thank you for your great course:

i am coding with : https://www.lynda.com/Stripe-API-tutorials/Adding-Stripe-Payments-your-Ruby-Rails-Application/540343-2.html

then i got an error as follows:


Stripe::InvalidRequestError in SubscriptionsController#create
Received unknown parameter: source
Extracted source (around line #11):
begin
subscription = customer.subscriptions.create(
source: params[:stripeToken],
plan: params[:plan]
)


other functions are working but only "Subscription" related part is not working.
as far as i researched, it's attribute to version upgrade of Stripe from 1.5 to 2
"The subscription endpoints no longer support the source parameter."
source: https://stripe.com/docs/upgrades

Is there any way i can quickly fix this?

thank you

Hey Raphael,

Basically like they said, you'd just create the source rather than passing it in to the subscription

customer = Stripe::Customer.create
customer.sources.create(source: params[:stripeToken])
customer.subscriptions.create(plan: params[:plan])

thank you but i still get error

undefined local variable or method `subscription' for #<SubscriptionsController:0x007ff010ecd7d8> Did you mean? subscription_url
Extracted source (around line #20):

18customer.subscriptions.create(plan: params[:plan])
19
20  current_user.assign_attributes(stripe_subscription_id: subscription.id)
21      current_user.assign_attributes(
22       card_brand: params[:card_brand],
23        card_last4: params[:card_last4],

with updated code:

class SubscriptionsController < ApplicationController
  before_action :authenticate_user!

  def new
  end

  def create
    customer = current_user.stripe_customer

    begin
  #    subscription = customer.subscriptions.create(
  #     customer = Stripe::Customer.create
  #       customer.sources.create(source: params[:stripeToken])
        # customer.subscriptions.create(plan: params[:plan])
  #     )
        customer = Stripe::Customer.create
        customer.sources.create(source: params[:stripeToken])
        customer.subscriptions.create(plan: params[:plan])

You need to save the new subscription to a variable.

subscription = customer.subscriptions.create(plan: params[:plan])

thank you very much :D

this is working! wonderful :D

  def create
    begin
    customer = current_user.stripe_customer
    customer.sources.create(source: params[:stripeToken])
    subscription = customer.subscriptions.create(plan: params[:plan])

Hi Chris,

I was dealing with this same error for days!!!! and with this responses you solve my problem!!! So many thanks!!! AMAZING TUTORIALS!

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 34,674+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.