Skip to content

Commit

Permalink
add external payment phases
Browse files Browse the repository at this point in the history
  • Loading branch information
amandamfielding committed Nov 22, 2023
1 parent 4ba0feb commit bcfb8e8
Show file tree
Hide file tree
Showing 19 changed files with 184 additions and 1 deletion.
1 change: 1 addition & 0 deletions Tests/Recurly/ExternalInvoice_List_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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_Stub', $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');
Expand Down
2 changes: 2 additions & 0 deletions Tests/Recurly/ExternalInvoice_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
29 changes: 29 additions & 0 deletions Tests/Recurly/ExternalPaymentPhase_List_Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php


class Recurly_ExternalPaymentPhaseListTest extends Recurly_TestCase
{

public function testGetAll() {
$url = '/external_subscriptions/swifdu8c9om9/external_payment_phases?';
$this->client->addResponse('GET', $url, 'external_payment_phases/index-200.xml');

$external_payment_phases = Recurly_ExternalPaymentPhaseList::get('swifdu8c9om9', array(), $this->client);
$this->assertInstanceOf('Recurly_ExternalPaymentPhaseList', $external_payment_phases);
$this->assertEquals($url, $external_payment_phases->getHref());

$external_payment_phase = $external_payment_phases->current();
$this->assertInstanceOf('Recurly_ExternalPaymentPhase', $external_payment_phase);
$this->assertEquals($external_payment_phase->id, 'sk0bmpw0wbby');
$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, '1');
$this->assertEquals($external_payment_phase->period_length, '2 MONTHS');
$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);
}
}
23 changes: 23 additions & 0 deletions Tests/Recurly/ExternalPaymentPhase_Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php


class Recurly_ExternalPaymentPhaseTest extends Recurly_TestCase
{
public function testGetPaymentPhase() {
$this->client->addResponse('GET', '/external_payment_phases/sk0bmpw0wbby', 'external_payment_phases/show-200.xml');

$external_payment_phase = Recurly_ExternalPaymentPhase::get('sk0bmpw0wbby', $this->client);
$this->assertInstanceOf('Recurly_ExternalPaymentPhase', $external_payment_phase);
$this->assertEquals($external_payment_phase->id, 'sk0bmpw0wbby');
$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, '1');
$this->assertEquals($external_payment_phase->period_length, '2 MONTHS');
$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);
}
}
2 changes: 2 additions & 0 deletions Tests/Recurly/ExternalSubscription_List_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions Tests/Recurly/ExternalSubscription_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions Tests/fixtures/external_invoices/index-200.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Content-Type: application/xml; charset=utf-8
<external_invoice href="https://api.recurly.com/v2/external_invoices/sd28t3zdm59r">
<account href="https://api.recurly.com/v2/accounts/1"/>
<external_subscription href="https://api.recurly.com/v2/external_subscriptions/1"/>
<external_payment_phase href="https://api.recurly.com/v2/external_payment_phases/pexv3leeop4w"/>
<external_id>external-id</external_id>
<state>paid</state>
<currency>USD</currency>
Expand Down Expand Up @@ -36,6 +37,7 @@ Content-Type: application/xml; charset=utf-8
<external_invoice href="https://api.recurly.com/v2/external_invoices/sd28t3zdm59p">
<account href="https://api.recurly.com/v2/accounts/2"/>
<external_subscription href="https://api.recurly.com/v2/external_subscriptions/1"/>
<external_payment_phase href="https://api.recurly.com/v2/external_payment_phases/pexv3leeop4w"/>
<external_id>external-id</external_id>
<state>paid</state>
<currency>USD</currency>
Expand Down
1 change: 1 addition & 0 deletions Tests/fixtures/external_invoices/show-200.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Content-Type: application/xml; charset=utf-8
<external_invoice href="https://api.recurly.com/v2/external_invoices/sd28t3zdm59r">
<account href="https://api.recurly.com/v2/accounts/1"/>
<external_subscription href="https://api.recurly.com/v2/external_subscriptions/1"/>
<external_payment_phase href="https://api.recurly.com/v2/external_payment_phases/pexv3leeop4w"/>
<external_id>external-id</external_id>
<state>paid</state>
<currency>USD</currency>
Expand Down
21 changes: 21 additions & 0 deletions Tests/fixtures/external_payment_phases/index-200.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
HTTP/1.1 200 OK
Content-Type: application/xml; charset=utf-8

<?xml version="1.0" encoding="UTF-8"?>
<external_payment_phases type="array">
<external_payment_phase href="https://api.recurly.com/v2/external_payment_phases/sk0bmpw0wbby">
<id>sk0bmpw0wbby</id>
<started_at type="datetime">2023-03-14T19:55:07Z</started_at>
<ends_at type="datetime">2023-04-14T19:55:07Z</ends_at>
<starting_billing_period_index>1</starting_billing_period_index>
<ending_billing_period_index>4</ending_billing_period_index>
<offer_type></offer_type>
<offer_name></offer_name>
<period_count>1</period_count>
<period_length>2 MONTHS</period_length>
<amount>0.00</amount>
<currency>USD</currency>
<created_at type="datetime">2023-03-14T19:55:07Z</created_at>
<updated_at type="datetime">2023-04-14T19:55:07Z</updated_at>
</external_payment_phase>
</external_payment_phases>
19 changes: 19 additions & 0 deletions Tests/fixtures/external_payment_phases/show-200.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
HTTP/1.1 200 OK
Content-Type: application/xml; charset=utf-8

<?xml version="1.0" encoding="UTF-8"?>
<external_payment_phase href="https://api.recurly.com/v2/external_payment_phases/sk0bmpw0wbby">
<id>sk0bmpw0wbby</id>
<started_at type="datetime">2023-03-14T19:55:07Z</started_at>
<ends_at type="datetime">2023-04-14T19:55:07Z</ends_at>
<starting_billing_period_index>1</starting_billing_period_index>
<ending_billing_period_index>4</ending_billing_period_index>
<offer_type></offer_type>
<offer_name></offer_name>
<period_count>1</period_count>
<period_length>2 MONTHS</period_length>
<amount>0.00</amount>
<currency>USD</currency>
<created_at type="datetime">2023-03-14T19:55:07Z</created_at>
<updated_at type="datetime">2023-04-14T19:55:07Z</updated_at>
</external_payment_phase>
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 @@ -5,6 +5,8 @@ Content-Type: application/xml; charset=utf-8
<external_subscriptions type="array">
<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_payment_phases href="https://api.recurly.com/v2/external_subscriptions/rjx71rx8gs2m/external_payment_phases"/>
<external_product_reference>
<id>rauqpcdmxc4a</id>
<reference_code>1234</reference_code>
Expand All @@ -29,6 +31,8 @@ Content-Type: application/xml; charset=utf-8
</external_subscription>
<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_payment_phases href="https://api.recurly.com/v2/external_subscriptions/rbf29tck8hpo/external_payment_phases"/>
<external_product_reference>
<id>rauqpcdmxc4b</id>
<reference_code>5678</reference_code>
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 @@ -4,6 +4,8 @@ Content-Type: application/xml; charset=utf-8
<?xml version="1.0" encoding="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_payment_phases href="https://api.recurly.com/v2/external_subscriptions/rjx71rx8gs2m/external_payment_phases"/>
<external_product_reference>
<id>rauqpcdmxc4a</id>
<reference_code>1234</reference_code>
Expand Down
2 changes: 2 additions & 0 deletions lib/recurly.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
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_payment_phase_list.php');
require_once(__DIR__ . '/recurly/external_subscription.php');
require_once(__DIR__ . '/recurly/external_subscription_list.php');
require_once(__DIR__ . '/recurly/invoice.php');
Expand Down
1 change: 1 addition & 0 deletions lib/recurly/client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
1 change: 1 addition & 0 deletions lib/recurly/external_invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* class Recurly_ExternalInvoice
* @property Recurly_Stub $account
* @property Recurly_Stub $external_subscription
* @property Recurly_Stub $external_payment_phase
* @property Recurly_ExternalCharge[] $line_items
* @property string $external_id
* @property boolean $state
Expand Down
45 changes: 45 additions & 0 deletions lib/recurly/external_payment_phase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
/**
* class Recurly_ExternalPaymentPhase
* @property string $id
* @property DateTime $started_at
* @property DateTime $ends_at
* @property string $starting_billing_period_index
* @property string $ending_billing_period_index
* @property string $offer_type
* @property string $offer_name
* @property string $period_count
* @property string $period_length
* @property string $amount
* @property string $currency
* @property DateTime $created_at
* @property DateTime $updated_at
*/
class Recurly_ExternalPaymentPhase extends Recurly_Resource
{
public function populateXmlDoc(&$doc, &$node, &$obj, $nested = false) {
if ($this->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);
}
}

public static function get($uuid, $client = null) {
return Recurly_Base::_get(Recurly_ExternalPaymentPhase::uriForExternalPaymentPhase($uuid), $client);
}

protected static function uriForExternalPaymentPhase($uuid) {
return self::_safeUri(Recurly_Client::PATH_EXTERNAL_PAYMENT_PHASES, $uuid);
}

protected function getNodeName() {
return 'external_payment_phase';
}


protected function getWriteableAttributes() {
return array();
}
}
23 changes: 23 additions & 0 deletions lib/recurly/external_payment_phase_list.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

class Recurly_ExternalPaymentPhaseList extends Recurly_Pager
{
public static function get($uuid, $params = null, $client = null) {
$uri = self::_uriWithParams(self::_safeUri(Recurly_Client::PATH_EXTERNAL_SUBSCRIPTIONS, $uuid, Recurly_Client::PATH_EXTERNAL_PAYMENT_PHASES), $params);
return new self($uri, $client);
}

/**
* Performs a request with the `per_page` set to `n` and only returns
* the first `n` results in the response.
*/
public static function take($n, $params = null, $client = null) {
$params['per_page'] = $n;
$pager = self::get($params, $client);
return $pager->get_first_page();
}

protected function getNodeName() {
return 'external_payment_phases';
}
}
3 changes: 2 additions & 1 deletion lib/recurly/external_subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -29,7 +30,7 @@ class Recurly_ExternalSubscription extends Recurly_Resource
public static function get($uuid, $client = null) {
return Recurly_Base::_get(Recurly_ExternalSubscription::uriForExternalSubscription($uuid), $client);
}

protected static function uriForExternalSubscription($uuid) {
return self::_safeUri(Recurly_Client::PATH_EXTERNAL_SUBSCRIPTIONS, $uuid);
}
Expand Down
2 changes: 2 additions & 0 deletions lib/recurly/util/xml_tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => 'Recurly_ExternalPaymentPhaseList',
'external_subscription' => 'Recurly_ExternalSubscription',
'external_subscriptions' => 'Recurly_ExternalSubscriptionList',
'fraud' => 'Recurly_FraudInfo',
Expand Down

0 comments on commit bcfb8e8

Please sign in to comment.