RailsCasts Pro episodes are now free!

Learn more or hide this

jscanlon13's Profile

GitHub User: jscanlon13

Comments by

Avatar

Hi Guys. Followed the tutorial above and getting an error with the stripe_token not being passed. Am getting the following error

Parameters: {"utf8"=>"V", "authenticity_token"=>"JLYuag3ojhYttMw3YOLBD5+J7NUly
zM61YFgRhKkc3M=", "subscription"=>{"stripe_card_token"=>"", "plan_id"=>"8", "ema
il"=>"test@mail.com"}, "commit"=>"Subscribe"}
←[1m←[35mPlan Load (0.0ms)←[0m SELECT "plans".* FROM "plans" WHERE "plans"."i
d" = ? ORDER BY "plans"."id" ASC LIMIT 1 [["id", 8]]
Stripe error while creating customer: You passed an empty string for 'card'. We
assume empty values are an attempt to unset a parameter; however 'card' cannot b
e unset. You should remove 'card' from your request or supply a non-empty value

subscription.rb
 class Subscription < ActiveRecord::Base
        belongs_to :plan
        validates_presence_of :plan_id
  validates_presence_of :email

  attr_accessor :stripe_card_token

  def save_with_payment
    if valid?
      customer = Stripe::Customer.create(description: email, plan: self.plan.name, card: stripe_card_token)
      self.stripe_customer_token = customer.id
      save!
    end
  rescue Stripe::InvalidRequestError => e
    logger.error "Stripe error while creating customer: #{e.message}"
    errors.add :base, "There was a problem with your credit card."
    false
  end

end

```jQuery ->
Stripe.setPublishableKey($('meta[name="stripe-key"]').attr('content'))
subscription.setupForm()

subscription =
setupForm: ->
$('#new_subscription').submit ->
$('input[type=submit]').attr('disabled', true)
subscription.processCard()
false

processCard: ->
card =
{number: $('#card_number').val(),
cvc: $('#card_code').val(),
expMonth: $('#card_month').val(),
expYear: $('#card_year').val()}

Stripe.createToken(card, subscription.handleStripeResponse)

handleStripeResponse: (status, response) ->
if status == 200
$('#subscription_stripe_card_token').val(response.id)
$('#new_subscription')[0].submit()
else
$('#stripe_error').text(response.error.message)
$('input[type=submit]').attr('disabled', false)```

Any help would be greatly appreciated