Skip to content

Commit

Permalink
API v2.11 Changes
Browse files Browse the repository at this point in the history
* Add preferred_locale support on Account.
* Add pause and resume support on Subscription.
* Add multi shipping address support in Purchase.
  • Loading branch information
bhelx committed Apr 3, 2018
1 parent ef41ec4 commit 7c27b8e
Show file tree
Hide file tree
Showing 13 changed files with 119 additions and 10 deletions.
5 changes: 4 additions & 1 deletion Tests/Recurly/Account_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public function testGetAccount() {
$this->assertEquals($account->entity_use_code, 'I');
$this->assertEquals($account->vat_location_valid, true);
$this->assertEquals($account->cc_emails, 'cheryl.hines@example.com,richard.lewis@example.com');
$this->assertEquals($account->has_paused_subscription, false);
$this->assertEquals($account->preferred_locale, 'en-US');
}

public function testCloseAccount() {
Expand Down Expand Up @@ -90,6 +92,7 @@ public function testXml() {
$account->address->address1 = "123 Main St.";
$account->tax_exempt = false;
$account->entity_use_code = 'I';
$account->preferred_locale = 'en-US';

// work shipping address
$shad1 = new Recurly_ShippingAddress();
Expand Down Expand Up @@ -121,7 +124,7 @@ public function testXml() {
$account->shipping_addresses = array($shad1, $shad2);

$this->assertEquals(
"<?xml version=\"1.0\"?>\n<account><account_code>act123</account_code><first_name>Verena</first_name><address><address1>123 Main St.</address1></address><tax_exempt>false</tax_exempt><entity_use_code>I</entity_use_code><shipping_addresses><shipping_address><address1>123 Main St.</address1><city>San Francisco</city><state>CA</state><zip>94110</zip><country>US</country><phone>555-555-5555</phone><email>verena@example.com</email><nickname>Work</nickname><first_name>Verena</first_name><last_name>Example</last_name><company>Recurly Inc.</company></shipping_address><shipping_address><address1>123 Dolores St.</address1><city>San Francisco</city><state>CA</state><zip>94110</zip><country>US</country><phone>555-555-5555</phone><email>verena@example.com</email><nickname>Home</nickname><first_name>Verena</first_name><last_name>Example</last_name></shipping_address></shipping_addresses></account>\n",
"<?xml version=\"1.0\"?>\n<account><account_code>act123</account_code><first_name>Verena</first_name><address><address1>123 Main St.</address1></address><tax_exempt>false</tax_exempt><entity_use_code>I</entity_use_code><shipping_addresses><shipping_address><address1>123 Main St.</address1><city>San Francisco</city><state>CA</state><zip>94110</zip><country>US</country><phone>555-555-5555</phone><email>verena@example.com</email><nickname>Work</nickname><first_name>Verena</first_name><last_name>Example</last_name><company>Recurly Inc.</company></shipping_address><shipping_address><address1>123 Dolores St.</address1><city>San Francisco</city><state>CA</state><zip>94110</zip><country>US</country><phone>555-555-5555</phone><email>verena@example.com</email><nickname>Home</nickname><first_name>Verena</first_name><last_name>Example</last_name></shipping_address></shipping_addresses><preferred_locale>en-US</preferred_locale></account>\n",
$account->xml()
);
}
Expand Down
16 changes: 15 additions & 1 deletion Tests/Recurly/Adjustment_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,25 @@ public function testXml() {
$charge->tax_code = 'fake-tax-code';
$charge->origin = 'external_gift_card';
$charge->product_code = 'abc123';
$charge->shipping_address_id = 123456789;

$charge->shipping_address = new Recurly_ShippingAddress();
$charge->shipping_address->nickname = "Work";
$charge->shipping_address->first_name = "Verena";
$charge->shipping_address->last_name = "Example";
$charge->shipping_address->company = "Recurly Inc.";
$charge->shipping_address->phone = "555-555-5555";
$charge->shipping_address->email = "verena@example.com";
$charge->shipping_address->address1 = "123 Main St.";
$charge->shipping_address->city = "San Francisco";
$charge->shipping_address->state = "CA";
$charge->shipping_address->zip = "94110";
$charge->shipping_address->country = "US";

// This deprecated parameter should be ignored:
$charge->taxable = 0;

$expected = "<?xml version=\"1.0\"?>\n<adjustment><currency>USD</currency><unit_amount_in_cents>5000</unit_amount_in_cents><quantity>1</quantity><description>Charge for extra bandwidth</description><accounting_code>bandwidth</accounting_code><tax_exempt>false</tax_exempt><tax_code>fake-tax-code</tax_code><origin>external_gift_card</origin><product_code>abc123</product_code></adjustment>\n";
$expected = "<?xml version=\"1.0\"?>\n<adjustment><currency>USD</currency><unit_amount_in_cents>5000</unit_amount_in_cents><quantity>1</quantity><description>Charge for extra bandwidth</description><accounting_code>bandwidth</accounting_code><tax_exempt>false</tax_exempt><tax_code>fake-tax-code</tax_code><origin>external_gift_card</origin><product_code>abc123</product_code><shipping_address><address1>123 Main St.</address1><city>San Francisco</city><state>CA</state><zip>94110</zip><country>US</country><phone>555-555-5555</phone><email>verena@example.com</email><nickname>Work</nickname><first_name>Verena</first_name><last_name>Example</last_name><company>Recurly Inc.</company></shipping_address><shipping_address_id>123456789</shipping_address_id></adjustment>\n";
$this->assertEquals($expected, $charge->xml());
}
}
14 changes: 13 additions & 1 deletion Tests/Recurly/Purchase_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ public function mockPurchase() {
$purchase->account->billing_info = new Recurly_BillingInfo();
$purchase->account->billing_info->token_id = '7z6furn4jvb9';

$shipping_address = new Recurly_ShippingAddress();
$shipping_address->first_name = 'Dolores';
$shipping_address->last_name = 'Du Monde';
$shipping_address->address1 = '400 Dolores St';
$shipping_address->city = 'San Francisco';
$shipping_address->state = 'CA';
$shipping_address->country = 'US';
$shipping_address->zip = '94110';
$shipping_address->nickname = 'Home';
$purchase->account->shipping_addresses = array($shipping_address);

$adjustment = new Recurly_Adjustment();
$adjustment->product_code = "abcd123";
$adjustment->unit_amount_in_cents = 1000;
Expand All @@ -45,7 +56,7 @@ public function testXml() {
$purchase = $this->mockPurchase();

$this->assertEquals(
"<?xml version=\"1.0\"?>\n<purchase><account><account_code>aba9209a-aa61-4790-8e61-0a2692435fee</account_code><billing_info><token_id>7z6furn4jvb9</token_id></billing_info><address><address1>123 Main St.</address1><city>San Francisco</city><state>CA</state><zip>94110</zip><country>US</country><phone>555-555-5555</phone></address></account><adjustments><adjustment><currency>USD</currency><unit_amount_in_cents>1000</unit_amount_in_cents><quantity>1</quantity><revenue_schedule_type>at_invoice</revenue_schedule_type><product_code>abcd123</product_code></adjustment></adjustments><collection_method>automatic</collection_method><currency>USD</currency><customer_notes>Customer Notes</customer_notes><terms_and_conditions>Terms and Conditions</terms_and_conditions><vat_reverse_charge_notes>VAT Reverse Charge Notes</vat_reverse_charge_notes></purchase>\n",
"<?xml version=\"1.0\"?>\n<purchase><account><account_code>aba9209a-aa61-4790-8e61-0a2692435fee</account_code><billing_info><token_id>7z6furn4jvb9</token_id></billing_info><address><address1>123 Main St.</address1><city>San Francisco</city><state>CA</state><zip>94110</zip><country>US</country><phone>555-555-5555</phone></address><shipping_addresses><shipping_address><address1>400 Dolores St</address1><city>San Francisco</city><state>CA</state><zip>94110</zip><country>US</country><nickname>Home</nickname><first_name>Dolores</first_name><last_name>Du Monde</last_name></shipping_address></shipping_addresses></account><adjustments><adjustment><currency>USD</currency><unit_amount_in_cents>1000</unit_amount_in_cents><quantity>1</quantity><revenue_schedule_type>at_invoice</revenue_schedule_type><product_code>abcd123</product_code></adjustment></adjustments><collection_method>automatic</collection_method><currency>USD</currency><customer_notes>Customer Notes</customer_notes><terms_and_conditions>Terms and Conditions</terms_and_conditions><vat_reverse_charge_notes>VAT Reverse Charge Notes</vat_reverse_charge_notes></purchase>\n",
$purchase->xml()
);
}
Expand All @@ -57,6 +68,7 @@ public function testInvoicePurchase() {
$this->assertInstanceOf('Recurly_InvoiceCollection', $collection);
$this->assertInstanceOf('Recurly_Invoice', $collection->charge_invoice);
$this->assertEquals('3d8648fcf2be67ed304ff242d6bbb9d4', $collection->charge_invoice->uuid);
$this->assertInstanceOf('Recurly_ShippingAddress', $collection->charge_invoice->line_items[0]->shipping_address);
}

public function testPreviewPurchase() {
Expand Down
16 changes: 16 additions & 0 deletions Tests/Recurly/Subscription_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,4 +259,20 @@ public function testGetSubscriptionRedemptions() {
$this->assertInstanceOf('Recurly_CouponRedemption', $r);
}
}

public function testPauseSubscription() {
$this->client->addResponse('GET', '/subscriptions/012345678901234567890123456789ab', 'subscriptions/show-200.xml');
$this->client->addResponse('PUT', 'https://api.recurly.com/v2/subscriptions/012345678901234567890123456789ab/pause', 'subscriptions/show-200.xml');
$subscription = Recurly_Subscription::get('012345678901234567890123456789ab', $this->client);
$subscription->pause(1);
$this->assertInstanceOf('DateTime', $subscription->paused_at);
$this->assertEquals($subscription->remaining_pause_cycles, 1);
}

public function testResumeSubscription() {
$this->client->addResponse('GET', '/subscriptions/012345678901234567890123456789ab', 'subscriptions/show-200.xml');
$this->client->addResponse('PUT', 'https://api.recurly.com/v2/subscriptions/012345678901234567890123456789ab/resume', 'subscriptions/show-200.xml');
$subscription = Recurly_Subscription::get('012345678901234567890123456789ab', $this->client);
$subscription->resume();
}
}
2 changes: 2 additions & 0 deletions Tests/fixtures/accounts/show-200.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Content-Type: application/xml; charset=utf-8
<has_future_subscription type="boolean">false</has_future_subscription>
<has_canceled_subscription type="boolean">false</has_canceled_subscription>
<has_past_due_invoice type="boolean">false</has_past_due_invoice>
<has_paused_subscription type="boolean">false</has_paused_subscription>
<preferred_locale>en-US</preferred_locale>
<address>
<address1>123 Main St.</address1>
<address2>APT #6</address2>
Expand Down
11 changes: 11 additions & 0 deletions Tests/fixtures/purchases/create-201.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ Location: https://api.recurly.com/v2/invoices/3704
<created_at type="datetime">2017-05-17T17:38:55Z</created_at>
<updated_at type="datetime">2017-05-17T17:38:55Z</updated_at>
<revenue_schedule_type>at_invoice</revenue_schedule_type>
<shipping_address>
<first_name>Dolores</first_name>
<last_name>Du Monde</last_name>
<address1>400 Dolores St</address1>
<address2 nil="nil"></address2>
<city>San Francisco</city>
<state>CA</state>
<zip>94110</zip>
<country>US</country>
<nickname>Home</nickname>
</shipping_address>
</adjustment>
</line_items>
<transactions type="array">
Expand Down
2 changes: 2 additions & 0 deletions Tests/fixtures/subscriptions/show-200.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ Content-Type: application/xml; charset=utf-8
<started_with_gift type="boolean">false</started_with_gift>
<no_billing_info_reason>plan_free_trial</no_billing_info_reason>
<converted_at nil="nil"></converted_at>
<remaining_pause_cycles type="integer">1</remaining_pause_cycles>>
<paused_at type="datetime">2020-01-01T01:00:00Z</paused_at>
<subscription_add_ons type="array">
<subscription_add_on>
<add_on_type>usage</add_on_type>
Expand Down
10 changes: 9 additions & 1 deletion lib/recurly/account.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
* @property Recurly_Address $address The nested address information of the account: address1, address2, city, state, zip, country, phone.
* @property string $accept_language The ISO 639-1 language code from the user's browser, indicating their preferred language and locale.
* @property string $hosted_login_token The unique token for automatically logging the account in to the hosted management pages. You may automatically log the user into their hosted management pages by directing the user to: https://:subdomain.recurly.com/account/:hosted_login_token.
* @property string $preferred_locale The locale for the emails
* @property string $has_live_subscription True if the account has at least one live subscription.
* @property string $has_active_subscription True if the account has at least one active subscription.
* @property string $has_future_subscription True if the account has at least one future subscription.
* @property string $has_canceled_subscription True if the account has at least one canceled subscription.
* @property string $has_paused_subscription True if the account has at least one paised subscription.
* @property string $has_past_due_invoice True if the account has at least one past due invoice.
* @property DateTime $created_at The date and time the account was created in Recurly.
* @property DateTime $updated_at The date and time the account or its billing info was last updated.
* @property DateTime $closed_at For closed accounts, the date and time it was closed.
Expand Down Expand Up @@ -95,7 +102,8 @@ protected function getWriteableAttributes() {
return array(
'account_code', 'username', 'first_name', 'last_name', 'vat_number',
'email', 'company_name', 'accept_language', 'billing_info', 'address',
'tax_exempt', 'entity_use_code', 'cc_emails', 'shipping_addresses'
'tax_exempt', 'entity_use_code', 'cc_emails', 'shipping_addresses',
'preferred_locale'
);
}
protected function getRequiredAttributes() {
Expand Down
5 changes: 4 additions & 1 deletion lib/recurly/adjustment.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
* @property string $tax_code Optional field for EU VAT merchants and Avalara AvaTax Pro merchants. If you are using Recurly's EU VAT feature, you can use values of unknown, physical, or digital. If you have your own AvaTax account configured, you can use Avalara tax codes to assign custom tax rules.
* @property string $product_code Merchant defined product code
* @property string $credit_reason_code Can be set if adjustment is a credit (unit_amount_in_cents < 0). Allowed values: [general, service, promotional, refund, gift_card, write_off]. Defaults to "general".
* @property Recurly_ShippingAddress $shipping_address The Recurly_ShippingAddress object associated with this adjustment.
* @property string $shipping_address_id The id of Recurly_ShippingAddress object associated with this adjustment.
* @property DateTime $start_date A timestamp associated with when the adjustment began.
* @property DateTime $end_date A timestamp associated with when the adjustment ended.
* @property DateTime $created_at A timestamp associated with when the adjustment was created.
Expand Down Expand Up @@ -101,7 +103,8 @@ protected function getWriteableAttributes() {
return array(
'currency', 'unit_amount_in_cents', 'quantity', 'description',
'accounting_code', 'tax_exempt', 'tax_code', 'start_date', 'end_date',
'revenue_schedule_type', 'origin', 'product_code', 'credit_reason_code'
'revenue_schedule_type', 'origin', 'product_code', 'credit_reason_code',
'shipping_address', 'shipping_address_id'
);
}
}
2 changes: 1 addition & 1 deletion lib/recurly/client.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Recurly_Client
/**
* API Version
*/
public static $apiVersion = '2.10';
public static $apiVersion = '2.11';

/**
* The path to your CA certs. Use only if needed (if you can't fix libcurl/php).
Expand Down
2 changes: 1 addition & 1 deletion lib/recurly/invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static function getInvoicePdf($invoiceNumber, $locale = null, $client = n
* @param string Unique account code
* @param array additional invoice attributes (see writeableAttributes)
* @return Recurly_InvoiceCollection collection of invoices on success
*/
**/
public static function invoicePendingCharges($accountCode, $attributes = array(), $client = null) {
$uri = Recurly_Client::PATH_ACCOUNTS . '/' . rawurlencode($accountCode) . Recurly_Client::PATH_INVOICES;
$invoice = new self();
Expand Down
3 changes: 2 additions & 1 deletion lib/recurly/purchase.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* @property string $customer_notes Optional notes field. This will default to the Customer Notes text specified on the Invoice Settings page in your Recurly admin. Custom notes made on an invoice for a one time charge will not carry over to subsequent invoices.
* @property string $terms_and_conditions Optional Terms and Conditions field. This will default to the Terms and Conditions text specified on the Invoice Settings page in your Recurly admin. Custom notes will stay with a subscription on all renewals.
* @property string $vat_reverse_charge_notes Optional VAT Reverse Charge Notes only appear if you have EU VAT enabled or are using your own Avalara AvaTax account and the customer is in the EU, has a VAT number, and is in a different country than your own. This will default to the VAT Reverse Charge Notes text specified on the Tax Settings page in your Recurly admin, unless custom notes were created with the original subscription. Custom notes will stay with a subscription on all renewals.
* @property integer $shipping_address_id Optional id of an existing ShippingAddress to be applied to all subscriptions and adjustments in purchase.
*/
class Recurly_Purchase extends Recurly_Resource
{
Expand Down Expand Up @@ -66,7 +67,7 @@ protected function getWriteableAttributes() {
return array(
'account', 'adjustments', 'collection_method', 'currency', 'po_number',
'net_terms', 'subscriptions', 'gift_card', 'coupon_codes', 'customer_notes',
'terms_and_conditions', 'vat_reverse_charge_notes'
'terms_and_conditions', 'vat_reverse_charge_notes', 'shipping_address_id'
);
}
}
Loading

0 comments on commit 7c27b8e

Please sign in to comment.