It looks like in Stripe you can retrieve a promo code by id:
Stripe::PromotionCode.retrieve(
'promo_1Hd0sBG03p6y1vChab7Jh6Zs',
)
However, I can not see a way to retrieve this by the actual customer facing code ex FIFTYOFF
. Is there any way to do this?
It doesn't seem to make sense this is not possible, since this is all the data the user would have. I would need to either keep a local database duplicate of each Promo code and correlate with the customer facing code, or lookup all of my codes and iterate over them to find the actual promo code id.
What are promo codes? Promotional codes are alphanumeric strings that online stores offer to encourage purchases on their website and are typically associated with an overarching promotional marketing strategy. The discount associated with a promo code can apply to individual products or an entire order.
Right-click just about anywhere on the website and select “View source.” Hit CTRL+F (or CMD+F) to search the code and type “promocode.” We will find two variables in particular that interest me: “dealPromoCodeApiUrl” and “promoCodeList.” The first variable contains a partial URL to a JSON-file (a file with some ...
The easiest solution is to use the List Promotion Codes API and pass the code
parameter. This will return a list of Promotion Codes with that code and since it has to be unique, the list will only contain one element which is what you are after:
promotion_codes = Stripe::PromotionCode.list({
code: 'FIFTYOFF',
})
promotion_code_id = promotion_codes.data[0].id
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With