Skip to content

Commit cf089b8

Browse files
committed
notification
1 parent ee8289d commit cf089b8

File tree

4 files changed

+104
-0
lines changed

4 files changed

+104
-0
lines changed

src/Gateway.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
namespace Omnipay\WanPay;
44

55
use Omnipay\Common\AbstractGateway;
6+
use Omnipay\Common\Message\NotificationInterface;
7+
use Omnipay\Common\Message\RequestInterface;
8+
use Omnipay\WanPay\Message\AcceptNotificationRequest;
69
use Omnipay\WanPay\Message\CompletePurchaseRequest;
710
use Omnipay\WanPay\Message\FetchTransactionRequest;
811
use Omnipay\WanPay\Message\PurchaseRequest;
@@ -39,6 +42,14 @@ public function completePurchase(array $options = [])
3942
return $this->createRequest(CompletePurchaseRequest::class, $options);
4043
}
4144

45+
/**
46+
* @return RequestInterface|NotificationInterface
47+
*/
48+
public function acceptNotification(array $options = [])
49+
{
50+
return $this->createRequest(AcceptNotificationRequest::class, $options);
51+
}
52+
4253
public function fetchTransaction(array $options = [])
4354
{
4455
return $this->createRequest(FetchTransactionRequest::class, $options);
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
namespace Omnipay\WanPay\Message;
4+
5+
use Omnipay\Common\Message\NotificationInterface;
6+
7+
class AcceptNotificationRequest extends CompletePurchaseRequest implements NotificationInterface
8+
{
9+
/**
10+
* @param array $data
11+
* @return AcceptNotificationResponse
12+
*/
13+
public function sendData($data)
14+
{
15+
return $this->response = new AcceptNotificationResponse($this, $data);
16+
}
17+
18+
/**
19+
* @return string
20+
*/
21+
public function getTransactionStatus()
22+
{
23+
return $this->getNotificationResponse()->getTransactionStatus();
24+
}
25+
26+
/**
27+
* @return string|null
28+
*/
29+
public function getMessage()
30+
{
31+
return $this->getNotificationResponse()->getMessage();
32+
}
33+
34+
/**
35+
* @return AcceptNotificationResponse
36+
*/
37+
private function getNotificationResponse()
38+
{
39+
return ! $this->response ? $this->send() : $this->response;
40+
}
41+
42+
/**
43+
* @return string
44+
*/
45+
public function getReply()
46+
{
47+
return $this->getNotificationResponse()->getReply();
48+
}
49+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace Omnipay\WanPay\Message;
4+
5+
use Omnipay\Common\Message\NotificationInterface;
6+
7+
class AcceptNotificationResponse extends CompletePurchaseResponse implements NotificationInterface
8+
{
9+
/**
10+
* @return string
11+
*/
12+
public function getTransactionStatus()
13+
{
14+
return $this->isSuccessful() ? self::STATUS_COMPLETED : self::STATUS_FAILED;
15+
}
16+
17+
/**
18+
* @return string
19+
*/
20+
public function getReply()
21+
{
22+
return 'success';
23+
}
24+
}

tests/GatewayTest.php

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

33
namespace Omnipay\WanPay\Tests;
44

5+
use Omnipay\Common\Message\NotificationInterface;
56
use Omnipay\Tests\GatewayTestCase;
67
use Omnipay\WanPay\Gateway;
78

@@ -62,6 +63,25 @@ public function testCompletePurchase()
6263
self::assertEquals('核准', $response->getMessage());
6364
}
6465

66+
public function testAcceptNotification()
67+
{
68+
$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';
69+
$parsed = parse_url($response);
70+
$options = [];
71+
parse_str($parsed['query'], $options);
72+
73+
$request = $this->gateway->acceptNotification($options);
74+
self::assertEquals('核准', $request->getMessage());
75+
self::assertEquals(NotificationInterface::STATUS_COMPLETED, $request->getTransactionStatus());
76+
77+
$response = $request->send();
78+
79+
self::assertTrue($response->isSuccessful());
80+
self::assertEquals('040911560243087HRC', $response->getTransactionId());
81+
self::assertEquals('0000', $response->getCode());
82+
self::assertEquals('success', $response->getReply());
83+
}
84+
6585
public function testFetchTransaction()
6686
{
6787
$this->setMockHttpResponse('FetchTransaction.txt');

0 commit comments

Comments
 (0)