refactor: 重构规范部分代码、邮件队列增加失败重试、去除多个支付方式、更新依赖

This commit is contained in:
xboard
2024-04-10 00:51:03 +08:00
parent ec63e05575
commit 4c6c7182e2
50 changed files with 421 additions and 1005 deletions
+18 -12
View File
@@ -1,11 +1,15 @@
<?php
namespace App\Payments;
use App\Exceptions\ApiException;
class BTCPay {
public function __construct($config) {
class BTCPay
{
protected $config;
public function __construct($config)
{
$this->config = $config;
}
@@ -35,7 +39,8 @@ class BTCPay {
];
}
public function pay($order) {
public function pay($order)
{
$params = [
'jsonResponse' => true,
@@ -52,7 +57,7 @@ class BTCPay {
$ret = @json_decode($ret_raw, true);
if(empty($ret['checkoutLink'])) {
if (empty($ret['checkoutLink'])) {
throw new ApiException("error!");
}
return [
@@ -61,7 +66,8 @@ class BTCPay {
];
}
public function notify($params) {
public function notify($params)
{
$payload = trim(get_request_content());
$headers = getallheaders();
@@ -76,7 +82,7 @@ class BTCPay {
$computedSignature = "sha256=" . \hash_hmac('sha256', $payload, $this->config['btcpay_webhook_key']);
if (!self::hashEqual($signraturHeader, $computedSignature)) {
throw new ApiException('HMAC signature does not match',400);
throw new ApiException('HMAC signature does not match', 400);
return false;
}
@@ -93,16 +99,16 @@ class BTCPay {
$out_trade_no = $invoiceDetail['metadata']["orderId"];
$pay_trade_no=$json_param['invoiceId'];
$pay_trade_no = $json_param['invoiceId'];
return [
'trade_no' => $out_trade_no,
'callback_no' => $pay_trade_no
];
}
private function _curlPost($url,$params=false){
private function _curlPost($url, $params = false)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
@@ -111,7 +117,9 @@ class BTCPay {
curl_setopt($ch, CURLOPT_TIMEOUT, 300);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt(
$ch, CURLOPT_HTTPHEADER, array('Authorization:' .'token '.$this->config['btcpay_api_key'], 'Content-Type: application/json')
$ch,
CURLOPT_HTTPHEADER,
array('Authorization:' . 'token ' . $this->config['btcpay_api_key'], 'Content-Type: application/json')
);
$result = curl_exec($ch);
curl_close($ch);
@@ -143,6 +151,4 @@ class BTCPay {
return !$ret;
}
}
}