Skip to content

Commit bba8ddd

Browse files
committed
新增line pay幕後、line pay退款、aftee幕後、後支付確認、交易取消超商代碼等相關api串接參數
1 parent 70eaeec commit bba8ddd

File tree

1 file changed

+42
-25
lines changed

1 file changed

+42
-25
lines changed

src/PayuniApi.php

+42-25
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class PayuniApi
2626
public $encryptInfo, $merKey, $merIV, $apiUrl, $parameter, $curlUrl;
2727
public function __construct(string $key, string $iv, string $type = '')
2828
{
29-
$this->encryptInfo = '';
29+
$this->encryptInfo = [];
3030
$this->merKey = $key;
3131
$this->merIV = $iv;
3232
$this->apiUrl = "api.payuni.com.tw/api/";
@@ -52,17 +52,22 @@ public function UniversalTrade(array $encryptInfo, string $tradeType, string $ve
5252
$this->encryptInfo = $encryptInfo;
5353
$this->parameter['Version'] = $version;
5454
$contrast = [
55-
'upp' => 'upp',
56-
'atm' => 'atm',
57-
'cvs' => 'cvs',
58-
'credit' => 'credit',
59-
'trade_query' => 'trade/query',
60-
'trade_close' => 'trade/close',
61-
'trade_cancel' => 'trade/cancel',
62-
'credit_bind_query' => 'credit_bind/query',
63-
'credit_bind_cancel' => 'credit_bind/cancel',
64-
'trade_refund_icash' => 'trade/common/refund/icash',
65-
'trade_refund_aftee' => 'trade/common/refund/aftee',
55+
'upp' => 'upp',
56+
'atm' => 'atm',
57+
'cvs' => 'cvs',
58+
'credit' => 'credit',
59+
'linepay' => 'linepay',
60+
'aftee_direct' => 'aftee_direct',
61+
'trade_query' => 'trade/query',
62+
'trade_close' => 'trade/close',
63+
'trade_cancel' => 'trade/cancel',
64+
'cancel_cvs' => 'cancel_cvs',
65+
'credit_bind_query' => 'credit_bind/query',
66+
'credit_bind_cancel' => 'credit_bind/cancel',
67+
'trade_refund_icash' => 'trade/common/refund/icash',
68+
'trade_refund_aftee' => 'trade/common/refund/aftee',
69+
'trade_confirm_aftee' => 'trade/common/confirm/aftee',
70+
'trade_refund_linepay' => 'trade/common/refund/linepay',
6671
];
6772
$checkArr = $this->CheckParams();
6873
if ($checkArr['success']) {
@@ -71,18 +76,23 @@ public function UniversalTrade(array $encryptInfo, string $tradeType, string $ve
7176
case 'upp': // 交易建立 整合式支付頁
7277
case 'atm': // 交易建立 虛擬帳號幕後
7378
case 'cvs': // 交易建立 超商代碼幕後
74-
if ($this->encryptInfo['MerTradeNo'] == null || $this->encryptInfo['MerTradeNo'] == '') {
79+
case 'linepay': // 交易建立 LINE Pay幕後
80+
case 'aftee_direct': // 交易建立 AFTEE幕後
81+
if ('linepay' == $tradeType) {
82+
$this->parameter['Version'] = '1.1';
83+
}
84+
if (empty($this->encryptInfo['MerTradeNo'])) {
7585
throw new Exception('商店訂單編號為必填(MerTradeNo is not setting)');
7686
}
77-
if ($this->encryptInfo['TradeAmt'] == null || $this->encryptInfo['TradeAmt'] == '') {
87+
if (empty($this->encryptInfo['TradeAmt'])) {
7888
throw new Exception('訂單金額為必填(TradeAmt is not setting)');
7989
}
8090
break;
8191
case 'credit': // 交易建立 信用卡幕後
82-
if ($this->encryptInfo['MerTradeNo'] == null || $this->encryptInfo['MerTradeNo'] == '') {
92+
if (empty($this->encryptInfo['MerTradeNo'])) {
8393
throw new Exception('商店訂單編號為必填(MerTradeNo is not setting)');
8494
}
85-
if ($this->encryptInfo['TradeAmt'] == null || $this->encryptInfo['TradeAmt'] == '') {
95+
if (empty($this->encryptInfo['TradeAmt'])) {
8696
throw new Exception('訂單金額為必填(TradeAmt is not setting)');
8797
}
8898
if (!isset($this->encryptInfo['CreditHash'])) {
@@ -98,32 +108,39 @@ public function UniversalTrade(array $encryptInfo, string $tradeType, string $ve
98108
}
99109
break;
100110
case 'trade_close': // 交易請退款
101-
if ($this->encryptInfo['TradeNo'] == null || $this->encryptInfo['TradeNo'] == '') {
111+
if (empty($this->encryptInfo['TradeNo'])) {
102112
throw new Exception('uni序號為必填(TradeNo is not setting)');
103113
}
104-
if ($this->encryptInfo['CloseType'] == null || $this->encryptInfo['CloseType'] == '') {
114+
if (empty($this->encryptInfo['CloseType'])) {
105115
throw new Exception('關帳類型為必填(CloseType is not setting)');
106116
}
107117
break;
108118
case 'trade_cancel': // 交易取消授權
109-
if ($this->encryptInfo['TradeNo'] == null || $this->encryptInfo['TradeNo'] == '') {
119+
case 'trade_confirm_aftee': // 後支付確認(AFTEE)
120+
if (empty($this->encryptInfo['TradeNo'])) {
110121
throw new Exception('uni序號為必填(TradeNo is not setting)');
111122
}
112123
break;
124+
case 'cancel_cvs': // 交易取消超商代碼(CVS)
125+
if (empty($this->encryptInfo['PayNo'])) {
126+
throw new Exception('超商代碼為必填(PayNo is not setting)');
127+
}
128+
break;
113129
case 'credit_bind_cancel': // 信用卡token取消(約定/記憶卡號)
114-
if ($this->encryptInfo['UseTokenType'] == null || $this->encryptInfo['UseTokenType'] == '') {
130+
if (empty($this->encryptInfo['UseTokenType'])) {
115131
throw new Exception('信用卡Token類型為必填(UseTokenType is not setting)');
116132
}
117-
if ($this->encryptInfo['BindVal'] == null || $this->encryptInfo['BindVal'] == '') {
133+
if (empty($this->encryptInfo['BindVal'])) {
118134
throw new Exception('綁定回傳值 /信用卡Token(BindVal is not setting)');
119135
}
120136
break;
121137
case 'trade_refund_icash': // 愛金卡退款(ICASH)
122138
case 'trade_refund_aftee': // 後支付退款(AFTEE)
123-
if ($this->encryptInfo['TradeNo'] == null || $this->encryptInfo['TradeNo'] == '') {
139+
case 'trade_refund_linepay': // LINE Pay退款(LINE)
140+
if (empty($this->encryptInfo['TradeNo'])) {
124141
throw new Exception('uni序號為必填(TradeNo is not setting)');
125142
}
126-
if ($this->encryptInfo['TradeAmt'] == null || $this->encryptInfo['TradeAmt'] == '') {
143+
if (empty($this->encryptInfo['TradeAmt'])) {
127144
throw new Exception('訂單金額為必填(TradeAmt is not setting)');
128145
}
129146
break;
@@ -200,10 +217,10 @@ public function ResultProcess($result)
200217
private function CheckParams()
201218
{
202219
try {
203-
if ($this->encryptInfo['MerID'] == null || $this->encryptInfo['MerID'] == '') {
220+
if (empty($this->encryptInfo['MerID'])) {
204221
throw new Exception('商店代號為必填(MerID is not setting)');
205222
}
206-
if ($this->encryptInfo['Timestamp'] == null || $this->encryptInfo['Timestamp'] == '') {
223+
if (empty($this->encryptInfo['Timestamp'])) {
207224
throw new Exception('時間戳記為必填(Timestamp is not setting)');
208225
}
209226
return ['success' => true, 'message' => 'params is set correctly'];

0 commit comments

Comments
 (0)