Coupon validation

349 views
Skip to first unread message

Jerome Kures

unread,
Feb 16, 2017, 3:16:19 PM2/16/17
to Stripe API Discussion
Good morning all

I am looking for a way to validate if the customer is allowed to use a coupon before asking for payment.
In my case, I use coupons which can be redeemed only once when attached to a customer: when I compute the amount for the cart, I need to be sure that the customer has not already used the coupon.

Is there a way to check if the coupon can still be used using Stripe API?

Many thanks for your tips.

Have a great day

JK

Zach Wick

unread,
Feb 16, 2017, 4:18:58 PM2/16/17
to api-d...@lists.stripe.com
Hi there,

In order to determine if a particular `Coupon` is already attached to a particular `Customer` object, you should inspect the `discounts` property on the `Customer` object (https://stripe.com/docs/api/python#customer_object-discount). This property will have a null value if there are currently no `Discount` objects associated with that particular `Customer` object. If there is a `Discount` object associated with this particular `Customer` object, then the `discount` property will contain the associated `Coupon` object (as the value of the `coupon` property), and the timestamp of when this particular `Coupon` was associated with this particular `Customer` as the value for the `start` property.

A `Customer` can only have a single associated `Coupon` at a given time, so inspecting this property on the `Customer` object will be sufficient to determine if the `Customer` has already been associated with this `Coupon`.

If you want a clean mapping of `Customer` objects to `Coupon` objects, you should maintain this mapping in your own system. There is not an easy way via the Stripe API to retrieve all of the uses of a particular `Coupon`. Maintaining such a mapping in your own system would also allow you to easily create a single unique `Coupon` per `Customer`.

If you have specific questions about implementing this, I would suggest that you write in to sup...@stripe.com instead of this list.

Good luck and happy hacking!
-zach






--
You received this message because you are subscribed to the Google Groups "Stripe API Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to api-discuss+unsubscribe@lists.stripe.com.
To post to this group, send email to api-d...@lists.stripe.com.
Visit this group at https://groups.google.com/a/lists.stripe.com/group/api-discuss/.

Jim Danz

unread,
Feb 16, 2017, 4:19:17 PM2/16/17
to api-d...@lists.stripe.com
Hi Jerome,

Yes, you'll want to retrieve the coupon from the API (GET
/v1/coupons/:code -- https://stripe.com/docs/api#retrieve_coupon) and
look at the `valid` property:

https://stripe.com/docs/api#coupon_object-valid
The valid property takes into account redemptions and determines
whether or not the coupon can still be applied to a customer.

Best,
Jim
> --
> You received this message because you are subscribed to the Google Groups
> "Stripe API Discussion" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to api-discuss...@lists.stripe.com.
Reply all
Reply to author
Forward
0 new messages