#yash_code

1 messages ยท Page 1 of 1 (latest)

woeful cedarBOT
#

๐Ÿ‘‹ Welcome to your new thread!

โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

๐Ÿ”— This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1405261225356689471

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

clear hornet
#

Hi there ๐Ÿ‘‹ sorry, but I don't think you shared enough context for me to really grasp what you're trying to do or what problem you're running into. Can you elaborate more about the code you're running, what response it's receiving, and what response you expected instead?

feral holly
#

Sure

#

I have a coupon in which I have added a applied products, now when user tries to apply a coupon for a product, I want to validate whether coupon is available for a product or not.
Currently we are just doing this:
def get_promo_code(code)
with_retries do
promo_code = Stripe::PromotionCode.list.data
promo_code.select { |item| item.code.downcase == code.downcase && item.active }[0]
end
end

which return true for all the products even it has validation, now what I tried I tried searching for product attach it, so from the doc I found they were not directly accessible, we need to find coupon with expand.

then I tried this

promo_codes = Stripe::PromotionCode.list(
  active: true,
  expand: ['applies_to']
)

which will return applies_to and by using it we can find the products but it return undefined methods

clear hornet
#

Gotcha. Your code is retrieving Promotion Code objects, but applies_to is a field on Coupon objects.

You'll need to list Coupon objects instead if you want to be able to expand the applies_to field on the results.

feral holly
#

promo_code = Stripe::PromotionCode.list.data

You mean I want to pass expand option with this?

#

coupons = Stripe::Coupon.list({
expand: ['data.applies_to']
})

Got with this Thank you

clear hornet
#

Ah, sorry, juggling a couple threads and you found the answer before I could finish typing it. Yup, you're spot on! Glad that helped!

While they're related, Promotion Codes and Coupons are two distinct types of objects within our API.

feral holly
#

Thanks what is the difference b/w them?

clear hornet
#

Coupons are the more internal object, and Promotion Codes are the more customer-facing object.

Your customers use Promotion Codes on hosted Stripe surfaces (like our Checkout Sessions) to redeem your Coupons. They have more restriction controls available as well.

Coupons cannot be used by your customers, they're only used by you and your system.

Coupons can have any number of Promotion Codes associated with them, but each Promotion Code can only be associated with a single Coupon.

feral holly
#

Hmm got it thank you soo much