Reputation: 2610
My app charges premium customers $X.00 per month, however, I would like certain actions to give customers a credit against their monthly subscription fee. For example, if a customer submits a record to the database, they are given a credit (stored in the database). I would like each credit they earn to give them $0.50 off of their next month's subscription, however, if they cancel their subscription, I do not want it to seem like I owe them that money (it should only be usable towards subscription fees). What is the best way to achieve this through the Stripe API?
If it makes a difference, I am using Rails 4, Ruby 2, Stripe, Koudoku for subscriptions, and Devise for authentication.
Thanks!
Upvotes: 2
Views: 3503
Reputation: 7714
I would give them a coupon. Coupons can have expiration dates and can be a simple percentage, which would ensure that you would owe them nothing should they unsubscribe. You could just convert your $0.50 to the appropriate percentage.
The api allows you to create coupons that you can give to users using the user update API:
Stripe.api_key = "sk_test_BQokikJOvBiI2HlWgH4olfQ2"
cu = Stripe::Customer.retrieve("cus_3oLCDGtGqkJElc")
cu.description = "Customer for [email protected]"
cu.coupon = "12OFF"
cu.save
Upvotes: 1
Reputation: 4676
You want to set your app up to handle Stripe web hooks if you haven't already done so. When a new invoice is created, if you have a web hook URL set up, it will notify you via the hook and wait an hour before processing payment. This design is setup for exactly what you want.
When you get notified the invoice has been created, if there are credits for the user, create one or more negative invoice items to represent the credits.
Since you aren't creating the credits in Stripe until right before payment processing, the scenario of them canceling with credit doesn't apply.
You can also of course do other things when adding the negative invoice items for the credits like check to make sure you aren't crediting them more than their invoice total.
Upvotes: 4