Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve a Stripe Promo code by code

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.

like image 231
riley Avatar asked Oct 17 '20 21:10

riley


People also ask

What is the promo code number?

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.

How do I find hidden promo codes on websites?

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 ...


1 Answers

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
like image 187
koopajah Avatar answered Oct 10 '22 09:10

koopajah