首页 > 解决方案 > Laravel Cashier 付款尝试失败,因为付款方式无效

问题描述

即使我在后端获得了支付方式 ID,我也获得了无效的支付网关。我正在尝试从印度进行操作,因此根据印度的规定,我必须在付款时提交地址和姓名。我猜我无法在这里整合那部分。请帮帮我,这花了我一整天的时间仍未解决。

$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'
        ]);



这是前端代码

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)
                    });
                }
            });
        })

我的收银台版本是 10.3

我也尝试过使用实时键。它显示相同的错误。谁能帮我?

标签: laravelstripe-paymentslaravel-cashier

解决方案


根据印度法规,只有注册的印度企业(即独资企业、有限责任合伙企业和公司,但不包括个人)可以接受国际支付。更多信息:https ://stripe.com/docs/india-exports

因此,该测试不适用于 4242 4242 4242 4242 卡和没有注册业务的印度条纹帐户...这件事杀死了我 3 小时..


推荐阅读