Skip to content

Commit f33e778

Browse files
committed
fix: send extend bug
1 parent 08809e6 commit f33e778

File tree

4 files changed

+30
-33
lines changed

4 files changed

+30
-33
lines changed

src/Message/PurchaseRequest.php

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public function getData()
9292
'HoldTradeAMT' => $this->getHoldTradeAMT(),
9393
];
9494

95-
return array_merge($sendFields, $this->getSendExtend($sendFields));
95+
return static::filterValues(array_merge($sendFields, $this->getSendExtend($sendFields)));
9696
}
9797

9898
/**
@@ -138,14 +138,12 @@ private function prepareItems()
138138
*/
139139
private function getSendExtend($sendFields)
140140
{
141-
return static::filterValues([
142-
'SendExtend' => array_merge(
143-
$this->getCreditFields($sendFields['ChoosePayment']),
144-
$this->getATMFields($sendFields['ChoosePayment']),
145-
$this->getCvsFields($sendFields['ChoosePayment']),
146-
$this->getInvoiceFields($sendFields['InvoiceMark'])
147-
),
148-
]);
141+
return array_merge(
142+
$this->getCreditFields($sendFields['ChoosePayment']),
143+
$this->getATMFields($sendFields['ChoosePayment']),
144+
$this->getCvsFields($sendFields['ChoosePayment']),
145+
$this->getInvoiceFields($sendFields['InvoiceMark'])
146+
);
149147
}
150148

151149
/**
@@ -157,7 +155,7 @@ private function getCreditFields($choosePayment)
157155
return in_array($choosePayment, [
158156
ECPay_PaymentMethod::ALL,
159157
ECPay_PaymentMethod::Credit,
160-
], true) ? static::filterValues([
158+
], true) ? [
161159
'CreditInstallment' => $this->getCreditInstallment(),
162160
'InstallmentAmount' => $this->getInstallmentAmount(),
163161
'Redeem' => $this->getRedeem(),
@@ -170,7 +168,7 @@ private function getCreditFields($choosePayment)
170168
'Frequency' => $this->getFrequency(),
171169
'ExecTimes' => $this->getExecTimes(),
172170
'PeriodReturnURL' => $this->getPeriodReturnURL(),
173-
]) : [];
171+
] : [];
174172
}
175173

176174
/**
@@ -182,11 +180,11 @@ private function getATMFields($choosePayment)
182180
return in_array($choosePayment, [
183181
ECPay_PaymentMethod::ALL,
184182
ECPay_PaymentMethod::ATM,
185-
], true) ? static::filterValues([
183+
], true) ? [
186184
'ExpireDate' => $this->getExpireDate(),
187185
'PaymentInfoURL' => $this->getPaymentInfoURL(),
188186
'ClientRedirectURL' => $this->getClientRedirectURL(),
189-
]) : [];
187+
] : [];
190188
}
191189

192190
/**
@@ -199,15 +197,15 @@ private function getCvsFields($choosePayment)
199197
ECPay_PaymentMethod::ALL,
200198
ECPay_PaymentMethod::CVS,
201199
ECPay_PaymentMethod::BARCODE,
202-
], true) ? static::filterValues([
200+
], true) ? [
203201
'Desc_1' => $this->getDesc_1(),
204202
'Desc_2' => $this->getDesc_2(),
205203
'Desc_3' => $this->getDesc_3(),
206204
'Desc_4' => $this->getDesc_4(),
207205
'PaymentInfoURL' => $this->getPaymentInfoURL(),
208206
'ClientRedirectURL' => $this->getClientRedirectURL(),
209207
'StoreExpireDate' => $this->getStoreExpireDate(),
210-
]) : [];
208+
] : [];
211209
}
212210

213211
/**
@@ -216,7 +214,7 @@ private function getCvsFields($choosePayment)
216214
*/
217215
private function getInvoiceFields($invoiceMark)
218216
{
219-
return $invoiceMark === ECPay_InvoiceState::Yes ? static::filterValues([
217+
return $invoiceMark === ECPay_InvoiceState::Yes ? [
220218
'RelateNumber' => $this->getRelateNumber(),
221219
'CustomerIdentifier' => $this->getCustomerIdentifier(),
222220
'CarruerType' => $this->getCarruerType(),
@@ -239,7 +237,7 @@ private function getInvoiceFields($invoiceMark)
239237
'InvoiceItemPrice' => $this->getInvoiceItemPrice(),
240238
'InvoiceItemTaxType' => $this->getInvoiceItemTaxType(),
241239
'InvType' => $this->getInvType(),
242-
]) : [];
240+
] : [];
243241
}
244242

245243
private static function filterValues($values)

src/Message/PurchaseResponse.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,19 @@ public function getRedirectData()
6262
{
6363
$ecPay = $this->createECPay($this->request);
6464
$ecPay->ServiceURL = $this->getRedirectUrl();
65+
$data = $this->getData();
66+
67+
foreach (array_keys($ecPay->Send) as $key) {
68+
if (empty($data[$key])) {
69+
continue;
70+
}
71+
if (array_key_exists($key, $data)) {
72+
$ecPay->Send[$key] = $data[$key];
73+
} else {
74+
$ecPay->SendExtend[$key] = $data[$key];
75+
}
76+
}
77+
6578

6679
try {
6780
return static::htmlToArray($ecPay->CheckoutString());

src/Traits/HasECPay.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,13 @@ trait HasECPay
1212
*/
1313
protected function createECPay($request)
1414
{
15-
$data = $this->updateCheckMacValueFromGlobals($this->getData());
16-
15+
$this->updateCheckMacValueFromGlobals($request->getData());
1716
$ecPay = new ECPay_AllInOne();
1817
$ecPay->HashKey = $request->getHashKey();
1918
$ecPay->HashIV = $request->getHashIV();
2019
$ecPay->MerchantID = $request->getMerchantID();
2120
$ecPay->EncryptType = $request->getEncryptType();
2221

23-
foreach (array_keys($ecPay->Send) as $key) {
24-
if (array_key_exists($key, $data) && ! empty($data[$key])) {
25-
$ecPay->Send[$key] = $data[$key];
26-
}
27-
}
28-
2922
return $ecPay;
3023
}
3124

tests/Message/PurchaseRequestTest.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
namespace Omnipay\ECPay\Tests\Message;
44

55
use ECPay_ExtraPaymentInfo;
6-
use ECPay_InvoiceState;
76
use ECPay_PaymentMethod;
8-
use ECPay_PaymentMethodItem;
97
use Omnipay\Common\Item;
108
use Omnipay\ECPay\Message\PurchaseRequest;
119
use Omnipay\Tests\TestCase;
@@ -27,19 +25,14 @@ public function testGetData()
2725
'TradeDesc' => 'good to drink',
2826
'ChoosePayment' => ECPay_PaymentMethod::Credit,
2927
'Remark' => 'remark',
30-
'ChooseSubPayment' => ECPay_PaymentMethodItem::None,
3128
'NeedExtraPaidInfo' => ECPay_ExtraPaymentInfo::No,
3229
'DeviceSource' => 'Desktop',
33-
'IgnorePayment' => 'ignore_payment',
34-
'PlatformID' => uniqid('platform_id', true),
35-
'InvoiceMark' => ECPay_InvoiceState::No,
3630
'Items' => [[
3731
'Name' => '歐付寶黑芝麻豆漿',
3832
'Price' => 2000,
3933
'Quantity' => 1,
4034
'Currency' => '',
4135
]],
42-
'StoreID' => uniqid('store_id', true),
4336
'CustomField1' => 'custom_field_1',
4437
'CustomField2' => 'custom_field_2',
4538
'CustomField3' => 'custom_field_3',
@@ -81,6 +74,6 @@ public function testSendData($results)
8174
self::assertTrue($response->isRedirect());
8275
self::assertEquals('POST', $response->getRedirectMethod());
8376
self::assertEquals('https://payment-stage.ecpay.com.tw/Cashier/AioCheckOut/V5', $response->getRedirectUrl());
84-
self::assertNotEmpty('EB947B8C27DBF00C0129C83E9E5C6', $redirectData['CheckMacValue']);
77+
self::assertNotEmpty($redirectData['CheckMacValue']);
8578
}
8679
}

0 commit comments

Comments
 (0)