Is this possible?
I need to print out the terms of the coupon. I'm able to successfully get the name of the coupon that was used with $('.coupon-results__code').text(data.name);
type of code.
But what I also need to do is get the "terms" so in other words:
Getting this somehow on the page after a successful call. I looked at the docs for the coupon object and don't see this as an option:
https://stripe.com/docs/api/coupons/object
{
"id": "KaaHJ1Lw",
"object": "coupon",
"amount_off": 700,
"created": 1556545860,
"currency": "usd",
"duration": "forever",
"duration_in_months": null,
"livemode": false,
"max_redemptions": null,
"metadata": {},
"name": "DISCONAPZ!",
"percent_off": null,
"redeem_by": null,
"times_redeemed": 0,
"valid": true
}
Is it at all possible to grab terms information? Or should this be done with metadata?
You do have the info, but you have to reconstruct it:
$.amount_off: 700
$.duration: "forever"
$.currency: "usd"
Stripe has decided not to add another field with info they are already providing. The bad thing is you have to write the logic yourself on how to reconstruct the terms, but the data is all there.
Terms
is just logically built from the other fields and localized, which you can do yourself.
When dealing with English, you take either the percentage off or the currency w/ amount , then append the duration (including the word "for" for recurring coupons).
Some examples:
{ percent_off: 5.0, duration: "forever" }
=> "5% off forever"
{ amount_off: 500, currency: "usd", duration: "once" }
=> "$5.00 off once"
{ amount_off: 500, currency: "usd", duration: "repeating", duration_in_months: "3" }
=> "$5.00 off for 3 months"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.