5

I have a subscription and if I update it with coupon how is the coupon going to apply? Client has already paid the amount and now I am going to apply a 100% discount coupon by editing from my admin dashboard.

How is this handled?

thanks

Shiva
  • 11,485
  • 2
  • 67
  • 84

2 Answers2

7

This is how I did.

First I updated the customer's subscription:

customer = Stripe::Customer.retrieve(customer_id)
subscription = customer.retrieve(subscription_id)
subscription.coupon = "coupon_id"
subscription.save

The customer's subscription is then updated with details of the coupon in the discount hash.

Then I manually refunded the charge object of that customer(if the coupon is 100% discount coupon).

charge = customer.retrieve(stripe_charge_id)
refund = charge.refund

This then updates the charge object with amount_refunded with the discounted amount after applying the coupon. Also refunded is set to true with updated refunds hash.

You can also create a refund for certain amount by passing the amount, like:

re = Stripe::Refund.create(  
                           charge: charge_id,
                           amount: amount_you_want_to_refund
                          )

For the upcoming invoices, the invoice is created for that discounted amount.

Neha Suwal
  • 371
  • 1
  • 7
  • means, if we do not refund manually, the discount will apply only to upcoming invoices? – Shiva Mar 16 '16 at 04:49
3

Here's how you'd update an existing subscription with a coupon in Ruby:

customer = Stripe::Customer.retrieve("cus_...")
subscription = customer.subscriptions.retrieve("sub_...")
subscription.coupon = "coupon_code"
subscription.save

The coupon will apply to the next invoice(s) for this subscription, but the past invoices will not be affected.

Ywain
  • 16,854
  • 4
  • 51
  • 67