【问题标题】:Catch Stripe Error is not catching捕获条纹错误未捕获
【发布时间】:2017-03-26 16:59:25
【问题描述】:

我正在做一个简单的测试,使用 Stripes 默认卡对 Stripe 客户 ID 进行收费以触发卡片拒绝,但我一直认为它不会捕获错误:

 try {
        \Stripe\Charge::create(array(
      "amount" => 1000, // Amount in cents
      "currency" => "usd",
      "customer" => $customer->id)
        );
            echo "Charge customer card entered";
        } catch(\Stripe\Error\Card $e) {
        echo "customer card declined exists";
        } catch(Stripe_CardError $e) {
          $error1 = $e->getMessage();
        } catch (Stripe_InvalidRequestError $e) {
          // Invalid parameters were supplied to Stripe's API
          $error2 = $e->getMessage();
        } catch (Stripe_AuthenticationError $e) {
          // Authentication with Stripe's API failed
          $error3 = $e->getMessage();
        } catch (Stripe_ApiConnectionError $e) {
          // Network communication with Stripe failed
          $error4 = $e->getMessage();
        } catch (Stripe_Error $e) {
          // Display a very generic error to the user, and maybe send
          // yourself an email
          $error5 = $e->getMessage();
        } catch (Exception $e) {
          // Something else happened, completely unrelated to Stripe
          $error6 = $e->getMessage();
        }

我不断收到未捕获的异常

【问题讨论】:

    标签: php stripe-payments


    【解决方案1】:

    我的代码错了。我将客户的创建放在 TRY 处理程序中,它起作用了:

     try {
          $customer = \Stripe\Customer::create(array(
          "source" => $token,
          "description" => "Example customer")
            );
    
          \Stripe\Charge::create(array(
          "amount" => 1000, // Amount in cents
          "currency" => "usd",
          "customer" => $customer->id)
            );
    
          echo "Charge customer card entered";
    
          } catch(\Stripe\Error\Card $e) {
    
          echo "customer card declined";
          exit;
    
        }
    

    【讨论】:

      猜你喜欢
      • 2017-08-27
      • 2018-01-06
      • 1970-01-01
      • 2017-08-26
      • 2017-06-14
      • 1970-01-01
      • 2011-02-24
      • 2014-09-28
      • 2021-06-23
      相关资源
      最近更新 更多