首页 > 解决方案 > 在 Slim PHP 中处理 Stripe 错误

问题描述

我正在努力寻找一种解决方案来处理来自 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
}

有任何想法吗?

标签: phpstripe-paymentsslim

解决方案


尝试捕获超薄错误页面中提到的异常类型“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
}

推荐阅读