Skip to content

Instantly share code, notes, and snippets.

@coderforhire
Created October 14, 2012 01:07
Show Gist options
  • Save coderforhire/3886841 to your computer and use it in GitHub Desktop.
Save coderforhire/3886841 to your computer and use it in GitHub Desktop.
def save_with_payment(plan, email,coupon_code)
if valid?
if coupon_code == 'LAUNCHDAY' || coupon_code = 'launchday'
customer = Stripe::Customer.create(description: "#{email}", plan: "#{plan}", card: stripe_card_token, coupon: "LAUNCHDAY")
self.stripe_customer_token = customer.id
save!
else
customer = Stripe::Customer.create(description: "#{email}", plan: "#{plan}", card: stripe_card_token )
self.stripe_customer_token = customer.id
save!
end
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
@coupon = params[:coupon_code][:coupon]
respond_to do |format|
if @subscription.save_with_payment(@subscription.plan, @user.email,@coupon) && @user.save
@Ryman
Copy link

Ryman commented Nov 12, 2012

The following condition will always be true, you should fix that if you haven't spotted it yet... The right hand is assigning, which is truthy.

if coupon_code == 'LAUNCHDAY' || coupon_code = 'launchday'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment