Rails Payola: Add a Coupon to an Existing Subscription

We are working on a SaaS product that uses Payola to process payment, and we would like to add referral promotion. Adding a referee coupon is quite simple (a hidden field in the form with a coupon code), but there seems to be no obvious way to apply the coupon to an existing subscription.

I checked the source of Payola and it seems that there are no methods applying the coupon code for an existing subscription, only for a new one.

Is it possible to simply get a Stripe :: Customer object and use this answer: How to apply a coupon to a Stripe client to apply a coupon? Will it ruin Payola?

+4
source share
1 answer

Payola , , Stripe. , subscription_controller.rb: 28, , Payola ( Payola , before_filter find_plan_coupon_and_quantity, change_plan. find_plan_coupon_and_quantity @coupon = cookies[:cc] || params[:cc] || params[:coupon_code] || params[:coupon]). , , Payola::ChangeSubscriptionPlan.call(@subscription, @plan), change_subscription_plan.rb: 3 retrieve_subscription_for_customer . , .

def self.retrieve_subscription_for_customer(subscription, secret_key)
  customer = Stripe::Customer.retrieve(subscription.stripe_customer_id, secret_key)
  customer.subscriptions.retrieve(subscription.stripe_id)
end

Payola .

, , Payola, . , messing Payola: , Payola, , , Payola, .

, , , .

+3

All Articles