Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 2.12.9 #442

Merged
merged 5 commits into from
Nov 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Recurly PHP Client Library CHANGELOG

## Version 2.12.9 (November 21, 2019)

This brings us up to API version 2.24. There are no breaking changes

* Add Item class [PR] (https://github.com/recurly/recurly-client-php/pull/441)

## Version 2.12.8 (October 22nd, 2019)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This got pulled in from v2 branch. We are moving forward releasing all code from master again.


* Add shipping address to Purchase [PR] (https://github.com/recurly/recurly-client-php/pull/435)
* Subscription timeframe changes [PR] (https://github.com/recurly/recurly-client-php/pull/419)

## Version 2.12.7 (September 20th, 2019)

* Fix issue with missing requires [PR](https://github.com/recurly/recurly-client-php/pull/434).
Expand Down
92 changes: 92 additions & 0 deletions Tests/Recurly/Item_Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php

class Recurly_ItemTest extends Recurly_TestCase
{
function defaultResponses() {
return array(
array('GET', '/items/plastic_gloves', 'items/show-200.xml'),
);
}

public function testConstructor() {
$client = new Recurly_Client;
$item = new Recurly_Item(null, $client);

$prop = new ReflectionProperty($item, '_client');
$prop->setAccessible(true);

$this->assertSame($client, $prop->getValue($item));
}

public function testGetItem() {
$item = Recurly_Item::get('plastic_gloves', $this->client);

$this->assertInstanceOf('Recurly_Item', $item);
$this->assertEquals('plastic_gloves', $item->item_code);
$this->assertEquals('Awesome Plastic Gloves', $item->name);
$this->assertEquals('Sleek Plastic', $item->description);
}

public function testNestedCustomFields() {
$item = Recurly_Item::get('plastic_gloves', $this->client);
$item->custom_fields[] = new Recurly_CustomField('size', 'small');

$this->assertEquals(
"<?xml version=\"1.0\"?>\n<item><custom_fields><custom_field><name>size</name><value>small</value></custom_field></custom_fields></item>\n",
$item->xml()
);
}

public function testDelete() {
$this->client->addResponse('DELETE', 'https://api.recurly.com/v2/items/plastic_gloves', 'items/destroy-204.xml');

$item = Recurly_Item::get('plastic_gloves', $this->client);
$item->delete();
}

public function testDeleteItem() {
$this->client->addResponse('DELETE', '/items/plastic_gloves', 'items/destroy-204.xml');

Recurly_Item::deleteItem('plastic_gloves', $this->client);
}

public function testReactivate() {
$this->client->addResponse('PUT', 'https://api.recurly.com/v2/items/plastic_gloves/reactivate', 'items/reactivate-200.xml');

$item = Recurly_Item::get('plastic_gloves', $this->client);
$item->reactivate();
$this->assertEquals('active', $item->state);
}

public function testReactivateItem() {
$this->client->addResponse('PUT', '/items/plastic_gloves/reactivate', 'items/reactivate-200.xml');

$item = Recurly_Item::reactivateItem('plastic_gloves', $this->client);
$this->assertInstanceOf('Recurly_Item', $item);
$this->assertEquals('active', $item->state);
}

public function testCreateXml() {
$item = new Recurly_Item();
$item->item_code = 'little_llama';
$item->name = 'Little Llama';
$item->description = 'A description about llamas';
$item->custom_fields[] = new Recurly_CustomField('size', 'small');

$this->assertEquals(
"<?xml version=\"1.0\"?>\n<item><item_code>little_llama</item_code><name>Little Llama</name><description>A description about llamas</description><custom_fields><custom_field><name>size</name><value>small</value></custom_field></custom_fields></item>\n",
$item->xml()
);
}

public function testUpdateXml() {
$item = Recurly_Item::get('plastic_gloves', $this->client);
$item->description = 'A new description about gloves.';

$this->assertEquals(
"<?xml version=\"1.0\"?>\n<item><description>A new description about gloves.</description></item>\n",
$item->xml()
);
}

}
2 changes: 2 additions & 0 deletions Tests/fixtures/items/destroy-204.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
HTTP/1.1 204 No Content

25 changes: 25 additions & 0 deletions Tests/fixtures/items/reactivate-200.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
HTTP/1.1 200 OK
Content-Type: application/xml; charset=utf-8
Location: https://api.recurly.com/v2/items/plastic_gloves.xml

<?xml version="1.0" encoding="UTF-8"?>
<item href="https://api.recurly.com/v2/items/plastic_gloves">
<item_code>plastic_gloves</item_code>
<name>Awesome Plastic Gloves</name>
<description>Sleek Plastic</description>
<external_sku>awesome-plastic-gloves</external_sku>
<accounting_code>1569273944</accounting_code>
<revenue_schedule_type>never</revenue_schedule_type>
<tax_exempt type="boolean">true</tax_exempt>
<tax_code nil="nil"/>
<state>active</state>
<custom_fields type="array">
<custom_field>
<name>color</name>
<value>blue</value>
</custom_field>
</custom_fields>
<created_at type="datetime">2019-09-23T21:25:45Z</created_at>
<updated_at type="datetime">2019-09-23T21:25:45Z</updated_at>
<deleted_at nil="nil"/>
</item>
24 changes: 24 additions & 0 deletions Tests/fixtures/items/show-200.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
HTTP/1.1 200 OK
Content-Type: application/xml; charset=utf-8

<?xml version="1.0" encoding="UTF-8"?>
<item href="https://api.recurly.com/v2/items/plastic_gloves">
<item_code>plastic_gloves</item_code>
<name>Awesome Plastic Gloves</name>
<description>Sleek Plastic</description>
<external_sku>awesome-plastic-gloves</external_sku>
<accounting_code>1569273944</accounting_code>
<revenue_schedule_type>never</revenue_schedule_type>
<tax_exempt type="boolean">true</tax_exempt>
<tax_code nil="nil"/>
<state>active</state>
<custom_fields type="array">
<custom_field>
<name>color</name>
<value>blue</value>
</custom_field>
</custom_fields>
<created_at type="datetime">2019-09-23T21:25:45Z</created_at>
<updated_at type="datetime">2019-09-23T21:25:45Z</updated_at>
<deleted_at nil="nil"/>
</item>
2 changes: 2 additions & 0 deletions lib/recurly.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
require_once(__DIR__ . '/recurly/invoice.php');
require_once(__DIR__ . '/recurly/invoice_collection.php');
require_once(__DIR__ . '/recurly/invoice_list.php');
require_once(__DIR__ . '/recurly/item.php');
require_once(__DIR__ . '/recurly/item_list.php');
require_once(__DIR__ . '/recurly/measured_unit.php');
require_once(__DIR__ . '/recurly/measured_unit_list.php');
require_once(__DIR__ . '/recurly/note.php');
Expand Down
3 changes: 2 additions & 1 deletion lib/recurly/adjustment.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* @property string $type The type of adjustment to return: charge or credit.
* @property Recurly_Stub $account The URL of the account for the specified adjustment.
* @property Recurly_Stub $invoice The URL of the invoice for the specified adjustment.
* @property Recurly_Stub $item The URL of the item for the specified adjustment.
* @property string $uuid The unique identifier of the adjustment.
* @property string $state The state of the adjustments to return: pending or invoiced.
* @property string $description Description of the adjustment for the adjustment. Max 255 characters.
Expand Down Expand Up @@ -104,7 +105,7 @@ protected function getWriteableAttributes() {
'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',
'shipping_address', 'shipping_address_id'
'shipping_address', 'shipping_address_id', 'item_code'
);
}
}
2 changes: 2 additions & 0 deletions lib/recurly/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ public function getLinks() {
'invoice' => 'Recurly_Invoice',
'invoices' => 'Recurly_InvoiceList',
'invoice_collection' => 'Recurly_InvoiceCollection',
'item' => 'Recurly_Item',
'items' => 'Recurly_ItemList',
'line_items' => 'array',
'measured_unit' => 'Recurly_MeasuredUnit',
'measured_units' => 'Recurly_MeasuredUnitList',
Expand Down
5 changes: 3 additions & 2 deletions lib/recurly/client.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Recurly_Client
/**
* API Version
*/
public static $apiVersion = '2.22';
public static $apiVersion = '2.24';

/**
* The path to your CA certs. Use only if needed (if you can't fix libcurl/php).
Expand Down Expand Up @@ -50,7 +50,7 @@ class Recurly_Client
private static $apiUrl = 'https://%s.recurly.com/v2';


const API_CLIENT_VERSION = '2.12.7';
const API_CLIENT_VERSION = '2.12.9';
const DEFAULT_ENCODING = 'UTF-8';

const GET = 'GET';
Expand All @@ -72,6 +72,7 @@ class Recurly_Client
const PATH_GIFT_CARDS = '/gift_cards';
const PATH_UNIQUE_COUPONS = '/unique_coupon_codes';
const PATH_INVOICES = '/invoices';
const PATH_ITEMS = '/items';
const PATH_NOTES = '/notes';
const PATH_PLANS = '/plans';
const PATH_SHIPPING_METHOD = '/shipping_methods';
Expand Down
77 changes: 77 additions & 0 deletions lib/recurly/item.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

/**
* Class Recurly Item
* @property string $item_code The unique identifer of the item.
* @property string $name The name of the item.
* @property string $description The description of the item.
* @property string $external_sku Stock keeping unit to link the item to other inventory.
* @property string $accounting_code Accounting code for invoice line items.
* @property string $revenue_schedule_type The revenue schedule type for the item.
* @property string $state The state of the item.
* @property Recurly_CustomFieldList $custom_fields Optional custom fields for the item.
*/

class Recurly_Item extends Recurly_Resource
{
public function __construct($href = null, $client = null) {
parent::__construct($href, $client);
$this->custom_fields = new Recurly_CustomFieldList();
}

/**
* @param $itemCode The item code
* @param Recurly_Client $client Optional client for the request, useful for mocking the client
* @return object
* @throws Recurly_Error
*/
public static function get($itemCode, $client = null) {
return Recurly_Base::_get(Recurly_item::uriForItem($itemCode), $client);
}

public function create() {
$this->_save(Recurly_Client::POST, Recurly_Client::PATH_ITEMS);
}

public function update() {
$this->_save(Recurly_Client::PUT, $this->uri());
}

public function delete() {
Recurly_Base::_delete($this->uri(), $this->_client);
}

public static function deleteItem($itemCode, $client = null) {
return Recurly_Base::_delete(Recurly_Item::uriForItem($itemCode), $client);
}

public function reactivate() {
$this->_save(Recurly_Client::PUT, $this->uri() . '/reactivate');
}

public static function reactivateItem($itemCode, $client = null) {
return Recurly_Base::_put(Recurly_Item::uriForItem($itemCode) . '/reactivate', $client);
}

protected function uri() {
if (!empty($this->_href))
return $this->getHref();
else
return Recurly_Item::uriForItem($this->item_code);
}

protected static function uriForItem($itemCode) {
return Recurly_Client::PATH_ITEMS . '/' . rawurlencode($itemCode);
}

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

protected function getWriteableAttributes() {
return array(
'item_code', 'name', 'description', 'external_sku',
'accounting_code', 'revenue', 'state', 'custom_fields'
);
}
}
13 changes: 13 additions & 0 deletions lib/recurly/item_list.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

class Recurly_ItemList extends Recurly_Pager
{
public static function get($params = null, $client = null) {
$uri = self::_uriWithParams(Recurly_Client::PATH_ITEMS, $params);
return new self($uri, $client);
}

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