From cccecac230f2752dc0c16626b811bf521d464c20 Mon Sep 17 00:00:00 2001 From: Barbara Meclazcke Date: Thu, 12 Jan 2017 14:20:39 -0300 Subject: [PATCH 1/2] Updated with tests and fixed class paths --- src/Gateway.php | 2 +- src/Message/ListPlansRequest.php | 2 +- tests/GatewayTest.php | 7 +++++ tests/Message/ListPlansTest.php | 38 ++++++++++++++++++++++++++ tests/Mock/ListPlansSuccess.txt | 46 ++++++++++++++++++++++++++++++++ 5 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 tests/Message/ListPlansTest.php create mode 100644 tests/Mock/ListPlansSuccess.txt diff --git a/src/Gateway.php b/src/Gateway.php index 8c1575a4..a4baa954 100644 --- a/src/Gateway.php +++ b/src/Gateway.php @@ -516,7 +516,7 @@ public function deletePlan(array $parameters = array()) */ public function listPlans(array $parameters = array()) { - return $this->createRequest('App\Lib\Omnipay\Stripe\Message\ListPlansRequest', $parameters); + return $this->createRequest('\Omnipay\Stripe\Message\ListPlansRequest', $parameters); } /** diff --git a/src/Message/ListPlansRequest.php b/src/Message/ListPlansRequest.php index 1a4d1b2f..11f64cd9 100644 --- a/src/Message/ListPlansRequest.php +++ b/src/Message/ListPlansRequest.php @@ -13,7 +13,7 @@ * @see Omnipay\Stripe\Gateway * @link https://stripe.com/docs/api/curl#list_plans */ -class ListPlansRequest extends \Omnipay\Stripe\Message\AbstractRequest +class ListPlansRequest extends AbstractRequest { public function getData() { diff --git a/tests/GatewayTest.php b/tests/GatewayTest.php index 1a68b4c0..d1ffe219 100644 --- a/tests/GatewayTest.php +++ b/tests/GatewayTest.php @@ -152,6 +152,13 @@ public function testDeletePlan() $this->assertSame('basic', $request->getId()); } + public function testListPlans() + { + $request = $this->gateway->listPlans(array()); + + $this->assertInstanceOf('Omnipay\Stripe\Message\ListPlansRequest', $request); + } + public function testCreateSubscription() { $request = $this->gateway->createSubscription(array('plan' => 'basic')); diff --git a/tests/Message/ListPlansTest.php b/tests/Message/ListPlansTest.php new file mode 100644 index 00000000..8afdfe80 --- /dev/null +++ b/tests/Message/ListPlansTest.php @@ -0,0 +1,38 @@ +request = new ListPlansRequest($this->getHttpClient(), $this->getHttpRequest()); + } + + public function testEndpoint() + { + $this->assertSame('https://api.stripe.com/v1/plans', $this->request->getEndpoint()); + } + + public function testSendSuccess() + { + $this->setMockHttpResponse('ListPlans.txt'); + $response = $this->request->send(); + + $this->assertTrue($response->isSuccessful()); + $this->assertFalse($response->isRedirect()); + $this->assertNotNull($response->getList()); + $this->assertNull($response->getMessage()); + } + + /** + * According to documentation: https://stripe.com/docs/api/php#list_plans + * This request should never throw an error. + */ + public function testSendFailure() + { + this->assertTrue(true); + } +} diff --git a/tests/Mock/ListPlansSuccess.txt b/tests/Mock/ListPlansSuccess.txt new file mode 100644 index 00000000..bb15919b --- /dev/null +++ b/tests/Mock/ListPlansSuccess.txt @@ -0,0 +1,46 @@ +HTTP/1.1 200 OK +Server: nginx +Date: Mon, 29 Feb 2016 02:40:46 GMT +Content-Type: application/json +Content-Length: 6247 +Connection: keep-alive +Access-Control-Allow-Credentials: true +Cache-Control: no-cache, no-store + +{ + "object" => "list", + "url" => "/v1/plans", + "has_more" => false, + "data" => [ + { + "id": "test-1", + "object": "plan", + "amount": 29995, + "created": 1483391153, + "currency": "usd", + "interval": "year", + "interval_count": 1, + "livemode": false, + "metadata": { + }, + "name": "Test 1", + "statement_descriptor": "Test 1", + "trial_period_days": 14 + }, + { + "id": "test-2", + "object": "plan", + "amount": 29995, + "created": 1483391153, + "currency": "usd", + "interval": "year", + "interval_count": 1, + "livemode": false, + "metadata": { + }, + "name": "Test 1", + "statement_descriptor": "Test 2", + "trial_period_days": 14 + } + ] +} \ No newline at end of file From 66da7f63645c289a4948d5e5671a9962a3a362f8 Mon Sep 17 00:00:00 2001 From: Barbara Meclazcke Date: Tue, 17 Jan 2017 21:08:35 -0300 Subject: [PATCH 2/2] List plans --- src/Message/ListPlansRequest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Message/ListPlansRequest.php b/src/Message/ListPlansRequest.php index 11f64cd9..2b71ec5d 100644 --- a/src/Message/ListPlansRequest.php +++ b/src/Message/ListPlansRequest.php @@ -3,7 +3,7 @@ /** * Stripe List Plans Request. */ -namespace App\Lib\Omnipay\Stripe\Message; +namespace Omnipay\Stripe\Message; // use Omnipay\Common\Message\AbstractRequest;