mirror of
https://github.com/lkddi/Xboard.git
synced 2026-04-27 14:17:28 +08:00
refactor: 规范状态码、抛出异常的使用
This commit is contained in:
@@ -58,7 +58,8 @@ class AlipayF2F {
|
||||
'data' => $gateway->getQrCodeUrl()
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
throw new ApiException(500, $e->getMessage());
|
||||
\Log::error($e);
|
||||
throw new ApiException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ class BTCPay {
|
||||
$ret = @json_decode($ret_raw, true);
|
||||
|
||||
if(empty($ret['checkoutLink'])) {
|
||||
throw new ApiException(500, "error!");
|
||||
throw new ApiException("error!");
|
||||
}
|
||||
return [
|
||||
'type' => 1, // Redirect to url
|
||||
@@ -76,7 +76,7 @@ class BTCPay {
|
||||
$computedSignature = "sha256=" . \hash_hmac('sha256', $payload, $this->config['btcpay_webhook_key']);
|
||||
|
||||
if (!self::hashEqual($signraturHeader, $computedSignature)) {
|
||||
throw new ApiException(400, 'HMAC signature does not match');
|
||||
throw new ApiException('HMAC signature does not match',400);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -98,7 +98,6 @@ class BTCPay {
|
||||
'trade_no' => $out_trade_no,
|
||||
'callback_no' => $pay_trade_no
|
||||
];
|
||||
return response('success', 200);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ class CoinPayments {
|
||||
{
|
||||
|
||||
if (!isset($params['merchant']) || $params['merchant'] != trim($this->config['coinpayments_merchant_id'])) {
|
||||
throw new ApiException(500, 'No or incorrect Merchant ID passed');
|
||||
throw new ApiException('No or incorrect Merchant ID passed');
|
||||
}
|
||||
|
||||
$headers = getallheaders();
|
||||
@@ -82,7 +82,7 @@ class CoinPayments {
|
||||
// }
|
||||
|
||||
if (!hash_equals($hmac, $signHeader)) {
|
||||
throw new ApiException(400, 'HMAC signature does not match');
|
||||
throw new ApiException('HMAC signature does not match', 400);
|
||||
}
|
||||
|
||||
// HMAC Signature verified at this point, load some variables.
|
||||
@@ -96,7 +96,7 @@ class CoinPayments {
|
||||
];
|
||||
} else if ($status < 0) {
|
||||
//payment error, this is usually final but payments will sometimes be reopened if there was no exchange rate conversion or with seller consent
|
||||
throw new ApiException(500, 'Payment Timed Out or Error');
|
||||
throw new ApiException('Payment Timed Out or Error');
|
||||
} else {
|
||||
//payment is pending, you can optionally add a note to the order page
|
||||
return('IPN OK: pending');
|
||||
|
||||
@@ -51,7 +51,7 @@ class Coinbase {
|
||||
$ret = @json_decode($ret_raw, true);
|
||||
|
||||
if(empty($ret['data']['hosted_url'])) {
|
||||
throw new ApiException(500, "error!");
|
||||
throw new ApiException("error!");
|
||||
}
|
||||
return [
|
||||
'type' => 1,
|
||||
@@ -71,7 +71,7 @@ class Coinbase {
|
||||
$computedSignature = \hash_hmac('sha256', $payload, $this->config['coinbase_webhook_key']);
|
||||
|
||||
if (!self::hashEqual($signatureHeader, $computedSignature)) {
|
||||
throw new ApiException(400, 'HMAC signature does not match');
|
||||
throw new ApiException( 'HMAC signature does not match', 400);
|
||||
}
|
||||
|
||||
$out_trade_no = $json_param['event']['data']['metadata']['outTradeNo'];
|
||||
@@ -80,7 +80,6 @@ class Coinbase {
|
||||
'trade_no' => $out_trade_no,
|
||||
'callback_no' => $pay_trade_no
|
||||
];
|
||||
return response('success', 200);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -63,21 +63,21 @@ class MGate {
|
||||
$curl->post($this->config['mgate_url'] . '/v1/gateway/fetch', http_build_query($params));
|
||||
$result = $curl->response;
|
||||
if (!$result) {
|
||||
throw new ApiException(500, '网络异常');
|
||||
throw new ApiException('网络异常');
|
||||
}
|
||||
if ($curl->error) {
|
||||
if (isset($result->errors)) {
|
||||
$errors = (array)$result->errors;
|
||||
throw new ApiException(500, $errors[array_keys($errors)[0]][0]);
|
||||
throw new ApiException($errors[array_keys($errors)[0]][0]);
|
||||
}
|
||||
if (isset($result->message)) {
|
||||
throw new ApiException(500, $result->message);
|
||||
throw new ApiException($result->message);
|
||||
}
|
||||
throw new ApiException(500, '未知错误');
|
||||
throw new ApiException('未知错误');
|
||||
}
|
||||
$curl->close();
|
||||
if (!isset($result->data->trade_no)) {
|
||||
throw new ApiException(500, '接口请求失败');
|
||||
throw new ApiException('接口请求失败');
|
||||
}
|
||||
return [
|
||||
'type' => 1, // 0:qrcode 1:url
|
||||
|
||||
@@ -41,7 +41,7 @@ class StripeAlipay {
|
||||
$currency = $this->config['currency'];
|
||||
$exchange = $this->exchange('CNY', strtoupper($currency));
|
||||
if (!$exchange) {
|
||||
throw new ApiException(500, __('Currency conversion has timed out, please try again later'));
|
||||
throw new ApiException(__('Currency conversion has timed out, please try again later'));
|
||||
}
|
||||
Stripe::setApiKey($this->config['stripe_sk_live']);
|
||||
$source = Source::create([
|
||||
@@ -59,7 +59,7 @@ class StripeAlipay {
|
||||
]
|
||||
]);
|
||||
if (!$source['redirect']['url']) {
|
||||
throw new ApiException(500, __('Payment gateway request failed'));
|
||||
throw new ApiException(__('Payment gateway request failed'));
|
||||
}
|
||||
return [
|
||||
'type' => 1,
|
||||
@@ -77,7 +77,7 @@ class StripeAlipay {
|
||||
$this->config['stripe_webhook_key']
|
||||
);
|
||||
} catch (\Stripe\Error\SignatureVerification $e) {
|
||||
throw new ApiException(400);
|
||||
abort(400);
|
||||
}
|
||||
switch ($event->type) {
|
||||
case 'source.chargeable':
|
||||
@@ -104,7 +104,7 @@ class StripeAlipay {
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new ApiException(500, 'event is not support');
|
||||
throw new ApiException('event is not support');
|
||||
}
|
||||
return('success');
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ class StripeCheckout {
|
||||
$currency = $this->config['currency'];
|
||||
$exchange = $this->exchange('CNY', strtoupper($currency));
|
||||
if (!$exchange) {
|
||||
throw new ApiException(500, __('Currency conversion has timed out, please try again later'));
|
||||
throw new ApiException(__('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';
|
||||
|
||||
@@ -87,7 +87,7 @@ class StripeCheckout {
|
||||
$session = Session::create($params);
|
||||
} catch (\Exception $e) {
|
||||
info($e);
|
||||
throw new ApiException(500, "Failed to create order. Error: {$e->getMessage}");
|
||||
throw new ApiException("Failed to create order. Error: {$e->getMessage}");
|
||||
}
|
||||
return [
|
||||
'type' => 1, // 0:qrcode 1:url
|
||||
@@ -105,7 +105,7 @@ class StripeCheckout {
|
||||
$this->config['stripe_webhook_key']
|
||||
);
|
||||
} catch (\Stripe\Error\SignatureVerification $e) {
|
||||
throw new ApiException(400);
|
||||
abort(400);
|
||||
}
|
||||
|
||||
switch ($event->type) {
|
||||
@@ -126,7 +126,7 @@ class StripeCheckout {
|
||||
];
|
||||
break;
|
||||
default:
|
||||
throw new ApiException(500, 'event is not support');
|
||||
throw new ApiException('event is not support');
|
||||
}
|
||||
return('success');
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ class StripeCredit {
|
||||
$currency = $this->config['currency'];
|
||||
$exchange = $this->exchange('CNY', strtoupper($currency));
|
||||
if (!$exchange) {
|
||||
throw new ApiException(500, __('Currency conversion has timed out, please try again later'));
|
||||
throw new ApiException(__('Currency conversion has timed out, please try again later'));
|
||||
}
|
||||
Stripe::setApiKey($this->config['stripe_sk_live']);
|
||||
try {
|
||||
@@ -63,10 +63,10 @@ class StripeCredit {
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
info($e);
|
||||
throw new ApiException(500, __('Payment failed. Please check your credit card information'));
|
||||
throw new ApiException(__('Payment failed. Please check your credit card information'));
|
||||
}
|
||||
if (!$charge->paid) {
|
||||
throw new ApiException(500, __('Payment failed. Please check your credit card information'));
|
||||
throw new ApiException(__('Payment failed. Please check your credit card information'));
|
||||
}
|
||||
return [
|
||||
'type' => 2,
|
||||
@@ -84,7 +84,8 @@ class StripeCredit {
|
||||
$this->config['stripe_webhook_key']
|
||||
);
|
||||
} catch (\Stripe\Error\SignatureVerification $e) {
|
||||
throw new ApiException(400);
|
||||
\Log::error($e);
|
||||
abort(400);
|
||||
}
|
||||
switch ($event->type) {
|
||||
case 'source.chargeable':
|
||||
@@ -111,7 +112,7 @@ class StripeCredit {
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new ApiException(500, 'event is not support');
|
||||
throw new ApiException('event is not support');
|
||||
}
|
||||
return('success');
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ class StripeWepay {
|
||||
$currency = $this->config['currency'];
|
||||
$exchange = $this->exchange('CNY', strtoupper($currency));
|
||||
if (!$exchange) {
|
||||
throw new ApiException(500, __('Currency conversion has timed out, please try again later'));
|
||||
throw new ApiException(__('Currency conversion has timed out, please try again later'));
|
||||
}
|
||||
Stripe::setApiKey($this->config['stripe_sk_live']);
|
||||
$source = Source::create([
|
||||
@@ -59,7 +59,7 @@ class StripeWepay {
|
||||
]
|
||||
]);
|
||||
if (!$source['wechat']['qr_code_url']) {
|
||||
throw new ApiException(500, __('Payment gateway request failed'));
|
||||
throw new ApiException(__('Payment gateway request failed'));
|
||||
}
|
||||
return [
|
||||
'type' => 0,
|
||||
@@ -77,7 +77,7 @@ class StripeWepay {
|
||||
$this->config['stripe_webhook_key']
|
||||
);
|
||||
} catch (\Stripe\Error\SignatureVerification $e) {
|
||||
throw new ApiException(400);
|
||||
abort(400);
|
||||
}
|
||||
switch ($event->type) {
|
||||
case 'source.chargeable':
|
||||
@@ -104,7 +104,7 @@ class StripeWepay {
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new ApiException(500, 'event is not support');
|
||||
throw new ApiException('event is not support');
|
||||
}
|
||||
return('success');
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ class WechatPayNative {
|
||||
$response = $request->send();
|
||||
$response = $response->getData();
|
||||
if ($response['return_code'] !== 'SUCCESS') {
|
||||
throw new ApiException(500, $response['return_msg']);
|
||||
throw new ApiException($response['return_msg']);
|
||||
}
|
||||
return [
|
||||
'type' => 0,
|
||||
|
||||
Reference in New Issue
Block a user