Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

uninitialized constant Stripe::Error

I'm hitting an uninitialized constant, while working with Stripe, Rails (3.2.8) and Ruby (1.9.2).

Initially, my Sales model used the following (this works!):

def charge_card
  begin
    save!
    charge = Stripe::Charge.create(
      amount: self.amount,
      currency: "usd",
      card: self.stripe_token,
      description: self.email,
    )
    self.finish!
  rescue Stripe::Error => e
    self.update_attributes(error: e.message)
    self.fail!
  end
end

Then, I decided I wanted to update that record with some additional information from Stripe, so I changed it to the following:

def charge_card
  begin
    save!
    charge = Stripe::Charge.create(
      amount: self.amount,
      currency: "usd",
      card: self.stripe_token,
      description: self.email,
    )
    self.update(
      stripe_id:       charge.id,
      card_expiration: Date.new(charge.card.exp_year, Charge.card.exp_month, 1),
      fee_amount:      charge.fee
    )
    self.finish!
  rescue Stripe::Error => e
    self.update_attributes(error: e.message)
    self.fail!
  end
end

This results in the following: uninitialized constant Stripe::Error

I'd love to get some help/guidance on how I can properly update the record.

Thanks!

like image 205
cmw Avatar asked Jul 16 '26 13:07

cmw


1 Answers

First add stripe to your gemfile

gem 'stripe'

then do a bundle install

then create a file config/initializers/stripe.rb and put in the following code

require "stripe"

now restart your server.

like image 67
Charizard_ Avatar answered Jul 19 '26 01:07

Charizard_



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!