Skip to content

Commit e4a0f9a

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

File tree

3 files changed

+47
-4
lines changed

3 files changed

+47
-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/Hasher.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,15 @@ public function __construct(string $key, string $iv)
1919
public function make(array $parameters): string
2020
{
2121
return sha1(base64_encode($this->cipher->encrypt(json_encode(
22-
$parameters,
22+
static::ensureString($parameters),
2323
JSON_FORCE_OBJECT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE
2424
))));
2525
}
26+
27+
private static function ensureString(array $parameters): array
28+
{
29+
return array_map(static function ($value) {
30+
return (string) $value;
31+
}, $parameters);
32+
}
2633
}

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)