Skip to content

Commit

Permalink
feat: allow enable multi payment gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
5aaee9 committed Oct 25, 2021
1 parent f532ee6 commit a61f12e
Show file tree
Hide file tree
Showing 17 changed files with 317 additions and 106 deletions.
13 changes: 4 additions & 9 deletions app/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,24 +98,19 @@
// getPcClient
$this->get('/getPcClient', App\Controllers\UserController::class . ':getPcClient');

$this->post('/code/f2fpay', App\Services\Payment::class . ':purchase');
$this->get('/code/codepay', App\Services\Payment::class . ':purchase');
$this->get('/code/vmqpay', App\Services\Payment::class . ':purchase');

//Reconstructed Payment System
$this->post('/payment/purchase', App\Services\Payment::class . ':purchase');
$this->get('/payment/return', App\Services\Payment::class . ':returnHTML');
$this->post('/payment/purchase/{type}', App\Services\Payment::class . ':purchase');
$this->get('/payment/return/{type}', App\Services\Payment::class . ':returnHTML');

$this->post('/doiam', App\Services\Payment::class . ':purchase');

})->add(new Auth());

$app->group('/payment', function () {
$this->get('/notify', App\Services\Payment::class . ':notify');
$this->post('/notify', App\Services\Payment::class . ':notify');
$this->get('/notify/{type}', App\Services\Payment::class . ':notify');
$this->post('/notify/{type}', App\Services\Payment::class . ':notify');
$this->post('/status', App\Services\Payment::class . ':getStatus');
$this->post('/coinpay/notify', App\Services\CoinPayment::class. ':notify');
// $this->post('/coinpay/notify', App\Services\CoinPayment::class. ':notify');
});

// Auth
Expand Down
8 changes: 7 additions & 1 deletion config/.config.example.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,15 +295,17 @@

//支付系统设置----------------------------------------------------------------------------------------
#取值 none | f2fpay | paymentwall | spay | payjs | theadpay | coinpay | vmqpay
$_ENV['payment_system'] = 'none'; // todo: ['gateway1', 'gateway2']
// $_ENV['payment_system'] = 'none'; // todo: ['gateway1', 'gateway2']

# vmqpay
$_ENV['vmqpay_key'] = ''; //v免签通讯密钥
$_ENV['vmqpay_gateway'] = ''; //v免签网关地址如 https://pay.com
$_ENV['vmqpay_enable'] = false;

# alipay,f2fpay
$_ENV['f2fpay_app_id'] = '';
$_ENV['f2fpay_p_id'] = '';
$_ENV['f2fpay_enable'] = false;
$_ENV['alipay_public_key'] = '';
$_ENV['merchant_private_key'] = '';
$_ENV['f2fNotifyUrl'] = null; //自定义当面付回调地址
Expand All @@ -313,6 +315,7 @@
$_ENV['pmw_privatekey'] = '';
$_ENV['pmw_widget'] = 'm2_1';
$_ENV['pmw_height'] = '350px';
$_ENV['pmw_enable'] = false;

# alipay,zfbjk.com
$_ENV['zfbjk_pid'] = '';
Expand All @@ -322,17 +325,20 @@
# PayJs
$_ENV['payjs_mchid'] = '';
$_ENV['payjs_key'] = '';
$_ENV['payjs_enable'] = false;

# 平头哥支付 https://theadpay.com/
$_ENV['theadpay_url'] = '';
$_ENV['theadpay_mchid'] = '';
$_ENV['theadpay_key'] = '';
$_ENV['theadpay_enable'] = false;

# CoinPay
$_ENV['coinpay_appid'] = ''; // CoinPay 应用ID (*)
$_ENV['coinpay_secret'] = ''; // CoinPay 验证密钥 (*)
$_ENV['coinpay_notify'] = ''; // 异步回调URL
$_ENV['coinpay_return'] = ''; // 同步返回URL
$_ENV['coinpay_enable'] = false;

#后台商品列表 销量统计
$_ENV['sales_period'] = 30; //统计指定周期内的销量,值为【expire/任意大于0的整数】
Expand Down
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
devShell = (pkgs.mkShell {
buildInputs = with pkgs; let
phpWithExtensions = php74.withExtensions ({ enabled, all }:
enabled ++ [ all.imagick ]);
enabled ++ [ all.imagick all.xdebug ]);
in [
phpWithExtensions php74Packages.composer
];
Expand Down
18 changes: 9 additions & 9 deletions resources/views/material/user/aopf2f.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@
<div class="col-lg-6 col-md-6">
<p class="card-heading">支付宝在线充值</p>
<div class="form-group form-group-label">
<label class="floating-label" for="amount">金额</label>
<input class="form-control" id="amount" type="text">
<label class="floating-label" for="amount-f2fpay">金额</label>
<input class="form-control" id="amount-f2fpay" type="text">
</div>
</div>
<div class="col-lg-6 col-md-6">
<div class="h5 margin-top-sm text-black-hint" id="qrarea"></div>
</div>
</div>
</div>
<a class="btn btn-flat waves-attach" id="pay" onclick="pay();"><span class="icon">check</span>&nbsp;充值</a>
<a class="btn btn-flat waves-attach" id="f2fpay" onclick="f2fpay();"><span class="icon">check</span>&nbsp;充值</a>
<script>
var pid = 0;
var flag = false;
function pay() {
function f2fpay() {
$("#readytopay").modal('show');
$.ajax({
type: "POST",
url: "/user/payment/purchase",
url: "/user/payment/purchase/f2fpay",
dataType: "json",
data: {
amount: $$getValue('amount')
amount: $$getValue('amount-f2fpay')
},
success: (data) => {
if (data.ret) {
Expand All @@ -39,7 +39,7 @@
});
$$.getElementById('qrcode').setAttribute('href', data.qrcode);
if(flag == false){
setTimeout(f, 1000);
setTimeout(ff2f, 1000);
flag = true;
}else{
return 0;
Expand All @@ -59,10 +59,10 @@
}
})
}
function f() {
function ff2f() {
$.ajax({
type: "POST",
url: "/payment/status",
url: "/payment/status/f2fpay",
dataType: "json",
data: {
pid: pid
Expand Down
16 changes: 9 additions & 7 deletions resources/views/material/user/code.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,18 @@
</div>
</div>
</div>
{if $pmw!=''}
<div class="col-lg-12 col-md-12">
<div class="card margin-bottom-no">
<div class="card-main">
<div class="card-inner">
{$pmw}
{if count($payments) > 0}
{foreach from=$payments item=payment}
<div class="col-lg-12 col-md-12">
<div class="card margin-bottom-no">
<div class="card-main" id="card-{$payment::_name()}">
<div class="card-inner">
{$payment::getPurchaseHTML()}
</div>
</div>
</div>
</div>
</div>
{/foreach}
{/if}
<div class="col-lg-12 col-md-12">
<div class="card margin-bottom-no">
Expand Down
18 changes: 9 additions & 9 deletions resources/views/material/user/payjs.tpl
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<div class="card-inner">
<p class="card-heading">输入充值金额后,点击下方的图标进行充值</p>
<div class="form-group form-group-label">
<label class="floating-label" for="amount">金额</label>
<input class="form-control" id="amount" type="text">
<label class="floating-label" for="amount-payjs">金额</label>
<input class="form-control" id="amount-payjs" type="text">
</div>
</div>
<div id="qrarea">
<button class="btn btn-flat waves-attach" id="btnSubmit" name="type" onclick="pay('wechat')">
<button class="btn btn-flat waves-attach" id="btnSubmit" name="type" onclick="payjs('wechat')">
<!-- iCon by SFont.Cn -->
<img src="data:image/svg+xml;base64,CjxzdmcgdmVyc2lvbj0iMS4xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB4PSIwcHgiIHk9IjBweCIgdmlld0JveD0iMCAwIDEwMDAgMTAwMCIgZW5hYmxlLWJhY2tncm91bmQ9Im5ldyAwIDAgMTAwMCAxMDAwIiB4bWw6c3BhY2U9InByZXNlcnZlIj4KPG1ldGFkYXRhPiDnn6Lph4/lm77moIfkuIvovb0gOiBodHRwOi8vd3d3LnNmb250LmNuLyA8L21ldGFkYXRhPjxnPjxwYXRoIGQ9Ik0zMTIuNiwzMTUuN2MtMTkuMSwwLTM4LjMsMTIuNi0zOC4zLDMxLjhjMCwxOSwxOS4yLDMxLjcsMzguMywzMS43YzE5LjEsMCwzMS43LTEyLjgsMzEuNy0zMS44QzM0NC4zLDMyOC4yLDMzMS43LDMxNS43LDMxMi42LDMxNS43TDMxMi42LDMxNS43TDMxMi42LDMxNS43eiBNNDkwLjMsMzc5LjFjMTkuMiwwLDMxLjgtMTIuOCwzMS44LTMxLjdjMC0xOS4xLTEyLjYtMzEuOC0zMS44LTMxLjhjLTE5LDAtMzguMSwxMi42LTM4LjEsMzEuOEM0NTIuMywzNjYuNCw0NzEuNCwzNzkuMSw0OTAuMywzNzkuMUw0OTAuMywzNzkuMUw0OTAuMywzNzkuMXogTTU3Mi45LDUwMGMtMTIuNiwwLTI1LjQs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MC0yMTYtODIuNS0yMTYtMTg0LjNjMC0xMDEuNiw5NS4xLTE4NC4zLDIxNi0xODQuM2MxMTQuMSwwLDIxNS44LDgyLjgsMjE1LjgsMTg0LjNDODU4LjgsNjM5LjgsODIwLjgsNjkwLjUsNzY5LjcsNzI4LjhMNzY5LjcsNzI4LjhMNzY5LjcsNzI4Ljh6IiBzdHlsZT0iZmlsbDojMTFjZDZlIj48L3BhdGg+PC9nPjwvc3ZnPiAg"
width="64" height="64">
Expand All @@ -15,10 +15,10 @@
<script>
var pid = 0;
var flag = false;
function pay(type) {
function payjs(type) {
if (type = 'wechat') {
}
var price = parseFloat($$getValue('amount'));
var price = parseFloat($$getValue('amount-payjs'));
//console.log("将要使用 " + type + " 充值" + price + "");
if (isNaN(price)) {
$("#readytopay").modal('hide');
Expand All @@ -28,7 +28,7 @@
}
$('#readytopay').modal();
$.ajax({
url: "/user/payment/purchase",
url: "/user/payment/purchase/payjs",
data: {
price,
type,
Expand All @@ -50,7 +50,7 @@
text: data.url //使用encodeURI()函数报会调低至错误
});
if(flag == false){
tid = setTimeout(f, 1000); //循环调用触发setTimeout
tid = setTimeout(fpayjs, 1000); //循环调用触发setTimeout
flag = true;
}else{
return 0;
Expand All @@ -64,10 +64,10 @@
}
});
}
function f() {
function fpayjs() {
$.ajax({
type: "POST",
url: "/payment/status",
url: "/payment/status/payjs",
dataType: "json",
data: {
pid
Expand Down
18 changes: 9 additions & 9 deletions resources/views/material/user/theadpay.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@
<div class="col-lg-6 col-md-6">
<p class="card-heading">支付宝/微信在线充值</p>
<div class="form-group form-group-label">
<label class="floating-label" for="amount">金额</label>
<input class="form-control" id="amount" type="text">
<label class="floating-label" for="amount-theadpay">金额</label>
<input class="form-control" id="amount-theadpay" type="text">
</div>
</div>
<div class="col-lg-6 col-md-6">
<div class="h5 margin-top-sm text-black-hint" id="qrarea"></div>
</div>
</div>
</div>
<a class="btn btn-flat waves-attach" id="pay" onclick="pay();"><span class="icon">check</span>&nbsp;立即充值</a>
<a class="btn btn-flat waves-attach" id="theadpay" onclick="theadpay();"><span class="icon">check</span>&nbsp;立即充值</a>
<script>
var pid = 0;
var flag = false;
function pay() {
function theadpay() {
$("#readytopay").modal('show');
$.ajax({
type: "POST",
url: "/user/payment/purchase",
url: "/user/payment/purchase/theadpay",
dataType: "json",
data: {
amount: $$getValue('amount')
amount: $$getValue('amount-theadpay')
},
success: (data) => {
if (data.ret) {
Expand All @@ -39,7 +39,7 @@
});
$$.getElementById('qrcode').setAttribute('href', data.qrcode);
if(flag == false){
setTimeout(f, 1000);
setTimeout(fthead, 1000);
flag = true;
}else{
return 0;
Expand All @@ -59,10 +59,10 @@
}
})
}
function f() {
function fthead() {
$.ajax({
type: "POST",
url: "/payment/status",
url: "/payment/status/theadpay",
dataType: "json",
data: {
pid: pid
Expand Down
3 changes: 2 additions & 1 deletion src/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ public function code($request, $response, $args)
return $response->write(
$this->view()
->assign('codes', $codes)
->assign('pmw', Payment::purchaseHTML())
->assign('payments', Payment::getPaymentsEnabled())
// ->assign('pmw', Payment::purchaseHTML())
->assign('render', $render)
->display('user/code.tpl')
);
Expand Down
29 changes: 28 additions & 1 deletion src/Services/Gateway/AbstractPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,25 @@ abstract public function purchase($request, $response, $args);
*/
abstract public function notify($request, $response, $args);

/**
* 支付网关的 codeName, 规则为 [0-9a-zA-Z_]*
*/
abstract public static function _name();

/**
* 是否启用支付网关
*
* TODO: 传入目前用户信, etc..
*/
abstract public static function _enable();

/**
* 显示给用户的名称
*/
public static function _readableName() {
return (get_called_class())::_name() . ' 充值';
}

/**
* @param Request $request
* @param Response $response
Expand All @@ -45,7 +64,15 @@ abstract public function getReturnHTML($request, $response, $args);
*/
abstract public function getStatus($request, $response, $args);

abstract public function getPurchaseHTML();
abstract public static function getPurchaseHTML();

protected static function getCallbackUrl() {
return $_ENV['baseUrl'] . '/payment/notify/' . (get_called_class())::_name();
}

protected static function getUserReturnUrl() {
return $_ENV['baseUrl'] . '/user/payment/return/' . (get_called_class())::_name();
}

public function postPayment($pid, $method)
{
Expand Down
18 changes: 16 additions & 2 deletions src/Services/Gateway/AopF2F.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,28 @@

class AopF2F extends AbstractPayment
{
public static function _name()
{
return 'f2fpay';
}

public static function _enable()
{
return $_ENV['f2fpay_enable'];
}

public static function _readableName() {
return "支付宝在线充值";
}

private function createGateway()
{
$gateway = Omnipay::create('Alipay_AopF2F');
$gateway->setSignType('RSA2'); //RSA/RSA2
$gateway->setAppId($_ENV['f2fpay_app_id']);
$gateway->setPrivateKey($_ENV['merchant_private_key']); // 可以是路径,也可以是密钥内容
$gateway->setAlipayPublicKey($_ENV['alipay_public_key']); // 可以是路径,也可以是密钥内容
$notifyUrl = $_ENV['f2fNotifyUrl'] ?? ($_ENV['baseUrl'] . '/payment/notify');
$notifyUrl = $_ENV['f2fNotifyUrl'] ?? (self::getCallbackUrl());
$gateway->setNotifyUrl($notifyUrl);
return $gateway;
}
Expand Down Expand Up @@ -89,7 +103,7 @@ public function notify($request, $response, $args)
}


public function getPurchaseHTML()
public static function getPurchaseHTML()
{
return View::getSmarty()->fetch('user/aopf2f.tpl');
}
Expand Down
Loading

0 comments on commit a61f12e

Please sign in to comment.