mirror of
https://github.com/lkddi/Xboard.git
synced 2026-04-27 22:40:38 +08:00
refactor: 规范Expection处理
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Payments;
|
||||
|
||||
use App\Exceptions\ApiException;
|
||||
use Stripe\Stripe;
|
||||
use Stripe\Checkout\Session;
|
||||
|
||||
@@ -47,7 +48,7 @@ class StripeCheckout {
|
||||
$currency = $this->config['currency'];
|
||||
$exchange = $this->exchange('CNY', strtoupper($currency));
|
||||
if (!$exchange) {
|
||||
abort(500, __('Currency conversion has timed out, please try again later'));
|
||||
throw new ApiException(500, __('Currency conversion has timed out, please try again later'));
|
||||
}
|
||||
$customFieldName = isset($this->config['stripe_custom_field_name']) ? $this->config['stripe_custom_field_name'] : 'Contact Infomation';
|
||||
|
||||
@@ -86,7 +87,7 @@ class StripeCheckout {
|
||||
$session = Session::create($params);
|
||||
} catch (\Exception $e) {
|
||||
info($e);
|
||||
abort(500, "Failed to create order. Error: {$e->getMessage}");
|
||||
throw new ApiException(500, "Failed to create order. Error: {$e->getMessage}");
|
||||
}
|
||||
return [
|
||||
'type' => 1, // 0:qrcode 1:url
|
||||
@@ -104,7 +105,7 @@ class StripeCheckout {
|
||||
$this->config['stripe_webhook_key']
|
||||
);
|
||||
} catch (\Stripe\Error\SignatureVerification $e) {
|
||||
abort(400);
|
||||
throw new ApiException(400);
|
||||
}
|
||||
|
||||
switch ($event->type) {
|
||||
@@ -125,7 +126,7 @@ class StripeCheckout {
|
||||
];
|
||||
break;
|
||||
default:
|
||||
abort(500, 'event is not support');
|
||||
throw new ApiException(500, 'event is not support');
|
||||
}
|
||||
return('success');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user