2016-02-06 15 views
0

我在我的laravel應用程序中使用cartalyst strip API創建了strip的付款計劃,它工作正常,但當strip顯示任何錯誤時,它直接顯示在DOM中。我想將它存儲在一個變量中,然後重定向到上一頁。我已經使用try...catch方法,但它不適用於創建計劃。Hadle cartledst strip plan error

下面是我的代碼

$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()); 
} 

回答

0

我不熟悉的圖書館,但我認爲這個問題是,你不要再追了錯誤的正確這裏Cartalyst有那些在自己的命名空間。你可以在自己的documentation看到他們就如何捕獲錯誤的一些例子:

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

+0

我會實施它,並讓你知道。謝謝 – HKumar