prasad kirpekar
prasad kirpekar

Reputation: 31

Laravel Cashier The payment attempt failed because of an invalid payment method

I am getting an invalid payment gateway even if I am getting a payment method id in the backend. I am trying to do it from India so as per Indian regulations I have to submit address and name while making payment. I am guessing I am not able to integrate that part here. please help me this took my whole day still not solved.

$user = auth()->user();
        $paymentMethod = $request->payment_method;

        $planId = $request->plan;


        $city="my city";
        $country="India";
        $address="user address"
        $zipCode="111111";
        $state="Maharashtra";

        $user->createOrGetStripeCustomer([
            'email' => $user->email,
            'name' => 'test',
            'description' => 'test description',
            "address" => ["city" => $city, "country" => $country, "line1" => $address, "line2" => "", "postal_code" => $zipCode, "state" => $state]
        ]);


        $user->newSubscription('main', $planId)->create($paymentMethod);

        return response([
            'success_url'=> redirect()->intended('/')->getTargetUrl(),
            'message'=>'success'
        ]);



This is frontend code

window.addEventListener('load', function() {


            const stripe = Stripe('{{env('STRIPE_KEY')}}');

            const elements = stripe.elements();
            const cardElement = elements.create('card');

            cardElement.mount('#card-element');

            const cardHolderName = document.getElementById('card-holder-name');
            const cardButton = document.getElementById('card-button');
            const clientSecret = cardButton.dataset.secret;

            const plan = document.getElementById('subscription-plan').value;

            cardButton.addEventListener('click', async (e) => {
                const { setupIntent, error } = await stripe.handleCardSetup(
                    clientSecret, cardElement, {
                        payment_method_data: {
                            billing_details: { name: cardHolderName.value }
                        }
                    }
                );

                if (error) {
                    // Display "error.message" to the user...
                } else {
                    // The card has been verified successfully...
                    console.log('handling success', setupIntent.payment_method);

                    axios.post('/subscribe',{
                        payment_method: setupIntent.payment_method,
                        plan : plan
                    }).then((data)=>{
                        location.replace(data.data.success_url)
                    });
                }
            });
        })

my cashier version is 10.3

I have tried with live keys as well. It shows the same errors. Can anyone help me?

Upvotes: 2

Views: 2645

Answers (1)

Ajith jojo
Ajith jojo

Reputation: 427

As per Indian regulations, only registered Indian businesses (i.e. sole proprietorships, limited liability partnerships and companies, but not individuals) can accept international payments. More info here: https://stripe.com/docs/india-exports

So the test wont work with 4242 4242 4242 4242 card with indian stripe account without a registred business ... this thing killed my 3 hours ..

Upvotes: 2

Related Questions