Laravel 5 Hadle cartlyst条带计划错误

Laravel 5 Hadle cartlyst条带计划错误,laravel-5,stripe-payments,Laravel 5,Stripe Payments,我在我的laravel应用程序中使用cartalyst strip API为strip创建付款计划,它工作正常,但当strip显示任何错误时,它会直接显示在DOM中。我想将其存储在一个变量中,然后重定向到上一页。我使用了try…catch方法,但它不适用于创建计划 下面是我的代码 $stripe = Stripe::make(STRIPE_KEY); try { $plan = $stripe->plans()->create([ 'id'

我在我的laravel应用程序中使用cartalyst strip API为strip创建付款计划,它工作正常,但当strip显示任何错误时,它会直接显示在DOM中。我想将其存储在一个变量中,然后重定向到上一页。我使用了
try…catch
方法,但它不适用于创建计划

下面是我的代码

$stripe = Stripe::make(STRIPE_KEY);
try {
    $plan = $stripe->plans()->create([
              'id'                    => 'monthly',
              'name'                  => 'palan name'
              'amount'                => '22',
              'currency'              => 'USD',
              'interval'              => 'month',
              'interval_count'        => '6',
              'statement_descriptor'  => 'test description'
            ]);
}
catch (Stripe\Error\Base $e) { 
    echo($e->getMessage());
}

我不熟悉该库,但我认为问题在于您没有正确地捕获错误,因为Cartalyst在其自己的名称空间中有这些错误。您可以在他们的示例中看到这一点,他们给出了一些关于如何捕获错误的示例:

try {
    $customer = $stripe->customers()->find('foobar');

    echo $customer['email'];
} catch (Cartalyst\Stripe\Exception\NotFoundException $e) {
    // Get the status code
    $code = $e->getCode();

    // Get the error message returned by Stripe
    $message = $e->getMessage();

    // Get the error type returned by Stripe
    $type = $e->getErrorType();
}

他们没有提到如何捕获
Base
一个,我也没有权限对代码进行双重检查,但我猜这是一个疏忽,您可以简单地捕获
Cartalyst\Stripe\Exception\Base$e

,我将实现它,并让您知道。谢谢