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

Add revrec attributes to items and giftcards #798

Merged
merged 1 commit into from
Feb 22, 2024
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
31 changes: 31 additions & 0 deletions Tests/Recurly/GiftCard_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,37 @@ public function testGetGiftCard() {
$this->assertInstanceOf('Recurly_Stub', $giftCard->gifter_account);
$this->assertInstanceOf('Recurly_Delivery', $giftCard->delivery);
$this->assertEquals($giftCard->getHref(),'https://api.recurly.com/v2/gift_cards/1988596967980562362');
$this->assertEquals($giftCard->redemption_code,'AI4VOVO1RC74H9E2');
$this->assertEquals($giftCard->product_code,'gift_card');
$this->assertEquals($giftCard->unit_amount_in_cents,'2000');
$this->assertEquals($giftCard->currency,'USD');
$this->assertEquals($giftCard->balance_in_cents,'2000');
$this->assertInstanceOf('DateTime', $giftCard->created_at);
$this->assertInstanceOf('DateTime', $giftCard->updated_at);
$this->assertInstanceOf('DateTime', $giftCard->redeemed_at);
$this->assertInstanceOf('DateTime', $giftCard->delivered_at);
}

public function testGetGiftCardWithRevRec() {
$this->client->addResponse('GET', '/gift_cards/1988596967980562362', 'gift_cards/show-200-revrec.xml');
$giftCard = Recurly_GiftCard::get(1988596967980562362, $this->client);

$this->assertInstanceOf('Recurly_GiftCard', $giftCard);
$this->assertInstanceOf('Recurly_Stub', $giftCard->gifter_account);
$this->assertInstanceOf('Recurly_Delivery', $giftCard->delivery);
$this->assertEquals($giftCard->getHref(),'https://api.recurly.com/v2/gift_cards/1988596967980562362');
$this->assertEquals($giftCard->redemption_code,'AI4VOVO1RC74H9E2');
$this->assertEquals($giftCard->product_code,'gift_card');
$this->assertEquals($giftCard->unit_amount_in_cents,'2000');
$this->assertEquals($giftCard->currency,'USD');
$this->assertEquals($giftCard->balance_in_cents,'2000');
$this->assertEquals($giftCard->liability_gl_account_id,'t5ejtge1xw0x');
$this->assertEquals($giftCard->revenue_gl_account_id,'t5ejtgf1vxh1');
$this->assertEquals($giftCard->performance_obligation_id,'4');
$this->assertInstanceOf('DateTime', $giftCard->created_at);
$this->assertInstanceOf('DateTime', $giftCard->updated_at);
$this->assertInstanceOf('DateTime', $giftCard->redeemed_at);
$this->assertInstanceOf('DateTime', $giftCard->delivered_at);
}

public function testRedeemGiftCard() {
Expand Down
18 changes: 17 additions & 1 deletion Tests/Recurly/Item_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ public function testGetItem() {
$this->assertEquals('Sleek Plastic', $item->description);
}

public function testGetItemWithRevRec() {
$this->client->addResponse('GET', '/items/plastic_gloves', 'items/show-200-revrec.xml');
$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);
$this->assertEquals($item->liability_gl_account_id,'t5ejtge1xw0x');
$this->assertEquals($item->revenue_gl_account_id,'t5ejtgf1vxh1');
$this->assertEquals($item->performance_obligation_id,'5');
}

public function testNestedCustomFields() {
$item = Recurly_Item::get('plastic_gloves', $this->client);
$item->custom_fields[] = new Recurly_CustomField('size', 'small');
Expand Down Expand Up @@ -72,9 +85,12 @@ public function testCreateXml() {
$item->name = 'Little Llama';
$item->description = 'A description about llamas';
$item->custom_fields[] = new Recurly_CustomField('size', 'small');
$item->liability_gl_account_id = 't5ejtge1xw0x';
$item->revenue_gl_account_id = 't5ejtgf1vxh1';
$item->performance_obligation_id = '5';

$this->assertEquals(
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\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",
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\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><liability_gl_account_id>t5ejtge1xw0x</liability_gl_account_id><revenue_gl_account_id>t5ejtgf1vxh1</revenue_gl_account_id><performance_obligation_id>5</performance_obligation_id></item>\n",
$item->xml()
);
}
Expand Down
41 changes: 41 additions & 0 deletions Tests/fixtures/gift_cards/show-200-revrec.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
HTTP/1.1 200 OK
Content-Type: application/xml; charset=utf-8

<?xml version="1.0" encoding="UTF-8"?>
<gift_card href="https://api.recurly.com/v2/gift_cards/1988596967980562362">
<gifter_account href="https://api.recurly.com/v2/accounts/myaccount" />
<invoice href="https://api.recurly.com/v2/invoices/1000" />
<recipient_account href="https://api.recurly.com/v2/accounts/myaccount" />
<id type="integer">1988596967980562362</id>
<redemption_code>AI4VOVO1RC74H9E2</redemption_code>
<product_code>gift_card</product_code>
<unit_amount_in_cents type="integer">2000</unit_amount_in_cents>
<currency>USD</currency>
<balance_in_cents type="integer">2000</balance_in_cents>
<delivery>
<method>email</method>
<deliver_at nil="nil"></deliver_at>
<email_address>[email protected]</email_address>
<first_name>John</first_name>
<last_name>Smith</last_name>
<address>
<address1></address1>
<address2></address2>
<city></city>
<state></state>
<zip></zip>
<country></country>
<phone nil="nil"></phone>
</address>
<gifter_name>Sally</gifter_name>
<personal_message>Hi John, Happy Birthday! I hope you have a great day! Love, Sally</personal_message>
</delivery>
<liability_gl_account_id>t5ejtge1xw0x</liability_gl_account_id>
<revenue_gl_account_id>t5ejtgf1vxh1</revenue_gl_account_id>
<performance_obligation_id>4</performance_obligation_id>
<created_at type="datetime">2016-04-15T07:00:00Z</created_at>
<updated_at type="datetime">2016-12-27T07:00:00Z</updated_at>
<delivered_at type="datetime">2016-12-25T07:00:05Z</delivered_at>
<redeemed_at type="datetime">2016-12-27T07:00:00Z</redeemed_at>
<canceled_at nil="nil"></canceled_at>
</gift_card>
27 changes: 27 additions & 0 deletions Tests/fixtures/items/show-200-revrec.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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>
<liability_gl_account_id>t5ejtge1xw0x</liability_gl_account_id>
<revenue_gl_account_id>t5ejtgf1vxh1</revenue_gl_account_id>
<performance_obligation_id>5</performance_obligation_id>
<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>
3 changes: 3 additions & 0 deletions lib/recurly/gift_card.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
* @property string $currency The currency of the unit_amount_in_cents and balance_in_cents.
* @property string $product_code The product code or SKU of the gift card product.
* @property int $unit_amount_in_cents The amount of the gift card, which is the amount of the charge to the gifter_account and the amount of credit that is applied to the recipient_account upon successful redemption.
* @property string $liability_gl_account_id The ID of the liability general ledger account associated with the gift card product.
* @property string $revenue_gl_account_id The ID of the revenue general ledger account associated with the gift card product.
* @property string $performance_obligation_id The ID of the performance obligation associated with the gift card product.
* @property Recurly_Delivery $delivery Block of delivery information.
* @property DateTime $created_at The date and time the gift card was created in Recurly.
* @property DateTime $updated_at The date and time the gift card was last updated.
Expand Down
6 changes: 5 additions & 1 deletion lib/recurly/item.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
* @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 string $liability_gl_account_id The ID of the liability general ledger account associated with the item.
* @property string $revenue_gl_account_id The ID of the revenue general ledger account associated with the item.
* @property string $performance_obligation_id The ID of the performance obligation associated with the item.
* @property Recurly_CustomFieldList $custom_fields Optional custom fields for the item.
*/

Expand Down Expand Up @@ -71,7 +74,8 @@ protected function getNodeName() {
protected function getWriteableAttributes() {
return array(
'item_code', 'name', 'description', 'external_sku',
'accounting_code', 'revenue', 'state', 'custom_fields'
'accounting_code', 'revenue', 'state', 'custom_fields',
'liability_gl_account_id', 'revenue_gl_account_id', 'performance_obligation_id'
);
}
}
Loading