#MarkoBoras
1 messages · Page 1 of 1 (latest)
Hi there, https://stripe.com/docs/api/promotion_codes/object?lang=node#promotion_code_object-times_redeemed you can get the times_redeemed from the promo code object directly.
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
and how can I get what email has activated that code
https://stripe.com/docs/api/events/types#event_types-promotion_code.updated and this is the event.
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
You mean the customer who has redeemed the promo code?
yeah
Are you using checkout sessions?
yeah
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.
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
From the same checkout session you can also get the customer_email (https://stripe.com/docs/api/checkout/sessions/object?lang=node#checkout_session_object-customer_email)
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
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?
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
I don't understand where I need to expand
when I am creating checkout
or in checkout.session.completed when I retrieve back session?
When you retrieve the checkout session in webhook handling.
so I use this id like this
stripe.charges.retrieve('xxxx', {
expand: ['discounts'],
});
No, you should retrieve the checkout session object with expand :['breakdown']
const session = await stripe.checkout.sessions.retrieve(
'{{SESSION_ID}}',
{
expand: ['breakdown'],
}
);
like this?
Yes you are right
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) {
const session = await stripe.checkout.sessions.retrieve(request.body.data.object.id, {
expand: ['breakdown'],
});
try total_details.breakdown
Hi! I'm taking over this thread.