Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GET external_subscription by external_id - V2 PHP #816

Merged
merged 1 commit into from
Jul 3, 2024
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
2 changes: 2 additions & 0 deletions Tests/Recurly/ExternalSubscription_List_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public function testGetAll() {
$this->assertEquals($external_subscription->state, 'active');
$this->assertEquals($external_subscription->auto_renew, false);
$this->assertEquals($external_subscription->in_grace_period, false);
$this->assertEquals($external_subscription->imported, false);
$this->assertEquals($external_subscription->test, false);
$this->assertInstanceOf('DateTime', $external_subscription->canceled_at);
$this->assertInstanceOf('DateTime', $external_subscription->expires_at);
$this->assertInstanceOf('DateTime', $external_subscription->trial_started_at);
Expand Down
32 changes: 32 additions & 0 deletions Tests/Recurly/ExternalSubscription_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,38 @@ public function testGetSubscription() {
$this->assertEquals($external_subscription->state, 'active');
$this->assertEquals($external_subscription->auto_renew, false);
$this->assertEquals($external_subscription->in_grace_period, false);
$this->assertEquals($external_subscription->imported, false);
$this->assertEquals($external_subscription->test, false);
$this->assertInstanceOf('DateTime', $external_subscription->canceled_at);
$this->assertInstanceOf('DateTime', $external_subscription->expires_at);
$this->assertInstanceOf('DateTime', $external_subscription->trial_started_at);
$this->assertInstanceOf('DateTime', $external_subscription->trial_ends_at);
$external_product_reference = $external_subscription->external_product_reference;
$this->assertEquals($external_product_reference->id, 'rauqpcdmxc4a');
$this->assertEquals($external_product_reference->reference_code, '1234');
$this->assertEquals($external_product_reference->external_connection_type, 'apple_app_store');
$this->assertInstanceOf('DateTime', $external_product_reference->created_at);
$this->assertInstanceOf('DateTime', $external_product_reference->updated_at);
}

public function testGetSubscriptionByExternalId() {
$this->client->addResponse('GET', '/external_subscriptions/external-id-1_ext_id', 'external_subscriptions/show-200.xml');

$external_subscription = Recurly_ExternalSubscription::getByExternalId('1_ext_id', $this->client);
$this->assertInstanceOf('Recurly_ExternalSubscription', $external_subscription);
$this->assertInstanceOf('Recurly_Stub', $external_subscription->account);
$this->assertEquals($external_subscription->account->getHref(), 'https://api.recurly.com/v2/accounts/1');
$this->assertEquals('https://api.recurly.com/v2/external_subscriptions/rjx71rx8gs2m/external_invoices', $external_subscription->external_invoices->getHref());
$this->assertEquals('https://api.recurly.com/v2/external_subscriptions/rjx71rx8gs2m/external_payment_phases', $external_subscription->external_payment_phases->getHref());
$this->assertInstanceOf('DateTime', $external_subscription->created_at);
$this->assertInstanceOf('DateTime', $external_subscription->updated_at);
$this->assertEquals($external_subscription->quantity, 18);
$this->assertEquals($external_subscription->external_id, '1_ext_id');
$this->assertEquals($external_subscription->state, 'active');
$this->assertEquals($external_subscription->auto_renew, false);
$this->assertEquals($external_subscription->in_grace_period, false);
$this->assertEquals($external_subscription->imported, false);
$this->assertEquals($external_subscription->test, false);
$this->assertInstanceOf('DateTime', $external_subscription->canceled_at);
$this->assertInstanceOf('DateTime', $external_subscription->expires_at);
$this->assertInstanceOf('DateTime', $external_subscription->trial_started_at);
Expand Down
4 changes: 4 additions & 0 deletions Tests/fixtures/external_subscriptions/index-200.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Content-Type: application/xml; charset=utf-8
<last_purchased nil="nil"></last_purchased>
<auto_renew type="boolean">false</auto_renew>
<in_grace_period type="boolean">false</in_grace_period>
<imported type="boolean">false</imported>
<test type="boolean">false</test>
<app_identifier nil="nil"></app_identifier>
<quantity type="integer">18</quantity>
<external_id>1_ext_id</external_id>
Expand All @@ -43,6 +45,8 @@ Content-Type: application/xml; charset=utf-8
<last_purchased nil="nil"></last_purchased>
<auto_renew type="boolean">false</auto_renew>
<in_grace_period type="boolean">false</in_grace_period>
<imported type="boolean">false</imported>
<test type="boolean">false</test>
<app_identifier nil="nil"></app_identifier>
<quantity type="integer">12</quantity>
<external_id>2_ext_id</external_id>
Expand Down
2 changes: 2 additions & 0 deletions Tests/fixtures/external_subscriptions/show-200.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Content-Type: application/xml; charset=utf-8
<last_purchased nil="nil"></last_purchased>
<auto_renew type="boolean">false</auto_renew>
<in_grace_period type="boolean">false</in_grace_period>
<imported type="boolean">false</imported>
<test type="boolean">false</test>
<app_identifier nil="nil"></app_identifier>
<quantity type="integer">18</quantity>
<external_id>1_ext_id</external_id>
Expand Down
16 changes: 16 additions & 0 deletions lib/recurly/external_subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* @property DateTime $last_purchased
* @property boolean $auto_renew
* @property boolean $in_grace_period
* @property boolean $imported
* @property boolean $test
* @property string $app_identifier
* @property integer $quantity
* @property string $external_id
Expand All @@ -31,6 +33,16 @@ public static function get($uuid, $client = null) {
return Recurly_Base::_get(Recurly_ExternalSubscription::uriForExternalSubscription($uuid), $client);
}

/**
* @param $external_id
* @param Recurly_Client $client Optional client for the request, useful for mocking the client
* @return Recurly_ExternalSubscription|null
* @throws Recurly_Error
*/
public static function getByExternalId($external_id, $client = null) {
return Recurly_Base::_get(Recurly_ExternalSubscription::uriForExternalSubscriptionExternalId($external_id), $client);
}

public function getExternalPaymentPhase($external_payment_phase_uuid, $client = null) {
return Recurly_Base::_get($this->uriForExternalPaymentPhase() . '/' . $external_payment_phase_uuid, $client);
}
Expand All @@ -46,6 +58,10 @@ protected static function uriForExternalSubscription($uuid) {
return self::_safeUri(Recurly_Client::PATH_EXTERNAL_SUBSCRIPTIONS, $uuid);
}

protected static function uriForExternalSubscriptionExternalId($external_id) {
return self::_safeUri(Recurly_Client::PATH_EXTERNAL_SUBSCRIPTIONS, "external-id-$external_id");
}

protected function uriForExternalPaymentPhase() {
return $this->uri() . '/' . Recurly_Client::PATH_EXTERNAL_PAYMENT_PHASES;
}
Expand Down
Loading