Skip to content

Commit fb1249e

Browse files
committed
get data from request
1 parent 0b84766 commit fb1249e

File tree

5 files changed

+53
-240
lines changed

5 files changed

+53
-240
lines changed

src/Message/AcceptNotificationRequest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ public function sendData($data)
1515
return $this->response = new AcceptNotificationResponse($this, $data);
1616
}
1717

18+
public function getTransactionId()
19+
{
20+
return $this->getNotificationResponse()->getTransactionId();
21+
}
22+
23+
public function getTransactionReference()
24+
{
25+
return $this->getNotificationResponse()->getTransactionReference();
26+
}
27+
1828
public function getTransactionStatus()
1929
{
2030
return $this->getNotificationResponse()->getTransactionStatus();

src/Message/CompletePurchaseRequest.php

Lines changed: 1 addition & 199 deletions
Original file line numberDiff line numberDiff line change
@@ -4,222 +4,24 @@
44

55
use Ecpay\Sdk\Response\VerifiedArrayResponse;
66
use Exception;
7-
use Omnipay\Common\Exception\InvalidRequestException;
87
use Omnipay\Common\Exception\InvalidResponseException;
98
use Omnipay\Common\Message\AbstractRequest;
10-
use Omnipay\ECPay\Traits\HasCustomFields;
119
use Omnipay\ECPay\Traits\HasDefaults;
1210
use Omnipay\ECPay\Traits\HasECPay;
13-
use Omnipay\ECPay\Traits\HasMerchantTradeNo;
14-
use Omnipay\ECPay\Traits\HasStoreID;
1511

1612
class CompletePurchaseRequest extends AbstractRequest
1713
{
1814
use HasECPay;
1915
use HasDefaults;
20-
use HasMerchantTradeNo;
21-
use HasStoreID;
22-
use HasCustomFields;
23-
24-
/**
25-
* @return string
26-
*/
27-
public function getPaymentDate()
28-
{
29-
return $this->getParameter('PaymentDate');
30-
}
31-
32-
/**
33-
* @param string $value
34-
* @return $this
35-
*/
36-
public function setPaymentDate($value)
37-
{
38-
return $this->setParameter('PaymentDate', $value);
39-
}
40-
41-
/**
42-
* @return string
43-
*/
44-
public function getPaymentType()
45-
{
46-
return $this->getParameter('PaymentType');
47-
}
48-
49-
/**
50-
* @param string $value
51-
* @return $this
52-
*/
53-
public function setPaymentType($value)
54-
{
55-
return $this->setParameter('PaymentType', $value);
56-
}
57-
58-
/**
59-
* @return string
60-
*/
61-
public function getPaymentTypeChargeFee()
62-
{
63-
return $this->getParameter('PaymentTypeChargeFee');
64-
}
65-
66-
/**
67-
* @param string $value
68-
* @return $this
69-
*/
70-
public function setPaymentTypeChargeFee($value)
71-
{
72-
return $this->setParameter('PaymentTypeChargeFee', $value);
73-
}
74-
75-
/**
76-
* @return string
77-
*/
78-
public function getRtnCode()
79-
{
80-
return $this->getParameter('RtnCode');
81-
}
82-
83-
/**
84-
* @param string $value
85-
* @return $this
86-
*/
87-
public function setRtnCode($value)
88-
{
89-
return $this->setParameter('RtnCode', $value);
90-
}
91-
92-
/**
93-
* @return string
94-
*/
95-
public function getRtnMsg()
96-
{
97-
return $this->getParameter('RtnMsg');
98-
}
99-
100-
/**
101-
* @param string $value
102-
* @return $this
103-
*/
104-
public function setRtnMsg($value)
105-
{
106-
return $this->setParameter('RtnMsg', $value);
107-
}
108-
109-
/**
110-
* @return string
111-
*/
112-
public function getSimulatePaid()
113-
{
114-
return $this->getParameter('SimulatePaid');
115-
}
116-
117-
/**
118-
* @param string $value
119-
* @return $this
120-
*/
121-
public function setSimulatePaid($value)
122-
{
123-
return $this->setParameter('SimulatePaid', $value);
124-
}
125-
126-
/**
127-
* @return string
128-
*/
129-
public function getTradeAmt()
130-
{
131-
return $this->getParameter('TradeAmt');
132-
}
133-
134-
/**
135-
* @param string $value
136-
* @return $this
137-
*/
138-
public function setTradeAmt($value)
139-
{
140-
return $this->setParameter('TradeAmt', $value);
141-
}
142-
143-
/**
144-
* @return string
145-
*/
146-
public function getTradeDate()
147-
{
148-
return $this->getParameter('TradeDate');
149-
}
150-
151-
/**
152-
* @param string $value
153-
* @return $this
154-
*/
155-
public function setTradeDate($value)
156-
{
157-
return $this->setParameter('TradeDate', $value);
158-
}
159-
160-
/**
161-
* @return string
162-
*/
163-
public function getTradeNo()
164-
{
165-
return $this->getTransactionReference();
166-
}
167-
168-
/**
169-
* @param string $value
170-
* @return $this
171-
*/
172-
public function setTradeNo($value)
173-
{
174-
return $this->setTransactionReference($value);
175-
}
176-
177-
/**
178-
* @return string
179-
*/
180-
public function getCheckMacValue()
181-
{
182-
return $this->getParameter('CheckMacValue');
183-
}
184-
185-
/**
186-
* @param string $value
187-
* @return $this
188-
*/
189-
public function setCheckMacValue($value)
190-
{
191-
return $this->setParameter('CheckMacValue', $value);
192-
}
19316

19417
/**
19518
* @return array
19619
*
197-
* @throws InvalidRequestException
19820
* @throws InvalidResponseException
19921
*/
20022
public function getData()
20123
{
202-
$this->validate('MerchantID', 'CheckMacValue');
203-
204-
return $this->checkMacValue([
205-
'CustomField1' => $this->getCustomField1(),
206-
'CustomField2' => $this->getCustomField2(),
207-
'CustomField3' => $this->getCustomField3(),
208-
'CustomField4' => $this->getCustomField4(),
209-
'MerchantID' => $this->getMerchantID(),
210-
'MerchantTradeNo' => $this->getMerchantTradeNo(),
211-
'PaymentDate' => $this->getPaymentDate(),
212-
'PaymentType' => $this->getPaymentType(),
213-
'PaymentTypeChargeFee' => $this->getPaymentTypeChargeFee(),
214-
'RtnCode' => $this->getRtnCode(),
215-
'RtnMsg' => $this->getRtnMsg(),
216-
'SimulatePaid' => $this->getSimulatePaid(),
217-
'StoreID' => $this->getStoreID(),
218-
'TradeAmt' => $this->getTradeAmt(),
219-
'TradeDate' => $this->getTradeDate(),
220-
'TradeNo' => $this->getTransactionReference(),
221-
'CheckMacValue' => $this->getCheckMacValue(),
222-
]);
24+
return $this->checkMacValue($this->httpRequest->request->all());
22325
}
22426

22527
/**

tests/GatewayTest.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,20 @@ public function setUp(): void
2020
{
2121
parent::setUp();
2222

23+
$this->options = ['testMode' => true];
2324
$this->gateway = new StubGateway($this->getHttpClient(), $this->getHttpRequest());
25+
$this->gateway->initialize($this->options);
26+
}
2427

25-
$this->options = [
28+
public function testPurchase()
29+
{
30+
$response = $this->gateway->purchase([
2631
'transactionId' => uniqid('MerchantTradeNo', true),
2732
'amount' => 2000,
2833
'description' => 'description',
2934
'returnUrl' => 'https://foo.bar/return_url',
3035
'notifyUrl' => 'https://foo.bar/notify_url',
31-
'testMode' => true,
32-
];
33-
}
34-
35-
public function testPurchase()
36-
{
37-
$response = $this->gateway->purchase(array_merge($this->options, []))->send();
36+
])->send();
3837

3938
self::assertFalse($response->isSuccessful());
4039
self::assertTrue($response->isRedirect());
@@ -44,7 +43,7 @@ public function testPurchase()
4443

4544
public function testCompletePurchase()
4645
{
47-
$response = $this->gateway->completePurchase(array_merge($this->options, [
46+
$this->getHttpRequest()->request->add([
4847
'CustomField1' => '',
4948
'CustomField2' => '',
5049
'CustomField3' => '',
@@ -62,15 +61,16 @@ public function testCompletePurchase()
6261
'TradeDate' => '2019/09/02 15:49:16',
6362
'TradeNo' => '1909021549160081',
6463
'CheckMacValue' => 'E7EC8DDC6C5C51B1A4D8BEA261246066858B38184C55FD3DD3D6DFF53F535A64',
65-
]))->send();
64+
]);
65+
$response = $this->gateway->completePurchase()->send();
6666

6767
self::assertTrue($response->isSuccessful());
6868
self::assertEquals('Succeeded', $response->getMessage());
6969
}
7070

7171
public function testAcceptNotification()
7272
{
73-
$response = $this->gateway->acceptNotification(array_merge($this->options, [
73+
$this->getHttpRequest()->request->add([
7474
'CustomField1' => '',
7575
'CustomField2' => '',
7676
'CustomField3' => '',
@@ -88,7 +88,8 @@ public function testAcceptNotification()
8888
'TradeDate' => '2019/09/02 15:49:16',
8989
'TradeNo' => '1909021549160081',
9090
'CheckMacValue' => 'E7EC8DDC6C5C51B1A4D8BEA261246066858B38184C55FD3DD3D6DFF53F535A64',
91-
]))->send();
91+
]);
92+
$response = $this->gateway->acceptNotification()->send();
9293

9394
self::assertTrue($response->isSuccessful());
9495
self::assertEquals('Succeeded', $response->getMessage());

tests/Message/AcceptNotificationRequestTest.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Omnipay\ECPay\Tests\Message;
44

5-
use Omnipay\Common\Exception\InvalidRequestException;
65
use Omnipay\Common\Exception\InvalidResponseException;
76
use Omnipay\Common\Message\NotificationInterface;
87
use Omnipay\ECPay\Message\AcceptNotificationRequest;
@@ -11,12 +10,11 @@
1110
class AcceptNotificationRequestTest extends TestCase
1211
{
1312
/**
14-
* @throws InvalidRequestException
1513
* @throws InvalidResponseException
1614
*/
1715
public function testGetData()
1816
{
19-
$options = [
17+
$data = [
2018
'CustomField1' => '',
2119
'CustomField2' => '',
2220
'CustomField3' => '',
@@ -36,18 +34,19 @@ public function testGetData()
3634
'CheckMacValue' => 'E7EC8DDC6C5C51B1A4D8BEA261246066858B38184C55FD3DD3D6DFF53F535A64',
3735
];
3836

37+
$this->getHttpRequest()->request->add($data);
3938
$request = new AcceptNotificationRequest($this->getHttpClient(), $this->getHttpRequest());
40-
$request->initialize(array_merge([
39+
$request->initialize([
4140
'HashKey' => '5294y06JbISpM5x9',
4241
'HashIV' => 'v77hoKGq4kWxNNIS',
4342
'EncryptType' => '1',
4443
'MerchantID' => '2000132',
45-
], $options));
44+
]);
4645
$request->setTestMode(true);
4746

48-
self::assertEquals($options, $request->getData());
47+
self::assertEquals($data, $request->getData());
4948

50-
return [$request, $options];
49+
return [$request, $data];
5150
}
5251

5352
/**
@@ -56,10 +55,10 @@ public function testGetData()
5655
public function testSendData($results)
5756
{
5857
$notification = $results[0];
59-
$options = $results[1];
58+
$data = $results[1];
6059

61-
self::assertEquals($options['MerchantTradeNo'], $notification->getTransactionId());
62-
self::assertEquals($options['TradeNo'], $notification->getTransactionReference());
60+
self::assertEquals($data['MerchantTradeNo'], $notification->getTransactionId());
61+
self::assertEquals($data['TradeNo'], $notification->getTransactionReference());
6362
self::assertEquals(NotificationInterface::STATUS_COMPLETED, $notification->getTransactionStatus());
6463
self::assertEquals('Succeeded', $notification->getMessage());
6564
self::assertEquals('1|OK', $notification->getReply());
@@ -70,7 +69,7 @@ public function testInvalidCheckMacValue()
7069
$this->expectException(InvalidResponseException::class);
7170
$this->expectExceptionMessage('CheckMacValue verify fail');
7271

73-
$options = [
72+
$data = [
7473
'CustomField1' => '',
7574
'CustomField2' => '',
7675
'CustomField3' => '',
@@ -90,13 +89,14 @@ public function testInvalidCheckMacValue()
9089
'CheckMacValue' => '7EC8DDC6C5C51B1A4D8BEA261246066858B38184C55FD3DD3D6DFF53F535A64',
9190
];
9291

92+
$this->getHttpRequest()->request->add($data);
9393
$request = new AcceptNotificationRequest($this->getHttpClient(), $this->getHttpRequest());
94-
$request->initialize(array_merge([
94+
$request->initialize([
9595
'HashKey' => '5294y06JbISpM5x9',
9696
'HashIV' => 'v77hoKGq4kWxNNIS',
9797
'EncryptType' => '1',
9898
'MerchantID' => '2000132',
99-
], $options));
99+
]);
100100
$request->setTestMode(true);
101101
$request->send();
102102
}

0 commit comments

Comments
 (0)