|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PayumTW\Collect; |
|
4
|
|
|
|
|
5
|
|
|
use Carbon\Carbon; |
|
6
|
|
|
|
|
7
|
|
|
class CollectUnionpayApi extends Api |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* @return string |
|
11
|
|
|
*/ |
|
12
|
1 |
|
public function getApiEndpoint($type = 'capture') |
|
13
|
|
|
{ |
|
14
|
|
|
$urls = [ |
|
15
|
1 |
|
'capture' => 'https://4128888card.com.tw/cocs/client_unionpay_append.php ', |
|
16
|
1 |
|
'refund' => 'https://4128888card.com.tw/cocs/client_unionpay_refund.php ', |
|
17
|
1 |
|
]; |
|
18
|
|
|
|
|
19
|
1 |
|
return $urls[$type]; |
|
20
|
|
|
// return $this->options['sandbox'] ? 'https://4128888card.com.tw/cocs/client_order_append.php' : 'https://4128888card.com.tw/cocs/client_order_append.php'; |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* createTransaction. |
|
25
|
|
|
* |
|
26
|
|
|
* @param array $params |
|
27
|
|
|
* @return array |
|
28
|
|
|
*/ |
|
29
|
1 |
|
public function createTransaction(array $params) |
|
30
|
|
|
{ |
|
31
|
|
|
$supportedParams = [ |
|
32
|
1 |
|
'link_id' => $this->options['link_id'], |
|
33
|
1 |
|
'cust_order_no' => null, |
|
34
|
1 |
|
'order_amount' => null, |
|
35
|
1 |
|
'order_detail' => null, |
|
36
|
|
|
/* |
|
37
|
|
|
* 指定分期參數 |
|
38
|
|
|
* esun.normal 玉山銀行一次性付款 |
|
39
|
|
|
* esun.m3 玉山銀行 3 期 |
|
40
|
|
|
* esun.m6 玉山銀行 6 期 |
|
41
|
|
|
* esun.m9 玉山銀行 9 期 |
|
42
|
|
|
*/ |
|
43
|
1 |
|
'limit_product_id' => null, |
|
44
|
1 |
|
'send_time' => Carbon::now(static::TIMEZONE)->toDateTimeString(), |
|
45
|
|
|
/* |
|
46
|
|
|
* 回傳方式 |
|
47
|
|
|
* redirect(直接重新導向)、 |
|
48
|
|
|
* plain(純文字)、 |
|
49
|
|
|
* xml(XML 格 式)、 |
|
50
|
|
|
* json(JSON 格式)。 |
|
51
|
|
|
*/ |
|
52
|
1 |
|
'return_type' => 'redirect', |
|
53
|
1 |
|
]; |
|
54
|
|
|
|
|
55
|
1 |
|
$params = array_filter(array_replace( |
|
56
|
1 |
|
$supportedParams, |
|
57
|
1 |
|
array_intersect_key($params, $supportedParams) |
|
58
|
1 |
|
)); |
|
59
|
|
|
|
|
60
|
1 |
|
$params['chk'] = $this->calculateHash($params, ['order_amount', 'send_time']); |
|
61
|
|
|
|
|
62
|
1 |
|
return $params; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* refundTransaction. |
|
67
|
|
|
* |
|
68
|
|
|
* @param array $params |
|
69
|
|
|
* @return array |
|
70
|
|
|
*/ |
|
71
|
1 |
|
public function refundTransaction(array $params) |
|
72
|
|
|
{ |
|
73
|
|
|
$supportedParams = [ |
|
74
|
1 |
|
'link_id' => $this->options['link_id'], |
|
75
|
1 |
|
'cust_order_no' => null, |
|
76
|
1 |
|
'order_amount' => null, |
|
77
|
1 |
|
'refund_amount' => null, |
|
78
|
1 |
|
'send_time' => Carbon::now(static::TIMEZONE)->toDateTimeString(), |
|
79
|
|
|
/* |
|
80
|
|
|
* 回傳方式 |
|
81
|
|
|
* redirect(直接重新導向)、 |
|
82
|
|
|
* plain(純文字)、 |
|
83
|
|
|
* xml(XML 格 式)、 |
|
84
|
|
|
* json(JSON 格式)。 |
|
85
|
|
|
*/ |
|
86
|
1 |
|
'return_type' => 'json', |
|
87
|
1 |
|
]; |
|
88
|
|
|
|
|
89
|
1 |
|
$params = array_filter(array_replace( |
|
90
|
1 |
|
$supportedParams, |
|
91
|
1 |
|
array_intersect_key($params, $supportedParams) |
|
92
|
1 |
|
)); |
|
93
|
|
|
|
|
94
|
1 |
|
$params['chk'] = $this->calculateHash($params, [ |
|
95
|
1 |
|
'cust_order_no', 'order_amount', 'refund_amount', 'send_time', |
|
96
|
1 |
|
]); |
|
97
|
|
|
|
|
98
|
1 |
|
return $this->doRequest('GET', $params, 'refund'); |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|