Skip to content

Commit 36e4ba0

Browse files
committed
Add PageGateway
1 parent ae4170b commit 36e4ba0

File tree

6 files changed

+172
-12
lines changed

6 files changed

+172
-12
lines changed

README.md

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ The following gateways are provided by this package:
3535

3636
| Gateway | Description |说明   | Links |
3737
|:--------------- |:--------------------------- |:--------- |:----------:|
38+
| Alipay_AopPage | Alipay Page Gateway |电脑网站支付 - new | [Usage][link-wiki-aop-page] [Doc][link-doc-aop-page] |
3839
| Alipay_AopApp | Alipay APP Gateway |APP支付 - new | [Usage][link-wiki-aop-app] [Doc][link-doc-aop-app] |
3940
| Alipay_AopF2F | Alipay Face To Face Gateway |当面付 - new | [Usage][link-wiki-aop-f2f] [Doc][link-doc-aop-f2f] |
4041
| Alipay_AopWap | Alipay WAP Gateway |手机网站支付 - new | [Usage][link-wiki-aop-wap] [Doc][link-doc-aop-wap] |
@@ -50,23 +51,25 @@ The following gateways are provided by this package:
5051
/**
5152
* @var AopAppGateway $gateway
5253
*/
53-
$gateway = Omnipay::create('Alipay_AopApp');
54+
$gateway = Omnipay::create('Alipay_AopPage');
55+
$gateway->setSignType('RSA2'); // RSA/RSA2/MD5
5456
$gateway->setAppId('the_app_id');
5557
$gateway->setPrivateKey('the_app_private_key');
58+
$gateway->setAlipayPublicKey('the_alipay_public_key');
59+
$gateway->setReturnUrl('https://www.example.com/return');
5660
$gateway->setNotifyUrl('https://www.example.com/notify');
5761

58-
$request = $gateway->purchase();
59-
$request->setBizContent([
62+
/**
63+
* @var AopTradePagePayResponse $response
64+
*/
65+
$response = $gateway->purchase()->setBizContent([
6066
'subject' => 'test',
6167
'out_trade_no' => date('YmdHis') . mt_rand(1000, 9999),
6268
'total_amount' => '0.01',
63-
'product_code' => 'QUICK_MSECURITY_PAY',
64-
]);
69+
'product_code' => 'FAST_INSTANT_TRADE_PAY',
70+
])->send();
6571

66-
/**
67-
* @var AopTradeAppPayResponse $response
68-
*/
69-
$response = $request->send();
72+
$url = $response->getRedirectUrl();
7073
```
7174

7275
For general usage instructions, please see the main [Omnipay](https://github.com/omnipay/omnipay)
@@ -113,12 +116,14 @@ or better yet, fork the library and submit a pull request.
113116
[link-donate]: https://cloud.githubusercontent.com/assets/1573211/18808259/a283d596-828f-11e6-8810-4a2e16d5e319.jpg
114117
[link-donate-paypal]: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=lokielse%40gmail%2ecom&lc=US&item_name=Omnipay%20Alipay&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donate_LG%2egif%3aNonHosted
115118

119+
[link-wiki-aop-page]: https://github.com/lokielse/omnipay-alipay/wiki/Aop-Page-Gateway
116120
[link-wiki-aop-app]: https://github.com/lokielse/omnipay-alipay/wiki/Aop-APP-Gateway
117121
[link-wiki-aop-f2f]: https://github.com/lokielse/omnipay-alipay/wiki/Aop-Face-To-Face-Gateway
118122
[link-wiki-aop-wap]: https://github.com/lokielse/omnipay-alipay/wiki/Aop-WAP-Gateway
119123
[link-wiki-legacy-app]: https://github.com/lokielse/omnipay-alipay/wiki/Legacy-APP-Gateway
120124
[link-wiki-legacy-express]: https://github.com/lokielse/omnipay-alipay/wiki/Legacy-Express-Gateway
121125
[link-wiki-legacy-wap]: https://github.com/lokielse/omnipay-alipay/wiki/Legacy-WAP-Gateway
126+
[link-doc-aop-page]: https://doc.open.alipay.com/doc2/detail.htm?treeId=270&articleId=105901&docType=1
122127
[link-doc-aop-app]: https://doc.open.alipay.com/docs/doc.htm?treeId=204&articleId=105051&docType=1
123128
[link-doc-aop-f2f]: https://doc.open.alipay.com/docs/doc.htm?treeId=194&articleId=105072&docType=1
124129
[link-doc-aop-wap]: https://doc.open.alipay.com/docs/doc.htm?treeId=203&articleId=105288&docType=1

src/AopPageGateway.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
namespace Omnipay\Alipay;
4+
5+
use Omnipay\Alipay\Requests\AopTradePagePayRequest;
6+
7+
/**
8+
* Class AopPageGateway
9+
* @package Omnipay\Alipay
10+
* @link https://doc.open.alipay.com/doc2/detail.htm?treeId=270&articleId=105901&docType=1
11+
*/
12+
class AopPageGateway extends AbstractAopGateway
13+
{
14+
15+
/**
16+
* Get gateway display name
17+
*
18+
* This can be used by carts to get the display name for each gateway.
19+
*/
20+
public function getName()
21+
{
22+
return 'Alipay Page Gateway';
23+
}
24+
25+
26+
/**
27+
* @return mixed
28+
*/
29+
public function getReturnUrl()
30+
{
31+
return $this->getParameter('return_url');
32+
}
33+
34+
35+
/**
36+
* @param $value
37+
*
38+
* @return $this
39+
*/
40+
public function setReturnUrl($value)
41+
{
42+
return $this->setParameter('return_url', $value);
43+
}
44+
45+
46+
/**
47+
* @param array $parameters
48+
*
49+
* @return \Omnipay\Common\Message\AbstractRequest
50+
*/
51+
public function purchase(array $parameters = [])
52+
{
53+
return $this->createRequest(AopTradePagePayRequest::class, $parameters);
54+
}
55+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace Omnipay\Alipay\Requests;
4+
5+
use Omnipay\Alipay\Responses\AopTradePagePayResponse;
6+
7+
/**
8+
* Class AopTradePagePayRequest
9+
* @package Omnipay\Alipay\Requests
10+
* @link https://doc.open.alipay.com/doc2/detail.htm?treeId=270&articleId=105901&docType=1
11+
*/
12+
class AopTradePagePayRequest extends AbstractAopRequest
13+
{
14+
15+
protected $method = 'alipay.trade.page.pay';
16+
17+
protected $returnable = true;
18+
19+
protected $notifiable = true;
20+
21+
22+
public function sendData($data)
23+
{
24+
return $this->response = new AopTradePagePayResponse($this, $data);
25+
}
26+
27+
28+
public function validateParams()
29+
{
30+
parent::validateParams();
31+
32+
$this->validateBizContent('subject', 'out_trade_no', 'total_amount', 'product_code');
33+
}
34+
35+
36+
protected function getRequestUrl($data)
37+
{
38+
$url = sprintf('%s?%s', $this->getEndpoint(), http_build_query($data));
39+
40+
return $url;
41+
}
42+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
namespace Omnipay\Alipay\Responses;
4+
5+
use Omnipay\Alipay\Requests\AopTradeWapPayRequest;
6+
use Omnipay\Common\Message\RedirectResponseInterface;
7+
8+
class AopTradePagePayResponse extends AbstractResponse implements RedirectResponseInterface
9+
{
10+
11+
/**
12+
* @var AopTradeWapPayRequest
13+
*/
14+
protected $request;
15+
16+
17+
/**
18+
* Is the response successful?
19+
*
20+
* @return boolean
21+
*/
22+
public function isSuccessful()
23+
{
24+
return true;
25+
}
26+
27+
28+
public function isRedirect()
29+
{
30+
return true;
31+
}
32+
33+
34+
/**
35+
* Gets the redirect target url.
36+
*/
37+
public function getRedirectUrl()
38+
{
39+
return sprintf('%s?%s', $this->request->getEndpoint(), http_build_query($this->data));
40+
}
41+
42+
43+
/**
44+
* Get the required redirect method (either GET or POST).
45+
*/
46+
public function getRedirectMethod()
47+
{
48+
return 'GET';
49+
}
50+
51+
52+
/**
53+
* Gets the redirect form data array, if the redirect method is POST.
54+
*/
55+
public function getRedirectData()
56+
{
57+
return $this->getData();
58+
}
59+
}

tests/AopF2FGatewayTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,10 @@ public function testQueryBillDownloadUrl()
175175
[
176176
'biz_content' => [
177177
'bill_type' => 'trade',
178-
'bill_date' => '2016-04-05',
178+
'bill_date' => '1999-04-05',
179179
]
180180
]
181181
)->send();
182-
183182
$this->assertArrayHasKey('alipay_data_dataservice_bill_downloadurl_query_response', $response->getData());
184183
$this->assertFalse($response->isSuccessful());
185184
}

tests/bootstrap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
$configFile = realpath(__DIR__ . '/../config.php');
1414

15-
if (file_exists($configFile)) {
15+
if (file_exists($configFile) && false) {
1616
include_once $configFile;
1717
} else {
1818
define('ALIPAY_PARTNER', '2088011436420182');

0 commit comments

Comments
 (0)