From d197566922dfd87cc88fb06dc098d7d976fce48b Mon Sep 17 00:00:00 2001 From: root Date: Fri, 27 Dec 2019 01:50:26 +0800 Subject: [PATCH] support bitpayx, notify is not work --- .../Controllers/Admin/ConfigController.php | 5 ++- app/Http/Controllers/OrderController.php | 37 +++++++++++++++++++ app/Http/Requests/Admin/ConfigSave.php | 5 +++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Admin/ConfigController.php b/app/Http/Controllers/Admin/ConfigController.php index 77ca920f..2b21987b 100755 --- a/app/Http/Controllers/Admin/ConfigController.php +++ b/app/Http/Controllers/Admin/ConfigController.php @@ -44,7 +44,10 @@ class ConfigController extends Controller 'stripe_pk_live' => config('v2board.stripe_pk_live'), 'stripe_alipay_enable' => (int)config('v2board.stripe_alipay_enable'), 'stripe_wepay_enable' => (int)config('v2board.stripe_wepay_enable'), - 'stripe_webhook_key' => config('v2board.stripe_webhook_key') + 'stripe_webhook_key' => config('v2board.stripe_webhook_key'), + // bitpayx + 'bitpayx_enable' => config('v2board.bitpayx_enable'), + 'bitpayx_appsecret' => config('v2board.bitpayx_appsecret') ], 'server' => [ 'server_token' => config('v2board.server_token') diff --git a/app/Http/Controllers/OrderController.php b/app/Http/Controllers/OrderController.php index 152d45eb..07e0b07a 100755 --- a/app/Http/Controllers/OrderController.php +++ b/app/Http/Controllers/OrderController.php @@ -13,6 +13,7 @@ use App\Utils\Helper; use Omnipay\Omnipay; use Stripe\Stripe; use Stripe\Source; +use Library\BitpayX; class OrderController extends Controller { @@ -142,6 +143,15 @@ class OrderController extends Controller 'type' => 0, 'data' => $this->stripeWepay($order) ]); + case 4: + // bitpayX + if (!(int)config('v2board.bitpayx_enable')) { + abort(500, '支付方式不可用'); + } + return response([ + 'type' => 1, + 'data' => $this->bitpayX($order) + ]); default: abort(500, '支付方式不存在'); } @@ -186,6 +196,14 @@ class OrderController extends Controller array_push($data, $stripeWepay); } + if ((int)config('v2board.bitpayx_enable')) { + $bitpayX = new \StdClass(); + $bitpayX->name = '虚拟货币'; + $bitpayX->method = 4; + $bitpayX->icon = 'bitcoin'; + array_push($data, $bitpayX); + } + return response([ 'data' => $data ]); @@ -262,4 +280,23 @@ class OrderController extends Controller Redis::expire($source['id'], 3600); return $source['wechat']['qr_code_url']; } + + private function bitpayX ($order) { + $bitpayX = new BitpayX(config('v2board.bitpayx_appsecret')); + $params = [ + 'merchant_order_id' => 'V2Board_' . $order->trade_no, + 'price_amount' => $order->total_amount / 100, + 'price_currency' => 'CNY', + 'title' => '支付单号:' . $order->trade_no, + 'description' => '充值:' . $order->total_amount / 100 . ' 元', + 'callback_url' => url('/api/v1/guest/order/bitpayXNotify'), + 'success_url' => config('v2board.app_url', env('APP_URL')) . '/#/order', + 'cancel_url' => config('v2board.app_url', env('APP_URL')) . '/#/order' + ]; + $strToSign = $bitpayX->prepareSignId($params['merchant_order_id']); + $params['token'] = $bitpayX->sign($strToSign); + $result = $bitpayX->mprequest($params); + Log::info('bitpayXSubmit: ' . json_encode($result)); + return isset($result['payment_url']) ? $result['payment_url'] : false; + } } diff --git a/app/Http/Requests/Admin/ConfigSave.php b/app/Http/Requests/Admin/ConfigSave.php index 858fc612..0a393f42 100755 --- a/app/Http/Requests/Admin/ConfigSave.php +++ b/app/Http/Requests/Admin/ConfigSave.php @@ -32,6 +32,9 @@ class ConfigSave extends FormRequest 'stripe_alipay_enable', 'stripe_wepay_enable', 'stripe_webhook_key', + // bitpayx, + 'bitpayx_enable', + 'bitpayx_appsecret', // tutorial 'apple_id', 'apple_id_password' @@ -65,6 +68,8 @@ class ConfigSave extends FormRequest // stripe 'stripe_alipay_enable' => 'in:0,1', 'stripe_wepay_enable' => 'in:0,1', + // bitpayx + 'bitpayx_enable' => 'in:0,1', // tutorial 'apple_id' => 'email' ];