#sergx_checkout-customer-tax-id
1 messages ยท Page 1 of 1 (latest)
๐ 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/1230802784002244640
๐ 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.
- sergx_docs, 12 hours ago, 16 messages
- sergx_webhooks, 3 days ago, 18 messages
hi! the billing address is saved to the PaymentMethod(not the Customer) by default.
what you can do I think is create a Customer object first, pass that to the CheckoutSession create call in customer , and also pass https://docs.stripe.com/api/checkout/sessions/create#create_checkout_session-customer_update-address to have Checkout write the address onto the customer.
customer:"cus_xxxx" (call the Customer Create API first)
Perfect got it, thank you so much, I'm going to try it
I have a dbout what I have to pass to customer_update.address
private function handleCheckoutOptions($user, $paymentTypes = ['card'], $allowCodes = false, $createInvoice = true, $succesRoute, $cancelRoute, $collectVAT = false, $passCustomer = false)
{
$options = [
'payment_method_types' => $paymentTypes,
'client_reference_id' => $user->id,
'billing_address_collection' => 'required',
'allow_promotion_codes' => $allowCodes,
'locale' => 'es',
'success_url' => route($succesRoute),
'cancel_url' => route($cancelRoute),
];
if ($createInvoice) {
$options['invoice_creation'] = [
'enabled' => true,
];
}
if ($collectVAT) {
$options['custom_fields'] = [
[
'key' => 'VAT',
'label' => [
'type' => 'custom',
'custom' => 'NIF/CIF',
],
'type' => 'text',
'optional' => false,
]
];
}
if ($passCustomer) {
$options['customer'] = $user->stripe_id;
$options['customer_update'] = [
'address' => '',
];
}
return $options;
}
what's the doubt?
I don't know what I have to put in 'address' =>
"billing_address_collection"
perfect thanks so much!
๐ taking over for my colleague. Let me know if there's any follow-up Qs I can answer!
Updated to
if ($passCustomer) {
$options['customer'] = $user->stripe_id;
$options['customer_update'] = [
'address' => 'billing_address_collection',
];
}
I got this error
Invalid customer_update[address]: must be one of auto or never
Then if I put it as auto, it will update customer details?
Putting it as 'auto' worked fine, and now it's updating billing details and showing them correctly into the invoce. Thanks very much
But now I have another problem. And is that in the invoice is not appearing the customer tax id, why?
I'm glad that my colleague was able to help you out
did you collect the customer's tax ID?
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Yes, in customer details appears there.
What I do is listen to checkout session completed webhook, for the first subscription payment and create customer tax id
public function createCustomerTaxId($data, $user)
{
if (isset($data['custom_fields']) && isset($data['custom_fields'][0]['text']['value'])) {
$value = $data['custom_fields'][0]['text']['value'];
try {
$this->stripe->customers->createTaxId($user->stripe_id, [
'type' => 'es_cif',
'value' => $value,
]);
} catch (InvalidRequestException $e) {
Log::error($e->getMessage());
}
}
}
But not showing on invoices
because due to my country, invoices will be valid when customer's tax id are mandatory.
Adding 'tax_id_collection' enabled as true, it appears the checkbox but some users don't fill it
I thought maybe was a better idea to add the custom field, and get the customer's VAT number as mandatory with that custom field
And then creating customer tax id via API, but for some reason, not appearing in the invoices
is it mandatory though to have a Tax ID?
yes our SaaS is B2B
ok I'm trying to figure this out, give me a second please
Sure, thank you very much!
sorry I'm still investigating this
Dont worry, thank you very much! When purchasing for products invoices works fine, I don't know if it's because of this parameter:
'invoice_creation' => [
'enabled' => true,
],
But If I remember well, in subscription it's not possible to pass that checkout option
Can you share the cus_xxx and in_xxx ID?
I suspect this is a race condition where the invoice is generated before you've set the tax ID on the customer
Sure!
cus_Px7cxGUCCjpEdw
Invoice with tax id problem: in_1P7DRaKYINwhn6n4ukAcFWHG
Invoice (product purchase) without the problem: in_1P7DrsKYINwhn6n4BkKi5Ql3
Because you're not using tax_id_collection on the payment page and creating the tax ID manually after
Yes, maybe it's because the webhook I used checkout.session.completed. The problem seems to appear only with the first generated invoice
Yep that makes sense
In reality we need to add a tax_id_collection[required] field which will support your use case
$options = [
'payment_method_types' => $paymentTypes,
'client_reference_id' => $user->id,
'billing_address_collection' => 'required',
'allow_promotion_codes' => $allowCodes,
'locale' => 'es',
'tax_id_collection' => [
'enabled' => true,
],
'success_url' => route($succesRoute),
'cancel_url' => route($cancelRoute),
];
The only workaround for the initial invoice would be to create the Customer object with tax IDs before subscribing and pass it on session creation
if I add 'tax_id_collection' => 'required' will work as mandatory?
i'm going to test it
No, I'm saying we should add that
Oh, yes that would be super cool as a feedback!
Right now it's optional if you have it enabled where as you want it to be mandatory
Yes, exact! Some countries requires it as a mandatory for invoices to be valid
Got it. I've logged the feedback
Thank you very much! The problem is that the user would have to put the VAT number before entering Stripe Checkout, and for UX maybe it could be hard for the user to interact with
Because it only happen in the first invoice, I guess it would be possible to edit invoice or some way to add manually tax id there?
Yeah it's not an ideal workaround
You can't as they're immutable once finalized/paid
Perfect will talk with my team how we could handle this, super cool if soon required option would be possible to add, thank you very much!
sergx_checkout-customer-tax-id
No problem, glad I could help!