This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * ECPay 物流 SDK. |
||
4 | * |
||
5 | * @author https://www.ecpay.com.tw |
||
6 | * @version 1.0.1012 |
||
7 | */ |
||
8 | |||
9 | /** |
||
10 | * 物流類型. |
||
11 | * |
||
12 | * @author https://www.ecpay.com.tw |
||
13 | * @category Options |
||
14 | * @version 1.0.1012 |
||
15 | */ |
||
16 | abstract class LogisticsType |
||
0 ignored issues
–
show
|
|||
17 | { |
||
18 | const CVS = 'CVS'; // 超商取貨 |
||
19 | const HOME = 'Home'; // 宅配 |
||
20 | } |
||
21 | |||
22 | /** |
||
23 | * 物流子類型. |
||
24 | * |
||
25 | * @author https://www.ecpay.com.tw |
||
26 | * @category Options |
||
27 | * @version 1.0.1012 |
||
28 | */ |
||
29 | abstract class LogisticsSubType |
||
0 ignored issues
–
show
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.
You can fix this by adding a namespace to your class: namespace YourVendor;
class YourClass { }
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries. ![]() |
|||
30 | { |
||
31 | const TCAT = 'TCAT'; // 黑貓(宅配) |
||
32 | const ECAN = 'ECAN'; // 宅配通 |
||
33 | const FAMILY = 'FAMI'; // 全家 |
||
34 | const UNIMART = 'UNIMART'; // 統一超商 |
||
35 | const HILIFE = 'HILIFE'; // 萊爾富 |
||
36 | const FAMILY_C2C = 'FAMIC2C'; // 全家店到店 |
||
37 | const UNIMART_C2C = 'UNIMARTC2C'; // 統一超商寄貨便 |
||
38 | const HILIFE_C2C = 'HILIFEC2C'; // 萊爾富富店到店 |
||
39 | } |
||
40 | |||
41 | /** |
||
42 | * 是否代收貨款. |
||
43 | * |
||
44 | * @author https://www.ecpay.com.tw |
||
45 | * @category Options |
||
46 | * @version 1.0.1012 |
||
47 | */ |
||
48 | abstract class IsCollection |
||
0 ignored issues
–
show
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.
You can fix this by adding a namespace to your class: namespace YourVendor;
class YourClass { }
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries. ![]() |
|||
49 | { |
||
50 | const YES = 'Y'; // 貨到付款 |
||
51 | const NO = 'N'; // 僅配送 |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * 使用設備. |
||
56 | * |
||
57 | * @author https://www.ecpay.com.tw |
||
58 | * @category Options |
||
59 | * @version 1.0.1012 |
||
60 | */ |
||
61 | abstract class Device |
||
0 ignored issues
–
show
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.
You can fix this by adding a namespace to your class: namespace YourVendor;
class YourClass { }
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries. ![]() |
|||
62 | { |
||
63 | const PC = 0; // PC |
||
64 | const MOBILE = 1; // 行動裝置 |
||
65 | } |
||
66 | |||
67 | /** |
||
68 | * 測試廠商編號 |
||
69 | * |
||
70 | * @author https://www.ecpay.com.tw |
||
71 | * @category Options |
||
72 | * @version 1.0.1012 |
||
73 | */ |
||
74 | abstract class ECPayTestMerchantID |
||
0 ignored issues
–
show
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.
You can fix this by adding a namespace to your class: namespace YourVendor;
class YourClass { }
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries. ![]() |
|||
75 | { |
||
76 | const B2C = '2000132'; // B2C |
||
77 | const C2C = '2000933'; // C2C |
||
78 | } |
||
79 | |||
80 | /** |
||
81 | * 正式環境網址 |
||
82 | * |
||
83 | * @author https://www.ecpay.com.tw |
||
84 | * @category Options |
||
85 | * @version 1.0.1012 |
||
86 | */ |
||
87 | abstract class ECPayURL |
||
0 ignored issues
–
show
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.
You can fix this by adding a namespace to your class: namespace YourVendor;
class YourClass { }
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries. ![]() |
|||
88 | { |
||
89 | const CVS_MAP = 'https://logistics.ecpay.com.tw/Express/map'; // 電子地圖 |
||
90 | const SHIPPING_ORDER = 'https://logistics.ecpay.com.tw/Express/Create'; // 物流訂單建立 |
||
91 | const HOME_RETURN_ORDER = 'https://logistics.ecpay.com.tw/Express/ReturnHome'; // 宅配逆物流訂單 |
||
92 | const UNIMART_RETURN_ORDER = 'https://logistics.ecpay.com.tw/express/ReturnUniMartCVS'; // 超商取貨逆物流訂單(統一超商B2C) |
||
93 | const HILIFE_RETURN_ORDER = 'https://logistics.ecpay.com.tw/express/ReturnHiLifeCVS'; // 超商取貨逆物流訂單(萊爾富超商B2C) |
||
94 | const FAMILY_RETURN_ORDER = 'https://logistics.ecpay.com.tw/express/ReturnCVS'; // 超商取貨逆物流訂單(全家超商B2C) |
||
95 | const FAMILY_RETURN_CHECK = 'https://logistics.ecpay.com.tw/Helper/LogisticsCheckAccoounts'; // 全家逆物流核帳(全家超商B2C) |
||
96 | const UNIMART_UPDATE_LOGISTICS_INFO = 'https://logistics.ecpay.com.tw/Helper/UpdateShipmentInfo'; // 統一修改物流資訊(全家超商B2C) |
||
97 | const UNIMART_UPDATE_STORE_INFO = 'https://logistics.ecpay.com.tw/Express/UpdateStoreInfo'; // 更新門市(統一超商C2C) |
||
98 | const UNIMART_CANCEL_LOGISTICS_ORDER = 'https://logistics.ecpay.com.tw/Express/CancelC2COrder'; // 取消訂單(統一超商C2C) |
||
99 | const QUERY_LOGISTICS_INFO = 'https://logistics.ecpay.com.tw/Helper/QueryLogisticsTradeInfo/V2'; // 物流訂單查詢 |
||
100 | const PRINT_TRADE_DOC = 'https://logistics.ecpay.com.tw/helper/printTradeDocument'; // 產生托運單(宅配)/一段標(超商取貨) |
||
101 | const PRINT_UNIMART_C2C_BILL = 'https://logistics.ecpay.com.tw/Express/PrintUniMartC2COrderInfo'; // 列印繳款單(統一超商C2C) |
||
102 | const PRINT_FAMILY_C2C_BILL = 'https://logistics.ecpay.com.tw/Express/PrintFAMIC2COrderInfo'; // 全家列印小白單(全家超商C2C) |
||
103 | const Print_HILIFE_C2C_BILL = 'https://logistics.ecpay.com.tw/Express/PrintHILIFEC2COrderInfo'; // 萊爾富列印小白單(萊爾富超商C2C) |
||
104 | const CREATE_TEST_DATA = 'https://logistics.ecpay.com.tw/Express/CreateTestData'; // 產生 B2C 測標資料 |
||
105 | } |
||
106 | |||
107 | /** |
||
108 | * 測試環境網址 |
||
109 | * |
||
110 | * @author https://www.ecpay.com.tw |
||
111 | * @category Options |
||
112 | * @version 1.0.1012 |
||
113 | */ |
||
114 | abstract class ECPayTestURL |
||
0 ignored issues
–
show
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.
You can fix this by adding a namespace to your class: namespace YourVendor;
class YourClass { }
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries. ![]() |
|||
115 | { |
||
116 | const CVS_MAP = 'https://logistics-stage.ecpay.com.tw/Express/map'; // 電子地圖 |
||
117 | const SHIPPING_ORDER = 'https://logistics-stage.ecpay.com.tw/Express/Create'; // 物流訂單建立 |
||
118 | const HOME_RETURN_ORDER = 'https://logistics-stage.ecpay.com.tw/Express/ReturnHome'; // 宅配逆物流訂單 |
||
119 | const UNIMART_RETURN_ORDER = 'https://logistics-stage.ecpay.com.tw/express/ReturnUniMartCVS'; // 超商取貨逆物流訂單(統一超商B2C) |
||
120 | const HILIFE_RETURN_ORDER = 'https://logistics-stage.ecpay.com.tw/express/ReturnHiLifeCVS'; // 超商取貨逆物流訂單(萊爾富超商B2C) |
||
121 | const FAMILY_RETURN_ORDER = 'https://logistics-stage.ecpay.com.tw/express/ReturnCVS'; // 超商取貨逆物流訂單(全家超商B2C) |
||
122 | const FAMILY_RETURN_CHECK = 'https://logistics-stage.ecpay.com.tw/Helper/LogisticsCheckAccoounts'; // 全家逆物流核帳(全家超商B2C) |
||
123 | const UNIMART_UPDATE_LOGISTICS_INFO = 'https://logistics-stage.ecpay.com.tw/Helper/UpdateShipmentInfo'; // 統一修改物流資訊(全家超商B2C) |
||
124 | const UNIMART_UPDATE_STORE_INFO = 'https://logistics-stage.ecpay.com.tw/Express/UpdateStoreInfo'; // 更新門市(統一超商C2C) |
||
125 | const UNIMART_CANCEL_LOGISTICS_ORDER = 'https://logistics-stage.ecpay.com.tw/Express/CancelC2COrder'; // 取消訂單(統一超商C2C) |
||
126 | const QUERY_LOGISTICS_INFO = 'https://logistics-stage.ecpay.com.tw/Helper/QueryLogisticsTradeInfo/V2'; // 物流訂單查詢 |
||
127 | const PRINT_TRADE_DOC = 'https://logistics-stage.ecpay.com.tw/helper/printTradeDocument'; // 產生托運單(宅配)/一段標(超商取貨) |
||
128 | const PRINT_UNIMART_C2C_BILL = 'https://logistics-stage.ecpay.com.tw/Express/PrintUniMartC2COrderInfo'; // 列印繳款單(統一超商C2C) |
||
129 | const PRINT_FAMILY_C2C_BILL = 'https://logistics-stage.ecpay.com.tw/Express/PrintFAMIC2COrderInfo'; // 全家列印小白單(全家超商C2C) |
||
130 | const Print_HILIFE_C2C_BILL = 'https://logistics-stage.ecpay.com.tw/Express/PrintHILIFEC2COrderInfo'; // 萊爾富列印小白單(萊爾富超商C2C) |
||
131 | const CREATE_TEST_DATA = 'https://logistics-stage.ecpay.com.tw/Express/CreateTestData'; // 產生 B2C 測標資料 |
||
132 | } |
||
133 | |||
134 | /** |
||
135 | * 溫層. |
||
136 | * |
||
137 | * @author https://www.ecpay.com.tw |
||
138 | * @category Options |
||
139 | * @version 1.0.1012 |
||
140 | */ |
||
141 | abstract class Temperature |
||
0 ignored issues
–
show
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.
You can fix this by adding a namespace to your class: namespace YourVendor;
class YourClass { }
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries. ![]() |
|||
142 | { |
||
143 | const ROOM = '0001'; // 常溫 |
||
144 | const REFRIGERATION = '0002'; // 冷藏 |
||
145 | const FREEZE = '0003'; // 冷凍 |
||
146 | } |
||
147 | |||
148 | /** |
||
149 | * 距離. |
||
150 | * |
||
151 | * @author https://www.ecpay.com.tw |
||
152 | * @category Options |
||
153 | * @version 1.0.1012 |
||
154 | */ |
||
155 | abstract class Distance |
||
0 ignored issues
–
show
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.
You can fix this by adding a namespace to your class: namespace YourVendor;
class YourClass { }
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries. ![]() |
|||
156 | { |
||
157 | const SAME = '00'; // 同縣市 |
||
158 | const OTHER = '01'; // 外縣市 |
||
159 | const ISLAND = '02'; // 離島 |
||
160 | } |
||
161 | |||
162 | /** |
||
163 | * 規格 |
||
164 | * |
||
165 | * @author https://www.ecpay.com.tw |
||
166 | * @category Options |
||
167 | * @version 1.0.1012 |
||
168 | */ |
||
169 | abstract class Specification |
||
0 ignored issues
–
show
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.
You can fix this by adding a namespace to your class: namespace YourVendor;
class YourClass { }
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries. ![]() |
|||
170 | { |
||
171 | const CM_60 = '0001'; // 60cm |
||
172 | const CM_90 = '0002'; // 90cm |
||
173 | const CM_120 = '0003'; // 120cm |
||
174 | const CM_150 = '0004'; // 150cm |
||
175 | } |
||
176 | |||
177 | /** |
||
178 | * 預計取件時段. |
||
179 | * |
||
180 | * @author https://www.ecpay.com.tw |
||
181 | * @category Options |
||
182 | * @version 1.0.1012 |
||
183 | */ |
||
184 | abstract class ScheduledPickupTime |
||
0 ignored issues
–
show
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.
You can fix this by adding a namespace to your class: namespace YourVendor;
class YourClass { }
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries. ![]() |
|||
185 | { |
||
186 | const TIME_9_12 = '1'; // 9~12時 |
||
187 | const TIME_12_17 = '2'; // 12~17時 |
||
188 | const TIME_17_20 = '3'; // 17~20時 |
||
189 | const UNLIMITED = '4'; // 不限時 |
||
190 | } |
||
191 | |||
192 | /** |
||
193 | * 預定送達時段. |
||
194 | * |
||
195 | * @author https://www.ecpay.com.tw |
||
196 | * @category Options |
||
197 | * @version 1.0.1012 |
||
198 | */ |
||
199 | abstract class ScheduledDeliveryTime |
||
0 ignored issues
–
show
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.
You can fix this by adding a namespace to your class: namespace YourVendor;
class YourClass { }
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries. ![]() |
|||
200 | { |
||
201 | const TIME_9_12 = '1'; // 9~12時 |
||
202 | const TIME_12_17 = '2'; // 12~17時 |
||
203 | const TIME_17_20 = '3'; // 17~20時 |
||
204 | const UNLIMITED = '4'; // 不限時 |
||
205 | const TIME_20_21 = '5'; // 20~21時(需限定區域) |
||
206 | const TIME_9_17 = '12'; // 早午 9~17 |
||
207 | const TIME_9_12_17_20 = '13'; // 早晚 9~12 & 17~20 |
||
208 | const TIME_13_20 = '23'; // 午晚 13~20 |
||
209 | } |
||
210 | |||
211 | /** |
||
212 | * 門市類型. |
||
213 | * |
||
214 | * @author https://www.ecpay.com.tw |
||
215 | * @category Options |
||
216 | * @version 1.0.1012 |
||
217 | */ |
||
218 | abstract class StoreType |
||
0 ignored issues
–
show
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.
You can fix this by adding a namespace to your class: namespace YourVendor;
class YourClass { }
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries. ![]() |
|||
219 | { |
||
220 | const RECIVE_STORE = '01'; // 取件門市 |
||
221 | const RETURN_STORE = '02'; // 退件門市 |
||
222 | } |
||
223 | |||
224 | /** |
||
225 | * 物流 SDK. |
||
226 | * |
||
227 | * @author https://www.ecpay.com.tw |
||
228 | * @category Options |
||
229 | * @version 1.0.1012 |
||
230 | */ |
||
231 | class ECPayLogistics |
||
0 ignored issues
–
show
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.
You can fix this by adding a namespace to your class: namespace YourVendor;
class YourClass { }
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries. ![]() |
|||
232 | { |
||
233 | public $ServiceURL = ''; |
||
234 | public $HashKey = ''; |
||
235 | public $HashIV = ''; |
||
236 | public $Send = []; |
||
237 | public $SendExtend = ''; |
||
238 | public $PostParams = []; |
||
239 | public $Encode = 'UTF-8'; |
||
240 | |||
241 | public function __construct() |
||
242 | { |
||
243 | } |
||
244 | |||
245 | /** |
||
246 | * 電子地圖. |
||
247 | * |
||
248 | * @author https://www.ecpay.com.tw |
||
249 | * @category SDK |
||
250 | * @param string $ButtonDesc 按鈕顯示名稱 |
||
251 | * @param string $Target 表單 action 目標 |
||
252 | * @return string |
||
253 | * @version 1.0.1012 |
||
254 | */ |
||
255 | public function CvsMap($ButtonDesc = '電子地圖', $Target = '_self') |
||
256 | { |
||
257 | // 參數初始化 |
||
258 | $ParamList = [ |
||
259 | 'MerchantID' => '', |
||
260 | 'MerchantTradeNo' => '', |
||
261 | 'LogisticsSubType' => '', |
||
262 | 'IsCollection' => '', |
||
263 | 'ServerReplyURL' => '', |
||
264 | 'ExtraData' => '', |
||
265 | 'Device' => Device::PC, |
||
266 | ]; |
||
267 | $this->PostParams = $this->GetPostParams($this->Send, $ParamList); |
||
268 | $this->PostParams['LogisticsType'] = LogisticsType::CVS; |
||
269 | |||
270 | // 參數檢查 |
||
271 | $this->ValidateID('MerchantID', $this->PostParams['MerchantID'], 10); |
||
272 | $this->ServiceURL = $this->GetURL('CVS_MAP'); |
||
273 | $this->ValidateLogisticsSubType(); |
||
274 | $this->ValidateIsCollection(); |
||
275 | $this->ValidateURL('ServerReplyURL', $this->PostParams['ServerReplyURL']); |
||
276 | $this->ValidateString('ExtraData', $this->PostParams['ExtraData'], 20, true); |
||
277 | $this->ValidateDevice(true); |
||
278 | |||
279 | return $this->GenPostHTML($ButtonDesc, $Target); |
||
280 | } |
||
281 | |||
282 | /** |
||
283 | * 物流訂單建立. |
||
284 | * |
||
285 | * @author https://www.ecpay.com.tw |
||
286 | * @category SDK |
||
287 | * @param string $ButtonDesc 按鈕顯示名稱 |
||
288 | * @param string $Target 表單 action 目標 |
||
289 | * @return string |
||
290 | * @version 1.0.1012 |
||
291 | */ |
||
292 | public function CreateShippingOrder($ButtonDesc = '物流訂單建立', $Target = '_self') |
||
293 | { |
||
294 | // 參數初始化 |
||
295 | $ParamList = [ |
||
296 | 'MerchantID' => '', |
||
297 | 'MerchantTradeNo' => '', |
||
298 | 'MerchantTradeDate' => '', |
||
299 | 'LogisticsType' => '', |
||
300 | 'LogisticsSubType' => '', |
||
301 | 'GoodsAmount' => 0, |
||
302 | 'CollectionAmount' => 0, |
||
303 | 'IsCollection' => IsCollection::NO, |
||
304 | 'GoodsName' => '', |
||
305 | 'SenderName' => '', |
||
306 | 'SenderPhone' => '', |
||
307 | 'SenderCellPhone' => '', |
||
308 | 'ReceiverName' => '', |
||
309 | 'ReceiverPhone' => '', |
||
310 | 'ReceiverCellPhone' => '', |
||
311 | 'ReceiverEmail' => '', |
||
312 | 'TradeDesc' => '', |
||
313 | 'ServerReplyURL' => '', |
||
314 | 'ClientReplyURL' => '', |
||
315 | 'LogisticsC2CReplyURL' => '', |
||
316 | 'Remark' => '', |
||
317 | 'PlatformID' => '', |
||
318 | ]; |
||
319 | $this->PostParams = $this->GetPostParams($this->Send, $ParamList); |
||
320 | $MinAmount = 1; // 金額下限 |
||
321 | $MaxAmount = 20000; // 金額上限 |
||
322 | |||
323 | // 參數檢查 |
||
324 | $this->ValidateHashKey(); |
||
325 | $this->ValidateHashIV(); |
||
326 | $this->ValidateID('MerchantID', $this->PostParams['MerchantID'], 10); |
||
327 | $this->ServiceURL = $this->GetURL('SHIPPING_ORDER'); |
||
328 | $this->ValidateMerchantTradeDate(); |
||
329 | $this->ValidateLogisticsType(); |
||
330 | $this->ValidateLogisticsSubType(); |
||
331 | |||
332 | // 依不同的物流類型(LogisticsType)設定專屬參數並檢查 |
||
333 | View Code Duplication | switch ($this->PostParams['LogisticsType']) { |
|
334 | case LogisticsType::CVS: |
||
335 | $CvsParamList = [ |
||
336 | 'ReceiverStoreID' => '', |
||
337 | 'ReturnStoreID' => '', |
||
338 | ]; |
||
339 | $this->PostParams = $this->GetPostParams($this->SendExtend, $CvsParamList, $this->PostParams); |
||
340 | |||
341 | $this->ValidateMixTypeID('ReceiverStoreID', $this->PostParams['ReceiverStoreID'], 6); |
||
342 | $this->ValidateMixTypeID('ReturnStoreID', $this->PostParams['ReturnStoreID'], 6, true); |
||
343 | break; |
||
344 | case LogisticsType::HOME: |
||
345 | $HomeParamList = [ |
||
346 | 'SenderZipCode' => '', |
||
347 | 'SenderAddress' => '', |
||
348 | 'ReceiverZipCode' => '', |
||
349 | 'ReceiverAddress' => '', |
||
350 | 'Temperature' => Temperature::ROOM, |
||
351 | 'Distance' => Distance::SAME, |
||
352 | 'Specification' => Specification::CM_60, |
||
353 | 'ScheduledDeliveryTime' => '', |
||
354 | 'ScheduledDeliveryDate' => '', |
||
355 | 'PackageCount' => 0, |
||
356 | ]; |
||
357 | $this->PostParams = $this->GetPostParams($this->SendExtend, $HomeParamList, $this->PostParams); |
||
358 | $this->PostParams['ScheduledPickupTime'] = ScheduledPickupTime::UNLIMITED; |
||
359 | |||
360 | $this->ValidateZipCode('SenderZipCode', $this->PostParams['SenderZipCode']); |
||
361 | $this->ValidateAddress('SenderAddress', $this->PostParams['SenderAddress'], 6, 60); |
||
362 | $this->ValidateZipCode('ReceiverZipCode', $this->PostParams['ReceiverZipCode']); |
||
363 | $this->ValidateAddress('ReceiverAddress', $this->PostParams['ReceiverAddress'], 6, 60); |
||
364 | $this->ValidateTemperature(); |
||
365 | $this->ValidateDistance(); |
||
366 | $this->ValidateSpecification(); |
||
367 | $this->ValidateScheduledDeliveryTime(true); |
||
368 | break; |
||
369 | default: |
||
370 | } |
||
371 | |||
372 | $this->ValidateAmount('GoodsAmount', $this->PostParams['GoodsAmount']); |
||
373 | View Code Duplication | if ( |
|
374 | $this->PostParams['LogisticsSubType'] == LogisticsSubType::UNIMART || |
||
375 | $this->PostParams['LogisticsSubType'] == LogisticsSubType::UNIMART_C2C |
||
376 | ) { |
||
377 | // 物流子類型(LogisticsSubType)為統一超商(UNIMART)或統一超商交貨便(UNIMARTC2C)時,商品金額範圍為1~19,999元 |
||
378 | $MaxAmount = 19999; |
||
379 | } |
||
380 | if ($this->PostParams['GoodsAmount'] < $MinAmount or $this->PostParams['GoodsAmount'] > $MaxAmount) { |
||
381 | throw new Exception('Invalid GoodsAmount.'); |
||
382 | } |
||
383 | |||
384 | $this->ValidateIsCollection(true); |
||
385 | View Code Duplication | if ($this->PostParams['IsCollection'] == IsCollection::NO) { |
|
386 | // 若設定為僅配送,清除代收金額 |
||
387 | unset($this->PostParams['CollectionAmount']); |
||
388 | } else { |
||
389 | $this->ValidateAmount('CollectionAmount', $this->PostParams['CollectionAmount']); |
||
390 | if ($this->PostParams['CollectionAmount'] < $MinAmount or $this->PostParams['CollectionAmount'] > $MaxAmount) { |
||
391 | throw new Exception('Invalid CollectionAmount.'); |
||
392 | } |
||
393 | } |
||
394 | |||
395 | View Code Duplication | if ($this->PostParams['LogisticsSubType'] == LogisticsSubType::HILIFE_C2C or $this->PostParams['LogisticsSubType'] == LogisticsSubType::UNIMART_C2C) { |
|
396 | // 物流子類型(LogisticsSubType)為萊爾富店到店(HILIFEC2C)、 統一超商交貨便(UNIMARTC2C)時,不可為空 |
||
397 | $this->ValidateString('GoodsName', $this->PostParams['GoodsName'], 60); |
||
398 | } else { |
||
399 | $this->ValidateString('GoodsName', $this->PostParams['GoodsName'], 60, true); |
||
400 | } |
||
401 | |||
402 | $this->ValidateString('SenderName', $this->PostParams['SenderName'], 10); |
||
403 | $this->ValidatePhoneNumber('SenderPhone', $this->PostParams['SenderPhone'], true); |
||
404 | $this->ValidateCellphoneNumber('SenderCellPhone', $this->PostParams['SenderCellPhone'], true); |
||
405 | View Code Duplication | if ($this->PostParams['LogisticsType'] == LogisticsType::HOME) { |
|
406 | // 物流類型(LogisticsType)為宅配(Home)時,寄件人電話(SenderPhone)或寄件人手機(SenderCellPhone)不可為空 |
||
407 | if (empty($this->PostParams['SenderPhone']) and empty($this->PostParams['SenderCellPhone'])) { |
||
408 | throw new Exception('SenderPhone or SenderCellPhone is required when LogisticsType is Home.'); |
||
409 | } |
||
410 | } elseif ($this->PostParams['LogisticsSubType'] == LogisticsSubType::HILIFE_C2C or $this->PostParams['LogisticsSubType'] == LogisticsSubType::UNIMART_C2C) { |
||
411 | // 物流子類型(LogisticsSubType)為統一超商交貨便(UNIMARTC2C)、萊爾富店到店(HILIFEC2C)時,寄件人手機(SenderCellPhone)不可為空 |
||
412 | if (empty($this->PostParams['SenderCellPhone'])) { |
||
413 | throw new Exception('SenderCellPhone is required when LogisticsSubType is UNIMARTC2C or HILIFEC2C.'); |
||
414 | } |
||
415 | } |
||
416 | |||
417 | $this->ValidateString('ReceiverName', $this->PostParams['ReceiverName'], 10); |
||
418 | $this->ValidatePhoneNumber('ReceiverPhone', $this->PostParams['ReceiverPhone'], true); |
||
419 | $this->ValidateCellphoneNumber('ReceiverCellPhone', $this->PostParams['ReceiverCellPhone'], true); |
||
420 | View Code Duplication | if ($this->PostParams['LogisticsType'] == LogisticsType::HOME) { |
|
421 | // 物流類型(LogisticsType)為宅配(Home)時,收件人電話(ReceiverPhone)或收件人手機(ReceiverCellPhone)不可為空 |
||
422 | if (empty($this->PostParams['ReceiverPhone']) and empty($this->PostParams['ReceiverCellPhone'])) { |
||
423 | throw new Exception('ReceiverPhone or ReceiverCellPhone is required when LogisticsType is Home.'); |
||
424 | } |
||
425 | } else { |
||
426 | // 物流子類型(LogisticsSubType)為統一超商(UNIMART)、全家(FAMILY)、萊爾富(HILIFE)、統一超商交貨便(UNIMARTC2C)、全家超商店到店(FAMILYC2C)、萊爾富富店到店(HILIFEC2C)時,收件人手機(ReceiverCellPhone)不可為空 |
||
427 | if (empty($this->PostParams['ReceiverCellPhone'])) { |
||
428 | throw new Exception('ReceiverCellPhone is required.'); |
||
429 | } |
||
430 | } |
||
431 | |||
432 | View Code Duplication | if ($this->PostParams['LogisticsSubType'] == LogisticsSubType::ECAN and $this->PostParams['Temperature'] !== Temperature::ROOM) { |
|
433 | // 物流子類型為宅配通(ECAN)時,溫層(Temperature)只能用常溫(ROOM) |
||
434 | throw new Exception('Temperature should be ROOM when LogisticsSubType is ECAN.'); |
||
435 | } |
||
436 | |||
437 | View Code Duplication | if ($this->PostParams['LogisticsSubType'] == LogisticsSubType::ECAN and date('Ymd', strtotime($this->PostParams['ScheduledDeliveryDate'])) < date('Ymd', strtotime('+3 day'))) { |
|
438 | // 指定送達日期為該訂單建立時間 + 3 天 |
||
439 | throw new Exception('ScheduledDeliveryDate should be the time that create order + 3 day.'); |
||
440 | } |
||
441 | |||
442 | $this->ValidateEmail('ReceiverEmail', $this->PostParams['ReceiverEmail'], 50, true); |
||
443 | $this->ValidateString('TradeDesc', $this->PostParams['TradeDesc'], 200, true); |
||
444 | $this->ValidateURL('ServerReplyURL', $this->PostParams['ServerReplyURL']); |
||
445 | $this->ValidateURL('ClientReplyURL', $this->PostParams['ClientReplyURL'], 200, true); |
||
446 | |||
447 | View Code Duplication | if ($this->PostParams['LogisticsSubType'] == LogisticsSubType::UNIMART_C2C) { |
|
448 | // 物流子類型(LogisticsSubType)為統一超商交貨便(UNIMARTC2C)時,此欄位不可為空 |
||
449 | $this->ValidateURL('LogisticsC2CReplyURL', $this->PostParams['LogisticsC2CReplyURL']); |
||
450 | } else { |
||
451 | $this->ValidateURL('LogisticsC2CReplyURL', $this->PostParams['LogisticsC2CReplyURL'], 200, true); |
||
452 | } |
||
453 | |||
454 | $this->ValidateString('Remark', $this->PostParams['Remark'], 200, true); |
||
455 | $this->ValidateID('PlatformID', $this->PostParams['PlatformID'], 10, true); |
||
456 | |||
457 | // 物流類型(LogisticsType)為宅配(Home)且溫層(Temperature)為冷凍(0003)時,規格(Specification)不可為 150cm(0004) |
||
458 | View Code Duplication | if ($this->PostParams['LogisticsType'] == LogisticsType::HOME and $this->PostParams['Temperature'] == Temperature::FREEZE) { |
|
459 | if ($this->PostParams['Specification'] == Specification::CM_150) { |
||
460 | throw new Exception('Specification could not be 150cm(0004) when LogisticsType is Home and Temperature is FREEZE(0003).'); |
||
461 | } |
||
462 | } |
||
463 | |||
464 | // 產生 CheckMacValue |
||
465 | $this->PostParams['CheckMacValue'] = ECPay_CheckMacValue::generate($this->PostParams, $this->HashKey, $this->HashIV); |
||
466 | |||
467 | return $this->GenPostHTML($ButtonDesc, $Target); |
||
468 | } |
||
469 | |||
470 | /** |
||
471 | * 幕後物流訂單建立. |
||
472 | * |
||
473 | * @author https://www.ecpay.com.tw |
||
474 | * @category SDK |
||
475 | * @return array |
||
476 | * @version 1.0.1012 |
||
477 | */ |
||
478 | public function BGCreateShippingOrder() |
||
479 | { |
||
480 | // 參數初始化 |
||
481 | $ParamList = [ |
||
482 | 'MerchantID' => '', |
||
483 | 'MerchantTradeNo' => '', |
||
484 | 'MerchantTradeDate' => '', |
||
485 | 'LogisticsType' => '', |
||
486 | 'LogisticsSubType' => '', |
||
487 | 'GoodsAmount' => 0, |
||
488 | 'CollectionAmount' => 0, |
||
489 | 'IsCollection' => IsCollection::NO, |
||
490 | 'GoodsName' => '', |
||
491 | 'SenderName' => '', |
||
492 | 'SenderPhone' => '', |
||
493 | 'SenderCellPhone' => '', |
||
494 | 'ReceiverName' => '', |
||
495 | 'ReceiverPhone' => '', |
||
496 | 'ReceiverCellPhone' => '', |
||
497 | 'ReceiverEmail' => '', |
||
498 | 'TradeDesc' => '', |
||
499 | 'ServerReplyURL' => '', |
||
500 | 'LogisticsC2CReplyURL' => '', |
||
501 | 'Remark' => '', |
||
502 | 'PlatformID' => '', |
||
503 | ]; |
||
504 | |||
505 | // 幕後物流訂單建立不可設定Client端回覆網址(ClientReplyURL) |
||
506 | if (! empty($this->Send['ClientReplyURL'])) { |
||
507 | throw new Exception('ClientReplyURL should be null.'); |
||
508 | } |
||
509 | |||
510 | $this->PostParams = $this->GetPostParams($this->Send, $ParamList); |
||
511 | $MinAmount = 1; // 金額下限 |
||
512 | $MaxAmount = 20000; // 金額上限 |
||
513 | |||
514 | // 參數檢查 |
||
515 | $this->ValidateHashKey(); |
||
516 | $this->ValidateHashIV(); |
||
517 | $this->ValidateID('MerchantID', $this->PostParams['MerchantID'], 10); |
||
518 | $this->ServiceURL = $this->GetURL('SHIPPING_ORDER'); |
||
519 | $this->ValidateMerchantTradeDate(); |
||
520 | $this->ValidateLogisticsType(); |
||
521 | $this->ValidateLogisticsSubType(); |
||
522 | |||
523 | // 依不同的物流類型(LogisticsType)設定專屬參數並檢查 |
||
524 | View Code Duplication | switch ($this->PostParams['LogisticsType']) { |
|
525 | case LogisticsType::CVS: |
||
526 | $CvsParamList = [ |
||
527 | 'ReceiverStoreID' => '', |
||
528 | 'ReturnStoreID' => '', |
||
529 | ]; |
||
530 | $this->PostParams = $this->GetPostParams($this->SendExtend, $CvsParamList, $this->PostParams); |
||
531 | |||
532 | $this->ValidateMixTypeID('ReceiverStoreID', $this->PostParams['ReceiverStoreID'], 6); |
||
533 | $this->ValidateMixTypeID('ReturnStoreID', $this->PostParams['ReturnStoreID'], 6, true); |
||
534 | break; |
||
535 | case LogisticsType::HOME: |
||
536 | $HomeParamList = [ |
||
537 | 'SenderZipCode' => '', |
||
538 | 'SenderAddress' => '', |
||
539 | 'ReceiverZipCode' => '', |
||
540 | 'ReceiverAddress' => '', |
||
541 | 'Temperature' => Temperature::ROOM, |
||
542 | 'Distance' => Distance::SAME, |
||
543 | 'Specification' => Specification::CM_60, |
||
544 | 'ScheduledDeliveryTime' => '', |
||
545 | 'ScheduledDeliveryDate' => '', |
||
546 | 'PackageCount' => 0, |
||
547 | ]; |
||
548 | $this->PostParams = $this->GetPostParams($this->SendExtend, $HomeParamList, $this->PostParams); |
||
549 | $this->PostParams['ScheduledPickupTime'] = ScheduledPickupTime::UNLIMITED; |
||
550 | |||
551 | $this->ValidateZipCode('SenderZipCode', $this->PostParams['SenderZipCode']); |
||
552 | $this->ValidateAddress('SenderAddress', $this->PostParams['SenderAddress'], 6, 60); |
||
553 | $this->ValidateZipCode('ReceiverZipCode', $this->PostParams['ReceiverZipCode']); |
||
554 | $this->ValidateAddress('ReceiverAddress', $this->PostParams['ReceiverAddress'], 6, 60); |
||
555 | $this->ValidateTemperature(); |
||
556 | $this->ValidateDistance(); |
||
557 | $this->ValidateSpecification(); |
||
558 | $this->ValidateScheduledDeliveryTime(true); |
||
559 | break; |
||
560 | default: |
||
561 | } |
||
562 | |||
563 | $this->ValidateAmount('GoodsAmount', $this->PostParams['GoodsAmount']); |
||
564 | View Code Duplication | if ( |
|
565 | $this->PostParams['LogisticsSubType'] == LogisticsSubType::UNIMART || |
||
566 | $this->PostParams['LogisticsSubType'] == LogisticsSubType::UNIMART_C2C |
||
567 | ) { |
||
568 | // 物流子類型(LogisticsSubType)為統一超商(UNIMART)或統一超商交貨便(UNIMARTC2C)時,商品金額範圍為1~19,999元 |
||
569 | $MaxAmount = 19999; |
||
570 | } |
||
571 | if ($this->PostParams['GoodsAmount'] < $MinAmount or $this->PostParams['GoodsAmount'] > $MaxAmount) { |
||
572 | throw new Exception('Invalid GoodsAmount.'); |
||
573 | } |
||
574 | |||
575 | $this->ValidateIsCollection(true); |
||
576 | View Code Duplication | if ($this->PostParams['IsCollection'] == IsCollection::NO) { |
|
577 | // 若設定為僅配送,清除代收金額 |
||
578 | unset($this->PostParams['CollectionAmount']); |
||
579 | } else { |
||
580 | $this->ValidateAmount('CollectionAmount', $this->PostParams['CollectionAmount']); |
||
581 | if ($this->PostParams['CollectionAmount'] < $MinAmount or $this->PostParams['CollectionAmount'] > $MaxAmount) { |
||
582 | throw new Exception('Invalid CollectionAmount.'); |
||
583 | } |
||
584 | } |
||
585 | |||
586 | View Code Duplication | if ($this->PostParams['LogisticsSubType'] == LogisticsSubType::HILIFE_C2C or $this->PostParams['LogisticsSubType'] == LogisticsSubType::UNIMART_C2C) { |
|
587 | // 物流子類型(LogisticsSubType)為萊爾富店到店(HILIFEC2C)、 統一超商交貨便(UNIMARTC2C)時,不可為空 |
||
588 | $this->ValidateString('GoodsName', $this->PostParams['GoodsName'], 60); |
||
589 | } else { |
||
590 | $this->ValidateString('GoodsName', $this->PostParams['GoodsName'], 60, true); |
||
591 | } |
||
592 | |||
593 | $this->ValidateString('SenderName', $this->PostParams['SenderName'], 10); |
||
594 | $this->ValidatePhoneNumber('SenderPhone', $this->PostParams['SenderPhone'], true); |
||
595 | $this->ValidateCellphoneNumber('SenderCellPhone', $this->PostParams['SenderCellPhone'], true); |
||
596 | View Code Duplication | if ($this->PostParams['LogisticsType'] == LogisticsType::HOME) { |
|
597 | // 物流類型(LogisticsType)為宅配(Home)時,寄件人電話(SenderPhone)或寄件人手機(SenderCellPhone)不可為空 |
||
598 | if (empty($this->PostParams['SenderPhone']) and empty($this->PostParams['SenderCellPhone'])) { |
||
599 | throw new Exception('SenderPhone or SenderCellPhone is required when LogisticsType is Home.'); |
||
600 | } |
||
601 | } elseif ($this->PostParams['LogisticsSubType'] == LogisticsSubType::HILIFE_C2C or $this->PostParams['LogisticsSubType'] == LogisticsSubType::UNIMART_C2C) { |
||
602 | // 物流子類型(LogisticsSubType)為統一超商交貨便(UNIMARTC2C)、萊爾富店到店(HILIFEC2C)時,寄件人手機(SenderCellPhone)不可為空 |
||
603 | if (empty($this->PostParams['SenderCellPhone'])) { |
||
604 | throw new Exception('SenderCellPhone is required when LogisticsSubType is UNIMARTC2C or HILIFEC2C.'); |
||
605 | } |
||
606 | } |
||
607 | |||
608 | $this->ValidateString('ReceiverName', $this->PostParams['ReceiverName'], 10); |
||
609 | $this->ValidatePhoneNumber('ReceiverPhone', $this->PostParams['ReceiverPhone'], true); |
||
610 | $this->ValidateCellphoneNumber('ReceiverCellPhone', $this->PostParams['ReceiverCellPhone'], true); |
||
611 | View Code Duplication | if ($this->PostParams['LogisticsType'] == LogisticsType::HOME) { |
|
612 | // 物流類型(LogisticsType)為宅配(Home)時,收件人電話(ReceiverPhone)或收件人手機(ReceiverCellPhone)不可為空 |
||
613 | if (empty($this->PostParams['ReceiverPhone']) and empty($this->PostParams['ReceiverCellPhone'])) { |
||
614 | throw new Exception('ReceiverPhone or ReceiverCellPhone is required when LogisticsType is Home.'); |
||
615 | } |
||
616 | } else { |
||
617 | // 物流子類型(LogisticsSubType)為統一超商(UNIMART)、全家(FAMILY)、萊爾富(HILIFE)、統一超商交貨便(UNIMARTC2C)、全家超商店到店(FAMILYC2C)、萊爾富富店到店(HILIFEC2C)時,收件人手機(ReceiverCellPhone)不可為空 |
||
618 | if (empty($this->PostParams['ReceiverCellPhone'])) { |
||
619 | throw new Exception('ReceiverCellPhone is required.'); |
||
620 | } |
||
621 | } |
||
622 | |||
623 | View Code Duplication | if ($this->PostParams['LogisticsSubType'] == LogisticsSubType::ECAN and $this->PostParams['Temperature'] !== Temperature::ROOM) { |
|
624 | // 物流子類型為宅配通(ECAN)時,溫層(Temperature)只能用常溫(ROOM) |
||
625 | throw new Exception('Temperature should be ROOM when LogisticsSubType is ECAN.'); |
||
626 | } |
||
627 | |||
628 | View Code Duplication | if ($this->PostParams['LogisticsSubType'] == LogisticsSubType::ECAN and date('Ymd', strtotime($this->PostParams['ScheduledDeliveryDate'])) < date('Ymd', strtotime('+3 day'))) { |
|
629 | // 指定送達日期為該訂單建立時間 + 3 天 |
||
630 | throw new Exception('ScheduledDeliveryDate should be the time that create order + 3 day.'); |
||
631 | } |
||
632 | |||
633 | $this->ValidateEmail('ReceiverEmail', $this->PostParams['ReceiverEmail'], 50, true); |
||
634 | $this->ValidateString('TradeDesc', $this->PostParams['TradeDesc'], 200, true); |
||
635 | $this->ValidateURL('ServerReplyURL', $this->PostParams['ServerReplyURL']); |
||
636 | |||
637 | View Code Duplication | if ($this->PostParams['LogisticsSubType'] == LogisticsSubType::UNIMART_C2C) { |
|
638 | // 物流子類型(LogisticsSubType)為統一超商交貨便(UNIMARTC2C)時,此欄位不可為空 |
||
639 | $this->ValidateURL('LogisticsC2CReplyURL', $this->PostParams['LogisticsC2CReplyURL']); |
||
640 | } else { |
||
641 | $this->ValidateURL('LogisticsC2CReplyURL', $this->PostParams['LogisticsC2CReplyURL'], 200, true); |
||
642 | } |
||
643 | |||
644 | $this->ValidateString('Remark', $this->PostParams['Remark'], 200, true); |
||
645 | $this->ValidateID('PlatformID', $this->PostParams['PlatformID'], 10, true); |
||
646 | |||
647 | // 物流類型(LogisticsType)為宅配(Home)且溫層(Temperature)為冷凍(0003)時,規格(Specification)不可為 150cm(0004) |
||
648 | View Code Duplication | if ($this->PostParams['LogisticsType'] == LogisticsType::HOME and $this->PostParams['Temperature'] == Temperature::FREEZE) { |
|
649 | if ($this->PostParams['Specification'] == Specification::CM_150) { |
||
650 | throw new Exception('Specification could not be 0004 when LogisticsType is Home and Temperature is 0003.'); |
||
651 | } |
||
652 | } |
||
653 | |||
654 | // 產生 CheckMacValue |
||
655 | $this->PostParams['CheckMacValue'] = ECPay_CheckMacValue::generate($this->PostParams, $this->HashKey, $this->HashIV); |
||
656 | |||
657 | // urlencode |
||
658 | foreach ($this->PostParams as $key => $value) { |
||
659 | $this->PostParams[$key] = urlencode($value); |
||
660 | } |
||
661 | |||
662 | // 解析回傳結果 |
||
663 | // 正確:1|MerchantID=XXX&MerchantTradeNo=XXX&RtnCode=XXX&RtnMsg=XXX&AllPayLogisticsID=XXX&LogisticsType=XXX&LogisticsSubType=XXX&GoodsAmount=XXX&UpdateStatusDate=XXX&ReceiverName=XXX&ReceiverPhone=XXX&ReceiverCellPhone=XXX&ReceiverEmail=XXX&ReceiverAddress=XXX&CVSPaymentNo=XXX&CVSValidationNo=XXX &CheckMacValue=XXX |
||
664 | // 錯誤:0|ErrorMessage |
||
665 | $Feedback = ECPay_IO::ServerPost($this->PostParams, $this->ServiceURL); |
||
666 | $Pieces = explode('|', $Feedback); |
||
667 | $Result = []; |
||
668 | $Result['ResCode'] = $Pieces[0]; |
||
669 | if ($Result['ResCode']) { |
||
670 | $RtnCont = []; |
||
671 | parse_str($Pieces[1], $RtnCont); |
||
672 | $Result = array_merge($Result, $RtnCont); |
||
673 | } else { |
||
674 | $Result['ErrorMessage'] = $Pieces[1]; |
||
675 | } |
||
676 | |||
677 | return $Result; |
||
678 | } |
||
679 | |||
680 | /** |
||
681 | * 回傳 CheckMacValue 檢查. |
||
682 | * |
||
683 | * @author https://www.ecpay.com.tw |
||
684 | * @category SDK |
||
685 | * @param array $Feedback ECPay 回傳資料 |
||
686 | * @version 1.0.1012 |
||
687 | */ |
||
688 | public function CheckOutFeedback($Feedback = []) |
||
689 | { |
||
690 | $this->ValidateHashKey(); |
||
691 | $this->ValidateHashIV(); |
||
692 | |||
693 | if (empty($Feedback)) { |
||
694 | throw new Exception('Feedback is required.'); |
||
695 | } |
||
696 | |||
697 | if (! isset($Feedback['CheckMacValue'])) { |
||
698 | throw new Exception('Feedback CheckMacValue is required.'); |
||
699 | } else { |
||
700 | $FeedbackCheckMacValue = $Feedback['CheckMacValue']; |
||
701 | unset($Feedback['CheckMacValue']); |
||
702 | unset($Feedback['ResCode']); |
||
703 | unset($Feedback['ErrorMessage']); |
||
704 | $CheckMacValue = ECPay_CheckMacValue::generate($Feedback, $this->HashKey, $this->HashIV); |
||
705 | if ($CheckMacValue != $FeedbackCheckMacValue) { |
||
706 | throw new Exception('CheckMacValue verify fail.'); |
||
707 | } |
||
708 | } |
||
709 | } |
||
710 | |||
711 | /** |
||
712 | * 宅配逆物流訂單產生 |
||
713 | * |
||
714 | * @author https://www.ecpay.com.tw |
||
715 | * @category SDK |
||
716 | * @return array |
||
717 | * @version 1.0.1012 |
||
718 | */ |
||
719 | public function CreateHomeReturnOrder() |
||
720 | { |
||
721 | |||
722 | // 參數初始化 |
||
723 | $ParamList = [ |
||
724 | 'MerchantID' => '', |
||
725 | 'AllPayLogisticsID' => '', |
||
726 | 'LogisticsSubType' => '', |
||
727 | 'ServerReplyURL' => '', |
||
728 | 'SenderName' => '', |
||
729 | 'SenderPhone' => '', |
||
730 | 'SenderCellPhone' => '', |
||
731 | 'SenderZipCode' => '', |
||
732 | 'SenderAddress' => '', |
||
733 | 'ReceiverName' => '', |
||
734 | 'ReceiverPhone' => '', |
||
735 | 'ReceiverCellPhone' => '', |
||
736 | 'ReceiverZipCode' => '', |
||
737 | 'ReceiverAddress' => '', |
||
738 | 'GoodsAmount' => '', |
||
739 | 'GoodsName' => '', |
||
740 | 'Temperature' => Temperature::ROOM, |
||
741 | 'Distance' => Distance::SAME, |
||
742 | 'Specification' => Specification::CM_60, |
||
743 | 'ScheduledPickupTime' => ScheduledPickupTime::UNLIMITED, |
||
744 | 'ScheduledDeliveryTime' => '', |
||
745 | 'ScheduledDeliveryDate' => '', |
||
746 | 'PackageCount' => 0, |
||
747 | 'Remark' => '', |
||
748 | 'PlatformID' => '', |
||
749 | ]; |
||
750 | $this->PostParams = $this->GetPostParams($this->Send, $ParamList); |
||
751 | $this->PostParams['ScheduledPickupTime'] = ScheduledPickupTime::UNLIMITED; // 預定取件時段(ScheduledPickupTime)固定為不限時 |
||
752 | $IsAllpayLogisticsIdEmpty = false; // 物流交易編號(AllPayLogisticsID)是否為空 |
||
753 | $IsAllowEmpty = true; |
||
754 | $MinAmount = 1; // 金額下限 |
||
755 | $MaxAmount = 20000; // 金額上限 |
||
756 | |||
757 | // 參數檢查 |
||
758 | $this->ValidateHashKey(); |
||
759 | $this->ValidateHashIV(); |
||
760 | $this->ValidateID('MerchantID', $this->PostParams['MerchantID'], 10); |
||
761 | $this->ServiceURL = $this->GetURL('HOME_RETURN_ORDER'); |
||
762 | |||
763 | $this->ValidateID('AllPayLogisticsID', $this->PostParams['AllPayLogisticsID'], 20, true); |
||
764 | |||
765 | $this->ValidateLogisticsSubType(true); |
||
766 | |||
767 | // 物流交易編號(AllPayLogisticsID)與物流子類型(LogisticsSubType)擇一不可為空 |
||
768 | if (empty($this->PostParams['AllPayLogisticsID'])) { |
||
769 | $IsAllpayLogisticsIdEmpty = true; |
||
770 | } |
||
771 | if ($IsAllpayLogisticsIdEmpty === true and empty($this->PostParams['LogisticsSubType'])) { |
||
772 | throw new Exception('One of AllPayLogisticsID and LogisticsSubType is required.'); |
||
773 | } |
||
774 | |||
775 | $this->ValidateURL('ServerReplyURL', $this->PostParams['ServerReplyURL']); |
||
776 | |||
777 | // 物流交易編號(AllPayLogisticsID)為空值時,退貨人姓名(SenderName)不可為空。 |
||
778 | if ($IsAllpayLogisticsIdEmpty) { |
||
779 | $IsAllowEmpty = false; |
||
780 | } |
||
781 | $this->ValidateString('SenderName', $this->PostParams['SenderName'], 10, $IsAllowEmpty); |
||
782 | |||
783 | $this->ValidatePhoneNumber('SenderPhone', $this->PostParams['SenderPhone'], true); |
||
784 | $this->ValidateCellphoneNumber('SenderCellPhone', $this->PostParams['SenderCellPhone'], true); |
||
785 | // 物流交易編號(AllPayLogisticsID)為空值時,退貨人電話(SenderPhone)與退貨人手機(SenderCellPhone)擇一不可為空。 |
||
786 | if ($IsAllpayLogisticsIdEmpty) { |
||
787 | if (empty($this->PostParams['SenderPhone']) and empty($this->PostParams['SenderCellPhone'])) { |
||
788 | throw new Exception('One of SenderPhone and SenderCellPhone is required.'); |
||
789 | } |
||
790 | } |
||
791 | |||
792 | // 物流交易編號(AllPayLogisticsID)為空值時,退貨人郵遞區號(SenderZipCode)不可為空。 |
||
793 | $this->ValidateZipCode('SenderZipCode', $this->PostParams['SenderZipCode'], $IsAllowEmpty); |
||
794 | |||
795 | // 物流交易編號(AllPayLogisticsID)為空值時,SenderAddress(SenderAddress)不可為空。 |
||
796 | $this->ValidateAddress('SenderAddress', $this->PostParams['SenderAddress'], 6, 60, $IsAllowEmpty); |
||
797 | |||
798 | // 若物流交易編號(AllPayLogisticsID)為空值時,收件人姓名(ReceiverName)不可為空。 |
||
799 | $this->ValidateString('ReceiverName', $this->PostParams['ReceiverName'], 10, $IsAllowEmpty); |
||
800 | |||
801 | $this->ValidatePhoneNumber('ReceiverPhone', $this->PostParams['ReceiverPhone'], 20, true); |
||
802 | $this->ValidateCellphoneNumber('ReceiverCellPhone', $this->PostParams['ReceiverCellPhone'], 20, true); |
||
803 | // 物流交易編號(AllPayLogisticsID)為空值時,收件人電話(ReceiverPhone)與收件人手機(ReceiverCellPhone)擇一不可為空。 |
||
804 | if ($IsAllpayLogisticsIdEmpty) { |
||
805 | if (empty($this->PostParams['ReceiverPhone']) and empty($this->PostParams['ReceiverCellPhone'])) { |
||
806 | throw new Exception('One of ReceiverPhone and ReceiverCellPhone is required.'); |
||
807 | } |
||
808 | } |
||
809 | |||
810 | // 若物流交易編號(AllPayLogisticsID)為空值時,收件人郵遞區號(ReceiverZipCode)不可為空。 |
||
811 | $this->ValidateZipCode('ReceiverZipCode', $this->PostParams['ReceiverZipCode'], $IsAllowEmpty); |
||
812 | |||
813 | // 若物流交易編號(AllPayLogisticsID)為空值時,收件人地址(ReceiverAddress)不可為空。 |
||
814 | $this->ValidateAddress('ReceiverAddress', $this->PostParams['ReceiverAddress'], 6, 60, $IsAllowEmpty); |
||
815 | |||
816 | View Code Duplication | if ($this->PostParams['LogisticsSubType'] == LogisticsSubType::ECAN and $this->PostParams['Temperature'] !== Temperature::ROOM) { |
|
817 | // 物流子類型為宅配通(ECAN)時,溫層(Temperature)只能用常溫(ROOM) |
||
818 | throw new Exception('Temperature should be ROOM when LogisticsSubType is ECAN.'); |
||
819 | } |
||
820 | |||
821 | View Code Duplication | if ($this->PostParams['LogisticsSubType'] == LogisticsSubType::ECAN and date('Ymd', strtotime($this->PostParams['ScheduledDeliveryDate'])) < date('Ymd', strtotime('+3 day'))) { |
|
822 | // 指定送達日期為該訂單建立時間 + 3 天 |
||
823 | throw new Exception('ScheduledDeliveryDate should be the time that create order + 3 day.'); |
||
824 | } |
||
825 | |||
826 | $this->ValidateAmount('GoodsAmount', $this->PostParams['GoodsAmount']); |
||
827 | if ($this->PostParams['GoodsAmount'] < $MinAmount or $this->PostParams['GoodsAmount'] > $MaxAmount) { |
||
828 | throw new Exception('Invalid GoodsAmount.'); |
||
829 | } |
||
830 | $this->ValidateString('GoodsName', $this->PostParams['GoodsName'], 60, true); |
||
831 | $this->ValidateTemperature(); |
||
832 | $this->ValidateDistance(); |
||
833 | $this->ValidateSpecification(); |
||
834 | $this->ValidateScheduledDeliveryTime(true); |
||
835 | $this->ValidateString('Remark', $this->PostParams['Remark'], 200, true); |
||
836 | |||
837 | $this->ValidateID('PlatformID', $this->PostParams['PlatformID'], 10, true); |
||
838 | |||
839 | // 產生 CheckMacValue |
||
840 | $this->PostParams['CheckMacValue'] = ECPay_CheckMacValue::generate($this->PostParams, $this->HashKey, $this->HashIV); |
||
841 | |||
842 | // 解析回傳結果 |
||
843 | // 正確:1|OK |
||
844 | // 錯誤:0|ErrorMessage |
||
845 | $Feedback = ECPay_IO::ServerPost($this->PostParams, $this->ServiceURL); |
||
846 | $Result = $this->ParseFeedback($Feedback); |
||
847 | |||
848 | return $Result; |
||
849 | } |
||
850 | |||
851 | /** |
||
852 | * 超商取貨逆物流訂單(統一超商B2C). |
||
853 | * |
||
854 | * @author https://www.ecpay.com.tw |
||
855 | * @category SDK |
||
856 | * @return array |
||
857 | * @version 1.0.1012 |
||
858 | */ |
||
859 | View Code Duplication | public function CreateUnimartB2CReturnOrder() |
|
860 | { |
||
861 | |||
862 | // 參數初始化 |
||
863 | $ParamList = [ |
||
864 | 'MerchantID' => '', |
||
865 | 'AllPayLogisticsID' => '', |
||
866 | 'ServerReplyURL' => '', |
||
867 | 'GoodsName' => '', |
||
868 | 'GoodsAmount' => 0, |
||
869 | 'SenderName' => '', |
||
870 | 'SenderPhone' => '', |
||
871 | 'Remark' => '', |
||
872 | 'PlatformID' => '', |
||
873 | ]; |
||
874 | $this->PostParams = $this->GetPostParams($this->Send, $ParamList); |
||
875 | $this->PostParams['CollectionAmount'] = 0; |
||
876 | $this->PostParams['ServiceType'] = 4; // 退貨不付款 |
||
877 | |||
878 | // 參數檢查 |
||
879 | $this->ValidateHashKey(); |
||
880 | $this->ValidateHashIV(); |
||
881 | $this->ValidateID('MerchantID', $this->PostParams['MerchantID'], 10); |
||
882 | $this->ServiceURL = $this->GetURL('UNIMART_RETURN_ORDER'); |
||
883 | $this->ValidateID('AllPayLogisticsID', $this->PostParams['AllPayLogisticsID'], 20, true); |
||
884 | $this->ValidateURL('ServerReplyURL', $this->PostParams['ServerReplyURL']); |
||
885 | $this->ValidateString('GoodsName', $this->PostParams['GoodsName'], 60, true); |
||
886 | $this->ValidateAmount('GoodsAmount', $this->PostParams['GoodsAmount']); |
||
887 | $this->ValidateString('SenderName', $this->PostParams['SenderName'], 50); |
||
888 | $this->ValidatePhoneNumber('SenderPhone', $this->PostParams['SenderPhone'], true); |
||
889 | $this->ValidateString('Remark', $this->PostParams['Remark'], 20, true); |
||
890 | $this->ValidateID('PlatformID', $this->PostParams['PlatformID'], 10, true); |
||
891 | |||
892 | $MinAmount = 1; // 金額下限 |
||
893 | $MaxAmount = 19999; // 金額上限 |
||
894 | if ($this->PostParams['GoodsAmount'] < $MinAmount or $this->PostParams['GoodsAmount'] > $MaxAmount) { |
||
895 | throw new Exception('Invalid GoodsAmount.'); |
||
896 | } |
||
897 | |||
898 | // 產生 CheckMacValue |
||
899 | $this->PostParams['CheckMacValue'] = ECPay_CheckMacValue::generate($this->PostParams, $this->HashKey, $this->HashIV); |
||
900 | |||
901 | // 解析回傳結果 |
||
902 | // 正確:RtnMerchantTradeNo | RtnOrderNo |
||
903 | // 錯誤:|ErrorMessage |
||
904 | $Feedback = ECPay_IO::ServerPost($this->PostParams, $this->ServiceURL); |
||
905 | $Pieces = explode('|', $Feedback); |
||
906 | $Result = ['RtnMerchantTradeNo' => '', 'RtnOrderNo' => '']; |
||
907 | if (empty($Pieces[0])) { |
||
908 | $Result = ['ErrorMessage' => $Pieces[1]]; |
||
909 | } else { |
||
910 | $Result['RtnMerchantTradeNo'] = $Pieces[0]; |
||
911 | $Result['RtnOrderNo'] = $Pieces[1]; |
||
912 | } |
||
913 | |||
914 | return $Result; |
||
915 | } |
||
916 | |||
917 | /** |
||
918 | * 超商取貨逆物流訂單(萊爾富超商B2C). |
||
919 | * |
||
920 | * @author https://www.ecpay.com.tw |
||
921 | * @category SDK |
||
922 | * @return array |
||
923 | * @version 1.0.1012 |
||
924 | */ |
||
925 | View Code Duplication | public function CreateHiLifeB2CReturnOrder() |
|
926 | { |
||
927 | |||
928 | // 參數初始化 |
||
929 | $ParamList = [ |
||
930 | 'MerchantID' => '', |
||
931 | 'AllPayLogisticsID' => '', |
||
932 | 'ServerReplyURL' => '', |
||
933 | 'GoodsName' => '', |
||
934 | 'GoodsAmount' => 0, |
||
935 | 'SenderName' => '', |
||
936 | 'SenderPhone' => '', |
||
937 | 'Remark' => '', |
||
938 | 'PlatformID' => '', |
||
939 | ]; |
||
940 | $this->PostParams = $this->GetPostParams($this->Send, $ParamList); |
||
941 | $this->PostParams['CollectionAmount'] = 0; |
||
942 | $this->PostParams['ServiceType'] = 4; // 退貨不付款 |
||
943 | |||
944 | // 參數檢查 |
||
945 | $this->ValidateHashKey(); |
||
946 | $this->ValidateHashIV(); |
||
947 | $this->ValidateID('MerchantID', $this->PostParams['MerchantID'], 10); |
||
948 | $this->ServiceURL = $this->GetURL('HILIFE_RETURN_ORDER'); |
||
949 | $this->ValidateID('AllPayLogisticsID', $this->PostParams['AllPayLogisticsID'], 20, true); |
||
950 | $this->ValidateURL('ServerReplyURL', $this->PostParams['ServerReplyURL']); |
||
951 | $this->ValidateString('GoodsName', $this->PostParams['GoodsName'], 60, true); |
||
952 | $this->ValidateAmount('GoodsAmount', $this->PostParams['GoodsAmount']); |
||
953 | $this->ValidateString('SenderName', $this->PostParams['SenderName'], 50); |
||
954 | $this->ValidatePhoneNumber('SenderPhone', $this->PostParams['SenderPhone'], true); |
||
955 | $this->ValidateString('Remark', $this->PostParams['Remark'], 20, true); |
||
956 | $this->ValidateID('PlatformID', $this->PostParams['PlatformID'], 10, true); |
||
957 | |||
958 | $MinAmount = 1; // 金額下限 |
||
959 | $MaxAmount = 20000; // 金額上限 |
||
960 | if ($this->PostParams['GoodsAmount'] < $MinAmount or $this->PostParams['GoodsAmount'] > $MaxAmount) { |
||
961 | throw new Exception('Invalid GoodsAmount.'); |
||
962 | } |
||
963 | |||
964 | // 產生 CheckMacValue |
||
965 | $this->PostParams['CheckMacValue'] = ECPay_CheckMacValue::generate($this->PostParams, $this->HashKey, $this->HashIV); |
||
966 | |||
967 | // 解析回傳結果 |
||
968 | // 正確:RtnMerchantTradeNo | RtnOrderNo |
||
969 | // 錯誤:|ErrorMessage |
||
970 | $Feedback = ECPay_IO::ServerPost($this->PostParams, $this->ServiceURL); |
||
971 | $Pieces = explode('|', $Feedback); |
||
972 | $Result = ['RtnMerchantTradeNo' => '', 'RtnOrderNo' => '']; |
||
973 | if (empty($Pieces[0])) { |
||
974 | $Result = ['ErrorMessage' => $Pieces[1]]; |
||
975 | } else { |
||
976 | $Result['RtnMerchantTradeNo'] = $Pieces[0]; |
||
977 | $Result['RtnOrderNo'] = $Pieces[1]; |
||
978 | } |
||
979 | |||
980 | return $Result; |
||
981 | } |
||
982 | |||
983 | /** |
||
984 | * 超商取貨逆物流訂單(全家超商B2C). |
||
985 | * |
||
986 | * @author https://www.ecpay.com.tw |
||
987 | * @category SDK |
||
988 | * @return array |
||
989 | * @version 1.0.1012 |
||
990 | */ |
||
991 | public function CreateFamilyB2CReturnOrder() |
||
992 | { |
||
993 | |||
994 | // 參數初始化 |
||
995 | $ParamList = [ |
||
996 | 'MerchantID' => '', |
||
997 | 'AllPayLogisticsID' => '', |
||
998 | 'ServerReplyURL' => '', |
||
999 | 'GoodsName' => '', |
||
1000 | 'GoodsAmount' => 0, |
||
1001 | 'SenderName' => '', |
||
1002 | 'SenderPhone' => '', |
||
1003 | 'Remark' => '', |
||
1004 | 'Quantity' => '', |
||
1005 | 'Cost' => '', |
||
1006 | 'PlatformID' => '', |
||
1007 | ]; |
||
1008 | $this->PostParams = $this->GetPostParams($this->Send, $ParamList); |
||
1009 | $this->PostParams['CollectionAmount'] = 0; |
||
1010 | $this->PostParams['ServiceType'] = 4; // 退貨不付款 |
||
1011 | |||
1012 | // 參數檢查 |
||
1013 | $this->ValidateHashKey(); |
||
1014 | $this->ValidateHashIV(); |
||
1015 | $this->ValidateID('MerchantID', $this->PostParams['MerchantID'], 10); |
||
1016 | $this->ServiceURL = $this->GetURL('FAMILY_RETURN_ORDER'); |
||
1017 | $this->ValidateID('AllPayLogisticsID', $this->PostParams['AllPayLogisticsID'], 20, true); |
||
1018 | $this->ValidateURL('ServerReplyURL', $this->PostParams['ServerReplyURL']); |
||
1019 | $this->ValidateString('GoodsName', $this->PostParams['GoodsName'], 50, true); |
||
1020 | $this->ValidateAmount('GoodsAmount', $this->PostParams['GoodsAmount']); |
||
1021 | $this->ValidateString('SenderName', $this->PostParams['SenderName'], 50); |
||
1022 | $this->ValidatePhoneNumber('SenderPhone', $this->PostParams['SenderPhone'], true); |
||
1023 | $this->ValidateString('Remark', $this->PostParams['Remark'], 20, true); |
||
1024 | $this->ValidateString('Quantity', $this->PostParams['Quantity'], 50, true); |
||
1025 | $this->ValidateString('Cost', $this->PostParams['Cost'], 50, true); |
||
1026 | $this->ValidateID('PlatformID', $this->PostParams['PlatformID'], 10, true); |
||
1027 | |||
1028 | // 檢查商品名稱, 數量 與 成本 |
||
1029 | $GoodsNameNumber = count(explode('#', $this->PostParams['GoodsName'])); |
||
1030 | $QuantityNumber = count(explode('#', $this->PostParams['Quantity'])); |
||
1031 | $CostNumber = count(explode('#', $this->PostParams['Cost'])); |
||
1032 | |||
1033 | View Code Duplication | if (! empty($this->PostParams['GoodsName']) and ! empty($this->PostParams['Quantity'])) { |
|
1034 | if ($GoodsNameNumber != $QuantityNumber) { |
||
1035 | throw new Exception('GoodsName number and Quantity number do not match.'); |
||
1036 | } |
||
1037 | } |
||
1038 | |||
1039 | View Code Duplication | if (! empty($this->PostParams['Quantity']) and ! empty($this->PostParams['Cost'])) { |
|
1040 | if ($GoodsNameNumber != $CostNumber) { |
||
1041 | throw new Exception('Quantity number and Cost number do not match.'); |
||
1042 | } |
||
1043 | } |
||
1044 | |||
1045 | View Code Duplication | if (! empty($this->PostParams['Cost']) and ! empty($this->PostParams['GoodsName'])) { |
|
1046 | if ($GoodsNameNumber != $CostNumber) { |
||
1047 | throw new Exception('Cost number and GoodsName number do not match.'); |
||
1048 | } |
||
1049 | } |
||
1050 | |||
1051 | $MinAmount = 1; // 金額下限 |
||
1052 | $MaxAmount = 20000; // 金額上限 |
||
1053 | if ($this->PostParams['GoodsAmount'] < $MinAmount or $this->PostParams['GoodsAmount'] > $MaxAmount) { |
||
1054 | throw new Exception('Invalid GoodsAmount.'); |
||
1055 | } |
||
1056 | |||
1057 | // 產生 CheckMacValue |
||
1058 | $this->PostParams['CheckMacValue'] = ECPay_CheckMacValue::generate($this->PostParams, $this->HashKey, $this->HashIV); |
||
1059 | |||
1060 | // 解析回傳結果 |
||
1061 | // 正確:RtnMerchantTradeNo | RtnOrderNo |
||
1062 | // 錯誤:|ErrorMessage |
||
1063 | $Feedback = ECPay_IO::ServerPost($this->PostParams, $this->ServiceURL); |
||
1064 | $Pieces = explode('|', $Feedback); |
||
1065 | $Result = ['RtnMerchantTradeNo' => '', 'RtnOrderNo' => '']; |
||
1066 | if (empty($Pieces[0])) { |
||
1067 | $Result = ['ErrorMessage' => $Pieces[1]]; |
||
1068 | } else { |
||
1069 | $Result['RtnMerchantTradeNo'] = $Pieces[0]; |
||
1070 | $Result['RtnOrderNo'] = $Pieces[1]; |
||
1071 | } |
||
1072 | |||
1073 | return $Result; |
||
1074 | } |
||
1075 | |||
1076 | /** |
||
1077 | * 全家逆物流核帳(全家超商B2C). |
||
1078 | * |
||
1079 | * @author https://www.ecpay.com.tw |
||
1080 | * @category SDK |
||
1081 | * @return array |
||
1082 | * @version 1.0.1012 |
||
1083 | */ |
||
1084 | public function CheckFamilyB2CLogistics() |
||
1085 | { |
||
1086 | |||
1087 | // 參數初始化 |
||
1088 | $ParamList = [ |
||
1089 | 'MerchantID' => '', |
||
1090 | 'RtnMerchantTradeNo' => '', |
||
1091 | 'PlatformID' => '', |
||
1092 | ]; |
||
1093 | $this->PostParams = $this->GetPostParams($this->Send, $ParamList); |
||
1094 | |||
1095 | // 參數檢查 |
||
1096 | $this->ValidateHashKey(); |
||
1097 | $this->ValidateHashIV(); |
||
1098 | $this->ValidateID('MerchantID', $this->PostParams['MerchantID'], 10); |
||
1099 | $this->ServiceURL = $this->GetURL('FAMILY_RETURN_CHECK'); |
||
1100 | $this->ValidateID('RtnMerchantTradeNo', $this->PostParams['RtnMerchantTradeNo'], 13); |
||
1101 | $this->ValidateID('PlatformID', $this->PostParams['PlatformID'], 10, true); |
||
1102 | |||
1103 | // 產生 CheckMacValue |
||
1104 | $this->PostParams['CheckMacValue'] = ECPay_CheckMacValue::generate($this->PostParams, $this->HashKey, $this->HashIV); |
||
1105 | |||
1106 | // 解析回傳結果 |
||
1107 | // 正確:1|OK |
||
1108 | // 錯誤:0|ErrorMessage |
||
1109 | $Feedback = ECPay_IO::ServerPost($this->PostParams, $this->ServiceURL); |
||
1110 | $Result = $this->ParseFeedback($Feedback); |
||
1111 | |||
1112 | return $Result; |
||
1113 | } |
||
1114 | |||
1115 | /** |
||
1116 | * 廠商修改出貨日期、取貨門市(統一超商B2C). |
||
1117 | * |
||
1118 | * @author https://www.ecpay.com.tw |
||
1119 | * @category SDK |
||
1120 | * @return array |
||
1121 | * @version 1.0.1012 |
||
1122 | */ |
||
1123 | public function UpdateUnimartLogisticsInfo() |
||
1124 | { |
||
1125 | |||
1126 | // 參數初始化 |
||
1127 | $ParamList = [ |
||
1128 | 'MerchantID' => '', |
||
1129 | 'AllPayLogisticsID' => '', |
||
1130 | 'ShipmentDate' => '', |
||
1131 | 'ReceiverStoreID' => '', |
||
1132 | 'PlatformID' => '', |
||
1133 | ]; |
||
1134 | $this->PostParams = $this->GetPostParams($this->Send, $ParamList); |
||
1135 | |||
1136 | // 參數檢查 |
||
1137 | $this->ValidateHashKey(); |
||
1138 | $this->ValidateHashIV(); |
||
1139 | $this->ValidateID('MerchantID', $this->PostParams['MerchantID'], 10); |
||
1140 | $this->ServiceURL = $this->GetURL('UNIMART_UPDATE_LOGISTICS_INFO'); |
||
1141 | $this->ValidateID('AllPayLogisticsID', $this->PostParams['AllPayLogisticsID'], 20); |
||
1142 | |||
1143 | $this->ValidateShipmentDate(true); |
||
1144 | $this->ValidateMixTypeID('ReceiverStoreID', $this->PostParams['ReceiverStoreID'], 6, true); |
||
1145 | if (empty($this->PostParams['ShipmentDate']) and empty($this->PostParams['ReceiverStoreID'])) { |
||
1146 | throw new Exception('ShipmentDate or ReceiverStoreID is required.'); |
||
1147 | } |
||
1148 | |||
1149 | $this->ValidateID('PlatformID', $this->PostParams['PlatformID'], 10, true); |
||
1150 | |||
1151 | // 產生 CheckMacValue |
||
1152 | $this->PostParams['CheckMacValue'] = ECPay_CheckMacValue::generate($this->PostParams, $this->HashKey, $this->HashIV); |
||
1153 | |||
1154 | // 解析回傳結果 |
||
1155 | // 正確:1|OK |
||
1156 | // 錯誤:0|ErrorMessage |
||
1157 | $Feedback = ECPay_IO::ServerPost($this->PostParams, $this->ServiceURL); |
||
1158 | $Result = $this->ParseFeedback($Feedback); |
||
1159 | |||
1160 | return $Result; |
||
1161 | } |
||
1162 | |||
1163 | /** |
||
1164 | * 更新門市(統一超商C2C). |
||
1165 | * |
||
1166 | * @author https://www.ecpay.com.tw |
||
1167 | * @category SDK |
||
1168 | * @return array |
||
1169 | * @version 1.0.1012 |
||
1170 | */ |
||
1171 | public function UpdateUnimartStore() |
||
1172 | { |
||
1173 | |||
1174 | // 參數初始化 |
||
1175 | $ParamList = [ |
||
1176 | 'MerchantID' => '', |
||
1177 | 'AllPayLogisticsID' => '', |
||
1178 | 'CVSPaymentNo' => '', |
||
1179 | 'CVSValidationNo' => '', |
||
1180 | 'StoreType' => '', |
||
1181 | 'ReceiverStoreID' => '', |
||
1182 | 'ReturnStoreID' => '', |
||
1183 | 'PlatformID' => '', |
||
1184 | ]; |
||
1185 | $this->PostParams = $this->GetPostParams($this->Send, $ParamList); |
||
1186 | |||
1187 | // 參數檢查 |
||
1188 | $this->ValidateHashKey(); |
||
1189 | $this->ValidateHashIV(); |
||
1190 | $this->ValidateID('MerchantID', $this->PostParams['MerchantID'], 10); |
||
1191 | $this->ServiceURL = $this->GetURL('UNIMART_UPDATE_STORE_INFO'); |
||
1192 | $this->ValidateID('AllPayLogisticsID', $this->PostParams['AllPayLogisticsID'], 20); |
||
1193 | $this->ValidateMixTypeID('CVSPaymentNo', $this->PostParams['CVSPaymentNo'], 15); |
||
1194 | $this->ValidateID('CVSValidationNo', $this->PostParams['CVSValidationNo'], 10); |
||
1195 | $this->ValidateStoreType(); |
||
1196 | |||
1197 | View Code Duplication | if ($this->PostParams['StoreType'] == StoreType::RECIVE_STORE) { |
|
1198 | $this->ValidateMixTypeID('ReceiverStoreID', $this->PostParams['ReceiverStoreID'], 6); |
||
1199 | } else { |
||
1200 | unset($this->PostParams['ReceiverStoreID']); |
||
1201 | } |
||
1202 | |||
1203 | View Code Duplication | if ($this->PostParams['StoreType'] == StoreType::RETURN_STORE) { |
|
1204 | $this->ValidateMixTypeID('ReturnStoreID', $this->PostParams['ReturnStoreID'], 6); |
||
1205 | } else { |
||
1206 | unset($this->PostParams['ReturnStoreID']); |
||
1207 | } |
||
1208 | |||
1209 | $this->ValidateID('PlatformID', $this->PostParams['PlatformID'], 10, true); |
||
1210 | |||
1211 | // 產生 CheckMacValue |
||
1212 | $this->PostParams['CheckMacValue'] = ECPay_CheckMacValue::generate($this->PostParams, $this->HashKey, $this->HashIV); |
||
1213 | |||
1214 | // 解析回傳結果 |
||
1215 | // 正確:1|OK |
||
1216 | // 錯誤:0|ErrorMessage |
||
1217 | $Feedback = ECPay_IO::ServerPost($this->PostParams, $this->ServiceURL); |
||
1218 | $Result = $this->ParseFeedback($Feedback); |
||
1219 | |||
1220 | return $Result; |
||
1221 | } |
||
1222 | |||
1223 | /** |
||
1224 | * 取消訂單(統一超商C2C). |
||
1225 | * |
||
1226 | * @author https://www.ecpay.com.tw |
||
1227 | * @category SDK |
||
1228 | * @return array |
||
1229 | * @version 1.0.1012 |
||
1230 | */ |
||
1231 | public function CancelUnimartLogisticsOrder() |
||
1232 | { |
||
1233 | |||
1234 | // 參數初始化 |
||
1235 | $ParamList = [ |
||
1236 | 'MerchantID' => '', |
||
1237 | 'AllPayLogisticsID' => '', |
||
1238 | 'CVSPaymentNo' => '', |
||
1239 | 'CVSValidationNo' => '', |
||
1240 | 'PlatformID' => '', |
||
1241 | ]; |
||
1242 | $this->PostParams = $this->GetPostParams($this->Send, $ParamList); |
||
1243 | |||
1244 | // 參數檢查 |
||
1245 | $this->ValidateHashKey(); |
||
1246 | $this->ValidateHashIV(); |
||
1247 | $this->ValidateID('MerchantID', $this->PostParams['MerchantID'], 10); |
||
1248 | $this->ServiceURL = $this->GetURL('UNIMART_CANCEL_LOGISTICS_ORDER'); |
||
1249 | $this->ValidateID('AllPayLogisticsID', $this->PostParams['AllPayLogisticsID'], 20); |
||
1250 | $this->ValidateMixTypeID('CVSPaymentNo', $this->PostParams['CVSPaymentNo'], 15); |
||
1251 | $this->ValidateID('CVSValidationNo', $this->PostParams['CVSValidationNo'], 10); |
||
1252 | $this->ValidateID('PlatformID', $this->PostParams['PlatformID'], 10, true); |
||
1253 | |||
1254 | // 產生 CheckMacValue |
||
1255 | $this->PostParams['CheckMacValue'] = ECPay_CheckMacValue::generate($this->PostParams, $this->HashKey, $this->HashIV); |
||
1256 | |||
1257 | // 解析回傳結果 |
||
1258 | // 正確:1|OK |
||
1259 | // 錯誤:0|ErrorMessage |
||
1260 | $Feedback = ECPay_IO::ServerPost($this->PostParams, $this->ServiceURL); |
||
1261 | $Result = $this->ParseFeedback($Feedback); |
||
1262 | |||
1263 | return $Result; |
||
1264 | } |
||
1265 | |||
1266 | /** |
||
1267 | * 物流訂單查詢. |
||
1268 | * |
||
1269 | * @author https://www.ecpay.com.tw |
||
1270 | * @category SDK |
||
1271 | * @return array |
||
1272 | * @version 1.0.1012 |
||
1273 | */ |
||
1274 | public function QueryLogisticsInfo() |
||
1275 | { |
||
1276 | |||
1277 | // 參數初始化 |
||
1278 | $ParamList = [ |
||
1279 | 'MerchantID' => '', |
||
1280 | 'AllPayLogisticsID' => '', |
||
1281 | 'PlatformID' => '', |
||
1282 | ]; |
||
1283 | $this->PostParams = $this->GetPostParams($this->Send, $ParamList); |
||
1284 | $this->PostParams['TimeStamp'] = strtotime('now'); |
||
1285 | |||
1286 | // 參數檢查 |
||
1287 | $this->ValidateHashKey(); |
||
1288 | $this->ValidateHashIV(); |
||
1289 | $this->ValidateID('MerchantID', $this->PostParams['MerchantID'], 10); |
||
1290 | $this->ServiceURL = $this->GetURL('QUERY_LOGISTICS_INFO'); |
||
1291 | $this->ValidateID('AllPayLogisticsID', $this->PostParams['AllPayLogisticsID'], 20); |
||
1292 | $this->ValidateID('PlatformID', $this->PostParams['PlatformID'], 10, true); |
||
1293 | |||
1294 | // 產生 CheckMacValue |
||
1295 | $this->PostParams['CheckMacValue'] = ECPay_CheckMacValue::generate($this->PostParams, $this->HashKey, $this->HashIV); |
||
1296 | |||
1297 | // 解析回傳結果 |
||
1298 | // 回應訊息:MerchantID=XXX&MerchantTradeNo=XXX&AllPayLogisticsID=XXX&GoodsAmount=XXX&LogisticsType=XXX&HandlingCharge=XXX&TradeDate=XXX&LogisticsStatus=XXX&GoodsName=XXX &CheckMacValue=XXX |
||
1299 | $Result = []; |
||
1300 | $Feedback = ECPay_IO::ServerPost($this->PostParams, $this->ServiceURL); |
||
1301 | parse_str($Feedback, $Result); |
||
1302 | |||
1303 | return $Result; |
||
1304 | } |
||
1305 | |||
1306 | /** |
||
1307 | * 產生托運單(宅配)/一段標(超商取貨). |
||
1308 | * |
||
1309 | * @author https://www.ecpay.com.tw |
||
1310 | * @category SDK |
||
1311 | * @param string $ButtonDesc 按鈕顯示名稱 |
||
1312 | * @param string $Target 表單 action 目標 |
||
1313 | * @return string |
||
1314 | * @version 1.0.1012 |
||
1315 | */ |
||
1316 | View Code Duplication | public function PrintTradeDoc($ButtonDesc = '產生托運單/一段標', $Target = '_blank') |
|
1317 | { |
||
1318 | |||
1319 | // 參數初始化 |
||
1320 | $ParamList = [ |
||
1321 | 'MerchantID' => '', |
||
1322 | 'AllPayLogisticsID' => '', |
||
1323 | 'PlatformID' => '', |
||
1324 | ]; |
||
1325 | $this->PostParams = $this->GetPostParams($this->Send, $ParamList); |
||
1326 | |||
1327 | // 參數檢查 |
||
1328 | $this->ValidateHashKey(); |
||
1329 | $this->ValidateHashIV(); |
||
1330 | $this->ValidateID('MerchantID', $this->PostParams['MerchantID'], 10); |
||
1331 | $this->ServiceURL = $this->GetURL('PRINT_TRADE_DOC'); |
||
1332 | $this->ValidateID('PlatformID', $this->PostParams['PlatformID'], 10, true); |
||
1333 | |||
1334 | // 產生 CheckMacValue |
||
1335 | $this->PostParams['CheckMacValue'] = ECPay_CheckMacValue::generate($this->PostParams, $this->HashKey, $this->HashIV); |
||
1336 | |||
1337 | return $this->GenPostHTML($ButtonDesc, $Target); |
||
1338 | } |
||
1339 | |||
1340 | /** |
||
1341 | * 列印繳款單(統一超商C2C). |
||
1342 | * |
||
1343 | * @author https://www.ecpay.com.tw |
||
1344 | * @category SDK |
||
1345 | * @param string $ButtonDesc 按鈕顯示名稱 |
||
1346 | * @param string $Target 表單 action 目標 |
||
1347 | * @return string |
||
1348 | * @version 1.0.1012 |
||
1349 | */ |
||
1350 | public function PrintUnimartC2CBill($ButtonDesc = '列印繳款單(統一超商C2C)', $Target = '_blank') |
||
1351 | { |
||
1352 | |||
1353 | // 參數初始化 |
||
1354 | $ParamList = [ |
||
1355 | 'MerchantID' => '', |
||
1356 | 'AllPayLogisticsID' => '', |
||
1357 | 'CVSPaymentNo' => '', |
||
1358 | 'CVSValidationNo' => '', |
||
1359 | 'PlatformID' => '', |
||
1360 | ]; |
||
1361 | $this->PostParams = $this->GetPostParams($this->Send, $ParamList); |
||
1362 | |||
1363 | // 參數檢查 |
||
1364 | $this->ValidateHashKey(); |
||
1365 | $this->ValidateHashIV(); |
||
1366 | $this->ValidateID('MerchantID', $this->PostParams['MerchantID'], 10); |
||
1367 | $this->ServiceURL = $this->GetURL('PRINT_UNIMART_C2C_BILL'); |
||
1368 | $this->ValidateID('AllPayLogisticsID', $this->PostParams['AllPayLogisticsID'], 20); |
||
1369 | $this->ValidateMixTypeID('CVSPaymentNo', $this->PostParams['CVSPaymentNo'], 15); |
||
1370 | $this->ValidateID('CVSValidationNo', $this->PostParams['CVSValidationNo'], 10); |
||
1371 | $this->ValidateID('PlatformID', $this->PostParams['PlatformID'], 10, true); |
||
1372 | |||
1373 | // 產生 CheckMacValue |
||
1374 | $this->PostParams['CheckMacValue'] = ECPay_CheckMacValue::generate($this->PostParams, $this->HashKey, $this->HashIV); |
||
1375 | |||
1376 | return $this->GenPostHTML($ButtonDesc, $Target); |
||
1377 | } |
||
1378 | |||
1379 | /** |
||
1380 | * 全家列印小白單(全家超商C2C). |
||
1381 | * |
||
1382 | * @author https://www.ecpay.com.tw |
||
1383 | * @category SDK |
||
1384 | * @param string $ButtonDesc 按鈕顯示名稱 |
||
1385 | * @param string $Target 表單 action 目標 |
||
1386 | * @return string |
||
1387 | * @version 1.0.1012 |
||
1388 | */ |
||
1389 | View Code Duplication | public function PrintFamilyC2CBill($ButtonDesc = '全家列印小白單(全家超商C2C)', $Target = '_blank') |
|
1390 | { |
||
1391 | |||
1392 | // 參數初始化 |
||
1393 | $ParamList = [ |
||
1394 | 'MerchantID' => '', |
||
1395 | 'AllPayLogisticsID' => '', |
||
1396 | 'CVSPaymentNo' => '', |
||
1397 | 'PlatformID' => '', |
||
1398 | ]; |
||
1399 | $this->PostParams = $this->GetPostParams($this->Send, $ParamList); |
||
1400 | |||
1401 | // 參數檢查 |
||
1402 | $this->ValidateHashKey(); |
||
1403 | $this->ValidateHashIV(); |
||
1404 | $this->ValidateID('MerchantID', $this->PostParams['MerchantID'], 10); |
||
1405 | $this->ServiceURL = $this->GetURL('PRINT_FAMILY_C2C_BILL'); |
||
1406 | $this->ValidateID('AllPayLogisticsID', $this->PostParams['AllPayLogisticsID'], 20); |
||
1407 | $this->ValidateMixTypeID('CVSPaymentNo', $this->PostParams['CVSPaymentNo'], 15); |
||
1408 | $this->ValidateID('PlatformID', $this->PostParams['PlatformID'], 10, true); |
||
1409 | |||
1410 | // 產生 CheckMacValue |
||
1411 | $this->PostParams['CheckMacValue'] = ECPay_CheckMacValue::generate($this->PostParams, $this->HashKey, $this->HashIV); |
||
1412 | |||
1413 | return $this->GenPostHTML($ButtonDesc, $Target); |
||
1414 | } |
||
1415 | |||
1416 | /** |
||
1417 | * 萊爾富列印小白單(萊爾富超商C2C). |
||
1418 | * |
||
1419 | * @author https://www.ecpay.com.tw |
||
1420 | * @category SDK |
||
1421 | * @param string $ButtonDesc 按鈕顯示名稱 |
||
1422 | * @param string $Target 表單 action 目標 |
||
1423 | * @return string |
||
1424 | * @version 1.0.1012 |
||
1425 | */ |
||
1426 | View Code Duplication | public function PrintHiLifeC2CBill($ButtonDesc = '萊爾富列印小白單(萊爾富超商C2C)', $Target = '_blank') |
|
1427 | { |
||
1428 | |||
1429 | // 參數初始化 |
||
1430 | $ParamList = [ |
||
1431 | 'MerchantID' => '', |
||
1432 | 'AllPayLogisticsID' => '', |
||
1433 | 'CVSPaymentNo' => '', |
||
1434 | 'PlatformID' => '', |
||
1435 | ]; |
||
1436 | $this->PostParams = $this->GetPostParams($this->Send, $ParamList); |
||
1437 | |||
1438 | // 參數檢查 |
||
1439 | $this->ValidateHashKey(); |
||
1440 | $this->ValidateHashIV(); |
||
1441 | $this->ValidateID('MerchantID', $this->PostParams['MerchantID'], 10); |
||
1442 | $this->ServiceURL = $this->GetURL('Print_HILIFE_C2C_BILL'); |
||
1443 | $this->ValidateID('AllPayLogisticsID', $this->PostParams['AllPayLogisticsID'], 20); |
||
1444 | $this->ValidateMixTypeID('CVSPaymentNo', $this->PostParams['CVSPaymentNo'], 15); |
||
1445 | $this->ValidateID('PlatformID', $this->PostParams['PlatformID'], 10, true); |
||
1446 | |||
1447 | // 產生 CheckMacValue |
||
1448 | $this->PostParams['CheckMacValue'] = ECPay_CheckMacValue::generate($this->PostParams, $this->HashKey, $this->HashIV); |
||
1449 | |||
1450 | return $this->GenPostHTML($ButtonDesc, $Target); |
||
1451 | } |
||
1452 | |||
1453 | /** |
||
1454 | * 產生 B2C 測標資料. |
||
1455 | * |
||
1456 | * @author https://www.ecpay.com.tw |
||
1457 | * @category SDK |
||
1458 | * @param string $ButtonDesc 按鈕顯示名稱 |
||
1459 | * @param string $Target 表單 action 目標 |
||
1460 | * @return string |
||
1461 | * @version 1.0.1012 |
||
1462 | */ |
||
1463 | View Code Duplication | public function CreateTestData($ButtonDesc = '產生 B2C 測標資料', $Target = '_blank') |
|
1464 | { |
||
1465 | |||
1466 | // 參數初始化 |
||
1467 | $ParamList = [ |
||
1468 | 'MerchantID' => '', |
||
1469 | 'ClientReplyURL' => '', |
||
1470 | 'LogisticsSubType' => '', |
||
1471 | 'PlatformID' => '', |
||
1472 | ]; |
||
1473 | $this->PostParams = $this->GetPostParams($this->Send, $ParamList); |
||
1474 | |||
1475 | // 參數檢查 |
||
1476 | $this->ValidateHashKey(); |
||
1477 | $this->ValidateHashIV(); |
||
1478 | $this->ValidateID('MerchantID', $this->PostParams['MerchantID'], 10); |
||
1479 | $this->ServiceURL = $this->GetURL('CREATE_TEST_DATA'); |
||
1480 | $this->ValidateLogisticsSubType(); |
||
1481 | $this->ValidateID('PlatformID', $this->PostParams['PlatformID'], 10, true); |
||
1482 | |||
1483 | // 產生 CheckMacValue |
||
1484 | $this->PostParams['CheckMacValue'] = ECPay_CheckMacValue::generate($this->PostParams, $this->HashKey, $this->HashIV); |
||
1485 | |||
1486 | return $this->GenPostHTML($ButtonDesc, $Target); |
||
1487 | } |
||
1488 | |||
1489 | /** |
||
1490 | * Hash Key 檢查. |
||
1491 | * |
||
1492 | * @author https://www.ecpay.com.tw |
||
1493 | * @category Validate |
||
1494 | * @version 1.0.1012 |
||
1495 | */ |
||
1496 | View Code Duplication | private function ValidateHashKey() |
|
1497 | { |
||
1498 | $Name = 'HashKey'; // 參數名稱 |
||
1499 | $Value = $this->HashKey; // 參數內容 |
||
1500 | $AllowEmpty = false; // 是否允許空值 |
||
1501 | |||
1502 | if (empty($Value)) { |
||
1503 | // 是否允許空值 |
||
1504 | $this->IsAllowEmpty($Name, $AllowEmpty); |
||
1505 | } |
||
1506 | } |
||
1507 | |||
1508 | /** |
||
1509 | * Hash IV 檢查. |
||
1510 | * |
||
1511 | * @author https://www.ecpay.com.tw |
||
1512 | * @category Validate |
||
1513 | * @version 1.0.1012 |
||
1514 | */ |
||
1515 | View Code Duplication | private function ValidateHashIV() |
|
1516 | { |
||
1517 | $Name = 'HashIV'; // 參數名稱 |
||
1518 | $Value = $this->HashKey; // 參數內容 |
||
1519 | $AllowEmpty = false; // 是否允許空值 |
||
1520 | |||
1521 | if (empty($Value)) { |
||
1522 | // 是否允許空值 |
||
1523 | $this->IsAllowEmpty($Name, $AllowEmpty); |
||
1524 | } |
||
1525 | } |
||
1526 | |||
1527 | /** |
||
1528 | * ID 檢查. |
||
1529 | * |
||
1530 | * @author https://www.ecpay.com.tw |
||
1531 | * @category Validate |
||
1532 | * @param string $Name 參數名稱 |
||
1533 | * @param string $Value 參數內容 |
||
1534 | * @param int $MaxLength 參數最大長度 |
||
1535 | * @param bool $AllowEmpty 是否允許空值 |
||
1536 | * @version 1.0.1012 |
||
1537 | */ |
||
1538 | View Code Duplication | private function ValidateID($Name, $Value, $MaxLength = 1, $AllowEmpty = false) |
|
1539 | { |
||
1540 | if (empty($Value)) { |
||
1541 | // 是否允許空值 |
||
1542 | $this->IsAllowEmpty($Name, $AllowEmpty); |
||
1543 | } else { |
||
1544 | // 格式檢查 |
||
1545 | $this->IsValidFormat($Name, '/^\d{1,'.$MaxLength.'}$/', $Value); |
||
1546 | } |
||
1547 | } |
||
1548 | |||
1549 | /** |
||
1550 | * URL 檢查. |
||
1551 | * |
||
1552 | * @author https://www.ecpay.com.tw |
||
1553 | * @category Validate |
||
1554 | * @param string $Name 參數名稱 |
||
1555 | * @param string $Value 參數內容 |
||
1556 | * @param int $MaxLength 參數最大長度 |
||
1557 | * @param bool $AllowEmpty 是否允許空值 |
||
1558 | * @version 1.0.1012 |
||
1559 | */ |
||
1560 | View Code Duplication | private function ValidateURL($Name, $Value, $MaxLength = 200, $AllowEmpty = false) |
|
1561 | { |
||
1562 | if (empty($Value)) { |
||
1563 | // 是否允許空值 |
||
1564 | $this->IsAllowEmpty($Name, $AllowEmpty); |
||
1565 | } else { |
||
1566 | // 格式檢查 |
||
1567 | $this->IsValidFormat($Name, '/^(http|https):\/\/+/', $Value); |
||
1568 | |||
1569 | // 長度檢查 |
||
1570 | $this->IsOverLength($Name, $this->StringLength($Value, $this->Encode), $MaxLength); |
||
1571 | } |
||
1572 | } |
||
1573 | |||
1574 | /** |
||
1575 | * 字串檢查. |
||
1576 | * |
||
1577 | * @author https://www.ecpay.com.tw |
||
1578 | * @category Validate |
||
1579 | * @param string $Name 參數名稱 |
||
1580 | * @param string $Value 參數內容 |
||
1581 | * @param int $MaxLength 參數最大長度 |
||
1582 | * @param bool $AllowEmpty 是否允許空值 |
||
1583 | * @version 1.0.1012 |
||
1584 | */ |
||
1585 | View Code Duplication | private function ValidateString($Name, $Value, $MaxLength = 1, $AllowEmpty = false) |
|
1586 | { |
||
1587 | if (empty($Value)) { |
||
1588 | // 是否允許空值 |
||
1589 | $this->IsAllowEmpty($Name, $AllowEmpty); |
||
1590 | } else { |
||
1591 | // 長度檢查 |
||
1592 | $this->IsOverLength($Name, $this->StringLength($Value, $this->Encode), $MaxLength); |
||
1593 | } |
||
1594 | } |
||
1595 | |||
1596 | /** |
||
1597 | * 金額檢查. |
||
1598 | * |
||
1599 | * @author https://www.ecpay.com.tw |
||
1600 | * @category Validate |
||
1601 | * @param string $Name 參數名稱 |
||
1602 | * @param string $Value 參數內容 |
||
1603 | * @param int $MaxLength 參數最大長度 |
||
1604 | * @param bool $AllowEmpty 是否允許空值 |
||
1605 | * @version 1.0.1012 |
||
1606 | */ |
||
1607 | private function ValidateAmount($Name, $Value, $AllowEmpty = false) |
||
1608 | { |
||
1609 | if (empty($Value)) { |
||
1610 | // 是否允許空值 |
||
1611 | $this->IsAllowEmpty($Name, $AllowEmpty); |
||
1612 | } else { |
||
1613 | // 資料型態檢查 |
||
1614 | $this->IsInteger($Name, $Value); |
||
1615 | |||
1616 | // 格式檢查 |
||
1617 | $this->IsValidFormat($Name, '/^\d+$/', $Value); |
||
1618 | } |
||
1619 | } |
||
1620 | |||
1621 | /** |
||
1622 | * 電話號碼檢查. |
||
1623 | * |
||
1624 | * @author https://www.ecpay.com.tw |
||
1625 | * @category Validate |
||
1626 | * @param string $Name 參數名稱 |
||
1627 | * @param string $Value 參數內容 |
||
1628 | * @param bool $AllowEmpty 是否允許空值 |
||
1629 | * @version 1.0.1012 |
||
1630 | */ |
||
1631 | private function ValidatePhoneNumber($Name, $Value, $AllowEmpty = false) |
||
1632 | { |
||
1633 | if (empty($Value)) { |
||
1634 | // 是否允許空值 |
||
1635 | $this->IsAllowEmpty($Name, $AllowEmpty); |
||
1636 | } else { |
||
1637 | // 格式檢查 |
||
1638 | $this->IsValidFormat($Name, '/^\(?\d{2}\)?\-?\d{2,6}\-?\d{2,6}(#\d{1,6}){0,1}$/', $Value); |
||
1639 | } |
||
1640 | } |
||
1641 | |||
1642 | /** |
||
1643 | * 手機號碼檢查. |
||
1644 | * |
||
1645 | * @author https://www.ecpay.com.tw |
||
1646 | * @category Validate |
||
1647 | * @param string $Name 參數名稱 |
||
1648 | * @param string $Value 參數內容 |
||
1649 | * @param bool $AllowEmpty 是否允許空值 |
||
1650 | * @version 1.0.1012 |
||
1651 | */ |
||
1652 | private function ValidateCellphoneNumber($Name, $Value, $AllowEmpty = false) |
||
1653 | { |
||
1654 | if (empty($Value)) { |
||
1655 | // 是否允許空值 |
||
1656 | $this->IsAllowEmpty($Name, $AllowEmpty); |
||
1657 | } else { |
||
1658 | // 格式檢查 |
||
1659 | $this->IsValidFormat($Name, '/^09\d{8}$/', $Value); |
||
1660 | } |
||
1661 | } |
||
1662 | |||
1663 | /** |
||
1664 | * 電子郵件檢查. |
||
1665 | * |
||
1666 | * @author https://www.ecpay.com.tw |
||
1667 | * @category Validate |
||
1668 | * @param string $Name 參數名稱 |
||
1669 | * @param string $Value 參數內容 |
||
1670 | * @param int $MaxLength 參數最大長度 |
||
1671 | * @param bool $AllowEmpty 是否允許空值 |
||
1672 | * @version 1.0.1012 |
||
1673 | */ |
||
1674 | View Code Duplication | private function ValidateEmail($Name, $Value, $MaxLength = 100, $AllowEmpty = false) |
|
1675 | { |
||
1676 | if (empty($Value)) { |
||
1677 | // 是否允許空值 |
||
1678 | $this->IsAllowEmpty($Name, $AllowEmpty); |
||
1679 | } else { |
||
1680 | // 長度檢查 |
||
1681 | $this->IsOverLength($Name, $this->StringLength($Value, $this->Encode), $MaxLength); |
||
1682 | |||
1683 | // 格式檢查 |
||
1684 | $this->IsValidFormat($Name, '/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z0-9]{2,4}$/', $Value); |
||
1685 | } |
||
1686 | } |
||
1687 | |||
1688 | /** |
||
1689 | * 郵遞區號檢查. |
||
1690 | * |
||
1691 | * @author https://www.ecpay.com.tw |
||
1692 | * @category Validate |
||
1693 | * @param string $Name 參數名稱 |
||
1694 | * @param string $Value 參數內容 |
||
1695 | * @param bool $AllowEmpty 是否允許空值 |
||
1696 | * @version 1.0.1012 |
||
1697 | */ |
||
1698 | private function ValidateZipCode($Name, $Value, $AllowEmpty = false) |
||
1699 | { |
||
1700 | if (empty($Value)) { |
||
1701 | // 是否允許空值 |
||
1702 | $this->IsAllowEmpty($Name, $AllowEmpty); |
||
1703 | } else { |
||
1704 | // 格式檢查 |
||
1705 | $this->IsValidFormat($Name, '/^\d{3,5}$/', $Value); |
||
1706 | } |
||
1707 | } |
||
1708 | |||
1709 | /** |
||
1710 | * 地址檢查. |
||
1711 | * |
||
1712 | * @author https://www.ecpay.com.tw |
||
1713 | * @category Validate |
||
1714 | * @param string $Name 參數名稱 |
||
1715 | * @param string $Value 參數內容 |
||
1716 | * @param int $MinLength 參數最小限制長度 |
||
1717 | * @param int $MaxLength 參數最大限制長度 |
||
1718 | * @param bool $AllowEmpty 是否允許空值 |
||
1719 | * @version 1.0.1012 |
||
1720 | */ |
||
1721 | private function ValidateAddress($Name, $Value, $MinLength = 1, $MaxLength = 1, $AllowEmpty = false) |
||
1722 | { |
||
1723 | if (empty($Value)) { |
||
1724 | // 是否允許空值 |
||
1725 | $this->IsAllowEmpty($Name, $AllowEmpty); |
||
1726 | } else { |
||
1727 | // 長度檢查 |
||
1728 | |||
1729 | if ($MinLength) { |
||
1730 | // 最小長度限制 |
||
1731 | $this->IsBelowLength($Name, $this->StringLength($Value, $this->Encode), $MinLength); |
||
1732 | } |
||
1733 | |||
1734 | if ($MaxLength) { |
||
1735 | // 最大長度限制 |
||
1736 | $this->IsOverLength($Name, $this->StringLength($Value, $this->Encode), $MaxLength); |
||
1737 | } |
||
1738 | } |
||
1739 | } |
||
1740 | |||
1741 | /** |
||
1742 | * 混合型態 ID 檢查. |
||
1743 | * |
||
1744 | * @author https://www.ecpay.com.tw |
||
1745 | * @category Validate |
||
1746 | * @param string $Name 參數名稱 |
||
1747 | * @param string $Value 參數內容 |
||
1748 | * @param bool $AllowEmpty 是否允許空值 |
||
1749 | * @version 1.0.1012 |
||
1750 | */ |
||
1751 | View Code Duplication | private function ValidateMixTypeID($Name, $Value, $MaxLength = 1, $AllowEmpty = false) |
|
1752 | { |
||
1753 | if (empty($Value)) { |
||
1754 | // 是否允許空值 |
||
1755 | $this->IsAllowEmpty($Name, $AllowEmpty); |
||
1756 | } else { |
||
1757 | // 格式檢查 |
||
1758 | $this->IsValidFormat($Name, '/^[0-9a-zA-Z]{1,'.$MaxLength.'}$/', $Value); |
||
1759 | } |
||
1760 | } |
||
1761 | |||
1762 | /** |
||
1763 | * 門市類型檢查. |
||
1764 | * |
||
1765 | * @author https://www.ecpay.com.tw |
||
1766 | * @category Validate |
||
1767 | * @version 1.0.1012 |
||
1768 | */ |
||
1769 | View Code Duplication | private function ValidateStoreType() |
|
1770 | { |
||
1771 | $Name = 'StoreType'; // 參數名稱 |
||
1772 | $Value = $this->PostParams['StoreType']; // 參數內容 |
||
1773 | $ClassName = 'StoreType'; // 合法資料 Class 名稱 |
||
1774 | $AllowEmpty = false; // 是否允許空值 |
||
1775 | |||
1776 | if (empty($Value)) { |
||
1777 | // 是否允許空值 |
||
1778 | $this->IsAllowEmpty($Name, $AllowEmpty); |
||
1779 | } else { |
||
1780 | // 內容檢查 |
||
1781 | $this->IsLegalValue($Name, $ClassName, $Value); |
||
1782 | } |
||
1783 | } |
||
1784 | |||
1785 | /** |
||
1786 | * 廠商交易編號檢查. |
||
1787 | * |
||
1788 | * @author https://www.ecpay.com.tw |
||
1789 | * @category Validate |
||
1790 | * @version 1.0.1012 |
||
1791 | */ |
||
1792 | View Code Duplication | private function ValidateMerchantTradeNo() |
|
1793 | { |
||
1794 | $Name = 'MerchantTradeNo'; // 參數名稱 |
||
1795 | $Value = $this->PostParams['MerchantTradeNo']; // 參數內容 |
||
1796 | $AllowEmpty = false; // 是否允許空值 |
||
1797 | |||
1798 | if (empty($Value)) { |
||
1799 | // 是否允許空值 |
||
1800 | $this->IsAllowEmpty($Name, $AllowEmpty); |
||
1801 | } else { |
||
1802 | // 格式檢查 |
||
1803 | $this->IsValidFormat($Name, '/^[a-zA-Z0-9]{1,20}$/', $Value); |
||
1804 | } |
||
1805 | } |
||
1806 | |||
1807 | /** |
||
1808 | * 物流類型檢查. |
||
1809 | * |
||
1810 | * @author https://www.ecpay.com.tw |
||
1811 | * @category Validate |
||
1812 | * @version 1.0.1012 |
||
1813 | */ |
||
1814 | View Code Duplication | private function ValidateLogisticsType() |
|
1815 | { |
||
1816 | $Name = 'LogisticsType'; // 參數名稱 |
||
1817 | $Value = $this->PostParams['LogisticsType']; // 參數內容 |
||
1818 | $ClassName = 'LogisticsType'; // 合法資料 Class 名稱 |
||
1819 | $AllowEmpty = false; // 是否允許空值 |
||
1820 | |||
1821 | if (empty($Value)) { |
||
1822 | // 是否允許空值 |
||
1823 | $this->IsAllowEmpty($Name, $AllowEmpty); |
||
1824 | } else { |
||
1825 | // 內容檢查 |
||
1826 | $this->IsLegalValue($Name, $ClassName, $Value); |
||
1827 | } |
||
1828 | } |
||
1829 | |||
1830 | /** |
||
1831 | * 物流子類型檢查. |
||
1832 | * |
||
1833 | * @author https://www.ecpay.com.tw |
||
1834 | * @category Validate |
||
1835 | * @param bool $AllowEmpty 是否允許空值 |
||
1836 | * @version 1.0.1012 |
||
1837 | */ |
||
1838 | private function ValidateLogisticsSubType($AllowEmpty = false) |
||
1839 | { |
||
1840 | $Name = 'LogisticsSubType'; // 參數名稱 |
||
1841 | $Value = $this->PostParams['LogisticsSubType']; // 參數內容 |
||
1842 | $ClassName = 'LogisticsSubType'; // 合法資料 Class 名稱 |
||
1843 | |||
1844 | if (empty($Value)) { |
||
1845 | // 是否允許空值 |
||
1846 | $this->IsAllowEmpty($Name, $AllowEmpty); |
||
1847 | } else { |
||
1848 | if (isset($this->PostParams['LogisticsType'])) { |
||
1849 | $LogisticsType = $this->PostParams['LogisticsType']; |
||
1850 | // 宅配物流子類型檢查 |
||
1851 | if ($LogisticsType === LogisticsType::HOME) { |
||
1852 | if ( |
||
1853 | $Value != LogisticsSubType::TCAT and |
||
1854 | $Value != LogisticsSubType::ECAN |
||
1855 | ) { |
||
1856 | throw new Exception('Invalid home delivery '.$Name.'.'); |
||
1857 | } |
||
1858 | } |
||
1859 | |||
1860 | // 超商取貨物流子類型檢查 |
||
1861 | if ($LogisticsType === LogisticsType::CVS) { |
||
1862 | if ( |
||
1863 | $Value != LogisticsSubType::FAMILY and |
||
1864 | $Value != LogisticsSubType::UNIMART and |
||
1865 | $Value != LogisticsSubType::HILIFE and |
||
1866 | $Value != LogisticsSubType::FAMILY_C2C and |
||
1867 | $Value != LogisticsSubType::UNIMART_C2C and |
||
1868 | $Value != LogisticsSubType::HILIFE_C2C |
||
1869 | ) { |
||
1870 | throw new Exception('Invalid CVS pickup '.$Name.'.'); |
||
1871 | } |
||
1872 | } |
||
1873 | } |
||
1874 | |||
1875 | // 物流類型無設定時的內容檢查 |
||
1876 | $this->IsLegalValue($Name, $ClassName, $Value); |
||
1877 | } |
||
1878 | } |
||
1879 | |||
1880 | /** |
||
1881 | * 是否代收貨款檢查. |
||
1882 | * |
||
1883 | * @author https://www.ecpay.com.tw |
||
1884 | * @category Validate |
||
1885 | * @param bool $AllowEmpty 是否允許空值 |
||
1886 | * @version 1.0.1012 |
||
1887 | */ |
||
1888 | private function ValidateIsCollection($AllowEmpty = false) |
||
1889 | { |
||
1890 | $Name = 'IsCollection'; // 參數名稱 |
||
1891 | $Value = $this->PostParams['IsCollection']; // 參數內容 |
||
1892 | $ClassName = 'IsCollection'; // 合法資料 Class 名稱 |
||
1893 | |||
1894 | if (empty($Value)) { |
||
1895 | // 是否允許空值 |
||
1896 | $this->IsAllowEmpty($Name, $AllowEmpty); |
||
1897 | } else { |
||
1898 | // 內容檢查 |
||
1899 | $this->IsLegalValue($Name, $ClassName, $Value); |
||
1900 | |||
1901 | // 目前物流類型(LogisticsType)宅配(Home)不支援代收貨款(IsCollection = Y) |
||
1902 | if ($this->PostParams['LogisticsType'] == LogisticsType::HOME and $Value == IsCollection::YES) { |
||
1903 | throw new Exception($Name.' could not be Y, when LogisticsType is Home.'); |
||
1904 | } |
||
1905 | } |
||
1906 | } |
||
1907 | |||
1908 | /** |
||
1909 | * 使用設備檢查. |
||
1910 | * |
||
1911 | * @author https://www.ecpay.com.tw |
||
1912 | * @category Validate |
||
1913 | * @param bool $AllowEmpty 是否允許空值 |
||
1914 | * @version 1.0.1012 |
||
1915 | */ |
||
1916 | View Code Duplication | private function ValidateDevice($AllowEmpty = false) |
|
1917 | { |
||
1918 | $Name = 'Device'; // 參數名稱 |
||
1919 | $Value = $this->PostParams['Device']; // 參數內容 |
||
1920 | $ClassName = 'Device'; // 合法資料 Class 名稱 |
||
1921 | |||
1922 | if (empty($Value)) { |
||
1923 | // 是否允許空值 |
||
1924 | $this->IsAllowEmpty($Name, $AllowEmpty); |
||
1925 | } else { |
||
1926 | // 資料型態檢查 |
||
1927 | $this->IsInteger($Name, $Value); |
||
1928 | |||
1929 | // 內容檢查 |
||
1930 | $this->IsLegalValue($Name, $ClassName, $Value); |
||
1931 | } |
||
1932 | } |
||
1933 | |||
1934 | /** |
||
1935 | * 廠商交易時間檢查. |
||
1936 | * |
||
1937 | * @author https://www.ecpay.com.tw |
||
1938 | * @category Validate |
||
1939 | * @version 1.0.1012 |
||
1940 | */ |
||
1941 | View Code Duplication | private function ValidateMerchantTradeDate() |
|
1942 | { |
||
1943 | $Name = 'MerchantTradeDate'; // 參數名稱 |
||
1944 | $Value = $this->PostParams['MerchantTradeDate']; // 參數內容 |
||
1945 | $ClassName = 'MerchantTradeDate'; // 合法資料 Class 名稱 |
||
1946 | $AllowEmpty = false; // 是否允許空值 |
||
1947 | |||
1948 | if (empty($Value)) { |
||
1949 | // 是否允許空值 |
||
1950 | $this->IsAllowEmpty($Name, $AllowEmpty); |
||
1951 | } else { |
||
1952 | // 日期檢查 |
||
1953 | $this->IsDate($Name, 'Y/m/d H:i:s', $Value); |
||
1954 | } |
||
1955 | } |
||
1956 | |||
1957 | /** |
||
1958 | * 溫層檢查. |
||
1959 | * |
||
1960 | * @author https://www.ecpay.com.tw |
||
1961 | * @category Validate |
||
1962 | * @version 1.0.1012 |
||
1963 | */ |
||
1964 | View Code Duplication | private function ValidateTemperature() |
|
1965 | { |
||
1966 | $Name = 'Temperature'; // 參數名稱 |
||
1967 | $Value = $this->PostParams['Temperature']; // 參數內容 |
||
1968 | $ClassName = 'Temperature'; // 合法資料 Class 名稱 |
||
1969 | $AllowEmpty = false; // 是否允許空值 |
||
1970 | |||
1971 | if (empty($Value)) { |
||
1972 | // 是否允許空值 |
||
1973 | $this->IsAllowEmpty($Name, $AllowEmpty); |
||
1974 | } else { |
||
1975 | // 內容檢查 |
||
1976 | $this->IsLegalValue($Name, $ClassName, $Value); |
||
1977 | } |
||
1978 | } |
||
1979 | |||
1980 | /** |
||
1981 | * 距離檢查. |
||
1982 | * |
||
1983 | * @author https://www.ecpay.com.tw |
||
1984 | * @category Validate |
||
1985 | * @version 1.0.1012 |
||
1986 | */ |
||
1987 | View Code Duplication | private function ValidateDistance() |
|
1988 | { |
||
1989 | $Name = 'Distance'; // 參數名稱 |
||
1990 | $Value = $this->PostParams['Distance']; // 參數內容 |
||
1991 | $ClassName = 'Distance'; // 合法資料 Class 名稱 |
||
1992 | $AllowEmpty = false; // 是否允許空值 |
||
1993 | |||
1994 | if (empty($Value)) { |
||
1995 | // 是否允許空值 |
||
1996 | $this->IsAllowEmpty($Name, $AllowEmpty); |
||
1997 | } else { |
||
1998 | // 內容檢查 |
||
1999 | $this->IsLegalValue($Name, $ClassName, $Value); |
||
2000 | } |
||
2001 | } |
||
2002 | |||
2003 | /** |
||
2004 | * 規格檢查. |
||
2005 | * |
||
2006 | * @author https://www.ecpay.com.tw |
||
2007 | * @category Validate |
||
2008 | * @version 1.0.1012 |
||
2009 | */ |
||
2010 | View Code Duplication | private function ValidateSpecification() |
|
2011 | { |
||
2012 | $Name = 'Specification'; // 參數名稱 |
||
2013 | $Value = $this->PostParams['Specification']; // 參數內容 |
||
2014 | $ClassName = 'Specification'; // 合法資料 Class 名稱 |
||
2015 | $AllowEmpty = false; // 是否允許空值 |
||
2016 | |||
2017 | if (empty($Value)) { |
||
2018 | // 是否允許空值 |
||
2019 | $this->IsAllowEmpty($Name, $AllowEmpty); |
||
2020 | } else { |
||
2021 | // 內容檢查 |
||
2022 | $this->IsLegalValue($Name, $ClassName, $Value); |
||
2023 | } |
||
2024 | } |
||
2025 | |||
2026 | /** |
||
2027 | * 預定送達時段檢查. |
||
2028 | * |
||
2029 | * @author https://www.ecpay.com.tw |
||
2030 | * @category Validate |
||
2031 | * @param bool $AllowEmpty 是否允許空值 |
||
2032 | * @version 1.0.1012 |
||
2033 | */ |
||
2034 | View Code Duplication | private function ValidateScheduledDeliveryTime($AllowEmpty = false) |
|
2035 | { |
||
2036 | $Name = 'ScheduledDeliveryTime'; // 參數名稱 |
||
2037 | $Value = $this->PostParams['ScheduledDeliveryTime']; // 參數內容 |
||
2038 | $ClassName = 'ScheduledDeliveryTime'; // 合法資料 Class 名稱 |
||
2039 | |||
2040 | if (empty($Value)) { |
||
2041 | // 是否允許空值 |
||
2042 | $this->IsAllowEmpty($Name, $AllowEmpty); |
||
2043 | } else { |
||
2044 | // 內容檢查 |
||
2045 | $this->IsLegalValue($Name, $ClassName, $Value); |
||
2046 | } |
||
2047 | } |
||
2048 | |||
2049 | /** |
||
2050 | * 物流訂單出貨日期檢查. |
||
2051 | * |
||
2052 | * @author https://www.ecpay.com.tw |
||
2053 | * @category Validate |
||
2054 | * @param bool $AllowEmpty 是否允許空值 |
||
2055 | * @version 1.0.1012 |
||
2056 | */ |
||
2057 | View Code Duplication | private function ValidateShipmentDate($AllowEmpty = false) |
|
2058 | { |
||
2059 | $Name = 'ShipmentDate'; // 參數名稱 |
||
2060 | $Value = $this->PostParams['ShipmentDate']; // 參數內容 |
||
2061 | $ClassName = 'ShipmentDate'; // 合法資料 Class 名稱 |
||
2062 | |||
2063 | if (empty($Value)) { |
||
2064 | // 是否允許空值 |
||
2065 | $this->IsAllowEmpty($Name, $AllowEmpty); |
||
2066 | } else { |
||
2067 | // 日期檢查 |
||
2068 | $this->IsDate($Name, 'Y/m/d', $Value); |
||
2069 | } |
||
2070 | } |
||
2071 | |||
2072 | /** |
||
2073 | * 是否允許空值 |
||
2074 | * |
||
2075 | * @author https://www.ecpay.com.tw |
||
2076 | * @category Validate |
||
2077 | * @param string $Name 參數名稱 |
||
2078 | * @param bool $AllowEmpty 是否允許空值 |
||
2079 | * @return bool |
||
2080 | * @version 1.0.1012 |
||
2081 | */ |
||
2082 | private function IsAllowEmpty($Name, $AllowEmpty) |
||
2083 | { |
||
2084 | if (! $AllowEmpty) { |
||
2085 | throw new Exception($Name.' is required.'); |
||
2086 | } |
||
2087 | } |
||
2088 | |||
2089 | /** |
||
2090 | * 是否超過長度限制. |
||
2091 | * |
||
2092 | * @author https://www.ecpay.com.tw |
||
2093 | * @category Validate |
||
2094 | * @param string $Name 參數名稱 |
||
2095 | * @param int $Length 參數長度 |
||
2096 | * @param int $MaxLength 參數限制長度 |
||
2097 | * @version 1.0.1012 |
||
2098 | */ |
||
2099 | private function IsOverLength($Name, $Length, $MaxLength) |
||
2100 | { |
||
2101 | if ($Length > $MaxLength) { |
||
2102 | throw new Exception($Name.' max length is '.$MaxLength.'.'); |
||
2103 | } |
||
2104 | } |
||
2105 | |||
2106 | /** |
||
2107 | * 是否超過長度限制. |
||
2108 | * |
||
2109 | * @author https://www.ecpay.com.tw |
||
2110 | * @category Validate |
||
2111 | * @param string $Name 參數名稱 |
||
2112 | * @param int $Length 參數長度 |
||
2113 | * @param int $MinLength 參數限制長度 |
||
2114 | * @version 1.0.1012 |
||
2115 | */ |
||
2116 | private function IsBelowLength($Name, $Length, $MinLength) |
||
2117 | { |
||
2118 | if ($Length < $MinLength) { |
||
2119 | throw new Exception($Name.' min length is '.$MinLength.'.'); |
||
2120 | } |
||
2121 | } |
||
2122 | |||
2123 | /** |
||
2124 | * 是否為指定格式. |
||
2125 | * |
||
2126 | * @author https://www.ecpay.com.tw |
||
2127 | * @category Validate |
||
2128 | * @param string $Name 參數名稱 |
||
2129 | * @param string $Pattern 格式檢查用正規表示法 |
||
2130 | * @param string $Value 參數內容 |
||
2131 | * @version 1.0.1012 |
||
2132 | */ |
||
2133 | private function IsValidFormat($Name, $Pattern, $Value) |
||
2134 | { |
||
2135 | if (! empty($Value)) { |
||
2136 | if (! preg_match($Pattern, $Value)) { |
||
2137 | throw new Exception('Invalid '.$Name.'.'); |
||
2138 | } |
||
2139 | } |
||
2140 | } |
||
2141 | |||
2142 | /** |
||
2143 | * 是否為數值 |
||
2144 | * |
||
2145 | * @author https://www.ecpay.com.tw |
||
2146 | * @category Validate |
||
2147 | * @param string $Name 參數名稱 |
||
2148 | * @param string $Value 參數內容 |
||
2149 | * @version 1.0.1012 |
||
2150 | */ |
||
2151 | private function IsInteger($Name, $Value) |
||
2152 | { |
||
2153 | if (! is_int($Value)) { |
||
2154 | throw new Exception($Name.' type should be integer.'); |
||
2155 | } |
||
2156 | } |
||
2157 | |||
2158 | /** |
||
2159 | * 是否為數值 |
||
2160 | * |
||
2161 | * @author https://www.ecpay.com.tw |
||
2162 | * @category Validate |
||
2163 | * @param string $Name 參數名稱 |
||
2164 | * @param string $ClassName 合法資料 Class 名稱 |
||
2165 | * @param string $Value 參數內容 |
||
2166 | * @version 1.0.1012 |
||
2167 | */ |
||
2168 | private function IsLegalValue($Name, $ClassName, $Value) |
||
2169 | { |
||
2170 | // 取得合法資料內容 |
||
2171 | $ReflectionObject = new ReflectionClass($ClassName); |
||
2172 | $ContentList = $ReflectionObject->getConstants(); |
||
2173 | unset($ReflectionObject); |
||
2174 | |||
2175 | // 檢查是否為合法資料 |
||
2176 | if (! in_array($Value, $ContentList)) { |
||
2177 | throw new Exception('Illegal '.$Name.'.'); |
||
2178 | } |
||
2179 | } |
||
2180 | |||
2181 | /** |
||
2182 | * 是否為正確日期 |
||
2183 | * |
||
2184 | * @author https://www.ecpay.com.tw |
||
2185 | * @category Validate |
||
2186 | * @param string $Name 參數名稱 |
||
2187 | * @param string $Format 日期格式 |
||
2188 | * @param string $Value 參數內容 |
||
2189 | * @version 1.0.1012 |
||
2190 | */ |
||
2191 | private function IsDate($Name, $Format, $Value) |
||
2192 | { |
||
2193 | if (date($Format, strtotime($Value)) != $Value) { |
||
2194 | throw new Exception('Invalid '.$Name.'.'); |
||
2195 | } |
||
2196 | } |
||
2197 | |||
2198 | /** |
||
2199 | * 取得並過濾 $_POST 參數. |
||
2200 | * |
||
2201 | * @author https://www.ecpay.com.tw |
||
2202 | * @category SDK_Misc |
||
2203 | * @param array $Source $_POST 參數來源 |
||
2204 | * @param array $ParamList 合法參數與預設值 |
||
2205 | * @param array $MergeParams 其他待合併參數 |
||
2206 | * @return array |
||
2207 | * @version 1.0.1012 |
||
2208 | */ |
||
2209 | private function GetPostParams($Source, $ParamList, $MergeParams = []) |
||
2210 | { |
||
2211 | // 過濾非法參數 |
||
2212 | $PostParams = []; |
||
2213 | foreach ($ParamList as $Name => $Value) { |
||
2214 | if (isset($Source[$Name])) { |
||
2215 | $PostParams[$Name] = $Source[$Name]; |
||
2216 | } else { |
||
2217 | // 若未設定則帶預設值 |
||
2218 | $PostParams[$Name] = $Value; |
||
2219 | } |
||
2220 | } |
||
2221 | |||
2222 | return array_merge($MergeParams, $PostParams); |
||
2223 | } |
||
2224 | |||
2225 | /** |
||
2226 | * 取得 ECPay URL. |
||
2227 | * |
||
2228 | * @author https://www.ecpay.com.tw |
||
2229 | * @category SDK_Misc |
||
2230 | * @param string $FunctionType 功能名稱 |
||
2231 | * @return string |
||
2232 | * @version 1.0.1012 |
||
2233 | */ |
||
2234 | private function GetURL($FunctionType) |
||
2235 | { |
||
2236 | $MerchantID = $this->PostParams['MerchantID']; |
||
2237 | $UrlList = []; |
||
2238 | if ($MerchantID == ECPayTestMerchantID::B2C or $MerchantID == ECPayTestMerchantID::C2C) { |
||
2239 | // 測試環境 |
||
2240 | $UrlList = [ |
||
2241 | 'CVS_MAP' => ECPayTestURL::CVS_MAP, |
||
2242 | 'SHIPPING_ORDER' => ECPayTestURL::SHIPPING_ORDER, |
||
2243 | 'HOME_RETURN_ORDER' => ECPayTestURL::HOME_RETURN_ORDER, |
||
2244 | 'UNIMART_RETURN_ORDER' => ECPayTestURL::UNIMART_RETURN_ORDER, |
||
2245 | 'HILIFE_RETURN_ORDER' => ECPayTestURL::HILIFE_RETURN_ORDER, |
||
2246 | 'FAMILY_RETURN_ORDER' => ECPayTestURL::FAMILY_RETURN_ORDER, |
||
2247 | 'FAMILY_RETURN_CHECK' => ECPayTestURL::FAMILY_RETURN_CHECK, |
||
2248 | 'UNIMART_UPDATE_LOGISTICS_INFO' => ECPayTestURL::UNIMART_UPDATE_LOGISTICS_INFO, |
||
2249 | 'UNIMART_UPDATE_STORE_INFO' => ECPayTestURL::UNIMART_UPDATE_STORE_INFO, |
||
2250 | 'UNIMART_CANCEL_LOGISTICS_ORDER' => ECPayTestURL::UNIMART_CANCEL_LOGISTICS_ORDER, |
||
2251 | 'QUERY_LOGISTICS_INFO' => ECPayTestURL::QUERY_LOGISTICS_INFO, |
||
2252 | 'PRINT_TRADE_DOC' => ECPayTestURL::PRINT_TRADE_DOC, |
||
2253 | 'PRINT_UNIMART_C2C_BILL' => ECPayTestURL::PRINT_UNIMART_C2C_BILL, |
||
2254 | 'PRINT_FAMILY_C2C_BILL' => ECPayTestURL::PRINT_FAMILY_C2C_BILL, |
||
2255 | 'Print_HILIFE_C2C_BILL' => ECPayTestURL::Print_HILIFE_C2C_BILL, |
||
2256 | 'CREATE_TEST_DATA' => ECPayTestURL::CREATE_TEST_DATA, |
||
2257 | ]; |
||
2258 | } else { |
||
2259 | // 正式環境 |
||
2260 | $UrlList = [ |
||
2261 | 'CVS_MAP' => ECPayURL::CVS_MAP, |
||
2262 | 'SHIPPING_ORDER' => ECPayURL::SHIPPING_ORDER, |
||
2263 | 'HOME_RETURN_ORDER' => ECPayURL::HOME_RETURN_ORDER, |
||
2264 | 'UNIMART_RETURN_ORDER' => ECPayURL::UNIMART_RETURN_ORDER, |
||
2265 | 'HILIFE_RETURN_ORDER' => ECPayURL::HILIFE_RETURN_ORDER, |
||
2266 | 'FAMILY_RETURN_ORDER' => ECPayURL::FAMILY_RETURN_ORDER, |
||
2267 | 'FAMILY_RETURN_CHECK' => ECPayURL::FAMILY_RETURN_CHECK, |
||
2268 | 'UNIMART_UPDATE_LOGISTICS_INFO' => ECPayURL::UNIMART_UPDATE_LOGISTICS_INFO, |
||
2269 | 'UNIMART_UPDATE_STORE_INFO' => ECPayURL::UNIMART_UPDATE_STORE_INFO, |
||
2270 | 'UNIMART_CANCEL_LOGISTICS_ORDER' => ECPayURL::UNIMART_CANCEL_LOGISTICS_ORDER, |
||
2271 | 'QUERY_LOGISTICS_INFO' => ECPayURL::QUERY_LOGISTICS_INFO, |
||
2272 | 'PRINT_TRADE_DOC' => ECPayURL::PRINT_TRADE_DOC, |
||
2273 | 'PRINT_UNIMART_C2C_BILL' => ECPayURL::PRINT_UNIMART_C2C_BILL, |
||
2274 | 'PRINT_FAMILY_C2C_BILL' => ECPayURL::PRINT_FAMILY_C2C_BILL, |
||
2275 | 'Print_HILIFE_C2C_BILL' => ECPayURL::Print_HILIFE_C2C_BILL, |
||
2276 | 'CREATE_TEST_DATA' => ECPayURL::CREATE_TEST_DATA, |
||
2277 | ]; |
||
2278 | } |
||
2279 | |||
2280 | return $UrlList[$FunctionType]; |
||
2281 | } |
||
2282 | |||
2283 | /** |
||
2284 | * 加入換行字元. |
||
2285 | * |
||
2286 | * @author https://www.ecpay.com.tw |
||
2287 | * @category Misc |
||
2288 | * @param string $Content 內容 |
||
2289 | * @return string |
||
2290 | * @version 1.0.1012 |
||
2291 | */ |
||
2292 | private function AddNextLine($Content) |
||
2293 | { |
||
2294 | return $Content.PHP_EOL; |
||
2295 | } |
||
2296 | |||
2297 | /** |
||
2298 | * 產生自動/手動 POST 提交表單. |
||
2299 | * |
||
2300 | * @author https://www.ecpay.com.tw |
||
2301 | * @category SDK_Misc |
||
2302 | * @param string $ButtonDesc 按鈕顯示名稱 |
||
2303 | * @param string $Target 表單 action 目標 |
||
2304 | * @return string |
||
2305 | * @version 1.0.1012 |
||
2306 | */ |
||
2307 | private function GenPostHTML($ButtonDesc = '', $Target = '_self') |
||
2308 | { |
||
2309 | $PostHTML = $this->AddNextLine('<div style="text-align:center;">'); |
||
2310 | $PostHTML .= $this->AddNextLine(' <form id="ECPayForm" method="POST" action="'.$this->ServiceURL.'" target="'.$Target.'">'); |
||
2311 | foreach ($this->PostParams as $Name => $Value) { |
||
2312 | $PostHTML .= $this->AddNextLine(' <input type="hidden" name="'.$Name.'" value="'.$Value.'" />'); |
||
2313 | } |
||
2314 | if (! empty($ButtonDesc)) { |
||
2315 | // 手動 |
||
2316 | $PostHTML .= $this->AddNextLine(' <input type="submit" id="__paymentButton" value="'.$ButtonDesc.'" />'); |
||
2317 | } else { |
||
2318 | // 自動 |
||
2319 | $PostHTML .= $this->AddNextLine(' <script>document.getElementById("ECPayForm").submit();</script>'); |
||
2320 | } |
||
2321 | $PostHTML .= $this->AddNextLine(' </form>'); |
||
2322 | $PostHTML .= $this->AddNextLine('</div>'); |
||
2323 | |||
2324 | return $PostHTML; |
||
2325 | } |
||
2326 | |||
2327 | /** |
||
2328 | * 依編碼方式取得字串長度. |
||
2329 | * |
||
2330 | * @author https://www.ecpay.com.tw |
||
2331 | * @category Misc |
||
2332 | * @param string $RetriveString 字串內容 |
||
2333 | * @param string $Encode 字串編碼 |
||
2334 | * @return int |
||
2335 | * @version 1.0.1012 |
||
2336 | */ |
||
2337 | private function StringLength($RetriveString, $Encode) |
||
2338 | { |
||
2339 | return mb_strlen($RetriveString, $Encode); |
||
2340 | } |
||
2341 | |||
2342 | /** |
||
2343 | * 解析 ECPay 回傳結果. |
||
2344 | * |
||
2345 | * @author https://www.ecpay.com.tw |
||
2346 | * @category SDK_Misc |
||
2347 | * @param string $Feedback 回傳結果 |
||
2348 | * @param array $FeedbackList 合法回傳參數 |
||
2349 | * @param string $Separator 分隔符號 |
||
2350 | * @return array |
||
2351 | * @version 1.0.1012 |
||
2352 | */ |
||
2353 | private function ParseFeedback($Feedback, $FeedbackList = ['RtnCode', 'RtnMsg'], $Separator = '|') |
||
2354 | { |
||
2355 | $Pieces = explode($Separator, $Feedback); |
||
2356 | $Feedback = []; |
||
2357 | // 回傳參數檢查 |
||
2358 | if (count($Pieces) == count($FeedbackList)) { |
||
2359 | foreach ($FeedbackList as $Idx => $Name) { |
||
2360 | $Feedback[$Name] = $Pieces[$Idx]; |
||
2361 | } |
||
2362 | } else { |
||
2363 | $Feedback['ParseMsg'] = 'Unknown feedback : '.$Feedback; |
||
2364 | } |
||
2365 | |||
2366 | return $Feedback; |
||
2367 | } |
||
2368 | } |
||
2369 | |||
2370 | if (! class_exists('ECPay_CheckMacValue', true)) { |
||
2371 | class ECPay_CheckMacValue |
||
0 ignored issues
–
show
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.
You can fix this by adding a namespace to your class: namespace YourVendor;
class YourClass { }
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries. ![]() |
|||
2372 | { |
||
2373 | /** |
||
2374 | * 產生檢查碼 |
||
2375 | */ |
||
2376 | public static function generate($arParameters = [], $HashKey = '', $HashIV = '') |
||
2377 | { |
||
2378 | $sMacValue = ''; |
||
2379 | |||
2380 | if (isset($arParameters)) { |
||
2381 | unset($arParameters['CheckMacValue']); |
||
2382 | uksort($arParameters, ['ECPay_CheckMacValue', 'merchantSort']); |
||
2383 | |||
2384 | // 組合字串 |
||
2385 | $sMacValue = 'HashKey='.$HashKey; |
||
2386 | foreach ($arParameters as $key => $value) { |
||
2387 | $sMacValue .= '&'.$key.'='.$value; |
||
2388 | } |
||
2389 | |||
2390 | $sMacValue .= '&HashIV='.$HashIV; |
||
2391 | |||
2392 | // URL Encode編碼 |
||
2393 | $sMacValue = urlencode($sMacValue); |
||
2394 | |||
2395 | // 轉成小寫 |
||
2396 | $sMacValue = strtolower($sMacValue); |
||
2397 | |||
2398 | // 取代為與 dotNet 相符的字元 |
||
2399 | $sMacValue = self::Replace_Symbol($sMacValue); |
||
2400 | |||
2401 | // 編碼 |
||
2402 | $sMacValue = md5($sMacValue); |
||
2403 | |||
2404 | $sMacValue = strtoupper($sMacValue); |
||
2405 | } |
||
2406 | |||
2407 | return $sMacValue; |
||
2408 | } |
||
2409 | |||
2410 | /** |
||
2411 | * 參數內特殊字元取代 |
||
2412 | * 傳入 $sParameters 參數 |
||
2413 | * 傳出 $sParameters 回傳取代後變數. |
||
2414 | */ |
||
2415 | public static function Replace_Symbol($sParameters) |
||
2416 | { |
||
2417 | if (! empty($sParameters)) { |
||
2418 | $sParameters = str_replace('%2D', '-', $sParameters); |
||
2419 | $sParameters = str_replace('%2d', '-', $sParameters); |
||
2420 | $sParameters = str_replace('%5F', '_', $sParameters); |
||
2421 | $sParameters = str_replace('%5f', '_', $sParameters); |
||
2422 | $sParameters = str_replace('%2E', '.', $sParameters); |
||
2423 | $sParameters = str_replace('%2e', '.', $sParameters); |
||
2424 | $sParameters = str_replace('%21', '!', $sParameters); |
||
2425 | $sParameters = str_replace('%2A', '*', $sParameters); |
||
2426 | $sParameters = str_replace('%2a', '*', $sParameters); |
||
2427 | $sParameters = str_replace('%28', '(', $sParameters); |
||
2428 | $sParameters = str_replace('%29', ')', $sParameters); |
||
2429 | } |
||
2430 | |||
2431 | return $sParameters; |
||
2432 | } |
||
2433 | |||
2434 | /** |
||
2435 | * 參數內特殊字元還原 |
||
2436 | * 傳入 $sParameters 參數 |
||
2437 | * 傳出 $sParameters 回傳取代後變數. |
||
2438 | */ |
||
2439 | public static function Replace_Symbol_Decode($sParameters) |
||
2440 | { |
||
2441 | if (! empty($sParameters)) { |
||
2442 | $sParameters = str_replace('-', '%2d', $sParameters); |
||
2443 | $sParameters = str_replace('_', '%5f', $sParameters); |
||
2444 | $sParameters = str_replace('.', '%2e', $sParameters); |
||
2445 | $sParameters = str_replace('!', '%21', $sParameters); |
||
2446 | $sParameters = str_replace('*', '%2a', $sParameters); |
||
2447 | $sParameters = str_replace('(', '%28', $sParameters); |
||
2448 | $sParameters = str_replace(')', '%29', $sParameters); |
||
2449 | $sParameters = str_replace('+', '%20', $sParameters); |
||
2450 | } |
||
2451 | |||
2452 | return $sParameters; |
||
2453 | } |
||
2454 | |||
2455 | /** |
||
2456 | * 自訂排序使用. |
||
2457 | */ |
||
2458 | private static function merchantSort($a, $b) |
||
2459 | { |
||
2460 | return strcasecmp($a, $b); |
||
2461 | } |
||
2462 | } |
||
2463 | } |
||
2464 | |||
2465 | if (! class_exists('ECPay_IO', true)) { |
||
2466 | class ECPay_IO |
||
0 ignored issues
–
show
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.
You can fix this by adding a namespace to your class: namespace YourVendor;
class YourClass { }
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries. ![]() |
|||
2467 | { |
||
2468 | public static function ServerPost($parameters, $ServiceURL) |
||
2469 | { |
||
2470 | $sSend_Info = ''; |
||
2471 | |||
2472 | // 組合字串 |
||
2473 | foreach ($parameters as $key => $value) { |
||
2474 | if ($sSend_Info == '') { |
||
2475 | $sSend_Info .= $key.'='.$value; |
||
2476 | } else { |
||
2477 | $sSend_Info .= '&'.$key.'='.$value; |
||
2478 | } |
||
2479 | } |
||
2480 | |||
2481 | $ch = curl_init(); |
||
2482 | |||
2483 | if (false === $ch) { |
||
2484 | throw new Exception('curl failed to initialize'); |
||
2485 | } |
||
2486 | |||
2487 | curl_setopt($ch, CURLOPT_URL, $ServiceURL); |
||
2488 | curl_setopt($ch, CURLOPT_HEADER, false); |
||
2489 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
||
2490 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); |
||
2491 | curl_setopt($ch, CURLOPT_POST, true); |
||
2492 | curl_setopt($ch, CURLOPT_POSTFIELDS, $sSend_Info); |
||
2493 | $rs = curl_exec($ch); |
||
2494 | |||
2495 | if (false === $rs) { |
||
2496 | throw new Exception(curl_error($ch), curl_errno($ch)); |
||
2497 | } |
||
2498 | |||
2499 | curl_close($ch); |
||
2500 | |||
2501 | return $rs; |
||
2502 | } |
||
2503 | } |
||
2504 | } |
||
2505 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.