@@ -26,7 +26,7 @@ class PayuniApi
26
26
public $ encryptInfo , $ merKey , $ merIV , $ apiUrl , $ parameter , $ curlUrl ;
27
27
public function __construct (string $ key , string $ iv , string $ type = '' )
28
28
{
29
- $ this ->encryptInfo = '' ;
29
+ $ this ->encryptInfo = [] ;
30
30
$ this ->merKey = $ key ;
31
31
$ this ->merIV = $ iv ;
32
32
$ this ->apiUrl = "api.payuni.com.tw/api/ " ;
@@ -52,17 +52,22 @@ public function UniversalTrade(array $encryptInfo, string $tradeType, string $ve
52
52
$ this ->encryptInfo = $ encryptInfo ;
53
53
$ this ->parameter ['Version ' ] = $ version ;
54
54
$ 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 ' ,
66
71
];
67
72
$ checkArr = $ this ->CheckParams ();
68
73
if ($ checkArr ['success ' ]) {
@@ -71,18 +76,23 @@ public function UniversalTrade(array $encryptInfo, string $tradeType, string $ve
71
76
case 'upp ' : // 交易建立 整合式支付頁
72
77
case 'atm ' : // 交易建立 虛擬帳號幕後
73
78
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 ' ])) {
75
85
throw new Exception ('商店訂單編號為必填(MerTradeNo is not setting) ' );
76
86
}
77
- if ($ this ->encryptInfo ['TradeAmt ' ] == null || $ this -> encryptInfo [ ' TradeAmt ' ] == '' ) {
87
+ if (empty ( $ this ->encryptInfo ['TradeAmt ' ]) ) {
78
88
throw new Exception ('訂單金額為必填(TradeAmt is not setting) ' );
79
89
}
80
90
break ;
81
91
case 'credit ' : // 交易建立 信用卡幕後
82
- if ($ this ->encryptInfo ['MerTradeNo ' ] == null || $ this -> encryptInfo [ ' MerTradeNo ' ] == '' ) {
92
+ if (empty ( $ this ->encryptInfo ['MerTradeNo ' ]) ) {
83
93
throw new Exception ('商店訂單編號為必填(MerTradeNo is not setting) ' );
84
94
}
85
- if ($ this ->encryptInfo ['TradeAmt ' ] == null || $ this -> encryptInfo [ ' TradeAmt ' ] == '' ) {
95
+ if (empty ( $ this ->encryptInfo ['TradeAmt ' ]) ) {
86
96
throw new Exception ('訂單金額為必填(TradeAmt is not setting) ' );
87
97
}
88
98
if (!isset ($ this ->encryptInfo ['CreditHash ' ])) {
@@ -98,32 +108,39 @@ public function UniversalTrade(array $encryptInfo, string $tradeType, string $ve
98
108
}
99
109
break ;
100
110
case 'trade_close ' : // 交易請退款
101
- if ($ this ->encryptInfo ['TradeNo ' ] == null || $ this -> encryptInfo [ ' TradeNo ' ] == '' ) {
111
+ if (empty ( $ this ->encryptInfo ['TradeNo ' ]) ) {
102
112
throw new Exception ('uni序號為必填(TradeNo is not setting) ' );
103
113
}
104
- if ($ this ->encryptInfo ['CloseType ' ] == null || $ this -> encryptInfo [ ' CloseType ' ] == '' ) {
114
+ if (empty ( $ this ->encryptInfo ['CloseType ' ]) ) {
105
115
throw new Exception ('關帳類型為必填(CloseType is not setting) ' );
106
116
}
107
117
break ;
108
118
case 'trade_cancel ' : // 交易取消授權
109
- if ($ this ->encryptInfo ['TradeNo ' ] == null || $ this ->encryptInfo ['TradeNo ' ] == '' ) {
119
+ case 'trade_confirm_aftee ' : // 後支付確認(AFTEE)
120
+ if (empty ($ this ->encryptInfo ['TradeNo ' ])) {
110
121
throw new Exception ('uni序號為必填(TradeNo is not setting) ' );
111
122
}
112
123
break ;
124
+ case 'cancel_cvs ' : // 交易取消超商代碼(CVS)
125
+ if (empty ($ this ->encryptInfo ['PayNo ' ])) {
126
+ throw new Exception ('超商代碼為必填(PayNo is not setting) ' );
127
+ }
128
+ break ;
113
129
case 'credit_bind_cancel ' : // 信用卡token取消(約定/記憶卡號)
114
- if ($ this ->encryptInfo ['UseTokenType ' ] == null || $ this -> encryptInfo [ ' UseTokenType ' ] == '' ) {
130
+ if (empty ( $ this ->encryptInfo ['UseTokenType ' ]) ) {
115
131
throw new Exception ('信用卡Token類型為必填(UseTokenType is not setting) ' );
116
132
}
117
- if ($ this ->encryptInfo ['BindVal ' ] == null || $ this -> encryptInfo [ ' BindVal ' ] == '' ) {
133
+ if (empty ( $ this ->encryptInfo ['BindVal ' ]) ) {
118
134
throw new Exception ('綁定回傳值 /信用卡Token(BindVal is not setting) ' );
119
135
}
120
136
break ;
121
137
case 'trade_refund_icash ' : // 愛金卡退款(ICASH)
122
138
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 ' ])) {
124
141
throw new Exception ('uni序號為必填(TradeNo is not setting) ' );
125
142
}
126
- if ($ this ->encryptInfo ['TradeAmt ' ] == null || $ this -> encryptInfo [ ' TradeAmt ' ] == '' ) {
143
+ if (empty ( $ this ->encryptInfo ['TradeAmt ' ]) ) {
127
144
throw new Exception ('訂單金額為必填(TradeAmt is not setting) ' );
128
145
}
129
146
break ;
@@ -200,10 +217,10 @@ public function ResultProcess($result)
200
217
private function CheckParams ()
201
218
{
202
219
try {
203
- if ($ this ->encryptInfo ['MerID ' ] == null || $ this -> encryptInfo [ ' MerID ' ] == '' ) {
220
+ if (empty ( $ this ->encryptInfo ['MerID ' ]) ) {
204
221
throw new Exception ('商店代號為必填(MerID is not setting) ' );
205
222
}
206
- if ($ this ->encryptInfo ['Timestamp ' ] == null || $ this -> encryptInfo [ ' Timestamp ' ] == '' ) {
223
+ if (empty ( $ this ->encryptInfo ['Timestamp ' ]) ) {
207
224
throw new Exception ('時間戳記為必填(Timestamp is not setting) ' );
208
225
}
209
226
return ['success ' => true , 'message ' => 'params is set correctly ' ];
0 commit comments