From f12e659c9793a3b623f0aa6c744d1a9baeb5c606 Mon Sep 17 00:00:00 2001 From: Islam Darwish Date: Tue, 7 Nov 2017 13:32:59 +0200 Subject: [PATCH 1/4] Implement list Plan and tests --- src/Message/RestListPlanRequest.php | 242 ++++++++++++++++++++++ src/RestGateway.php | 17 +- tests/Message/RestListPlanRequestTest.php | 33 +++ tests/RestGatewayTest.php | 21 ++ 4 files changed, 312 insertions(+), 1 deletion(-) create mode 100755 src/Message/RestListPlanRequest.php create mode 100644 tests/Message/RestListPlanRequestTest.php diff --git a/src/Message/RestListPlanRequest.php b/src/Message/RestListPlanRequest.php new file mode 100755 index 0000000..18e2ab6 --- /dev/null +++ b/src/Message/RestListPlanRequest.php @@ -0,0 +1,242 @@ + + * // Create a gateway for the PayPal RestGateway + * // (routes to GatewayFactory::create) + * $gateway = Omnipay::create('PayPal_Rest'); + * + * // Initialise the gateway + * $gateway->initialize(array( + * 'clientId' => 'MyPayPalClientId', + * 'secret' => 'MyPayPalSecret', + * 'testMode' => true, // Or false when you are ready for live transactions + * )); + * + * + * #### List all plans that have state CREATED + * + * + * // List all billing plans + * $transaction = $gateway->listPlan([ + * 'state' => CREATED, + * ]); + * $response = $transaction->send(); + * $data = $response->getData(); + * echo "Gateway listPlan response data == " . print_r($data, true) . "\n"; + * + * + * ### Request Sample + * + * This is from the PayPal web site: + * + * + * curl -v -X GET https://api.sandbox.paypal.com/v1/payments/billing-plans?page_size=3&status=ACTIVE&page_size=2&page=1&total_required=yes \ + * -H "Content-Type:application/json" \ + * -H "Authorization: Bearer Access-Token" + * + * + * ### Response Sample + * + * This is from the PayPal web site: + * + * + * { + * "total_items": "166", + * "total_pages": "83", + * "plans": [ + * { + * "id": "P-7DC96732KA7763723UOPKETA", + * "state": "ACTIVE", + * "name": "Plan with Regular and Trial Payment Definitions", + * "description": "Plan with regular and trial billing payment definitions.", + * "type": "FIXED", + * "create_time": "2017-08-22T04:41:52.836Z", + * "update_time": "2017-08-22T04:41:53.169Z", + * "links": [ + * { + * "href": "https://api.sandbox.paypal.com//v1/payments/billing-plans/P-7DC96732KA7763723UOPKETA", + * "rel": "self", + * "method": "GET" + * } + * ] + * }, + * { + * "id": "P-1TV69435N82273154UPWDU4I", + * "state": "ACTIVE", + * "name": "Plan with Regular Payment Definition", + * "description": "Plan with one regular payment definition, minimal merchant preferences, and no shipping fees or tax.", + * "type": "INFINITE", + * "create_time": "2017-08-22T04:41:55.623Z", + * "update_time": "2017-08-22T04:41:56.055Z", + * "links": [ + * { + * "href": "https://api.sandbox.paypal.com//v1/payments/billing-plans/P-1TV69435N82273154UPWDU4I", + * "rel": "self", + * "method": "GET" + * } + * ] + * } + * ], + * "links": [ + * { + * "href": "https://api.sandbox.paypal.com/v1/payments/billing-plans?page_size=2&page=1&start=3&status=active", + * "rel": "start", + * "method": "GET" + * }, + * { + * "href": "https://api.sandbox.paypal.com/v1/payments/billing-plans?page_size=2&page=0&status=active", + * "rel": "previous_page", + * "method": "GET" + * }, + * { + * "href": "https://api.sandbox.paypal.com/v1/payments/billing-plans?page_size=2&page=2&status=active", + * "rel": "next_page", + * "method": "GET" + * }, + * { + * "href": "https://api.sandbox.paypal.com/v1/payments/billing-plans?page_size=2&page=82&status=active", + * "rel": "last", + * "method": "GET" + * } + * ] + * } + * + * + * + * @link https://developer.paypal.com/docs/api/payments.billing-plans#plan_list + */ +class RestListPlanRequest extends AbstractRestRequest +{ + /** + * + * Get the request page + * + * @return integer + */ + + public function getPage() + { + return $this->getParameter('page'); + } + + + /** + * Set the request page + * + * @param integer $value + * @return AbstractRestRequest provides a fluent interface. + */ + public function setPage($value) + { + return $this->setParameter('page', $value); + } + + /** + * Get the request status + * + * @return string + */ + public function getStatus() + { + return $this->getParameter('status'); + } + + /** + * Set the request status + * + * @param string $value + * @return AbstractRestRequest provides a fluent interface. + */ + public function setStatus($value) + { + return $this->setParameter('status', $value); + } + + /** + * Get the request page size + * + * @return string + */ + public function getPageSize() + { + return $this->getParameter('pageSize'); + } + + /** + * Set the request page size + * + * @param string $value + * @return AbstractRestRequest provides a fluent interface. + */ + public function setPageSize($value) + { + return $this->setParameter('pageSize', $value); + } + + /** + * Get the request total required + * + * @return string + */ + public function getTotalRequired() + { + return $this->getParameter('totalRequired'); + } + + /** + * Set the request total required + * + * @param string $value + * @return AbstractRestRequest provides a fluent interface. + */ + public function setTotalRequired($value) + { + return $this->setParameter('totalRequired', $value); + } + + + + + public function getData() + { + return array( + 'page' => $this->getPage(), + 'status' => $this->getStatus(), + 'page_size' => $this->getPageSize(), + 'total_required' => $this->getTotalRequired() + ); + } + + /** + * Get HTTP Method. + * + * The HTTP method for list plans requests must be GET. + * + * @return string + */ + protected function getHttpMethod() + { + return 'GET'; + } + + public function getEndpoint() + { + return parent::getEndpoint() . '/payments/billing-plans'; + } +} diff --git a/src/RestGateway.php b/src/RestGateway.php index 3e822e2..7013053 100644 --- a/src/RestGateway.php +++ b/src/RestGateway.php @@ -603,7 +603,22 @@ public function updatePlan(array $parameters = array()) } // TODO: Retrieve a plan - // TODO: List plans + + + /** + * List billing plans. + * + * Use this call to get a list of plans in any state (CREATED, ACTIVE, etc.). + * The plans returned are the plans made by the merchant making the call. + * + * @link https://developer.paypal.com/docs/api/payments.billing-plans#plan_list + * @param array $parameters + * @return \Omnipay\PayPal\Message\RestListPlanRequest + */ + public function listPlan(array $parameters = array()) + { + return $this->createRequest('\Omnipay\PayPal\Message\RestListPlanRequest', $parameters); + } /** * Create a subscription. diff --git a/tests/Message/RestListPlanRequestTest.php b/tests/Message/RestListPlanRequestTest.php new file mode 100644 index 0000000..ba1867e --- /dev/null +++ b/tests/Message/RestListPlanRequestTest.php @@ -0,0 +1,33 @@ +getHttpClient(); + $request = $this->getHttpRequest(); + $this->request = new RestListPlanRequest($client, $request); + } + + public function testGetData() + { + $data = $this->request->getData(); + $this->assertArrayHasKey('page',$data); + $this->assertArrayHasKey('status',$data); + $this->assertArrayHasKey('page_size',$data); + $this->assertArrayHasKey('total_required',$data); + } + + public function testEndpoint() + { + $this->assertStringEndsWith('/payments/billing-plans', $this->request->getEndpoint()); + } + +} diff --git a/tests/RestGatewayTest.php b/tests/RestGatewayTest.php index 3e8d061..db89871 100644 --- a/tests/RestGatewayTest.php +++ b/tests/RestGatewayTest.php @@ -154,6 +154,27 @@ public function testFetchTransaction() $this->assertEmpty($data); } + public function testListPlan() + { + $request = $this->gateway->listPlan(array( + 'page' => 0, + 'status' => 'ACTIVE', + 'pageSize' => 10, //number of plans in a single page + 'totalRequired' => 'yes' + )); + + $this->assertInstanceOf('\Omnipay\PayPal\Message\RestListPlanRequest', $request); + $this->assertSame(0, $request->getPage()); + $this->assertSame('ACTIVE', $request->getStatus()); + $this->assertSame(10, $request->getPageSize()); + $this->assertSame('yes', $request->getTotalRequired()); + + $endPoint = $request->getEndpoint(); + $this->assertSame('https://api.paypal.com/v1/payments/billing-plans', $endPoint); + $data = $request->getData(); + $this->assertNotEmpty($data); + } + public function testFetchPurchase() { $request = $this->gateway->fetchPurchase(array('transactionReference' => 'abc123')); From daeb6c64ae6691b4c5b0bddab314f34e4f59daa9 Mon Sep 17 00:00:00 2001 From: Islam Darwish Date: Tue, 7 Nov 2017 17:42:00 +0200 Subject: [PATCH 2/4] Fix psr2 guidelines --- phpunit.xml.dist~ | 25 +++++++++++++++++++++++++ src/Message/RestListPlanRequest.php | 4 ++-- 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 phpunit.xml.dist~ diff --git a/phpunit.xml.dist~ b/phpunit.xml.dist~ new file mode 100644 index 0000000..a35b736 --- /dev/null +++ b/phpunit.xml.dist~ @@ -0,0 +1,25 @@ + + + + + ./tests/ + + + + + + + + ./src + + + diff --git a/src/Message/RestListPlanRequest.php b/src/Message/RestListPlanRequest.php index 18e2ab6..035ead6 100755 --- a/src/Message/RestListPlanRequest.php +++ b/src/Message/RestListPlanRequest.php @@ -46,7 +46,7 @@ * This is from the PayPal web site: * * - * curl -v -X GET https://api.sandbox.paypal.com/v1/payments/billing-plans?page_size=3&status=ACTIVE&page_size=2&page=1&total_required=yes \ + * curl -v -X GET https://api.sandbox.paypal.com/v1/payments/billing-plans?page_size=3&status=ACTIVE&page=1\ * -H "Content-Type:application/json" \ * -H "Authorization: Bearer Access-Token" * @@ -80,7 +80,7 @@ * "id": "P-1TV69435N82273154UPWDU4I", * "state": "ACTIVE", * "name": "Plan with Regular Payment Definition", - * "description": "Plan with one regular payment definition, minimal merchant preferences, and no shipping fees or tax.", + * "description": "Plan with one regular payment definition, minimal merchant preferences, and no shipping fee", * "type": "INFINITE", * "create_time": "2017-08-22T04:41:55.623Z", * "update_time": "2017-08-22T04:41:56.055Z", From a8d999bbfb2e76f0f43e4a3e13e2eae42a788dae Mon Sep 17 00:00:00 2001 From: Islam Darwish Date: Tue, 7 Nov 2017 18:49:30 +0200 Subject: [PATCH 3/4] Fix travis PHP 5.3 to use precise --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 6028718..0e7957d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,6 +17,7 @@ matrix: include: - php: 5.3 env: setup=lowest + dist: precise - php: 5.5 env: setup=stable From b4d781827e4aabcd45d3146c3e271ec23fa185e0 Mon Sep 17 00:00:00 2001 From: Islam Darwish Date: Tue, 7 Nov 2017 19:49:41 +0200 Subject: [PATCH 4/4] Fix travis PHP 5.3 --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 0e7957d..77109ff 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ language: php php: - - 5.3 - 5.4 - 5.5 - 5.6