From cb8abf3bbd446c54a46b78fcbc5e33441335c037 Mon Sep 17 00:00:00 2001 From: Amanda Date: Tue, 13 Aug 2024 12:11:42 -0700 Subject: [PATCH] get external sub by uuid --- .../ExternalSubscription_List_Test.php | 1 + Tests/Recurly/ExternalSubscription_Test.php | 33 +++++++++++++++++++ .../external_subscriptions/index-200.xml | 6 ++-- .../external_subscriptions/show-200.xml | 3 +- lib/recurly/external_subscription.php | 15 +++++++++ 5 files changed, 55 insertions(+), 3 deletions(-) diff --git a/Tests/Recurly/ExternalSubscription_List_Test.php b/Tests/Recurly/ExternalSubscription_List_Test.php index 03511247..3d6d0e14 100644 --- a/Tests/Recurly/ExternalSubscription_List_Test.php +++ b/Tests/Recurly/ExternalSubscription_List_Test.php @@ -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'); diff --git a/Tests/Recurly/ExternalSubscription_Test.php b/Tests/Recurly/ExternalSubscription_Test.php index e49d5244..3ebee1b3 100644 --- a/Tests/Recurly/ExternalSubscription_Test.php +++ b/Tests/Recurly/ExternalSubscription_Test.php @@ -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'); @@ -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'); diff --git a/Tests/fixtures/external_subscriptions/index-200.xml b/Tests/fixtures/external_subscriptions/index-200.xml index 31d8bbed..74f85512 100644 --- a/Tests/fixtures/external_subscriptions/index-200.xml +++ b/Tests/fixtures/external_subscriptions/index-200.xml @@ -6,6 +6,8 @@ Content-Type: application/xml; charset=utf-8 + 1_ext_id + 72bb9966bb5dc3767461ce4368a6b366 rauqpcdmxc4a @@ -21,7 +23,6 @@ Content-Type: application/xml; charset=utf-8 false 18 - 1_ext_id 2022-09-13T18:55:15Z 2026-09-13T18:55:15Z 2026-09-13T18:55:15Z @@ -34,6 +35,8 @@ Content-Type: application/xml; charset=utf-8 + 2_ext_id + 72bba6cc3a2323d04632374f0fb44a5a rauqpcdmxc4b @@ -49,7 +52,6 @@ Content-Type: application/xml; charset=utf-8 false 12 - 2_ext_id 2022-09-13T18:55:15Z 2026-09-13T18:55:15Z 2025-09-13T18:55:15Z diff --git a/Tests/fixtures/external_subscriptions/show-200.xml b/Tests/fixtures/external_subscriptions/show-200.xml index 01c864c6..8cd328bd 100644 --- a/Tests/fixtures/external_subscriptions/show-200.xml +++ b/Tests/fixtures/external_subscriptions/show-200.xml @@ -5,6 +5,8 @@ Content-Type: application/xml; charset=utf-8 + 1_ext_id + 72bb9966bb5dc3767461ce4368a6b366 rauqpcdmxc4a @@ -20,7 +22,6 @@ Content-Type: application/xml; charset=utf-8 false 18 - 1_ext_id 2022-09-13T18:55:15Z 2026-09-13T18:55:15Z 2026-09-13T18:55:15Z diff --git a/lib/recurly/external_subscription.php b/lib/recurly/external_subscription.php index d0871634..69034ef7 100644 --- a/lib/recurly/external_subscription.php +++ b/lib/recurly/external_subscription.php @@ -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 @@ -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); } @@ -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; }