Skip to content

Commit df577c9

Browse files
committed
get data from request
1 parent 4f233e3 commit df577c9

File tree

6 files changed

+44
-90
lines changed

6 files changed

+44
-90
lines changed

src/Hasher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ public function make(array $data)
3434
}
3535
$body = substr($body, 0, -1);
3636

37-
return strtoupper(md5($body));
37+
return strtoupper(md5((string) $body));
3838
}
3939
}

src/Message/AbstractRequest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ protected function mergeSign(array $data)
2727

2828
protected function makeHash(array $data)
2929
{
30-
$hasher = new Hasher($this->getKey());
31-
32-
return $hasher->make($data);
30+
return (new Hasher($this->getKey()))->make($data);
3331
}
3432
}

src/Message/AcceptNotificationRequest.php

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

18+
/**
19+
* @return string
20+
*/
21+
public function getTransactionId()
22+
{
23+
return $this->getNotificationResponse()->getTransactionId();
24+
}
25+
26+
/**
27+
* @return string
28+
*/
29+
public function getTransactionReference()
30+
{
31+
return $this->getNotificationResponse()->getTransactionReference();
32+
}
33+
1834
/**
1935
* @return string
2036
*/

src/Message/CompletePurchaseRequest.php

Lines changed: 17 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -8,96 +8,35 @@
88

99
class CompletePurchaseRequest extends AbstractRequest
1010
{
11-
use HasAmount;
12-
use HasCommon;
13-
14-
public function getStatus()
15-
{
16-
return $this->getParameter('status');
17-
}
18-
19-
public function setStatus($value)
20-
{
21-
return $this->setParameter('status', $value);
22-
}
23-
24-
public function getResult()
25-
{
26-
return $this->getParameter('result');
27-
}
28-
29-
public function setResult($value)
30-
{
31-
return $this->setParameter('result', $value);
32-
}
33-
34-
public function getOrderdate()
35-
{
36-
return $this->getParameter('orderdate');
37-
}
38-
39-
public function setOrderdate($value)
40-
{
41-
return $this->setParameter('orderdate', $value);
42-
}
43-
44-
public function getAuthcode()
45-
{
46-
return $this->getParameter('authcode');
47-
}
48-
49-
public function setAuthcode($value)
50-
{
51-
return $this->setParameter('authcode', $value);
52-
}
53-
54-
public function getBankcard()
55-
{
56-
return $this->getParameter('bankcoard');
57-
}
58-
59-
public function setBankcard($value)
60-
{
61-
return $this->setParameter('bankcoard', $value);
62-
}
63-
64-
public function getPeriods()
65-
{
66-
return $this->getParameter('periods');
67-
}
68-
69-
public function setPeriods($value)
70-
{
71-
return $this->setParameter('periods', $value);
72-
}
73-
7411
public function getData()
7512
{
76-
return [
77-
'orgno' => $this->getOrgNo(),
78-
'secondtimestamp' => $this->getSecondTimestamp(),
79-
'nonce_str' => $this->getNonceStr(),
80-
'sign' => $this->getSign(),
81-
'out_trade_no' => $this->getTransactionId(),
82-
'status' => $this->getStatus(),
83-
'result' => $this->getResult(),
84-
'total_fee' => $this->getAmount(),
85-
'orderdate' => $this->getOrderdate(),
86-
'authcode' => $this->getAuthcode(),
87-
'bankcard' => $this->getBankcard(),
88-
'periods' => $this->getPeriods(),
89-
];
13+
return $this->httpRequest->request->all();
9014
}
9115

9216
/**
9317
* @throws InvalidRequestException
9418
*/
9519
public function sendData($data)
9620
{
97-
if ($data['sign'] !== $this->makeHash($data)) {
21+
if (! hash_equals($this->httpRequest->request->get('sign', ''), $this->makeHash($data))) {
9822
throw new InvalidRequestException('Incorrect hash');
9923
}
10024

10125
return $this->response = new CompletePurchaseResponse($this, $data);
10226
}
27+
28+
protected function makeHash(array $data)
29+
{
30+
$temp = [];
31+
$keys = [
32+
'authcode', 'bankcard', 'nonce_str', 'orderdate', 'orgno', 'out_trade_no', 'result', 'status',
33+
'secondtimestamp', 'total_fee',
34+
];
35+
36+
foreach ($keys as $key) {
37+
$temp[$key] = $data[$key];
38+
}
39+
40+
return parent::makeHash($temp);
41+
}
10342
}

src/Message/PurchaseRequest.php

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

33
namespace Omnipay\WanPay\Message;
44

5-
use JsonException;
65
use Omnipay\Common\Exception\InvalidRequestException;
76
use Omnipay\Common\Exception\InvalidResponseException;
87
use Omnipay\Common\ItemBag;
@@ -178,7 +177,7 @@ public function sendData($data)
178177
$body
179178
);
180179

181-
$responseData = json_decode((string) $response->getBody(), true, 512, JSON_THROW_ON_ERROR);
180+
$responseData = json_decode((string) $response->getBody(), true);
182181

183182
if ($responseData['status'] !== '900') {
184183
throw new InvalidResponseException($responseData['info'], $responseData['status']);

tests/GatewayTest.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,11 @@ public function testCompletePurchase()
6262
{
6363
$response = 'https://member.healthchain.com.tw/MHC01SSV2TEST/Checkout/CheckOutShowResultWangPay.aspx?authcode=154566&bankcard=552199******1898&nonce_str=46444248&orgno=21001719&out_trade_no=040911560243087HRC&result=核准&secondtimestamp=1586404583&status=0000&total_fee=100&orderdate=2020-04-09 11:56:02&trxtoken=&storename=旺旺電子商務-快點付&details=固定金額 免收件地址&payername=0409&payermobile=0409&payeremail=0409&sign=7F015EB2B4674CD76C9C62090B6DF3E2';
6464
$parsed = parse_url($response);
65-
$options = [];
66-
parse_str($parsed['query'], $options);
65+
$data = [];
66+
parse_str($parsed['query'], $data);
6767

68-
$response = $this->gateway->completePurchase($options)->send();
68+
$this->getHttpRequest()->request->add($data);
69+
$response = $this->gateway->completePurchase()->send();
6970

7071
self::assertTrue($response->isSuccessful());
7172
self::assertEquals('0000', $response->getCode());
@@ -77,10 +78,11 @@ public function testAcceptNotification()
7778
{
7879
$response = 'https://member.healthchain.com.tw/MHC01SSV2TEST/Checkout/CheckOutShowResultWangPay.aspx?authcode=154566&bankcard=552199******1898&nonce_str=46444248&orgno=21001719&out_trade_no=040911560243087HRC&result=核准&secondtimestamp=1586404583&status=0000&total_fee=100&orderdate=2020-04-09 11:56:02&trxtoken=&storename=旺旺電子商務-快點付&details=固定金額 免收件地址&payername=0409&payermobile=0409&payeremail=0409&sign=C720CD30C24DB5A372A33B90D2906C46';
7980
$parsed = parse_url($response);
80-
$options = [];
81-
parse_str($parsed['query'], $options);
81+
$data = [];
82+
parse_str($parsed['query'], $data);
8283

83-
$request = $this->gateway->acceptNotification($options);
84+
$this->getHttpRequest()->request->add($data);
85+
$request = $this->gateway->acceptNotification();
8486
self::assertEquals('核准', $request->getMessage());
8587
self::assertEquals(NotificationInterface::STATUS_COMPLETED, $request->getTransactionStatus());
8688

0 commit comments

Comments
 (0)