# Output
There was a problem with your credit card... Invalid token id: {"id":"tok_0mGwLfZ5qsNQNF","created":1353523130,"livemode":false,"object":"token","used":false,"card":{"address_city":null,"address_country":null,"address_line1":null,"address_line2":null,"address_state":null,"address_zip":null,"country":"US","exp_month":11,"exp_year":2013,"fingerprint":"R9OsenuJeu0Pp5CS","last4":"4242","name":null,"object":"card","type":"Visa"}}
person_1@example.com
------------------
# ... In Spec...
before do
subscription.plan_id = "swc_teacher"
subscription.stripe_card_token = Stripe::Token.create( card: { number: "4242424242424242", exp_month: Date.today.month, exp_year: Date.today.year+1, cvc: "314" } )
puts subscription.save_with_payment
puts subscription.user.email
end
------------
# ... In SubscriptionController ...
def save_with_payment
if self.valid?
customer = Stripe::Customer.create(description: self.user.email, plan: self.plan_id, card: self.stripe_card_token )
self.stripe_customer_token = customer.id
self.subscription_expires_on = 1.year.from_now
self.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... #{e.message}"
end