Codeigniter PHP STRIPE lib 支付错误(使用卡号拒绝响应_

Error in Codeigniter PHP STRIPE lib payment (using a card number for a declined response_

我正在尝试使用 stripe php 库(最新版本)来捕获 codeigniter 3 中的错误 因此,当我使用正确的测试卡号时,付款正常,但是当我使用被拒绝的测试卡号进行测试时,出现错误: 输入:Stripe\Exception\CardException

消息:您的卡已被拒绝。enter image description here

文件名:/opt/lampp/htdocs/plataforma_asociaciones/application/third_party/stripe-php-old/lib/Exception/ApiErrorException.php

行号:38

回溯:

文件:/opt/lampp/htdocs/plataforma_asociaciones/application/third_party/stripe-php-old/lib/Exception/CardException.php 线路:38 函数:工厂

文件:/opt/lampp/htdocs/plataforma_asociaciones/application/third_party/stripe-php-old/lib/ApiRequestor.php 线路:195 函数:工厂

您的代码似乎只捕获了所有可能错误的一部分。看看 the PHP error handling sample snippet in the Stripe API reference:

try {
  // Use Stripe's library to make requests...
} catch(\Stripe\Exception\CardException $e) {
  // Since it's a decline, \Stripe\Exception\CardException will be caught
  echo 'Status is:' . $e->getHttpStatus() . '\n';
  echo 'Type is:' . $e->getError()->type . '\n';
  echo 'Code is:' . $e->getError()->code . '\n';
  // param is '' in this case
  echo 'Param is:' . $e->getError()->param . '\n';
  echo 'Message is:' . $e->getError()->message . '\n';
} catch (\Stripe\Exception\RateLimitException $e) {
  // Too many requests made to the API too quickly
} catch (\Stripe\Exception\InvalidRequestException $e) {
  // Invalid parameters were supplied to Stripe's API
} catch (\Stripe\Exception\AuthenticationException $e) {
  // Authentication with Stripe's API failed
  // (maybe you changed API keys recently)
} catch (\Stripe\Exception\ApiConnectionException $e) {
  // Network communication with Stripe failed
} catch (\Stripe\Exception\ApiErrorException $e) {
  // Display a very generic error to the user, and maybe send
  // yourself an email
} catch (Exception $e) {
  // Something else happened, completely unrelated to Stripe
}

ApiErrorException 只是众多异常中的一种。如果您想处理其他类型的异常,您需要添加代码。