Skip to content

Commit 544d687

Browse files
committed
when value is null must convert to ''
1 parent 74444b1 commit 544d687

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

src/Gateway.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ public function getName()
2525
public function getDefaultParameters()
2626
{
2727
return [
28-
'merchantId' => '',
29-
'key' => '',
30-
'iv' => '',
28+
'merchantId' => '1604000006',
29+
'key' => 'zBaw7bzzD8K1THSGoIbev08xEJp5yzyeuv1MWJDR2L0=',
30+
'iv' => 'YeQInQjfelvkBcWuyhWDAw==',
3131
'testMode' => false,
3232
];
3333
}

src/Traits/HasYiPay.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public function checkCode($keys, $data)
100100
{
101101
$signed = [];
102102
foreach ($keys as $key) {
103-
$signed[$key] = $data[$key];
103+
$signed[$key] = $data[$key] ?? '';
104104
}
105105

106106
return (new Hasher($this->getKey(), $this->getIv()))->make($signed);

tests/Message/CompletePurchaseRequestTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,42 @@ public function testSendCreditCardData()
4343
self::assertEquals('C0216111500000000001', $response->getTransactionReference());
4444
}
4545

46+
public function testSendCreditCardDataWithFailure()
47+
{
48+
$httpRequest = $this->getHttpRequest();
49+
$httpRequest->request->replace([
50+
'merchantId' => '1604000006',
51+
'type' => '2',
52+
'amount' => '1500',
53+
'orderNo' => 'YP2016111503353',
54+
'transactionNo' => 'C0216111500000000001',
55+
'statusCode' => '05',
56+
'statusMessage' => '交易拒絕',
57+
'approvalCode' => null,
58+
'last4CardNumber' => '2222',
59+
'checkCode' => 'd861e547ec81b62cc9b1f0c6bbe23f1bc95ad23a',
60+
]);
61+
62+
$request = new CompletePurchaseRequest($this->getHttpClient(), $httpRequest);
63+
$request->initialize([
64+
'merchantId' => '1604000006',
65+
'key' => 'zBaw7bzzD8K1THSGoIbev08xEJp5yzyeuv1MWJDR2L0',
66+
'iv' => 'YeQInQjfelvkBcWuyhWDAw==',
67+
'testMode' => true,
68+
]);
69+
$request->setReturnUrl('https://gateway-test.yipay.com.tw/demo/return');
70+
$request->setCancelUrl('https://gateway-test.yipay.com.tw/demo/cancel');
71+
$request->setNotifyUrl('https://gateway-test.yipay.com.tw/demo/notify');
72+
73+
$response = $request->send();
74+
75+
self::assertFalse($response->isSuccessful());
76+
self::assertEquals('05', $response->getCode());
77+
self::assertEquals('交易拒絕', $response->getMessage());
78+
self::assertEquals('YP2016111503353', $response->getTransactionId());
79+
self::assertEquals('C0216111500000000001', $response->getTransactionReference());
80+
}
81+
4682
public function testSendCVSData()
4783
{
4884
$httpRequest = $this->getHttpRequest();

0 commit comments

Comments
 (0)