jazzjazzy's avatar

Cashier keeps throwing 'The customer's location isn't recognized'

I am trying to get Cashier to work in lavarel 8 to add a subscription for Stripe

i had it working fine when I user stripe.js elements.create('card'), but I didn't want that the single row so I changed it to

javascript : const elements = stripe.elements()

var cardNumberElement = elements.create('cardNumber', {
    style: style,
    placeholder: 'Card Number',
    showIcon: true,
});
cardNumberElement.mount('#card-number-element');

var cardExpiryElement = elements.create('cardExpiry', {
    style: style,
    placeholder: 'Card expiry date',
});
cardExpiryElement.mount('#card-expiry-element');

var cardCvcElement = elements.create('cardCvc', {
    style: style,
    placeholder: 'CVC',
});
cardCvcElement.mount('#card-cvc-element');

and updated newSubscription to

                $user->newSubscription($plan->stripe_name, $plan->stripe_id)
                    ->create($paymentMethod, [
                        'name' => $request->get('name'),
                        'email' => $user->email,
                        'payment_method' => $paymentMethod,
                        'address' => [
                            'postal_code' => $request->get('postal_code'),
                            'country' => $request->get('country'),
                        ],
                    ]);

but I keep getting the error

The customer's location isn't recognized. Set a valid customer address in order to automatically calculate tax.

array:4 [ // app/Http/Controllers/SubscriberController.php:63
  "name" => "user test"
  "email" => "[email protected]"
  "payment_method" => "pm_1N22xuC...Q7Qj24Y"
  "address" => array:2 [
   		 "postal_code" => "3078"
   	     "country" => 'Australia'
  ]
]

I tried multiple variations on the same idea but I still continually got the same error. so either I am not doing it right or that this is a general error and it not related to that address at all.

0 likes
1 reply
jazzjazzy's avatar
jazzjazzy
OP
Best Answer
Level 1

Sorry, I sorted it, confusing myself over 2 days by reading 2 different sources of documentation didn't make it clearer :)

so the issue was. in Cashier you need to add the address with updateStripeCustomer before you do the newSubscription - this was why I was getting the same message

The customer's location isn't recognized. Set a valid customer address in order to automatically calculate tax.

here is the updated code

                $user->updateStripeCustomer([
                    'address' => [
                        'postal_code' => $request->get('postal_code'),
                        'country' => 'AU',
                    ],
                ]);

                // Create a new subscription for the user
                $user->newSubscription($request->plan, $plan->stripe_id)
                    ->create($paymentMethod, [
                        'name' => $request->get('name'),
                        'email' => $user->email,
                        'payment_method' => $paymentMethod,
                    ]);

hopes this helps some in the future :)

1 like

Please or to participate in this conversation.