尝试在laravel中尝试捕获块

时间:2019-09-14 12:00:57

标签: php laravel laravel-5 stripe-payments

我必须尝试捕获块以进行条带支付以处理错误响应,现在我正在使用laravel进行编码。

但是在捕获到错误后,我却得到了500个内部服务器错误,而不是存储异常消息,而是通过 500 Internal Server 捕获了错误?

这是我的代码:

try {
    $customer = \Stripe\Customer::create([
        'email' => $email,
        'source' => $token,
    ]);

    $customer_id = $customer->id;
    $subscription = \Stripe\Subscription::create([
        'customer' => $customer_id,
        'items' => [['plan' => 'plan_id']], //plan-id is static as there is single plan
    ]);


    $chargeJson = $subscription->jsonSerialize(); 
}
catch(Stripe_CardError $e) {
    $error = $e->getMessage();
} catch (Stripe_InvalidRequestError $e) {

    // Invalid parameters were supplied to Stripe's API
    $error = $e->getMessage();
} catch (Stripe_AuthenticationError $e) {

    // Authentication with Stripe's API failed
    $error = $e->getMessage();
} catch (Stripe_ApiConnectionError $e) {

    // Network communication with Stripe failed
    $error = $e->getMessage();
} catch (Stripe_Error $e) {

    // Display a very generic error to the user, and maybe send
    // yourself an email
    $error = $e->getMessage();
} catch (Exception $e) {

    // Something else happened, completely unrelated to Stripe
    $error = $e->getMessage();
}

$resp = array();
if(isset($chargeJson) && !empty($chargeJson['id'])) {

    $resp['status'] = 1;
    $resp['transactions_log'] = $chargeJson;
    $resp['current_period_end'] = $chargeJson['current_period_end'];
    $resp['transaction_id'] = $chargeJson['id']; // which is actually subcsription id
} else {

    $resp['status'] = 0;
    $resp['error'] = $error;
}
return $resp;

我不确定如何处理和存储它。 我非常确定我已经捕获到异常,但是我无法存储它并进一步使用它。

0 个答案:

没有答案