Skip to content

Commit d3c2592

Browse files
Add FetchSubscriptionSchedulesRequest (#181)
1 parent 3878249 commit d3c2592

File tree

5 files changed

+195
-0
lines changed

5 files changed

+195
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
/**
4+
* Stripe Fetch Subscription Request.
5+
*/
6+
7+
namespace Omnipay\Stripe\Message;
8+
9+
/**
10+
* Stripe Fetch Subscription Request.
11+
*
12+
* @link https://stripe.com/docs/api/subscription_schedules/retrieve
13+
*/
14+
class FetchSubscriptionSchedulesRequest extends AbstractRequest
15+
{
16+
/**
17+
* Get the subscription reference.
18+
*
19+
* @return string
20+
*/
21+
public function getSubscriptionSchedulesReference()
22+
{
23+
return $this->getParameter('subscriptionSchedulesReference');
24+
}
25+
26+
/**
27+
* Set the subscription reference.
28+
*
29+
* @param $value
30+
* @return \Omnipay\Common\Message\AbstractRequest|FetchSubscriptionRequest
31+
*/
32+
public function setSubscriptionSchedulesReference($value)
33+
{
34+
return $this->setParameter('subscriptionSchedulesReference', $value);
35+
}
36+
37+
public function getData()
38+
{
39+
$this->validate('subscriptionSchedulesReference');
40+
41+
return array();
42+
}
43+
44+
public function getEndpoint()
45+
{
46+
return $this->endpoint.'/subscription_schedules/'.$this->getSubscriptionSchedulesReference();
47+
}
48+
49+
public function getHttpMethod()
50+
{
51+
return 'GET';
52+
}
53+
}

src/Message/Response.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,20 @@ public function getSubscriptionReference()
261261
return null;
262262
}
263263

264+
/**
265+
* Get the subscription schedule reference from the response of FetchSubscriptionSchedulesRequest.
266+
*
267+
* @return array|null
268+
*/
269+
public function getSubscriptionSchedulesReference()
270+
{
271+
if (isset($this->data['object']) && $this->data['object'] == 'subscription_schedule') {
272+
return $this->data['id'];
273+
}
274+
275+
return null;
276+
}
277+
264278
/**
265279
* Get the event reference from the response of FetchEventRequest.
266280
*
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace Omnipay\Stripe\Message;
4+
5+
use Omnipay\Tests\TestCase;
6+
7+
class FetchSubscriptionSchedulesRequestTest extends TestCase
8+
{
9+
public function setUp()
10+
{
11+
$this->request = new FetchSubscriptionSchedulesRequest($this->getHttpClient(), $this->getHttpRequest());
12+
$this->request->setSubscriptionSchedulesReference('sub_sched_1GagVZKscivsTrcFhfMufnWP');
13+
}
14+
15+
public function testEndpoint()
16+
{
17+
$endpoint = 'https://api.stripe.com/v1/subscription_schedules/sub_sched_1GagVZKscivsTrcFhfMufnWP';
18+
$this->assertSame($endpoint, $this->request->getEndpoint());
19+
}
20+
21+
public function testSendSuccess()
22+
{
23+
$this->setMockHttpResponse('FetchSubscriptionSchedulesSuccess.txt');
24+
$response = $this->request->send();
25+
26+
$this->assertTrue($response->isSuccessful());
27+
$this->assertFalse($response->isRedirect());
28+
$this->assertSame('sub_sched_1GagVZKscivsTrcFhfMufnWP', $response->getSubscriptionSchedulesReference());
29+
$this->assertNull($response->getMessage());
30+
}
31+
32+
public function testSendFailure()
33+
{
34+
$this->setMockHttpResponse('FetchSubscriptionSchedulesFailure.txt');
35+
$response = $this->request->send();
36+
37+
$this->assertFalse($response->isSuccessful());
38+
$this->assertFalse($response->isRedirect());
39+
$this->assertNull($response->getSubscriptionReference());
40+
$message = 'No such subscription schedule: sub_sched_1GagVZKscivsTrcFhfMufnWP';
41+
$this->assertSame($message, $response->getMessage());
42+
}
43+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
HTTP/1.1 404 Not Found
2+
Server: nginx
3+
Date: Mon, 26 Jun 2020 13:41:33 GMT
4+
Content-Type: application/json
5+
Content-Length: 188
6+
Connection: keep-alive
7+
Cache-Control: no-cache, no-store
8+
9+
{
10+
"error": {
11+
"code": "resource_missing",
12+
"doc_url": "https://stripe.com/docs/error-codes/resource-missing",
13+
"message": "No such subscription schedule: sub_sched_1GagVZKscivsTrcFhfMufnWP",
14+
"param": "id",
15+
"type": "invalid_request_error"
16+
}
17+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
HTTP/1.1 200 OK
2+
Server: nginx
3+
Date: Mon, 26 Jun 2020 13:41:33 GMT
4+
Content-Type: application/json
5+
Content-Length: 784
6+
Connection: keep-alive
7+
Cache-Control: no-cache, no-store
8+
9+
{
10+
"id": "sub_sched_1GagVZKscivsTrcFhfMufnWP",
11+
"object": "subscription_schedule",
12+
"canceled_at": null,
13+
"completed_at": null,
14+
"created": 1593158960,
15+
"current_phase": null,
16+
"customer": "cus_7lqqgOm33t4xSU",
17+
"default_settings": {
18+
"billing_thresholds": null,
19+
"collection_method": "charge_automatically",
20+
"default_payment_method": null,
21+
"default_source": null,
22+
"invoice_settings": null,
23+
"transfer_data": null
24+
},
25+
"end_behavior": "release",
26+
"livemode": false,
27+
"metadata": {
28+
},
29+
"phases": [
30+
{
31+
"add_invoice_items": [
32+
33+
],
34+
"application_fee_percent": null,
35+
"billing_thresholds": null,
36+
"collection_method": null,
37+
"coupon": null,
38+
"default_payment_method": null,
39+
"default_tax_rates": [
40+
41+
],
42+
"end_date": 1596960367,
43+
"invoice_settings": null,
44+
"plans": [
45+
{
46+
"billing_thresholds": null,
47+
"plan": "plan_GXzqnSohdy458I",
48+
"price": "plan_GXzqnSohdy458I",
49+
"quantity": 1,
50+
"tax_rates": [
51+
52+
]
53+
}
54+
],
55+
"prorate": true,
56+
"proration_behavior": "create_prorations",
57+
"start_date": 1595750767,
58+
"tax_percent": null,
59+
"transfer_data": null,
60+
"trial_end": null
61+
}
62+
],
63+
"released_at": null,
64+
"released_subscription": null,
65+
"renewal_interval": null,
66+
"status": "not_started",
67+
"subscription": null
68+
}

0 commit comments

Comments
 (0)