Skip to content

Commit 2277911

Browse files
committed
All test method testCompleteRefund() added.
1 parent 810615e commit 2277911

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

tests/AopF2FGatewayTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Omnipay\Alipay\AopF2FGateway;
66
use Omnipay\Alipay\Common\Signer;
77
use Omnipay\Alipay\Responses\AopCompletePurchaseResponse;
8+
use Omnipay\Alipay\Responses\AopCompleteRefundResponse;
89
use Omnipay\Alipay\Responses\DataServiceBillDownloadUrlQueryResponse;
910
use Omnipay\Alipay\Responses\AopTradePayResponse;
1011
use Omnipay\Alipay\Responses\AopTradePreCreateResponse;
@@ -235,4 +236,42 @@ public function testCompletePurchase()
235236
$this->assertTrue($response->isPaid());
236237
$this->assertEquals('2015061121001004400068549373', $response->getData()['trade_no']);
237238
}
239+
240+
public function testCompleteRefund()
241+
{
242+
$testPrivateKey = ALIPAY_ASSET_DIR . '/dist/common/rsa_private_key.pem';
243+
$testPublicKey = ALIPAY_ASSET_DIR . '/dist/common/rsa_public_key.pem';
244+
245+
$this->gateway = new AopF2FGateway($this->getHttpClient(), $this->getHttpRequest());
246+
$this->gateway->setAppId($this->appId);
247+
$this->gateway->setPrivateKey($this->appPrivateKey);
248+
$this->gateway->setNotifyUrl('https://www.example.com/notify');
249+
250+
$str = 'gmt_payment=2015-06-11 22:33:59&notify_id=42af7baacd1d3746cf7b56752b91edcj34&[email protected]&notify_type=trade_status_sync&sign=kPbQIjX+xQc8F0/A6/AocELIjhhZnGbcBN6G4MM/HmfWL4ZiHM6fWl5NQhzXJusaklZ1LFuMo+lHQUELAYeugH8LYFvxnNajOvZhuxNFbN2LhF0l/KL8ANtj8oyPM4NN7Qft2kWJTDJUpQOzCzNnV9hDxh5AaT9FPqRS6ZKxnzM=&trade_no=2015061121001004400068549373&out_trade_no=21repl2ac2eOutTradeNo322&gmt_create=2015-06-11 22:33:46&seller_id=2088211521646673&notify_time=2015-06-11 22:34:03&subject=FACE_TO_FACE_PAYMENT_PRECREATE中文&trade_status=TRADE_SUCCESS&sign_type=RSA';
251+
252+
parse_str($str, $data);
253+
254+
$signer = new Signer($data);
255+
$signer->setSort(true);
256+
$signer->setEncodePolicy(Signer::ENCODE_POLICY_QUERY);
257+
$data['sign'] = $signer->signWithRSA($testPrivateKey);
258+
$data['sign_type'] = 'RSA';
259+
260+
$this->gateway->setAlipayPublicKey($testPublicKey);
261+
262+
/**
263+
* @var AopCompleteRefundResponse $response
264+
*/
265+
$response = $this->gateway->completeRefund(['params' => $data])->send();
266+
267+
$this->assertEquals(
268+
'{"gmt_payment":"2015-06-11 22:33:59","notify_id":"42af7baacd1d3746cf7b56752b91edcj34","seller_email":"[email protected]","notify_type":"trade_status_sync","sign":"T4JCUXoO5sK\/7UjupKEfsSQnjDnw\/1aSJnC6s53SYJyqdjFl+1Lt8dWdNuuXl5yX39leQsYzmk2CDwZx6F\/YIQWCo1LHZME3DYMqH\/F5wT5uiSUk2KYsYbLluW9pi7YHtBXRWKB6jtnn73DWWbC2sN3tDky9KySPizL5jQ1Cd0I=","trade_no":"2015061121001004400068549373","out_trade_no":"21repl2ac2eOutTradeNo322","gmt_create":"2015-06-11 22:33:46","seller_id":"2088211521646673","notify_time":"2015-06-11 22:34:03","subject":"FACE_TO_FACE_PAYMENT_PRECREATE\u4e2d\u6587","trade_status":"TRADE_SUCCESS","sign_type":"RSA"}',
269+
json_encode($response->data())
270+
);
271+
272+
$this->assertEquals('21repl2ac2eOutTradeNo322', $response->data('out_trade_no'));
273+
$this->assertTrue($response->isSuccessful());
274+
$this->assertTrue($response->isRefunded());
275+
$this->assertEquals('2015061121001004400068549373', $response->getData()['trade_no']);
276+
}
238277
}

tests/AopWapGatewayTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Omnipay\Alipay\AopWapGateway;
66
use Omnipay\Alipay\Common\Signer;
77
use Omnipay\Alipay\Responses\AopCompletePurchaseResponse;
8+
use Omnipay\Alipay\Responses\AopCompleteRefundResponse;
89
use Omnipay\Alipay\Responses\AopTradeWapPayResponse;
910

1011
class AopWapGatewayTest extends AbstractGatewayTestCase
@@ -85,4 +86,39 @@ public function testCompletePurchase()
8586
$this->assertTrue($response->isSuccessful());
8687
$this->assertFalse($response->isPaid());
8788
}
89+
90+
public function testCompleteRefund()
91+
{
92+
$testPrivateKey = ALIPAY_ASSET_DIR . '/dist/common/rsa_private_key.pem';
93+
$testPublicKey = ALIPAY_ASSET_DIR . '/dist/common/rsa_public_key.pem';
94+
95+
$this->gateway = new AopWapGateway($this->getHttpClient(), $this->getHttpRequest());
96+
$this->gateway->setAppId($this->appId);
97+
$this->gateway->setPrivateKey($this->appPrivateKey);
98+
$this->gateway->setNotifyUrl('https://www.example.com/notify');
99+
$this->gateway->setReturnUrl('https://www.example.com/return');
100+
101+
$str = 'total_amount=0.01&timestamp=2016-09-23+18%3A21%3A58&trade_no=201609232100100306012345678&auth_app_id=201511280012345678&charset=UTF-8&seller_id=20880114612345678&method=alipay.trade.wap.pay.return&app_id=20151128001234567&out_trade_no=201609231211234567&version=1.0';
102+
103+
parse_str($str, $data);
104+
105+
$data['sign'] = (new Signer($data))->signWithRSA($testPrivateKey);
106+
$data['sign_type'] = 'RSA';
107+
108+
$this->gateway->setAlipayPublicKey($testPublicKey);
109+
110+
/**
111+
* @var AopCompleteRefundResponse $response
112+
*/
113+
$response = $this->gateway->completeRefund(['params' => $data])->send();
114+
115+
$this->assertEquals(
116+
'{"total_amount":"0.01","timestamp":"2016-09-23 18:21:58","trade_no":"201609232100100306012345678","auth_app_id":"201511280012345678","charset":"UTF-8","seller_id":"20880114612345678","method":"alipay.trade.wap.pay.return","app_id":"20151128001234567","out_trade_no":"201609231211234567","version":"1.0","sign":"ZuYCQRwbU50H2x1qevu0ZEFKwTE1piXpBG7GATUh3AZXF3S7CZ07Jj+mVDoa6WrOCGFfA8lHSbE28RX\/pl5QGxRuT+8B4KVo\/NWm3R10NCgqhkvBB+qPfUMSaBgaM+RR5m647QiKROmzX8sd4IgcedIZNKGicem+DJwNPayTLug=","sign_type":"RSA","trade_status":null}',
117+
json_encode($response->data())
118+
);
119+
120+
$this->assertEquals('201609231211234567', $response->data('out_trade_no'));
121+
$this->assertTrue($response->isSuccessful());
122+
$this->assertFalse($response->isRefunded());
123+
}
88124
}

0 commit comments

Comments
 (0)