Обрабатывать ошибки Stripe в Slim PHP - PullRequest
0 голосов
/ 02 апреля 2020

Я изо всех сил пытаюсь найти решение для обработки сообщений об ошибках от Stripe в Slim. Когда я получаю ответ, 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
}

Есть идеи?

1 Ответ

0 голосов
/ 02 апреля 2020

Попробуйте перехватить тип исключения, упомянутый на странице с ошибками 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
}
...