Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions src/Message/FetchSubscriptionSchedulesRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

/**
* Stripe Fetch Subscription Request.
*/

namespace Omnipay\Stripe\Message;

/**
* Stripe Fetch Subscription Request.
*
* @link https://stripe.com/docs/api/subscription_schedules/retrieve
*/
class FetchSubscriptionSchedulesRequest extends AbstractRequest
{
/**
* Get the subscription reference.
*
* @return string
*/
public function getSubscriptionSchedulesReference()
{
return $this->getParameter('subscriptionSchedulesReference');
}

/**
* Set the subscription reference.
*
* @param $value
* @return \Omnipay\Common\Message\AbstractRequest|FetchSubscriptionRequest
*/
public function setSubscriptionSchedulesReference($value)
{
return $this->setParameter('subscriptionSchedulesReference', $value);
}

public function getData()
{
$this->validate('subscriptionSchedulesReference');

return array();
}

public function getEndpoint()
{
return $this->endpoint.'/subscription_schedules/'.$this->getSubscriptionSchedulesReference();
}

public function getHttpMethod()
{
return 'GET';
}
}
14 changes: 14 additions & 0 deletions src/Message/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,20 @@ public function getSubscriptionReference()
return null;
}

/**
* Get the subscription schedule reference from the response of FetchSubscriptionSchedulesRequest.
*
* @return array|null
*/
public function getSubscriptionSchedulesReference()
{
if (isset($this->data['object']) && $this->data['object'] == 'subscription_schedule') {
return $this->data['id'];
}

return null;
}

/**
* Get the event reference from the response of FetchEventRequest.
*
Expand Down
43 changes: 43 additions & 0 deletions tests/Message/FetchSubscriptionSchedulesRequestTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace Omnipay\Stripe\Message;

use Omnipay\Tests\TestCase;

class FetchSubscriptionSchedulesRequestTest extends TestCase
{
public function setUp()
{
$this->request = new FetchSubscriptionSchedulesRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->setSubscriptionSchedulesReference('sub_sched_1GagVZKscivsTrcFhfMufnWP');
}

public function testEndpoint()
{
$endpoint = 'https://api.stripe.com/v1/subscription_schedules/sub_sched_1GagVZKscivsTrcFhfMufnWP';
$this->assertSame($endpoint, $this->request->getEndpoint());
}

public function testSendSuccess()
{
$this->setMockHttpResponse('FetchSubscriptionSchedulesSuccess.txt');
$response = $this->request->send();

$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('sub_sched_1GagVZKscivsTrcFhfMufnWP', $response->getSubscriptionSchedulesReference());
$this->assertNull($response->getMessage());
}

public function testSendFailure()
{
$this->setMockHttpResponse('FetchSubscriptionSchedulesFailure.txt');
$response = $this->request->send();

$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getSubscriptionReference());
$message = 'No such subscription schedule: sub_sched_1GagVZKscivsTrcFhfMufnWP';
$this->assertSame($message, $response->getMessage());
}
}
17 changes: 17 additions & 0 deletions tests/Mock/FetchSubscriptionSchedulesFailure.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
HTTP/1.1 404 Not Found
Server: nginx
Date: Mon, 26 Jun 2020 13:41:33 GMT
Content-Type: application/json
Content-Length: 188
Connection: keep-alive
Cache-Control: no-cache, no-store

{
"error": {
"code": "resource_missing",
"doc_url": "https://stripe.com/docs/error-codes/resource-missing",
"message": "No such subscription schedule: sub_sched_1GagVZKscivsTrcFhfMufnWP",
"param": "id",
"type": "invalid_request_error"
}
}
68 changes: 68 additions & 0 deletions tests/Mock/FetchSubscriptionSchedulesSuccess.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
HTTP/1.1 200 OK
Server: nginx
Date: Mon, 26 Jun 2020 13:41:33 GMT
Content-Type: application/json
Content-Length: 784
Connection: keep-alive
Cache-Control: no-cache, no-store

{
"id": "sub_sched_1GagVZKscivsTrcFhfMufnWP",
"object": "subscription_schedule",
"canceled_at": null,
"completed_at": null,
"created": 1593158960,
"current_phase": null,
"customer": "cus_7lqqgOm33t4xSU",
"default_settings": {
"billing_thresholds": null,
"collection_method": "charge_automatically",
"default_payment_method": null,
"default_source": null,
"invoice_settings": null,
"transfer_data": null
},
"end_behavior": "release",
"livemode": false,
"metadata": {
},
"phases": [
{
"add_invoice_items": [

],
"application_fee_percent": null,
"billing_thresholds": null,
"collection_method": null,
"coupon": null,
"default_payment_method": null,
"default_tax_rates": [

],
"end_date": 1596960367,
"invoice_settings": null,
"plans": [
{
"billing_thresholds": null,
"plan": "plan_GXzqnSohdy458I",
"price": "plan_GXzqnSohdy458I",
"quantity": 1,
"tax_rates": [

]
}
],
"prorate": true,
"proration_behavior": "create_prorations",
"start_date": 1595750767,
"tax_percent": null,
"transfer_data": null,
"trial_end": null
}
],
"released_at": null,
"released_subscription": null,
"renewal_interval": null,
"status": "not_started",
"subscription": null
}