From 2dfcf45352c101f17d9d0493302465a7d5ae2286 Mon Sep 17 00:00:00 2001 From: Amanda Fielding Date: Tue, 21 Nov 2023 14:15:54 -0800 Subject: [PATCH] add external payment phases --- Tests/Recurly/ExternalInvoice_List_Test.php | 1 + Tests/Recurly/ExternalInvoice_Test.php | 2 + .../ExternalPaymentPhase_List_Test.php | 30 +++++++++++++ Tests/Recurly/ExternalPaymentPhase_Test.php | 44 +++++++++++++++++++ .../ExternalSubscription_List_Test.php | 2 + Tests/Recurly/ExternalSubscription_Test.php | 2 + .../fixtures/external_invoices/index-200.xml | 2 + Tests/fixtures/external_invoices/show-200.xml | 1 + .../external_payment_phases/index-200.xml | 21 +++++++++ .../external_payment_phases/show-200.xml | 19 ++++++++ .../external_subscriptions/index-200.xml | 4 ++ .../external_subscriptions/show-200.xml | 2 + lib/recurly.php | 1 + lib/recurly/client.php | 1 + lib/recurly/external_invoice.php | 1 + lib/recurly/external_payment_phase.php | 37 ++++++++++++++++ lib/recurly/external_subscription.php | 9 ++++ lib/recurly/util/xml_tools.php | 2 + 18 files changed, 181 insertions(+) create mode 100644 Tests/Recurly/ExternalPaymentPhase_List_Test.php create mode 100644 Tests/Recurly/ExternalPaymentPhase_Test.php create mode 100644 Tests/fixtures/external_payment_phases/index-200.xml create mode 100644 Tests/fixtures/external_payment_phases/show-200.xml create mode 100644 lib/recurly/external_payment_phase.php diff --git a/Tests/Recurly/ExternalInvoice_List_Test.php b/Tests/Recurly/ExternalInvoice_List_Test.php index f9bf75d9..dea72e26 100644 --- a/Tests/Recurly/ExternalInvoice_List_Test.php +++ b/Tests/Recurly/ExternalInvoice_List_Test.php @@ -16,6 +16,7 @@ public function testGetAll() { $this->assertInstanceOf('Recurly_ExternalInvoice', $external_invoice); $this->assertInstanceOf('Recurly_Stub', $external_invoice->account); $this->assertInstanceOf('Recurly_Stub', $external_invoice->external_subscription); + $this->assertInstanceOf('Recurly_ExternalPaymentPhase', $external_invoice->external_payment_phase); $this->assertEquals($external_invoice->external_id, 'external-id'); $this->assertEquals($external_invoice->state, 'paid'); $this->assertEquals($external_invoice->currency, 'USD'); diff --git a/Tests/Recurly/ExternalInvoice_Test.php b/Tests/Recurly/ExternalInvoice_Test.php index 34a128d5..58a7b49b 100644 --- a/Tests/Recurly/ExternalInvoice_Test.php +++ b/Tests/Recurly/ExternalInvoice_Test.php @@ -12,6 +12,8 @@ public function testGetInvoice() { $this->assertEquals($external_invoice->account->getHref(), 'https://api.recurly.com/v2/accounts/1'); $this->assertInstanceOf('Recurly_Stub', $external_invoice->external_subscription); $this->assertEquals($external_invoice->external_subscription->getHref(), 'https://api.recurly.com/v2/external_subscriptions/1'); + $this->assertInstanceOf('Recurly_Stub', $external_invoice->external_payment_phase); + $this->assertEquals($external_invoice->external_payment_phase->getHref(), 'https://api.recurly.com/v2/external_payment_phases/pexv3leeop4w'); $this->assertEquals($external_invoice->external_id, 'external-id'); $this->assertEquals($external_invoice->state, 'paid'); $this->assertEquals($external_invoice->currency, 'USD'); diff --git a/Tests/Recurly/ExternalPaymentPhase_List_Test.php b/Tests/Recurly/ExternalPaymentPhase_List_Test.php new file mode 100644 index 00000000..14633cc3 --- /dev/null +++ b/Tests/Recurly/ExternalPaymentPhase_List_Test.php @@ -0,0 +1,30 @@ +client->addResponse('GET', $url, 'external_payment_phases/index-200.xml'); + + $external_subscription = new Recurly_ExternalSubscription(); + $external_subscription->uuid = 'swifdu8c9om9'; + + $external_payment_phases = $external_subscription->listExternalPaymentPhases($this->client); + $external_payment_phase = $external_payment_phases[0]; + + $this->assertInstanceOf('Recurly_ExternalPaymentPhase', $external_payment_phase); + $this->assertEquals($external_payment_phase->id, 'sd28t3zdm59r'); + $this->assertInstanceOf('DateTime', $external_payment_phase->started_at); + $this->assertInstanceOf('DateTime', $external_payment_phase->ends_at); + $this->assertEquals($external_payment_phase->starting_billing_period_index, '1'); + $this->assertEquals($external_payment_phase->ending_billing_period_index, '4'); + $this->assertEquals($external_payment_phase->period_count, '4'); + $this->assertEquals($external_payment_phase->period_length, '4'); + $this->assertEquals($external_payment_phase->amount, '0.00'); + $this->assertEquals($external_payment_phase->currency, 'USD'); + $this->assertInstanceOf('DateTime', $external_payment_phase->created_at); + $this->assertInstanceOf('DateTime', $external_payment_phase->updated_at); + } +} diff --git a/Tests/Recurly/ExternalPaymentPhase_Test.php b/Tests/Recurly/ExternalPaymentPhase_Test.php new file mode 100644 index 00000000..6f8edd76 --- /dev/null +++ b/Tests/Recurly/ExternalPaymentPhase_Test.php @@ -0,0 +1,44 @@ +client->addResponse('GET', '/external_payment_phases/sd28t3zdm59r', 'external_payment_phases/show-200.xml'); + + $external_payment_phase = Recurly_ExternalPaymentPhase::get('sd28t3zdm59r', $this->client); + $this->assertInstanceOf('Recurly_ExternalPaymentPhase', $external_payment_phase); + $this->assertEquals($external_payment_phase->id, 'sd28t3zdm59r'); + $this->assertInstanceOf('DateTime', $external_payment_phase->started_at); + $this->assertInstanceOf('DateTime', $external_payment_phase->ends_at); + $this->assertEquals($external_payment_phase->starting_billing_period_index, '1'); + $this->assertEquals($external_payment_phase->ending_billing_period_index, '4'); + $this->assertEquals($external_payment_phase->period_count, '4'); + $this->assertEquals($external_payment_phase->period_length, '4'); + $this->assertEquals($external_payment_phase->amount, '0.00'); + $this->assertEquals($external_payment_phase->currency, 'USD'); + $this->assertInstanceOf('DateTime', $external_payment_phase->created_at); + $this->assertInstanceOf('DateTime', $external_payment_phase->updated_at); + } + + public function testGetPaymentPhaseByExternalSubscription() { + $this->client->addResponse('GET', '/external_subscriptions/swifdu8c9om9/external_payment_phases/sd28t3zdm59r', 'external_payment_phases/show-200.xml'); + + $external_subscription = new Recurly_ExternalSubscription(); + $external_subscription->uuid = 'swifdu8c9om9'; + + $external_payment_phase = $external_subscription->getExternalPaymentPhase('sd28t3zdm59r', $this->client); + $this->assertInstanceOf('Recurly_ExternalPaymentPhase', $external_payment_phase); + $this->assertEquals($external_payment_phase->id, 'sd28t3zdm59r'); + $this->assertInstanceOf('DateTime', $external_payment_phase->started_at); + $this->assertInstanceOf('DateTime', $external_payment_phase->ends_at); + $this->assertEquals($external_payment_phase->starting_billing_period_index, '1'); + $this->assertEquals($external_payment_phase->ending_billing_period_index, '4'); + $this->assertEquals($external_payment_phase->period_count, '4'); + $this->assertEquals($external_payment_phase->period_length, '4'); + $this->assertEquals($external_payment_phase->amount, '0.00'); + $this->assertEquals($external_payment_phase->currency, 'USD'); + $this->assertInstanceOf('DateTime', $external_payment_phase->created_at); + $this->assertInstanceOf('DateTime', $external_payment_phase->updated_at); + } +} diff --git a/Tests/Recurly/ExternalSubscription_List_Test.php b/Tests/Recurly/ExternalSubscription_List_Test.php index a0da3213..b5f46a8d 100644 --- a/Tests/Recurly/ExternalSubscription_List_Test.php +++ b/Tests/Recurly/ExternalSubscription_List_Test.php @@ -15,6 +15,8 @@ public function testGetAll() { $external_subscription = $external_subscriptions->current(); $this->assertInstanceOf('Recurly_ExternalSubscription', $external_subscription); $this->assertInstanceOf('Recurly_Stub', $external_subscription->account); + $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); diff --git a/Tests/Recurly/ExternalSubscription_Test.php b/Tests/Recurly/ExternalSubscription_Test.php index de78d7d0..d9e10da6 100644 --- a/Tests/Recurly/ExternalSubscription_Test.php +++ b/Tests/Recurly/ExternalSubscription_Test.php @@ -10,6 +10,8 @@ public function testGetSubscription() { $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); diff --git a/Tests/fixtures/external_invoices/index-200.xml b/Tests/fixtures/external_invoices/index-200.xml index 9d9e2f2f..6db8e906 100644 --- a/Tests/fixtures/external_invoices/index-200.xml +++ b/Tests/fixtures/external_invoices/index-200.xml @@ -6,6 +6,7 @@ Content-Type: application/xml; charset=utf-8 + external-id paid USD @@ -36,6 +37,7 @@ Content-Type: application/xml; charset=utf-8 + external-id paid USD diff --git a/Tests/fixtures/external_invoices/show-200.xml b/Tests/fixtures/external_invoices/show-200.xml index 780d3ad4..8dadab35 100644 --- a/Tests/fixtures/external_invoices/show-200.xml +++ b/Tests/fixtures/external_invoices/show-200.xml @@ -5,6 +5,7 @@ Content-Type: application/xml; charset=utf-8 + external-id paid USD diff --git a/Tests/fixtures/external_payment_phases/index-200.xml b/Tests/fixtures/external_payment_phases/index-200.xml new file mode 100644 index 00000000..980e9464 --- /dev/null +++ b/Tests/fixtures/external_payment_phases/index-200.xml @@ -0,0 +1,21 @@ +HTTP/1.1 200 OK +Content-Type: application/xml; charset=utf-8 + + + + + sk0bmpw0wbby + 2023-03-14T19:55:07Z + 2023-04-14T19:55:07Z + 1 + 4 + + + 1 + 2 MONTHS + 0.00 + USD + 2023-03-14T19:55:07Z + 2023-04-14T19:55:07Z + + diff --git a/Tests/fixtures/external_payment_phases/show-200.xml b/Tests/fixtures/external_payment_phases/show-200.xml new file mode 100644 index 00000000..fc67d314 --- /dev/null +++ b/Tests/fixtures/external_payment_phases/show-200.xml @@ -0,0 +1,19 @@ +HTTP/1.1 200 OK +Content-Type: application/xml; charset=utf-8 + + + + sk0bmpw0wbby + 2023-03-14T19:55:07Z + 2023-04-14T19:55:07Z + + 4 + + + 1 + 2 MONTHS + 0.00 + USD + 2023-03-14T19:55:07Z + 2023-04-14T19:55:07Z + diff --git a/Tests/fixtures/external_subscriptions/index-200.xml b/Tests/fixtures/external_subscriptions/index-200.xml index d5b0e00c..554369e9 100644 --- a/Tests/fixtures/external_subscriptions/index-200.xml +++ b/Tests/fixtures/external_subscriptions/index-200.xml @@ -5,6 +5,8 @@ Content-Type: application/xml; charset=utf-8 + + rauqpcdmxc4a 1234 @@ -29,6 +31,8 @@ Content-Type: application/xml; charset=utf-8 + + rauqpcdmxc4b 5678 diff --git a/Tests/fixtures/external_subscriptions/show-200.xml b/Tests/fixtures/external_subscriptions/show-200.xml index 51b8eda2..559c08e0 100644 --- a/Tests/fixtures/external_subscriptions/show-200.xml +++ b/Tests/fixtures/external_subscriptions/show-200.xml @@ -4,6 +4,8 @@ Content-Type: application/xml; charset=utf-8 + + rauqpcdmxc4a 1234 diff --git a/lib/recurly.php b/lib/recurly.php index 2653a97d..0831a10f 100644 --- a/lib/recurly.php +++ b/lib/recurly.php @@ -59,6 +59,7 @@ require_once(__DIR__ . '/recurly/external_product.php'); require_once(__DIR__ . '/recurly/external_product_list.php'); require_once(__DIR__ . '/recurly/external_product_reference.php'); +require_once(__DIR__ . '/recurly/external_payment_phase.php'); require_once(__DIR__ . '/recurly/external_subscription.php'); require_once(__DIR__ . '/recurly/external_subscription_list.php'); require_once(__DIR__ . '/recurly/invoice.php'); diff --git a/lib/recurly/client.php b/lib/recurly/client.php index 2018a804..faad8aba 100644 --- a/lib/recurly/client.php +++ b/lib/recurly/client.php @@ -89,6 +89,7 @@ class Recurly_Client const PATH_EXTERNAL_SUBSCRIPTIONS = 'external_subscriptions'; const PATH_EXTERNAL_PRODUCTS = 'external_products'; const PATH_EXTERNAL_PRODUCT_REFERENCES = 'external_product_references'; + const PATH_EXTERNAL_PAYMENT_PHASES = 'external_payment_phases'; const PATH_EXTERNAL_INVOICES = 'external_invoices'; const PATH_EXTERNAL_ACCOUNTS = 'external_accounts'; const PATH_BUSINESS_ENTITIES = 'business_entities'; diff --git a/lib/recurly/external_invoice.php b/lib/recurly/external_invoice.php index b7dbd535..6f97558f 100644 --- a/lib/recurly/external_invoice.php +++ b/lib/recurly/external_invoice.php @@ -3,6 +3,7 @@ * class Recurly_ExternalInvoice * @property Recurly_Stub $account * @property Recurly_Stub $external_subscription + * @property Recurly_ExternalPaymentPhase $external_payment_phase * @property Recurly_ExternalCharge[] $line_items * @property string $external_id * @property boolean $state diff --git a/lib/recurly/external_payment_phase.php b/lib/recurly/external_payment_phase.php new file mode 100644 index 00000000..77a93f28 --- /dev/null +++ b/lib/recurly/external_payment_phase.php @@ -0,0 +1,37 @@ +isEmbedded($node, 'external_payment_phases')) { + $external_payment_phase_node = $node->appendChild($doc->createElement($this->getNodeName())); + parent::populateXmlDoc($doc, $external_payment_phase_node, $obj, $nested); + } else { + parent::populateXmlDoc($doc, $node, $obj, $nested); + } + } + + protected function getNodeName() { + return 'external_payment_phase'; + } + + + protected function getWriteableAttributes() { + return array(); + } +} diff --git a/lib/recurly/external_subscription.php b/lib/recurly/external_subscription.php index 06602b8e..fc9d8306 100644 --- a/lib/recurly/external_subscription.php +++ b/lib/recurly/external_subscription.php @@ -3,6 +3,7 @@ * class Recurly_ExternalSubscription * @property Recurly_Stub $account * @property Recurly_ExternalProductReference $external_product_reference + * @property Recurly_ExternalPaymentPhase[] $external_payment_phases * @property DateTime $last_purchased * @property boolean $auto_renew * @property boolean $in_grace_period @@ -30,6 +31,14 @@ public static function get($uuid, $client = null) { return Recurly_Base::_get(Recurly_ExternalSubscription::uriForExternalSubscription($uuid), $client); } + public function listExternalPaymentPhases($client = null) { + return Recurly_Base::_get($this->uriForExternalPaymentPhase(), $client); + } + + public function getExternalPaymentPhase($external_payment_phase_uuid, $client = null) { + return Recurly_Base::_get($this->uriForExternalPaymentPhase() . '/' . $external_payment_phase_uuid, $client); + } + protected static function uriForExternalSubscription($uuid) { return self::_safeUri(Recurly_Client::PATH_EXTERNAL_SUBSCRIPTIONS, $uuid); } diff --git a/lib/recurly/util/xml_tools.php b/lib/recurly/util/xml_tools.php index 857a39fa..6bb7e6e2 100644 --- a/lib/recurly/util/xml_tools.php +++ b/lib/recurly/util/xml_tools.php @@ -64,6 +64,8 @@ class XmlTools 'external_products' => 'Recurly_ExternalProductList', 'external_product_reference' => 'Recurly_ExternalProductReference', 'external_product_references' => 'array', + 'external_payment_phase' => 'Recurly_ExternalPaymentPhase', + 'external_payment_phases' => 'array', 'external_subscription' => 'Recurly_ExternalSubscription', 'external_subscriptions' => 'Recurly_ExternalSubscriptionList', 'fraud' => 'Recurly_FraudInfo',