#MarkoBoras

1 messages · Page 1 of 1 (latest)

sharp grailBOT
mellow halo
ruby magnet
#

and how can I get what email has activated that code

mellow halo
#

You mean the customer who has redeemed the promo code?

ruby magnet
#

yeah

mellow halo
#

Are you using checkout sessions?

ruby magnet
#

yeah

mellow halo
#

OK, then you need to listen to checkout.session.completed event, and expand the breakdown field (https://stripe.com/docs/api/checkout/sessions/object?lang=node#checkout_session_object-total_details-breakdown-discounts-discount), check the discounts array to see what promo_code was used in this checkout session.

ruby magnet
#

how can I use expand breakdown discounts

#

const session = await stripe.checkout.sessions.create({
line_items: [
{
price: priceId,
quantity: quantity || 1,
},
],
mode: 'payment',
customer: customerId,
success_url: successUrl,
cancel_url: cancelUrl,
automatic_tax: { enabled: true },
customer_update: { name: 'auto' },
tax_id_collection: {
enabled: true,
},
locale: 'auto',
expand: ['breakdown'],
...options,
});

#

like this?

mellow halo
ruby magnet
#

I don't understand where I need to expand

#

when I am creating checkout

#

or in checkout.session.completed when I retrieve back session?

mellow halo
#

When you retrieve the checkout session in webhook handling.

ruby magnet
#

so I use this id like this

stripe.charges.retrieve('xxxx', {
expand: ['discounts'],
});

mellow halo
#

No, you should retrieve the checkout session object with expand :['breakdown']

ruby magnet
#

const session = await stripe.checkout.sessions.retrieve(
'{{SESSION_ID}}',
{
expand: ['breakdown'],
}
);

#

like this?

mellow halo
#

Yes you are right

ruby magnet
#

ok

#

let me hceck

#

StripeInvalidRequestError: This property cannot be expanded (breakdown).
at StripeError.generate (/layers/google.nodejs.yarn/yarn_modules/node_modules/stripe/cjs/Error.js:10:20)
at res.toJSON.then.Error_js_1.StripeAPIError.message (/layers/google.nodejs.yarn/yarn_modules/node_modules/stripe/cjs/RequestSender.js:105:54)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {

mellow halo
#

try total_details.breakdown

sharp grailBOT
ruby magnet
#

expand: ['total_details.breakdown'],

#

like this?

icy spoke
#

Hi! I'm taking over this thread.