Skip to content

Commit 46e297e

Browse files
committed
錯誤訊息增加中文提示
1 parent 5800031 commit 46e297e

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

src/PayuniApi.php

+21-22
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ public function __construct(string $key, string $iv, string $type = '')
3535
$prefix .= "sandbox-";
3636
}
3737
$this->apiUrl = $prefix . $this->apiUrl;
38-
3938
$this->parameter = [
4039
'MerID' => '',
4140
'Version' => '1.0',
@@ -72,66 +71,66 @@ public function UniversalTrade(array $encryptInfo, string $tradeType)
7271
case 'atm': // 交易建立 虛擬帳號幕後
7372
case 'cvs': // 交易建立 超商代碼幕後
7473
if ($this->encryptInfo['MerTradeNo'] == null || $this->encryptInfo['MerTradeNo'] == '') {
75-
throw new Exception('MerTradeNo is not setting');
74+
throw new Exception('商店訂單編號為必填(MerTradeNo is not setting)');
7675
}
7776
if ($this->encryptInfo['TradeAmt'] == null || $this->encryptInfo['TradeAmt'] == '') {
78-
throw new Exception('TradeAmt is not setting');
77+
throw new Exception('訂單金額為必填(TradeAmt is not setting)');
7978
}
8079
break;
8180
case 'credit': // 交易建立 信用卡幕後
8281
if ($this->encryptInfo['MerTradeNo'] == null || $this->encryptInfo['MerTradeNo'] == '') {
83-
throw new Exception('MerTradeNo is not setting');
82+
throw new Exception('商店訂單編號為必填(MerTradeNo is not setting)');
8483
}
8584
if ($this->encryptInfo['TradeAmt'] == null || $this->encryptInfo['TradeAmt'] == '') {
86-
throw new Exception('TradeAmt is not setting');
85+
throw new Exception('訂單金額為必填(TradeAmt is not setting)');
8786
}
8887
if (!isset($this->encryptInfo['CreditHash'])) {
8988
if ($this->encryptInfo['CardNo'] == null || $this->encryptInfo['CardNo'] == '') {
90-
throw new Exception('CardNo is not setting');
89+
throw new Exception('信用卡卡號為必填(CardNo is not setting)');
9190
}
9291
if ($this->encryptInfo['CardExpired'] == null || $this->encryptInfo['CardExpired'] == '') {
93-
throw new Exception('CardExpired is not setting');
92+
throw new Exception('信用卡到期年月為必填(CardExpired is not setting)');
9493
}
9594
if ($this->encryptInfo['CardCVC'] == null || $this->encryptInfo['CardCVC'] == '') {
96-
throw new Exception('CardCVC is not setting');
95+
throw new Exception('信用卡安全碼為必填(CardCVC is not setting)');
9796
}
9897
}
9998
break;
10099
case 'trade_close': // 交易請退款
101100
if ($this->encryptInfo['TradeNo'] == null || $this->encryptInfo['TradeNo'] == '') {
102-
throw new Exception('TradeNo is not setting');
101+
throw new Exception('uni序號為必填(TradeNo is not setting)');
103102
}
104103
if ($this->encryptInfo['CloseType'] == null || $this->encryptInfo['CloseType'] == '') {
105-
throw new Exception('CloseType is not setting');
104+
throw new Exception('關帳類型為必填(CloseType is not setting)');
106105
}
107106
break;
108107
case 'trade_cancel': // 交易取消授權
109108
if ($this->encryptInfo['TradeNo'] == null || $this->encryptInfo['TradeNo'] == '') {
110-
throw new Exception('TradeNo is not setting');
109+
throw new Exception('uni序號為必填(TradeNo is not setting)');
111110
}
112111
break;
113112
case 'credit_bind_cancel': // 信用卡token取消(約定/記憶卡號)
114113
if ($this->encryptInfo['UseTokenType'] == null || $this->encryptInfo['UseTokenType'] == '') {
115-
throw new Exception('UseTokenType is not setting');
114+
throw new Exception('信用卡Token類型為必填(UseTokenType is not setting)');
116115
}
117116
if ($this->encryptInfo['BindVal'] == null || $this->encryptInfo['BindVal'] == '') {
118-
throw new Exception('BindVal is not setting');
117+
throw new Exception('綁定回傳值 /信用卡Token(BindVal is not setting)');
119118
}
120119
break;
121120
case 'trade_refund_icash': // 愛金卡退款(ICASH)
122121
case 'trade_refund_aftee': // 後支付退款(AFTEE)
123122
if ($this->encryptInfo['TradeNo'] == null || $this->encryptInfo['TradeNo'] == '') {
124-
throw new Exception('TradeNo is not setting');
123+
throw new Exception('uni序號為必填(TradeNo is not setting)');
125124
}
126125
if ($this->encryptInfo['TradeAmt'] == null || $this->encryptInfo['TradeAmt'] == '') {
127-
throw new Exception('TradeAmt is not setting');
126+
throw new Exception('訂單金額為必填(TradeAmt is not setting)');
128127
}
129128
break;
130129
case 'trade_query': // 交易查詢
131130
case 'credit_bind_query': // 信用卡token查詢(約定)
132131
break;
133132
default:
134-
throw new Exception('Unknown params');
133+
throw new Exception('未提供該參數類型(Unknown params)');
135134
break;
136135
}
137136
$this->SetParams($contrast[$tradeType]);
@@ -162,7 +161,7 @@ public function ResultProcess($result)
162161
} else {
163162
$resultArr = json_decode($result, true);
164163
if (!is_array($resultArr)) {
165-
throw new Exception('Result must be an array');
164+
throw new Exception('傳入參數需為陣列(Result must be an array)');
166165
}
167166
}
168167
if ("ERROR" == $resultArr['Status']) {
@@ -172,15 +171,15 @@ public function ResultProcess($result)
172171
if (isset($resultArr['HashInfo'])) {
173172
$chkHash = $this->HashInfo($resultArr['EncryptInfo']);
174173
if ($chkHash != $resultArr['HashInfo']) {
175-
throw new Exception('Hash mismatch');
174+
throw new Exception('Hash值比對失敗(Hash mismatch)');
176175
}
177176
$resultArr['EncryptInfo'] = $this->Decrypt($resultArr['EncryptInfo']);
178177
return ['success' => true, 'message' => $resultArr];
179178
} else {
180-
throw new Exception('missing HashInfo');
179+
throw new Exception('缺少Hash資訊(missing HashInfo)');
181180
}
182181
} else {
183-
throw new Exception('missing EncryptInfo');
182+
throw new Exception('缺少加密字串(missing EncryptInfo)');
184183
}
185184
} catch (Exception $e) {
186185
return ['success' => false, 'message' => $e->getMessage()];
@@ -195,10 +194,10 @@ private function CheckParams()
195194
{
196195
try {
197196
if ($this->encryptInfo['MerID'] == null || $this->encryptInfo['MerID'] == '') {
198-
throw new Exception('MerID is not setting');
197+
throw new Exception('商店代號為必填(MerID is not setting)');
199198
}
200199
if ($this->encryptInfo['Timestamp'] == null || $this->encryptInfo['Timestamp'] == '') {
201-
throw new Exception('Timestamp is not setting');
200+
throw new Exception('時間戳記為必填(Timestamp is not setting)');
202201
}
203202
return ['success' => true, 'message' => 'params is set correctly'];
204203
} catch (Exception $e) {

0 commit comments

Comments
 (0)