-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathonepaid_bank.php
165 lines (156 loc) · 5.97 KB
/
onepaid_bank.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<?php
if (!defined("WHMCS")) {
die("This file cannot be accessed directly");
}
use WHMCS\Database\Capsule;
function onepaid_bank_MetaData()
{
return array(
'DisplayName' => 'onepaid_bank',
'APIVersion' => '1.5',
'DisableLocalCreditCardInput' => true,
'TokenisedStorage' => false,
);
}
function onepaid_bank_config()
{
return array(
// the friendly display name for a payment gateway should be
// defined here for backwards compatibility
'FriendlyName' => array(
'Type' => 'System',
'Value' => 'OnePaid (萬付通)銀行轉帳-背景取號',
),
// a text field type allows for single line text input
'MerID' => array(
'FriendlyName' => 'MerchantID (商店代號)',
'Type' => 'text',
'Size' => '100',
'Default' => '',
'Description' => 'MerchantID',
),
// a password field type allows for masked text input
'SecurityCode' => array(
'FriendlyName' => 'SecurityCode',
'Type' => 'text',
'Size' => '100',
'Default' => '',
'Description' => 'SecurityCode',
),
'PaymentType' => array(
'FriendlyName' => '銀行選擇',
'Type' => 'text',
'Size' => '100',
'Default' => '',
'Description' => '請輸入銀行數字(請參考<a href="https://www.onepaid.com/CashFlowAPI"><strong>API文件</strong></a>第26頁)請注意!本付款方式為實體ATM,並非WebATM,若輸入為WebATM的代號將會無法開單!',
),
'd' => array(
'FriendlyName' => '說明',
'Type' => 'readonly',
'Size' => '1000',
'Value' => '',
'Description' => '付款通知網址請設定:<網址>/modules/gateways/callback/onepaid.php 舉例:https://shop.easy-store.tw/modules/gateways/callback/onepaid.php',
'Default' => '',
),
);
}
function onepaid_bank_link($params){
// 網關參數
$MerID = $params['MerID'];
$SecurityCode = $params['SecurityCode'];
$bankcode = $params['PaymentType'];
// 帳單參數
$invoiceId = $params['invoiceid'];
$description = $params["description"];
//由於支付接口不支援小數金額,因此取整數金額。
$amount = round($params['amount']);
$amount = $amount.'.00';
// 客戶參數
$firstname = $params['clientdetails']['firstname'];
$lastname = $params['clientdetails']['lastname'];
$email = $params['clientdetails']['email'];
$address1 = $params['clientdetails']['address1'];
$address2 = $params['clientdetails']['address2'];
$city = $params['clientdetails']['city'];
$state = $params['clientdetails']['state'];
$postcode = $params['clientdetails']['postcode'];
$country = $params['clientdetails']['country'];
$phone = $params['clientdetails']['phonenumber'];
// 系統參數
$companyName = $params['companyname'];
$systemUrl = $params['systemurl'];
$returnUrl = $params['returnurl'];
$langPayNow = $params['langpaynow'];
$moduleDisplayName = $params['name'];
$moduleName = $params['paymentmethod'];
$whmcsVersion = $params['whmcsVersion'];
$url = 'https://payment.onepaid.com/payment/PayLaterOrder';
$time = date("Y-m-d H:i:s");
$oid = date("YmdHis");
//交易參數
$post = array(
'MerID' => trim($MerID),
'MerTradeNo' => 'WHMCS'.$oid,
'MerTradeDate' => $time,
'PaymentType' => $bankcode,
'ProductName' => "Invoice".$invoiceId,
'CurrencyType' => '1',
'TotalAmt' => $amount,
'Remark' => $invoiceId,
);
//產生檢核碼
ksort($post);
$postfields = http_build_query($post);
$postfields = "SecurityCode=".$SecurityCode."&".$postfields;
$postfields = urlencode($postfields);
$postfields = str_replace('%2d', '-', $postfields);
$postfields = str_replace('%5f', '_', $postfields);
$postfields = str_replace('%2e', '.', $postfields);
$postfields = str_replace('%21', '!', $postfields);
$postfields = str_replace('%2a', '*', $postfields);
$postfields = str_replace('%28', '(', $postfields);
$postfields = str_replace('%29', ')', $postfields);
$postfields = str_replace('&', '%3d', $postfields);
$postfields = strtolower($postfields);
$postfields = str_replace('%253a%252f%252f', '%3a%2f%2f', $postfields);
$postfields = str_replace('%2b', '+', $postfields);
$postfields = str_replace('%253a', '%3a', $postfields);
$postfields = str_replace('%252f', '%2f', $postfields);
$SignCode = md5($postfields);
$data = array(
'MerID' => trim($MerID),
'MerTradeNo' => 'WHMCS'.$oid,
'MerTradeDate' => $time,
'PaymentType' => $bankcode,
'ProductName' => "Invoice".$invoiceId,
'CurrencyType' => '1',
'TotalAmt' => $amount,
'Remark' => $invoiceId,
'SignCode' => $SignCode,
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST,true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST,'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$result = curl_exec($ch);
curl_close ($ch);
$data = json_decode($result, true);
$eee = $data['CustomeArgs'];
$info = str_replace("]","",str_replace("[","",$eee));
$info = json_decode($info, true);
global $_LANG;
$PaymentNo = $info['BankNo'];
$VirtualAccount = $info['VirtualAccount'];
$ExpireDateStr = $info['PayDeadline'];
$code = '<div class="text-left alert alert-info"><p><b>銀行代碼:</b><code>'.$PaymentNo.'</code></p>'.
'<p><b>繳費代碼:</b><code>'.$VirtualAccount.'</code></p>'.
'<p><b>繳費期限:</b><code>'.$ExpireDateStr.'</code></p></div>';
return $code;
echo '<meta http-equiv="refresh" content="0;url='.$params['returnurl'].'" />';
}
function curl_post($url,$data)
{
return $result;
}