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..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; @@ -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