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 sub by uuid #820

Merged
merged 1 commit into from
Aug 27, 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
1 change: 1 addition & 0 deletions Tests/Recurly/ExternalSubscription_List_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function testGetAll() {
$this->assertInstanceOf('DateTime', $external_subscription->expires_at);
$this->assertInstanceOf('DateTime', $external_subscription->trial_started_at);
$this->assertInstanceOf('DateTime', $external_subscription->trial_ends_at);
$this->assertEquals($external_subscription->uuid, '72bb9966bb5dc3767461ce4368a6b366');
$external_product_reference = $external_subscription->external_product_reference;
$this->assertEquals($external_product_reference->id, 'rauqpcdmxc4a');
$this->assertEquals($external_product_reference->reference_code, '1234');
Expand Down
33 changes: 33 additions & 0 deletions Tests/Recurly/ExternalSubscription_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public function testGetSubscription() {
$this->assertInstanceOf('DateTime', $external_subscription->expires_at);
$this->assertInstanceOf('DateTime', $external_subscription->trial_started_at);
$this->assertInstanceOf('DateTime', $external_subscription->trial_ends_at);
$this->assertEquals($external_subscription->uuid, '72bb9966bb5dc3767461ce4368a6b366');
$external_product_reference = $external_subscription->external_product_reference;
$this->assertEquals($external_product_reference->id, 'rauqpcdmxc4a');
$this->assertEquals($external_product_reference->reference_code, '1234');
Expand Down Expand Up @@ -55,6 +56,38 @@ public function testGetSubscriptionByExternalId() {
$this->assertInstanceOf('DateTime', $external_subscription->expires_at);
$this->assertInstanceOf('DateTime', $external_subscription->trial_started_at);
$this->assertInstanceOf('DateTime', $external_subscription->trial_ends_at);
$this->assertEquals($external_subscription->uuid, '72bb9966bb5dc3767461ce4368a6b366');
$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 testGetSubscriptionByUuid() {
$this->client->addResponse('GET', '/external_subscriptions/uuid-72bb9966bb5dc3767461ce4368a6b366', 'external_subscriptions/show-200.xml');

$external_subscription = Recurly_ExternalSubscription::getByUuid('72bb9966bb5dc3767461ce4368a6b366', $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);
$this->assertInstanceOf('DateTime', $external_subscription->trial_ends_at);
$this->assertEquals($external_subscription->uuid, '72bb9966bb5dc3767461ce4368a6b366');
$external_product_reference = $external_subscription->external_product_reference;
$this->assertEquals($external_product_reference->id, 'rauqpcdmxc4a');
$this->assertEquals($external_product_reference->reference_code, '1234');
Expand Down
6 changes: 4 additions & 2 deletions Tests/fixtures/external_subscriptions/index-200.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Content-Type: application/xml; charset=utf-8
<external_subscription href="https://api.recurly.com/v2/external_subscriptions/rjx71rx8gs2m">
<account href="https://api.recurly.com/v2/accounts/1"/>
<external_invoices href="https://api.recurly.com/v2/external_subscriptions/rjx71rx8gs2m/external_invoices"/>
<external_id>1_ext_id</external_id>
<uuid>72bb9966bb5dc3767461ce4368a6b366</uuid>
<external_payment_phases href="https://api.recurly.com/v2/external_subscriptions/rjx71rx8gs2m/external_payment_phases"/>
<external_product_reference>
<id>rauqpcdmxc4a</id>
Expand All @@ -21,7 +23,6 @@ Content-Type: application/xml; charset=utf-8
<test type="boolean">false</test>
<app_identifier nil="nil"></app_identifier>
<quantity type="integer">18</quantity>
<external_id>1_ext_id</external_id>
<activated_at type="datetime">2022-09-13T18:55:15Z</activated_at>
<canceled_at type="datetime">2026-09-13T18:55:15Z</canceled_at>
<expires_at type="datetime">2026-09-13T18:55:15Z</expires_at>
Expand All @@ -34,6 +35,8 @@ Content-Type: application/xml; charset=utf-8
<external_subscription href="https://api.recurly.com/v2/external_subscriptions/rbf29tck8hpo">
<account href="https://api.recurly.com/v2/accounts/2"/>
<external_invoices href="https://api.recurly.com/v2/external_subscriptions/rbf29tck8hpo/external_invoices"/>
<external_id>2_ext_id</external_id>
<uuid>72bba6cc3a2323d04632374f0fb44a5a</uuid>
<external_payment_phases href="https://api.recurly.com/v2/external_subscriptions/rbf29tck8hpo/external_payment_phases"/>
<external_product_reference>
<id>rauqpcdmxc4b</id>
Expand All @@ -49,7 +52,6 @@ Content-Type: application/xml; charset=utf-8
<test type="boolean">false</test>
<app_identifier nil="nil"></app_identifier>
<quantity type="integer">12</quantity>
<external_id>2_ext_id</external_id>
<activated_at type="datetime">2022-09-13T18:55:15Z</activated_at>
<canceled_at type="datetime">2026-09-13T18:55:15Z</canceled_at>
<expires_at type="datetime">2025-09-13T18:55:15Z</expires_at>
Expand Down
3 changes: 2 additions & 1 deletion Tests/fixtures/external_subscriptions/show-200.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Content-Type: application/xml; charset=utf-8
<external_subscription href="https://api.recurly.com/v2/external_subscriptions/rjx71rx8gs2m">
<account href="https://api.recurly.com/v2/accounts/1"/>
<external_invoices href="https://api.recurly.com/v2/external_subscriptions/rjx71rx8gs2m/external_invoices"/>
<external_id>1_ext_id</external_id>
<uuid>72bb9966bb5dc3767461ce4368a6b366</uuid>
<external_payment_phases href="https://api.recurly.com/v2/external_subscriptions/rjx71rx8gs2m/external_payment_phases"/>
<external_product_reference>
<id>rauqpcdmxc4a</id>
Expand All @@ -20,7 +22,6 @@ Content-Type: application/xml; charset=utf-8
<test type="boolean">false</test>
<app_identifier nil="nil"></app_identifier>
<quantity type="integer">18</quantity>
<external_id>1_ext_id</external_id>
<activated_at type="datetime">2022-09-13T18:55:15Z</activated_at>
<canceled_at type="datetime">2026-09-13T18:55:15Z</canceled_at>
<expires_at type="datetime">2026-09-13T18:55:15Z</expires_at>
Expand Down
15 changes: 15 additions & 0 deletions lib/recurly/external_subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* @property Recurly_Stub $account
* @property Recurly_ExternalProductReference $external_product_reference
* @property Recurly_ExternalPaymentPhase[] $external_payment_phases
* @property string $uuid
* @property DateTime $last_purchased
* @property boolean $auto_renew
* @property boolean $in_grace_period
Expand Down Expand Up @@ -43,6 +44,16 @@ public static function getByExternalId($external_id, $client = null) {
return Recurly_Base::_get(Recurly_ExternalSubscription::uriForExternalSubscriptionExternalId($external_id), $client);
}

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

public function getExternalPaymentPhase($external_payment_phase_uuid, $client = null) {
return Recurly_Base::_get($this->uriForExternalPaymentPhase() . '/' . $external_payment_phase_uuid, $client);
}
Expand All @@ -62,6 +73,10 @@ protected static function uriForExternalSubscriptionExternalId($external_id) {
return self::_safeUri(Recurly_Client::PATH_EXTERNAL_SUBSCRIPTIONS, "external-id-$external_id");
}

protected static function uriForExternalSubscriptionUuid($uuid) {
return self::_safeUri(Recurly_Client::PATH_EXTERNAL_SUBSCRIPTIONS, "uuid-$uuid");
}

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