Created
October 14, 2012 01:07
-
-
Save coderforhire/3886841 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@coupon = params[:coupon_code][:coupon] | |
respond_to do |format| | |
if @subscription.save_with_payment(@subscription.plan, @user.email,@coupon) && @user.save |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.