【问题标题】:why the payment passes even I put code expired_card, without giving exception?为什么即使我把代码 expired_card 付款也通过了,没有例外?
【发布时间】:2021-11-30 10:05:50
【问题描述】:

我尝试为我的网站在线付款,我使用stripe,付款成功完成,但我添加CardErrorException 来处理特殊错误消息,当我将代码 4000 0000 0000 0069 放入处理expired_card 异常,它正常通过而不处理“您的卡已过期”异常。

CheckoutController.php

public function store(Request $request)
    {
        $contents = Cart::content()->map(function ($item) {
            return $item->model->name.', '.$item->qty;
        })->values()->toJson();

        try {
           // Enter Your Stripe Secret
             \Stripe\Stripe::setApiKey('sk_test_PcRh9XreG5jbXyhCchJf9NCK00dku1xYGi');
            
            $payment_intent = \Stripe\PaymentIntent::create([
                'amount' => round(Cart::total() / 100),
                'currency' => 'MAD',
                'description' => 'Stripe Test Payment ddd',
                'receipt_email' => $request->email,
                'payment_method_types' => ['card'],
                'metadata' => [
                    'content'  => $contents,
                    'quantity' => Cart::instance('default')->count(),
                ]
            ]);
            $intent = $payment_intent->client_secret;

            Cart::instance('default')->destroy();

        return redirect()->route('confirmation.index')->with('success_message', 'Thank you! Your payment has been successfully accepted!');
        } catch (CardErrorException $e) {
            return back()->withErrors('Error! ' . $e->getMessage());

        }
    }

【问题讨论】:

  • 你用的是什么库?
  • @VincentDecaux composer require cartalyst/cart
  • @VincentDecaux 谢谢你的回答。我在此链接link 中找到了这些示例

标签: php laravel stripe-payments


【解决方案1】:

您的代码已成功创建付款意图,但您没有确认它。 Payment is not attempted until the Payment Intent gets confirmed.

您使用的返回expired_card 拒绝的特殊测试卡号在尝试付款之前不会触发。这就是为什么这段代码没有按预期工作的原因。

您可能想要add 'confirm' => 'true' to your arguments(假设您要在服务器端确认支付意图)或use Stripe.js to confirm the Payment Intent client-side(推荐)。

【讨论】:

    猜你喜欢
    • 2021-06-23
    • 1970-01-01
    • 2018-04-30
    • 1970-01-01
    • 2014-06-11
    • 2021-09-18
    • 2016-09-03
    • 2016-10-15
    • 2021-06-17
    相关资源
    最近更新 更多