#sergx_checkout-customer-tax-id

1 messages ยท Page 1 of 1 (latest)

glass lintelBOT
#

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

vagrant cryptBOT
#

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.

torn nimbus
pulsar river
#

hi! the billing address is saved to the PaymentMethod(not the Customer) by default.

#

customer:"cus_xxxx" (call the Customer Create API first)

torn nimbus
#

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;
    }
glass lintelBOT
pulsar river
#

what's the doubt?

torn nimbus
#

I don't know what I have to put in 'address' =>

pulsar river
#

"billing_address_collection"

torn nimbus
#

perfect thanks so much!

lone tulip
#

๐Ÿ‘‹ taking over for my colleague. Let me know if there's any follow-up Qs I can answer!

torn nimbus
#

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?

lone tulip
#

I'm glad that my colleague was able to help you out

#

did you collect the customer's tax ID?

torn nimbus
#

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

lone tulip
#

why are you creating custom fields for Tax ID collection?

#

I'm not sure I follow

torn nimbus
#

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

lone tulip
#

is it mandatory though to have a Tax ID?

torn nimbus
#

yes our SaaS is B2B

lone tulip
#

ok I'm trying to figure this out, give me a second please

torn nimbus
#

Sure, thank you very much!

lone tulip
#

sorry I'm still investigating this

torn nimbus
#

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

abstract crow
#

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

torn nimbus
#

Sure!

cus_Px7cxGUCCjpEdw

Invoice with tax id problem: in_1P7DRaKYINwhn6n4ukAcFWHG

Invoice (product purchase) without the problem: in_1P7DrsKYINwhn6n4BkKi5Ql3

abstract crow
#

Because you're not using tax_id_collection on the payment page and creating the tax ID manually after

torn nimbus
#

Yes, maybe it's because the webhook I used checkout.session.completed. The problem seems to appear only with the first generated invoice

abstract crow
#

Yep that makes sense

#

In reality we need to add a tax_id_collection[required] field which will support your use case

torn nimbus
#
$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),
        ];
abstract crow
#

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

torn nimbus
#

if I add 'tax_id_collection' => 'required' will work as mandatory?

#

i'm going to test it

abstract crow
#

No, I'm saying we should add that

torn nimbus
#

Oh, yes that would be super cool as a feedback!

abstract crow
#

Right now it's optional if you have it enabled where as you want it to be mandatory

torn nimbus
#

Yes, exact! Some countries requires it as a mandatory for invoices to be valid

abstract crow
#

Got it. I've logged the feedback

torn nimbus
#

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?

abstract crow
abstract crow
torn nimbus
#

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!

glass lintelBOT
#

sergx_checkout-customer-tax-id

abstract crow
#

No problem, glad I could help!