Skip to content

Commit 9e44c31

Browse files
authored
Merge pull request #182 from islamdarwish/master
Implement list Plan and tests
2 parents 9638528 + b4d7818 commit 9e44c31

File tree

6 files changed

+338
-2
lines changed

6 files changed

+338
-2
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
language: php
22

33
php:
4-
- 5.3
54
- 5.4
65
- 5.5
76
- 5.6
@@ -17,6 +16,7 @@ matrix:
1716
include:
1817
- php: 5.3
1918
env: setup=lowest
19+
dist: precise
2020
- php: 5.5
2121
env: setup=stable
2222

phpunit.xml.dist~

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
backupStaticAttributes="false"
4+
bootstrap="vendor/autoload.php"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
processIsolation="false"
10+
stopOnFailure="false"
11+
syntaxCheck="false">
12+
<testsuites>
13+
<testsuite name="Omnipay Test Suite">
14+
<directory>./tests/</directory>
15+
</testsuite>
16+
</testsuites>
17+
<listeners>
18+
<listener class="Mockery\Adapter\Phpunit\TestListener" file="vendor/mockery/mockery/library/Mockery/Adapter/Phpunit/TestListener.php" />
19+
</listeners>
20+
<filter>
21+
<whitelist>
22+
<directory>./src</directory>
23+
</whitelist>
24+
</filter>
25+
</phpunit>
Lines changed: 242 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
1+
<?php
2+
/**
3+
* PayPal REST List Plans Request
4+
*/
5+
6+
namespace Omnipay\PayPal\Message;
7+
8+
/**
9+
* PayPal REST List Plans Request
10+
*
11+
* Use this call to get a list of plans in any state (CREATED, ACTIVE, etc.).
12+
* The plans returned are the plans made by the merchant making the call.
13+
*
14+
*
15+
* ### Example
16+
*
17+
* #### Initialize Gateway
18+
*
19+
* <code>
20+
* // Create a gateway for the PayPal RestGateway
21+
* // (routes to GatewayFactory::create)
22+
* $gateway = Omnipay::create('PayPal_Rest');
23+
*
24+
* // Initialise the gateway
25+
* $gateway->initialize(array(
26+
* 'clientId' => 'MyPayPalClientId',
27+
* 'secret' => 'MyPayPalSecret',
28+
* 'testMode' => true, // Or false when you are ready for live transactions
29+
* ));
30+
* </code>
31+
*
32+
* #### List all plans that have state CREATED
33+
* <code>
34+
*
35+
* // List all billing plans
36+
* $transaction = $gateway->listPlan([
37+
* 'state' => CREATED,
38+
* ]);
39+
* $response = $transaction->send();
40+
* $data = $response->getData();
41+
* echo "Gateway listPlan response data == " . print_r($data, true) . "\n";
42+
* </code>
43+
*
44+
* ### Request Sample
45+
*
46+
* This is from the PayPal web site:
47+
*
48+
* <code>
49+
* curl -v -X GET https://api.sandbox.paypal.com/v1/payments/billing-plans?page_size=3&status=ACTIVE&page=1\
50+
* -H "Content-Type:application/json" \
51+
* -H "Authorization: Bearer Access-Token"
52+
* </code>
53+
*
54+
* ### Response Sample
55+
*
56+
* This is from the PayPal web site:
57+
*
58+
* <code>
59+
* {
60+
* "total_items": "166",
61+
* "total_pages": "83",
62+
* "plans": [
63+
* {
64+
* "id": "P-7DC96732KA7763723UOPKETA",
65+
* "state": "ACTIVE",
66+
* "name": "Plan with Regular and Trial Payment Definitions",
67+
* "description": "Plan with regular and trial billing payment definitions.",
68+
* "type": "FIXED",
69+
* "create_time": "2017-08-22T04:41:52.836Z",
70+
* "update_time": "2017-08-22T04:41:53.169Z",
71+
* "links": [
72+
* {
73+
* "href": "https://api.sandbox.paypal.com//v1/payments/billing-plans/P-7DC96732KA7763723UOPKETA",
74+
* "rel": "self",
75+
* "method": "GET"
76+
* }
77+
* ]
78+
* },
79+
* {
80+
* "id": "P-1TV69435N82273154UPWDU4I",
81+
* "state": "ACTIVE",
82+
* "name": "Plan with Regular Payment Definition",
83+
* "description": "Plan with one regular payment definition, minimal merchant preferences, and no shipping fee",
84+
* "type": "INFINITE",
85+
* "create_time": "2017-08-22T04:41:55.623Z",
86+
* "update_time": "2017-08-22T04:41:56.055Z",
87+
* "links": [
88+
* {
89+
* "href": "https://api.sandbox.paypal.com//v1/payments/billing-plans/P-1TV69435N82273154UPWDU4I",
90+
* "rel": "self",
91+
* "method": "GET"
92+
* }
93+
* ]
94+
* }
95+
* ],
96+
* "links": [
97+
* {
98+
* "href": "https://api.sandbox.paypal.com/v1/payments/billing-plans?page_size=2&page=1&start=3&status=active",
99+
* "rel": "start",
100+
* "method": "GET"
101+
* },
102+
* {
103+
* "href": "https://api.sandbox.paypal.com/v1/payments/billing-plans?page_size=2&page=0&status=active",
104+
* "rel": "previous_page",
105+
* "method": "GET"
106+
* },
107+
* {
108+
* "href": "https://api.sandbox.paypal.com/v1/payments/billing-plans?page_size=2&page=2&status=active",
109+
* "rel": "next_page",
110+
* "method": "GET"
111+
* },
112+
* {
113+
* "href": "https://api.sandbox.paypal.com/v1/payments/billing-plans?page_size=2&page=82&status=active",
114+
* "rel": "last",
115+
* "method": "GET"
116+
* }
117+
* ]
118+
* }
119+
*
120+
* </code>
121+
*
122+
* @link https://developer.paypal.com/docs/api/payments.billing-plans#plan_list
123+
*/
124+
class RestListPlanRequest extends AbstractRestRequest
125+
{
126+
/**
127+
*
128+
* Get the request page
129+
*
130+
* @return integer
131+
*/
132+
133+
public function getPage()
134+
{
135+
return $this->getParameter('page');
136+
}
137+
138+
139+
/**
140+
* Set the request page
141+
*
142+
* @param integer $value
143+
* @return AbstractRestRequest provides a fluent interface.
144+
*/
145+
public function setPage($value)
146+
{
147+
return $this->setParameter('page', $value);
148+
}
149+
150+
/**
151+
* Get the request status
152+
*
153+
* @return string
154+
*/
155+
public function getStatus()
156+
{
157+
return $this->getParameter('status');
158+
}
159+
160+
/**
161+
* Set the request status
162+
*
163+
* @param string $value
164+
* @return AbstractRestRequest provides a fluent interface.
165+
*/
166+
public function setStatus($value)
167+
{
168+
return $this->setParameter('status', $value);
169+
}
170+
171+
/**
172+
* Get the request page size
173+
*
174+
* @return string
175+
*/
176+
public function getPageSize()
177+
{
178+
return $this->getParameter('pageSize');
179+
}
180+
181+
/**
182+
* Set the request page size
183+
*
184+
* @param string $value
185+
* @return AbstractRestRequest provides a fluent interface.
186+
*/
187+
public function setPageSize($value)
188+
{
189+
return $this->setParameter('pageSize', $value);
190+
}
191+
192+
/**
193+
* Get the request total required
194+
*
195+
* @return string
196+
*/
197+
public function getTotalRequired()
198+
{
199+
return $this->getParameter('totalRequired');
200+
}
201+
202+
/**
203+
* Set the request total required
204+
*
205+
* @param string $value
206+
* @return AbstractRestRequest provides a fluent interface.
207+
*/
208+
public function setTotalRequired($value)
209+
{
210+
return $this->setParameter('totalRequired', $value);
211+
}
212+
213+
214+
215+
216+
public function getData()
217+
{
218+
return array(
219+
'page' => $this->getPage(),
220+
'status' => $this->getStatus(),
221+
'page_size' => $this->getPageSize(),
222+
'total_required' => $this->getTotalRequired()
223+
);
224+
}
225+
226+
/**
227+
* Get HTTP Method.
228+
*
229+
* The HTTP method for list plans requests must be GET.
230+
*
231+
* @return string
232+
*/
233+
protected function getHttpMethod()
234+
{
235+
return 'GET';
236+
}
237+
238+
public function getEndpoint()
239+
{
240+
return parent::getEndpoint() . '/payments/billing-plans';
241+
}
242+
}

src/RestGateway.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,22 @@ public function updatePlan(array $parameters = array())
603603
}
604604

605605
// TODO: Retrieve a plan
606-
// TODO: List plans
606+
607+
608+
/**
609+
* List billing plans.
610+
*
611+
* Use this call to get a list of plans in any state (CREATED, ACTIVE, etc.).
612+
* The plans returned are the plans made by the merchant making the call.
613+
*
614+
* @link https://developer.paypal.com/docs/api/payments.billing-plans#plan_list
615+
* @param array $parameters
616+
* @return \Omnipay\PayPal\Message\RestListPlanRequest
617+
*/
618+
public function listPlan(array $parameters = array())
619+
{
620+
return $this->createRequest('\Omnipay\PayPal\Message\RestListPlanRequest', $parameters);
621+
}
607622

608623
/**
609624
* Create a subscription.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace Omnipay\PayPal\Message;
4+
5+
use Omnipay\Tests\TestCase;
6+
7+
class RestListPlanRequestTest extends TestCase
8+
{
9+
/** @var \Omnipay\PayPal\Message\RestListPlanRequest */
10+
private $request;
11+
12+
public function setUp()
13+
{
14+
$client = $this->getHttpClient();
15+
$request = $this->getHttpRequest();
16+
$this->request = new RestListPlanRequest($client, $request);
17+
}
18+
19+
public function testGetData()
20+
{
21+
$data = $this->request->getData();
22+
$this->assertArrayHasKey('page',$data);
23+
$this->assertArrayHasKey('status',$data);
24+
$this->assertArrayHasKey('page_size',$data);
25+
$this->assertArrayHasKey('total_required',$data);
26+
}
27+
28+
public function testEndpoint()
29+
{
30+
$this->assertStringEndsWith('/payments/billing-plans', $this->request->getEndpoint());
31+
}
32+
33+
}

tests/RestGatewayTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,27 @@ public function testFetchTransaction()
154154
$this->assertEmpty($data);
155155
}
156156

157+
public function testListPlan()
158+
{
159+
$request = $this->gateway->listPlan(array(
160+
'page' => 0,
161+
'status' => 'ACTIVE',
162+
'pageSize' => 10, //number of plans in a single page
163+
'totalRequired' => 'yes'
164+
));
165+
166+
$this->assertInstanceOf('\Omnipay\PayPal\Message\RestListPlanRequest', $request);
167+
$this->assertSame(0, $request->getPage());
168+
$this->assertSame('ACTIVE', $request->getStatus());
169+
$this->assertSame(10, $request->getPageSize());
170+
$this->assertSame('yes', $request->getTotalRequired());
171+
172+
$endPoint = $request->getEndpoint();
173+
$this->assertSame('https://api.paypal.com/v1/payments/billing-plans', $endPoint);
174+
$data = $request->getData();
175+
$this->assertNotEmpty($data);
176+
}
177+
157178
public function testFetchPurchase()
158179
{
159180
$request = $this->gateway->fetchPurchase(array('transactionReference' => 'abc123'));

0 commit comments

Comments
 (0)