|
2 | 2 |
|
3 | 3 | namespace Omnipay\YiPAY\Message; |
4 | 4 |
|
| 5 | +use Omnipay\YiPAY\Traits\HasCVS; |
| 6 | +use Omnipay\YiPAY\Traits\HasDefaults; |
5 | 7 | use Omnipay\YiPAY\Traits\HasYiPAY; |
6 | 8 |
|
7 | 9 | class PurchaseRequest extends AbstractRequest |
8 | 10 | { |
9 | 11 | use HasYiPAY; |
10 | | - |
11 | | - /** |
12 | | - * 取得付款方式 |
13 | | - * |
14 | | - * @return int|null 付款方式 |
15 | | - */ |
16 | | - public function getType() |
17 | | - { |
18 | | - return $this->getParameter('type'); |
19 | | - } |
20 | | - |
21 | | - /** |
22 | | - * 設定付款方式 |
23 | | - * |
24 | | - * 1 信用卡付款 |
25 | | - * 2 信用卡 3D 付款 |
26 | | - * 3 超商代碼繳費 |
27 | | - * 4 ATM 虛擬帳號繳款 |
28 | | - * |
29 | | - * @param int $value 付款方式 (Int, 長度: 1, 參閱《附錄 C. 付款方式》) |
30 | | - */ |
31 | | - public function setType($value) |
32 | | - { |
33 | | - $this->setParameter('type', $value); |
34 | | - } |
35 | | - |
36 | | - /** |
37 | | - * 取得商家訂單編號 |
38 | | - * |
39 | | - * @return string|null 商家訂單編號 |
40 | | - */ |
41 | | - public function getOrderNo() |
42 | | - { |
43 | | - return $this->getTransactionId(); |
44 | | - } |
45 | | - |
46 | | - /** |
47 | | - * 設定商家訂單編號 |
48 | | - * |
49 | | - * @param string $value 商家自訂的訂單編號 (String, 長度: 20, 唯一值不可重複) |
50 | | - */ |
51 | | - public function setOrderNo($value) |
52 | | - { |
53 | | - $this->setTransactionId($value); |
54 | | - } |
55 | | - |
56 | | - /** |
57 | | - * 取得交易內容 |
58 | | - * |
59 | | - * @return string|null 交易內容 |
60 | | - */ |
61 | | - public function getOrderDescription() |
62 | | - { |
63 | | - return $this->getDescription(); |
64 | | - } |
65 | | - |
66 | | - /** |
67 | | - * 設定交易內容 |
68 | | - * |
69 | | - * @param string $value 消費者購買內容 (String, 長度: 200) |
70 | | - */ |
71 | | - public function setOrderDescription($value) |
72 | | - { |
73 | | - $this->setDescription($value); |
74 | | - } |
75 | | - |
76 | | - /** |
77 | | - * 取得交易備註 1 |
78 | | - * |
79 | | - * @return string|null 交易備註 1 |
80 | | - */ |
81 | | - public function getOrderNote1() |
82 | | - { |
83 | | - return $this->getParameter('orderNote1'); |
84 | | - } |
85 | | - |
86 | | - /** |
87 | | - * 設定交易備註 1 |
88 | | - * |
89 | | - * @param string $value 商家自定義 1 (String, 長度: 200) |
90 | | - */ |
91 | | - public function setOrderNote1($value) |
92 | | - { |
93 | | - $this->setParameter('orderNote1', $value); |
94 | | - } |
95 | | - |
96 | | - /** |
97 | | - * 取得交易備註 2 |
98 | | - * |
99 | | - * @return string|null 交易備註 2 |
100 | | - */ |
101 | | - public function getOrderNote2() |
102 | | - { |
103 | | - return $this->getParameter('orderNote2'); |
104 | | - } |
105 | | - |
106 | | - /** |
107 | | - * 設定交易備註 2 |
108 | | - * |
109 | | - * @param string $value 商家自定義 2 (String, 長度: 200) |
110 | | - */ |
111 | | - public function setOrderNote2($value) |
112 | | - { |
113 | | - $this->setParameter('orderNote2', $value); |
114 | | - } |
115 | | - |
116 | | - public function getNotificationEmail() |
117 | | - { |
118 | | - return $this->getParameter('notificationEmail'); |
119 | | - } |
120 | | - |
121 | | - // 設置與獲取 notificationEmail |
122 | | - |
123 | | - /** |
124 | | - * 設定成功交易 Email 通知 |
125 | | - * |
126 | | - * 當交易成功時將交易結果寄送至商家指定的 Email,若有多筆 Email 以分號「;」區隔。請 注意此處為通知商家消費者已完成交易用 |
127 | | - * |
128 | | - * @param string $value 成功交易 Email (String, 長度: 200) |
129 | | - */ |
130 | | - public function setNotificationEmail($value) |
131 | | - { |
132 | | - $this->setParameter('notificationEmail', $value); |
133 | | - } |
134 | | - |
135 | | - /** |
136 | | - * 取得背景回傳網址 |
137 | | - * |
138 | | - * @return string|null 背景回傳網址 |
139 | | - */ |
140 | | - public function getBackgroundURL() |
141 | | - { |
142 | | - return $this->getNotifyUrl(); |
143 | | - } |
144 | | - |
145 | | - /** |
146 | | - * 設定背景回傳網址 |
147 | | - * |
148 | | - * @param string $value 交易完成後 YiPay 以背景方式 POST 回傳結果的網址 |
149 | | - */ |
150 | | - public function setBackgroundURL($value) |
151 | | - { |
152 | | - return $this->setNotifyUrl($value); |
153 | | - } |
154 | | - |
155 | | - /** |
156 | | - * 取得交易逾時秒數 |
157 | | - * |
158 | | - * @return int|null 交易逾時秒數 |
159 | | - */ |
160 | | - public function getTimeout() |
161 | | - { |
162 | | - return $this->getParameter('timeout'); |
163 | | - } |
164 | | - |
165 | | - /** |
166 | | - * 設定交易逾時秒數 |
167 | | - * |
168 | | - * @param int $value 交易逾時秒數,範圍 90 ~ 28800,無限制為 0 |
169 | | - */ |
170 | | - public function setTimeout($value) |
171 | | - { |
172 | | - $this->setParameter('timeout', $value); |
173 | | - } |
174 | | - |
175 | | - /** |
176 | | - * 取得進入頁面有效時間 |
177 | | - * |
178 | | - * @return string|null 交易有效時間 |
179 | | - */ |
180 | | - public function getValidTime() |
181 | | - { |
182 | | - return $this->getParameter('validTime'); |
183 | | - } |
184 | | - |
185 | | - /** |
186 | | - * 設定進入頁面有效時間 |
187 | | - * |
188 | | - * @param string $value 交易有效時間 (格式: yyyyMMddHHmm) |
189 | | - */ |
190 | | - public function setValidTime($value) |
191 | | - { |
192 | | - $this->setParameter('validTime', $value); |
193 | | - } |
194 | | - |
195 | | - /** |
196 | | - * 取得逾時返回網址 |
197 | | - * |
198 | | - * @return string|null 逾時返回網址 |
199 | | - */ |
200 | | - public function getTimeoutUrl() |
201 | | - { |
202 | | - return $this->getParameter('timeoutURL'); |
203 | | - } |
204 | | - |
205 | | - /** |
206 | | - * 設定逾時返回網址 |
207 | | - * |
208 | | - * @param string $value 交易逾時時返回商家指定的網址 |
209 | | - */ |
210 | | - public function setTimeoutURL($value) |
211 | | - { |
212 | | - $this->setParameter('timeoutURL', $value); |
213 | | - } |
| 12 | + use HasDefaults; |
| 13 | + use HasCVS; |
214 | 14 |
|
215 | 15 | public function getData() |
216 | 16 | { |
217 | | - $this->validate('amount', 'transactionId', 'returnUrl'); |
| 17 | + $this->validate('amount', 'transactionId'); |
218 | 18 |
|
219 | | - return array_filter([ |
| 19 | + $type = (int) ($this->getType() ?: 2); |
| 20 | + $data = [ |
220 | 21 | 'merchantId' => $this->getMerchantId(), |
221 | | - 'type' => $this->getType() ?: 2, |
| 22 | + 'type' => $type, |
222 | 23 | 'amount' => (string) ((int) $this->getAmount()), |
223 | 24 | 'orderNo' => $this->getTransactionId(), |
224 | 25 | 'orderDescription' => $this->getDescription(), |
225 | 26 | 'orderNote1' => $this->getOrderNote1(), |
226 | 27 | 'orderNote2' => $this->getOrderNote2(), |
227 | 28 | 'notificationEmail' => $this->getNotificationEmail(), |
228 | | - 'returnURL' => $this->getReturnUrl(), |
229 | | - 'cancelURL' => $this->getCancelUrl(), |
230 | | - 'backgroundURL' => $this->getNotifyUrl(), |
231 | 29 | 'timeout' => $this->getTimeout(), |
232 | 30 | 'validTime' => $this->getValidTime(), |
233 | 31 | 'timeoutURL' => $this->getTimeoutUrl(), |
234 | | - ], static function ($value) { |
| 32 | + ]; |
| 33 | + |
| 34 | + if ($type === 3) { |
| 35 | + $data['expirationDay'] = $this->getExpirationDay(); |
| 36 | + } |
| 37 | + |
| 38 | + return array_filter(array_merge($data, $this->getUrls($data)), static function ($value) { |
235 | 39 | return $value !== null; |
236 | 40 | }); |
237 | 41 | } |
|
0 commit comments