#emilevl_promotion-codes

1 messages ยท Page 1 of 1 (latest)

teal cometBOT
#

๐Ÿ‘‹ 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/1460287447467298939

๐Ÿ“ 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.

fringe plover
#

Hello again
You add the expand as an second additional parameter to the all function

#

The doc I shared has an example

#

Something like

                    'code' => $couponCode,
                    'active' => true,
                    'limit' => 1,
                    'expand' => ['data.applies_to']
                  ]);```
subtle cedar
#

Ok, I tried that, but it's not working.
Here's what I send, and what's the result :

$promotionCodes = $stripe->promotionCodes->all([
'code' => $couponCode,
'active' => true,
'limit' => 1
]);
Log::info('Promotion code lookup', [
'coupon_code' => $couponCode,
'found_count' => count($promotionCodes->data),
]);
Log::info("PROMOTION CODES", ['promotion_codes' => $promotionCodes->data]);

[2026-01-12 15:05:33] local.INFO: Promotion code lookup {"coupon_code":"ADVANCED12","found_count":1}
[2026-01-12 15:05:33] local.INFO: PROMOTION CODES {"promotion_codes":[{"Stripe\PromotionCode":{"id":"promo_xyz","object":"promotion_code","active":true,"code":"ADVANCED12","coupon":{"id":"12","object":"coupon","amount_off":null,"created":1768224332,"currency":null,"duration":"once","duration_in_months":null,"livemode":false,"max_redemptions":null,"metadata":[],"name":"12 ON Advanced","percent_off":12.0,"redeem_by":null,"times_redeemed":0,"valid":true},"created":1768224332,"customer":null,"customer_account":null,"expires_at":null,"livemode":false,"max_redemptions":null,"metadata":[],"restrictions":{"first_time_transaction":false,"minimum_amount":null,"minimum_amount_currency":null},"times_redeemed":0}}]}

-> No "applies_to"

With the expand :

$promotionCodes = $stripe->promotionCodes->all([
'code' => $couponCode,
'active' => true,
'limit' => 1,
'expand' => ['data.applies_to'],
]);
Log::info('Promotion code lookup', [
'coupon_code' => $couponCode,
'found_count' => count($promotionCodes->data),
]);
Log::info("PROMOTION CODES", ['promotion_codes' => $promotionCodes->data]);

Nothing changes on the log

fringe plover
#

Are you sure you've saved your code and your server is running your latest code?

subtle cedar
#

Yes

fringe plover
#

I just tested it with my test account and seems to work for me

subtle cedar
#

If I understand well the doc, I can expand a parameter that is a part of the response, such as "coupon", or "customer".
Which means that I cannot see the applies_to as it doesn't exist in the response

#

Here's my coupon :

#

It applies only on the produc "Advanced"

teal cometBOT
subtle cedar
#

I added a log "Hello world" to see it's updated :
Log::info("Hello world");
$promotionCodes = $stripe->promotionCodes->all([
'code' => $couponCode,
'active' => true,
'limit' => 1,
'expand' => ['data.applies_to']
]);
Log::info('Promotion code lookup', [
'coupon_code' => $couponCode,
'found_count' => count($promotionCodes->data),
]);
Log::info("PROMOTION CODES", ['promotion_codes' => $promotionCodes->data]);
return;

The response :
[2026-01-12 15:14:18] local.INFO: Hello world

-> it doesn't show the rest (probably because I'm on try-catch method and an error occurs when I added the 'expand'

fringe plover
#

Ah wait

#

you're getting all promotions codes

subtle cedar
#

Yes, but add the 'code' and limit to 1 to get the specific coupon code

fringe plover
#

the exapnd needs to be on coupon instead

#

try passing expand => ['data.coupon.applies_to']

subtle cedar
#

[2026-01-12 15:17:13] local.INFO: Promotion code lookup {"coupon_code":"ADVANCED12","found_count":1}
[2026-01-12 15:17:13] local.INFO: PROMOTION CODES {"promotion_codes":[{"Stripe\PromotionCode":{"id":"promo_1Sol7gQKHTcUY7RJ1yZEQOYo","object":"promotion_code","active":true,"code":"ADVANCED12","coupon":{"id":"12","object":"coupon","amount_off":null,"applies_to":{"products":["prod_SglSWn9yCsKOP7"]},"created":1768224332,"currency":null,"duration":"once","duration_in_months":null,"livemode":false,"max_redemptions":null,"metadata":[],"name":"12 ON Advanced","percent_off":12.0,"redeem_by":null,"times_redeemed":0,"valid":true},"created":1768224332,"customer":null,"customer_account":null,"expires_at":null,"livemode":false,"max_redemptions":null,"metadata":[],"restrictions":{"first_time_transaction":false,"minimum_amount":null,"minimum_amount_currency":null},"times_redeemed":0}}]}

#

It worked

#

Thank you

fringe plover
#

NP! ๐Ÿ™‚ Happy to help
Sorry for the confusion

teal cometBOT