diff --git a/Tests/Recurly/ExternalSubscription_List_Test.php b/Tests/Recurly/ExternalSubscription_List_Test.php
index b5f46a8d..f219e393 100644
--- a/Tests/Recurly/ExternalSubscription_List_Test.php
+++ b/Tests/Recurly/ExternalSubscription_List_Test.php
@@ -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->import, 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);
diff --git a/Tests/Recurly/ExternalSubscription_Test.php b/Tests/Recurly/ExternalSubscription_Test.php
index d9e10da6..97cfaca8 100644
--- a/Tests/Recurly/ExternalSubscription_Test.php
+++ b/Tests/Recurly/ExternalSubscription_Test.php
@@ -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->import, 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->import, 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);
diff --git a/Tests/fixtures/external_subscriptions/index-200.xml b/Tests/fixtures/external_subscriptions/index-200.xml
index 554369e9..9236f289 100644
--- a/Tests/fixtures/external_subscriptions/index-200.xml
+++ b/Tests/fixtures/external_subscriptions/index-200.xml
@@ -17,6 +17,8 @@ Content-Type: application/xml; charset=utf-8
false
false
+ false
+ false
18
1_ext_id
@@ -43,6 +45,8 @@ Content-Type: application/xml; charset=utf-8
false
false
+ false
+ false
12
2_ext_id
diff --git a/Tests/fixtures/external_subscriptions/show-200.xml b/Tests/fixtures/external_subscriptions/show-200.xml
index 559c08e0..c5337da9 100644
--- a/Tests/fixtures/external_subscriptions/show-200.xml
+++ b/Tests/fixtures/external_subscriptions/show-200.xml
@@ -16,6 +16,8 @@ Content-Type: application/xml; charset=utf-8
false
false
+ false
+ false
18
1_ext_id
diff --git a/lib/recurly/external_subscription.php b/lib/recurly/external_subscription.php
index 17cd76d7..a17423d4 100644
--- a/lib/recurly/external_subscription.php
+++ b/lib/recurly/external_subscription.php
@@ -7,6 +7,8 @@
* @property DateTime $last_purchased
* @property boolean $auto_renew
* @property boolean $in_grace_period
+ * @property boolean $import
+ * @property boolean $test
* @property string $app_identifier
* @property integer $quantity
* @property string $external_id
@@ -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);
}
@@ -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;
}