#puya_17680
1 messages · Page 1 of 1 (latest)
Hello! We'll be with you shortly. 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.
- puya_17680, 23 hours ago, 30 messages
- puya_17680, 1 day ago, 70 messages
It should just work AFAIK? Does it not? Is there an error?
the tax_id_collection it's working yes
but I need to add a custom field just when it's enabled
how I can do it?
Then you'd add some logic to your code to only add the custom_fields parameter when you're passing tax_id_collection
is there any example?
Not really no. Would depend on what language you're using
i'm using nextjs
Ok, so Node.js. So you likely want to conditionally add the custom_field parameter depending on some state or something:
...(addCustomFields && {
custom_fields: [...]
})
return from(stripe.checkout.sessions.create({
client_reference_id: ulid(),
payment_method_types: ['card', 'paypal'],
custom_fields: [
{
key: 'codice_fiscale',
label: {type: 'custom', custom: 'Codice Fiscale'},
type: 'text'
}
],
tax_id_collection: {
enabled: true,
},
}))
so now I have this one, right?
the tax_ic_collection tha is enabled
so I want to add a new field call VAT2 just when is enabled
and remove when is disabled
You're going to need to have a parameter somewhere in your Next.js action/route handler that controls whether tax_id_collection is passed and then conditionally include custom_fields, like this
Share you full route handler code please
const session$ = defer(() => product$.pipe(
concatMap((product) => {
return from(stripe.checkout.sessions.create({
client_reference_id: ulid(),
payment_method_types: ['card', 'paypal'],
line_items: [
{
price_data: {
product_data: {name: Custom Patch ${product.id}},
currency: "eur",
unit_amount:
parseFloat((product.price as number * 100).toFixed(2)),
},
quantity: 1,
},
],
custom_fields: [
{
key: 'codice_fiscale',
label: {type: 'custom', custom: 'Codice Fiscale'},
type: 'text'
}
],
tax_id_collection: {
enabled: true,
},
shipping_address_collection: {allowed_countries: ['IT', 'GB']},
mode: "payment",
success_url: `${process.env.FRONTEND_URL}/payment?success=true`,
cancel_url: `${process.env.FRONTEND_URL}/payment?canceled=true`,
}))
})
))
Yes, but how are you invoking this server-side call from your React front-end?
const product$ = defer(() => formData$.pipe(
concatMap((formData) => {
jwt = formData.get('jwt') as string;
return from(
getProduct(
request.url.replace("/payment", "").split("/").pop() as any,
jwt
)
).pipe(map((product) => {
productId = product.id as string;
return product
}))
})
))
const updateProperties$ = defer(() =>
product$.pipe(
concatMap((product) => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { patchType: _, font: __, ...data } = payload;
for (const key in data)
if (data[key] === 'null') data[key] = undefined;
for (const key of ['patchWidth', 'patchHeight', 'quantity'])
if (payload[key]) payload[key] = parseFloat(payload[key]);
Object.assign(product, data);
if (image) product.image = image.filename;
return of(product);
}),
concatMap((product) => {
const { patchType } = payload;
if (
patchType !== 'null' &&
typeof patchType !== 'undefined' &&
patchType !== product?.patchType?.id
)
return from(
this.patchTypeRepo.findOneOrFail({
id: patchType,
}),
).pipe(
map((patchType) => {
product.patchType = patchType;
return product;
}),
catchError(() => {
throw new NotFoundException('Patch type not found');
}),
);
return of(product);
}),
concatMap((product) => {
const { font } = payload;
if (
font !== 'null' &&
typeof font !== 'undefined' &&
font !== product?.font?.id
)
return from(this.fontRepo.findOneOrFail({ id: font })).pipe(
concatMap((font) => {
product.font = font;
return of(product);
}),
catchError(() => {
return throwError(
() => new NotFoundException('Font not found'),
);
}),
);
return of(product);
}),
catchError((e) => throwError(() => e)),
),
);
and here there is the logic to call it
Yeah that is hard for me to grok. In any case you need to pass a field/parameter in the body of your request to that server-side function that creates the Checkout Session. Then you can use that to determine whether to pass tax_id_collection and conditionally add custom_fields