Skip to content

Commit

Permalink
Merge pull request #246 from recurly/api-2.3
Browse files Browse the repository at this point in the history
Changes for API 2.3
  • Loading branch information
bhelx committed Aug 1, 2016
2 parents 5572e6c + ddcf220 commit 0bf311d
Show file tree
Hide file tree
Showing 21 changed files with 157 additions and 39 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Recurly PHP Client Library CHANGELOG

## Version 2.6.0 (unreleased)

* Added support for `original_transaction` to `Recurly_Transaction` [#238](https://github.com/recurly/recurly-client-php/pull/238)
* Added `Recurly_AccountBalance` [#239](https://github.com/recurly/recurly-client-php/pull/239)
* Print warnings when using a deprecated version of the API. [#250](https://github.com/recurly/recurly-client-php/pull/250):
* Added support new pagination options [#249](https://github.com/recurly/recurly-client-php/pull/249):
- `sort` accepts `created_at` or `updated_at`, defaults to `created_at`.
- `order` accepts `desc` or `asc`, defaults to `desc`.
- `begin_time` and `end_time` accepts an ISO 8601 date or date and time.
* Changed `Recurly_AddonList::get()` and `Recurly_NoteList::get()` to add `$params` as the second parameter so sort, order and date filtering can be passed in [#249](https://github.com/recurly/recurly-client-php/pull/249)
* Added support for `revenue_schedule_type` to `Recurly_Addon`, `Recurly_Adjustment`, `Recurly_Plan`, `Recurly_Subscription` and `Recurly_SubscriptionAddOn` classes [#257](https://github.com/recurly/recurly-client-php/pull/257)

## Version 2.5.3 (July 5th, 2016)

* Added support for setting `free_trial_amount` and `free_trial_unit` to `Recurly_Coupon` [#224](https://github.com/recurly/recurly-client-php/pull/224)
Expand Down
23 changes: 23 additions & 0 deletions Tests/Recurly/AccountBalance_Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

class Recurly_AccountBalanceTest extends Recurly_TestCase
{
function defaultResponses() {
return array(
array('GET', '/accounts/abcdef1234567890/balance', 'balance/show-200.xml'),
);
}

public function testGet() {
$balance = Recurly_AccountBalance::get('abcdef1234567890', $this->client);

$this->assertInstanceOf('Recurly_AccountBalance', $balance);
$this->assertEquals($balance->getHref(), 'https://api.recurly.com/v2/accounts/abcdef1234567890/balance');
$this->assertInstanceOf('Recurly_Stub', $balance->account);
$this->assertEquals(true, $balance->past_due);

$this->assertInstanceOf('Recurly_CurrencyList', $balance->balance_in_cents);
$this->assertEquals(2910, $balance->balance_in_cents['USD']->amount_in_cents);
$this->assertEquals(-520, $balance->balance_in_cents['EUR']->amount_in_cents);
}
}
7 changes: 7 additions & 0 deletions Tests/Recurly/Client_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
class Recurly_ClientTest extends Recurly_TestCase
{

public function testDeprecationError() {
$this->client->addResponse('GET', '/accounts', 'client/deprecated-200.xml');

// This should print an error but not raise.
$accounts = Recurly_AccountList::get(null, $this->client)->count();
}

public function testUnauthorizedError() {
$this->client->addResponse('GET', '/accounts/abcdef1234567890', 'client/unauthorized-401.xml');

Expand Down
4 changes: 2 additions & 2 deletions Tests/Recurly/Note_List_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
class Recurly_NoteListTest extends Recurly_TestCase
{
public function testGetNotes() {
$this->client->addResponse('GET', '/accounts/abcdef1234567890/notes', 'notes/index-200.xml');
$this->client->addResponse('GET', '/accounts/abcdef1234567890/notes?', 'notes/index-200.xml');

$notes = Recurly_NoteList::get('abcdef1234567890', $this->client);
$notes = Recurly_NoteList::get('abcdef1234567890', array(), $this->client);
$this->assertInstanceOf('Recurly_NoteList', $notes);
$this->assertEquals($notes->count(), 2);

Expand Down
5 changes: 3 additions & 2 deletions Tests/Recurly/Pager_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ protected function getNodeName() {
return 'mocks';
}

public function _loadFrom($uri, $params = null) {
parent::_loadFrom($uri, $params);
// Overridden to make it public.
public function _loadFrom($uri) {
parent::_loadFrom($uri);
}
}
Recurly_Resource::$class_map['mocks'] = 'Mock_Pager';
Expand Down
14 changes: 13 additions & 1 deletion Tests/Recurly/Transaction_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,23 @@ public function testGetTransaction() {
$transaction = Recurly_Transaction::get('012345678901234567890123456789ab', $this->client);

$this->assertInstanceOf('Recurly_Transaction', $transaction);
$this->assertEquals($transaction->getHref(), 'https://api.recurly.com/v2/transactions/abcdef1234567890');

$this->assertInstanceOf('Recurly_Stub', $transaction->account);
$this->assertEquals($transaction->account->getHref(), 'https://api.recurly.com/v2/accounts/verena');

$this->assertInstanceOf('Recurly_Stub', $transaction->invoice);
$this->assertEquals($transaction->invoice->getHref(), 'https://api.recurly.com/v2/invoices/1012');

$this->assertInstanceOf('Recurly_Stub', $transaction->subscription);
$this->assertEquals($transaction->subscription->getHref(), 'https://api.recurly.com/v2/subscriptions/1234567890abcdef');

$this->assertInstanceOf('Recurly_Stub', $transaction->original_transaction);
$this->assertEquals($transaction->original_transaction->getHref(), 'https://api.recurly.com/v2/transactions/abcdef1000000000');

$this->assertEquals($transaction->action, 'refund');
$this->assertEquals($transaction->amount_in_cents, '30000');

$this->assertEquals($transaction->account->getHref(), 'https://api.recurly.com/v2/accounts/verena');
$this->assertEquals($transaction->ip_address, '127.0.0.1');

$this->assertInstanceOf('Recurly_FraudInfo', $transaction->fraud);
Expand Down
12 changes: 12 additions & 0 deletions Tests/fixtures/balance/show-200.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
HTTP/1.1 200 OK
Content-Type: application/xml; charset=utf-8

<?xml version="1.0" encoding="UTF-8"?>
<account_balance href="https://api.recurly.com/v2/accounts/abcdef1234567890/balance">
<account href="https://api.recurly.com/v2/accounts/abcdef1234567890"/>
<past_due type="boolean">true</past_due>
<balance_in_cents>
<USD type="integer">2910</USD>
<EUR type="integer">-520</EUR>
</balance_in_cents>
</account_balance>
21 changes: 21 additions & 0 deletions Tests/fixtures/client/deprecated-200.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
HTTP/1.1 200 OK
X-Api-Version: 1.999
Recurly-Deprecated: true
Recurly-Sunset-Date: 2014-01-01T00:00:00+00:00
Content-Language: en-US
X-RateLimit-Limit: 2000
X-RateLimit-Remaining: 1998
X-RateLimit-Reset: 1467912540
X-Records: 3
Link: <https://api.recurly.com/v2/accounts?order=asc&per_page=1>; rel="start", <https://api.recurly.com/v2/accounts?cursor=-1963376195782139893&order=asc&per_page=1>; rel="prev"
ETag: "d41d8cd98f00b204e9800998ecf8427e"
Content-Type: application/xml; charset=utf-8
Cache-Control: max-age=0, private, must-revalidate
X-Request-Id: 6a8c07775f9dac83402cea1a28752a55
X-Runtime: 0.048038
Connection: close
Transfer-Encoding: chunked

<?xml version="1.0" encoding="UTF-8"?>
<accounts type="array">
</accounts>
37 changes: 20 additions & 17 deletions Tests/fixtures/transactions/show-200.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ HTTP/1.1 200 OK
Content-Type: application/xml; charset=utf-8

<?xml version="1.0" encoding="UTF-8"?>
<transaction href="https://api.recurly.com/v2/transactions/abcdef1234567890">
<transaction href="https://api.recurly.com/v2/transactions/abcdef1234567890" type="credit_card">
<account href="https://api.recurly.com/v2/accounts/verena"/>
<invoice href="https://api.recurly.com/v2/invoices/abcdef1234567890"/>
<invoice href="https://api.recurly.com/v2/invoices/1012"/>
<subscription href="https://api.recurly.com/v2/subscriptions/1234567890abcdef"/>
<original_transaction href="https://api.recurly.com/v2/transactions/abcdef1000000000"/>
<uuid>abcdef1234567890</uuid>
<action>purchase</action>
<action>refund</action>
<amount_in_cents type="integer">30000</amount_in_cents>
<tax_in_cents type="integer">0</tax_in_cents>
<currency>USD</currency>
Expand All @@ -18,13 +19,14 @@ Content-Type: application/xml; charset=utf-8
<recurring type="boolean">false</recurring>
<test type="boolean">true</test>
<voidable type="boolean">true</voidable>
<refundable type="boolean">true</refundable>
<refundable type="boolean">false</refundable>
<ip_address>127.0.0.1</ip_address>
<cvv_result code="M">Match</cvv_result>
<avs_result code="D">Street address and postal code match.</avs_result>
<avs_result_street>Y</avs_result_street>
<avs_result_postal>Y</avs_result_postal>
<created_at type="datetime">2011-04-30T12:00:00Z</created_at>
<ip_address>127.0.0.1</ip_address>
<created_at type="datetime">2016-06-21T16:37:40Z</created_at>
<updated_at type="datetime">2016-06-21T16:37:40Z</updated_at>
<details>
<account>
<account_code>gob</account_code>
Expand All @@ -33,19 +35,19 @@ Content-Type: application/xml; charset=utf-8
<company nil="nil"></company>
<email>gobias@bluth-company.com</email>
<billing_info type="credit_card">
<first_name nil="nil"></first_name>
<last_name nil="nil"></last_name>
<address1 nil="nil"></address1>
<first_name>Larry</first_name>
<last_name>David</last_name>
<address1>123 Pretty Pretty Good St.</address1>
<address2 nil="nil"></address2>
<city nil="nil"></city>
<state nil="nil"></state>
<zip nil="nil"></zip>
<country nil="nil"></country>
<city>Los Angeles</city>
<state>CA</state>
<zip>90210</zip>
<country>US</country>
<phone nil="nil"></phone>
<vat_number nil="nil"></vat_number>
<cc_type>visa</cc_type>
<year type="integer">2011</year>
<month type="integer">12</month>
<vat_number>2000</vat_number>
<card_type>Visa</card_type>
<year type="integer">2016</year>
<month type="integer">6</month>
<first_six>411111</first_six>
<last_four>1111</last_four>
</billing_info>
Expand All @@ -55,4 +57,5 @@ Content-Type: application/xml; charset=utf-8
<score type="integer">99</score>
<decision>DECLINE</decision>
</fraud>
<a name="refund" href="https://api.recurly.com/v2/transactions/abcdef1234567890" method="delete"/>
</transaction>
21 changes: 21 additions & 0 deletions lib/recurly/account_balance.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

class Recurly_AccountBalance extends Recurly_Resource
{
public static function get($accountCode, $client = null) {
return Recurly_Base::_get(Recurly_Client::PATH_ACCOUNTS . '/' . rawurlencode($accountCode) . Recurly_Client::PATH_BALANCE, $client);
}

function __construct() {
parent::__construct();
$this->balance_in_cents = new Recurly_CurrencyList('balance_in_cents');
}

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

protected function getWriteableAttributes() {
return array();
}
}
2 changes: 1 addition & 1 deletion lib/recurly/addon.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static function init()
Recurly_Addon::$_writeableAttributes = array(
'add_on_code','name','display_quantity','default_quantity',
'unit_amount_in_cents','accounting_code','tax_code',
'measured_unit_id','usage_type','add_on_type'
'measured_unit_id','usage_type','add_on_type','revenue_schedule_type'
);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/recurly/addon_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

class Recurly_AddonList extends Recurly_Pager
{
public static function get($planCode, $client = null)
public static function get($planCode, $params = null, $client = null)
{
$uri = Recurly_Client::PATH_PLANS . '/' . rawurlencode($planCode) . Recurly_Client::PATH_ADDONS;
$uri = self::_uriWithParams(Recurly_Client::PATH_PLANS . '/' . rawurlencode($planCode) . Recurly_Client::PATH_ADDONS, $params);
return new self($uri, $client);
}

Expand Down
3 changes: 2 additions & 1 deletion lib/recurly/adjustment.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ public static function init()
{
Recurly_Adjustment::$_writeableAttributes = array(
'currency','unit_amount_in_cents','quantity','description',
'accounting_code','tax_exempt','tax_code','start_date','end_date'
'accounting_code','tax_exempt','tax_code','start_date','end_date',
'revenue_schedule_type',
);
}

Expand Down
4 changes: 3 additions & 1 deletion lib/recurly/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,14 @@ public function getLinks() {
static $class_map = array(
'account' => 'Recurly_Account',
'accounts' => 'Recurly_AccountList',
'account_balance' => 'Recurly_AccountBalance',
'address' => 'Recurly_Address',
'add_on' => 'Recurly_Addon',
'add_ons' => 'Recurly_AddonList',
'billing_info' => 'Recurly_BillingInfo',
'adjustment' => 'Recurly_Adjustment',
'adjustments' => 'Recurly_AdjustmentList',
'balance_in_cents' => 'Recurly_CurrencyList',
'billing_info' => 'Recurly_BillingInfo',
'coupon' => 'Recurly_Coupon',
'unique_coupon_codes' => 'Recurly_UniqueCouponCodeList',
'currency' => 'Recurly_Currency',
Expand Down
3 changes: 2 additions & 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.2';
public static $apiVersion = '2.3';

/**
* The path to your CA certs. Use only if needed (if you can't fix libcurl/php).
Expand Down Expand Up @@ -56,6 +56,7 @@ class Recurly_Client
const PATH_ACCOUNTS = '/accounts';
const PATH_ADDONS = '/add_ons';
const PATH_ADJUSTMENTS = '/adjustments';
const PATH_BALANCE = '/balance';
const PATH_BILLING_INFO = '/billing_info';
const PATH_COUPON = '/coupon';
const PATH_COUPON_REDEMPTION = '/redemption';
Expand Down
9 changes: 3 additions & 6 deletions lib/recurly/note_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@

class Recurly_NoteList extends Recurly_Pager
{
public static function get($accountCode, $client = null) {
return Recurly_Base::_get(Recurly_NoteList::uriForNotes($accountCode), $client);
}

protected static function uriForNotes($accountCode) {
return Recurly_Client::PATH_ACCOUNTS . '/' . rawurlencode($accountCode) . Recurly_Client::PATH_NOTES;
public static function get($accountCode, $params = null, $client = null) {
$uri = self::_uriWithParams(Recurly_Client::PATH_ACCOUNTS . '/' . rawurlencode($accountCode) . Recurly_Client::PATH_NOTES, $params);
return new self($uri, $client);
}

protected function getNodeName() {
Expand Down
5 changes: 2 additions & 3 deletions lib/recurly/pager.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,11 @@ public function valid() {
/**
* Load another page of results into this pager.
*/
protected function _loadFrom($uri, $params = null) {
protected function _loadFrom($uri) {
if (empty($uri)) {
return;
}

$uri = Recurly_Base::_uriWithParams($uri, $params);
$response = $this->_client->request(Recurly_Client::GET, $uri);
$response->assertValidResponse();

Expand All @@ -101,9 +100,9 @@ protected function _loadFrom($uri, $params = null) {
}

protected function _afterParseResponse($response, $uri) {
$this->_href = $uri;
$this->_loadRecordCount($response);
$this->_loadLinks($response);
$this->_href = isset($this->_links['start']) ? $this->_links['start'] : $uri;
}

protected static function _setState($params, $state) {
Expand Down
1 change: 1 addition & 0 deletions lib/recurly/plan.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public static function init()
'plan_interval_length','plan_interval_unit','trial_interval_length',
'trial_interval_unit','unit_amount_in_cents','setup_fee_in_cents',
'total_billing_cycles','accounting_code','setup_fee_accounting_code',
'revenue_schedule_type', 'setup_fee_revenue_schedule_type',
'tax_exempt','tax_code'
);
}
Expand Down
4 changes: 4 additions & 0 deletions lib/recurly/response.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public function assertSuccessResponse($object)

public function assertValidResponse()
{
if (!empty($this->headers['Recurly-Deprecated'])) {
error_log("WARNING: API version {$this->headers['X-Api-Version']} is deprecated and will only be available until {$this->headers['Recurly-Sunset-Date']}. Please upgrade the Recurly PHP client.");
}

// Successful response code
if ($this->statusCode >= 200 && $this->statusCode < 400)
return;
Expand Down
2 changes: 1 addition & 1 deletion lib/recurly/subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static function init()
'currency','starts_at','trial_ends_at','total_billing_cycles', 'first_renewal_date',
'timeframe', 'subscription_add_ons', 'net_terms', 'po_number', 'collection_method',
'cost_in_cents', 'remaining_billing_cycles', 'bulk', 'terms_and_conditions', 'customer_notes',
'vat_reverse_charge_notes', 'bank_account_authorized_at'
'vat_reverse_charge_notes', 'bank_account_authorized_at', 'revenue_schedule_type',
);
}

Expand Down
3 changes: 2 additions & 1 deletion lib/recurly/subscription_addon.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public static function init() {
'unit_amount_in_cents',
'add_on_type',
'usage_type',
'usage_percentage'
'usage_percentage',
'revenue_schedule_type',
);
}

Expand Down

0 comments on commit 0bf311d

Please sign in to comment.