【问题标题】:Handle Stripe errors in Slim PHP在 Slim PHP 中处理 Stripe 错误
【发布时间】:2020-04-02 14:09:34
【问题描述】:

我正在努力寻找一种解决方案来处理来自 Slim 中 Stripe 的错误消息。当我收到回复时,Slim 正在加载:

<h1>Slim Application Error</h1>
<p>The application could not run because of the following error:</p>
<h2>Details</h2>
<div><strong>Type:</strong> Stripe\Exception\InvalidRequestException</div>
<div><strong>Message:</strong> Must provide source or customer.</div>

我似乎无法获得错误的 JSON 表示形式。

我有一个 try/catch 块,但似乎没有什么不同。

try {
   $charge = \Stripe\Charge::create([
       "amount" => $total_amount * 100,
       "currency" => "aud",
       "customer" => $customer_id,
       "description" => 'Payment for order ID #' . $request['orderID']
   ]);
}  catch (\Stripe\Error\Card $e) {
   // Handle "hard declines" e.g. insufficient funds, expired card, etc
   // See https://stripe.com/docs/declines/codes for more
}

有什么想法吗?

【问题讨论】:

    标签: php stripe-payments slim


    【解决方案1】:

    尝试捕获slim错误页面中提到的异常类型,“Stripe\Exception\InvalidRequestException”

    try {
       $charge = \Stripe\Charge::create([
           "amount" => $total_amount * 100,
           "currency" => "aud",
           "customer" => $customer_id,
           "description" => 'Payment for order ID #' . $request['orderID']
       ]);
    }  catch (\Stripe\Exception\InvalidRequestException $e) {
       // Handle "hard declines" e.g. insufficient funds, expired card, etc
       // See https://stripe.com/docs/declines/codes for more
    }
    

    【讨论】:

      猜你喜欢
      • 2014-05-11
      • 1970-01-01
      • 2021-07-12
      • 2015-07-01
      • 2021-11-08
      • 2017-03-14
      • 2015-02-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多