Class: Account::CouponsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Account::CouponsController
- Defined in:
- app/controllers/tang/account/coupons_controller.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/controllers/tang/account/coupons_controller.rb', line 5 def create @coupon = Coupon.find_by(stripe_id: params[:coupon][:stripe_id]) if @coupon.present? if current_customer.subscription.present? subscription = ApplySubscriptionDiscount.call( current_customer.subscription, @coupon ) if subscription.errors.any? redirect_to account_subscription_path, alert: 'Coupon could not be applied.' return end else current_customer.subscription_coupon = @coupon current_customer.save end redirect_to account_subscription_path, notice: 'Coupon was successfully applied.' else redirect_to account_subscription_path, alert: 'Coupon could not be applied.' end end |
#destroy ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/controllers/tang/account/coupons_controller.rb', line 27 def destroy if current_customer.subscription.present? RemoveSubscriptionDiscount.call( current_customer.subscription ) else current_customer.subscription_coupon = nil current_customer.save end redirect_to account_subscription_path, notice: 'Coupon was successfully removed.' end |