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 Custom Fields on Adjustments #740

Merged
merged 3 commits into from
Jan 23, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 2 additions & 1 deletion Tests/Recurly/Purchase_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public function mockPurchase() {
$adjustment->currency = 'USD';
$adjustment->quantity = 1;
$adjustment->revenue_schedule_type = 'at_invoice';
$adjustment->custom_fields[] = new Recurly_CustomField('size', 'small');

$purchase->adjustments[] = $adjustment;

Expand All @@ -63,7 +64,7 @@ public function testXml() {
$purchase = $this->mockPurchase();

$this->assertEquals(
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\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><dunning_campaign_id>1234abcd</dunning_campaign_id></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><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><gateway_code>aBcD1234</gateway_code><transaction_type>moto</transaction_type></purchase>\n",
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\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><dunning_campaign_id>1234abcd</dunning_campaign_id></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><custom_fields><custom_field><name>size</name><value>small</value></custom_field></custom_fields></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><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><gateway_code>aBcD1234</gateway_code><transaction_type>moto</transaction_type></purchase>\n",
$purchase->xml()
);
}
Expand Down
6 changes: 6 additions & 0 deletions Tests/fixtures/adjustments/show-200.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ Content-Type: application/xml; charset=utf-8
<description>$12 Annual Subscription</description>
<accounting_code></accounting_code>
<product_code nil="nil"></product_code>
<custom_fields>
Copy link
Contributor

Choose a reason for hiding this comment

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

In some cases (it happens for ruby) when the element does not have the type=array then it is not parsed as an array, but as a single element. So I suggest to add the type to comply with the actual response:

Suggested change
<custom_fields>
<custom_fields type="array">

<custom_field>
<name>size</name>
<value>small</value>
</custom_field>
</custom_fields>
<origin>plan</origin>
<unit_amount_in_cents type="integer">1200</unit_amount_in_cents>
<quantity type="integer">1</quantity>
Expand Down
6 changes: 6 additions & 0 deletions Tests/fixtures/purchases/authorize-200.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ Location: https://api.recurly.com/v2/invoices
<created_at nil="nil"></created_at>
<updated_at nil="nil"></updated_at>
<revenue_schedule_type>at_invoice</revenue_schedule_type>
<custom_fields>
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as before

<custom_field>
<name>size</name>
<value>small</value>
</custom_field>
</custom_fields>
</adjustment>
</line_items>
<transactions type="array">
Expand Down
6 changes: 6 additions & 0 deletions Tests/fixtures/purchases/cancel-200.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ Location: https://api.recurly.com/v2/invoices
<created_at nil="nil"></created_at>
<updated_at nil="nil"></updated_at>
<revenue_schedule_type>at_invoice</revenue_schedule_type>
<custom_fields>
<custom_field>
<name>size</name>
<value>small</value>
</custom_field>
</custom_fields>
</adjustment>
</line_items>
<transactions type="array">
Expand Down
6 changes: 6 additions & 0 deletions Tests/fixtures/purchases/capture-200.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ Location: https://api.recurly.com/v2/invoices
<created_at nil="nil"></created_at>
<updated_at nil="nil"></updated_at>
<revenue_schedule_type>at_invoice</revenue_schedule_type>
<custom_fields>
<custom_field>
<name>size</name>
<value>small</value>
</custom_field>
</custom_fields>
</adjustment>
</line_items>
<transactions type="array">
Expand Down
6 changes: 6 additions & 0 deletions Tests/fixtures/purchases/create-201.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ Location: https://api.recurly.com/v2/invoices/3704
<country>US</country>
<nickname>Home</nickname>
</shipping_address>
<custom_fields>
<custom_field>
<name>size</name>
<value>small</value>
</custom_field>
</custom_fields>
</adjustment>
</line_items>
<transactions type="array">
Expand Down
6 changes: 6 additions & 0 deletions Tests/fixtures/purchases/pending-200.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ Location: https://api.recurly.com/v2/invoices
<created_at nil="nil"></created_at>
<updated_at nil="nil"></updated_at>
<revenue_schedule_type>at_invoice</revenue_schedule_type>
<custom_fields>
<custom_field>
<name>size</name>
<value>small</value>
</custom_field>
</custom_fields>
</adjustment>
</line_items>
<transactions type="array">
Expand Down
6 changes: 6 additions & 0 deletions Tests/fixtures/purchases/preview-200.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ Location: https://api.recurly.com/v2/invoices
<created_at nil="nil"></created_at>
<updated_at nil="nil"></updated_at>
<revenue_schedule_type>at_invoice</revenue_schedule_type>
<custom_fields>
<custom_field>
<name>size</name>
<value>small</value>
</custom_field>
</custom_fields>
</adjustment>
</line_items>
<transactions type="array">
Expand Down
8 changes: 7 additions & 1 deletion lib/recurly/adjustment.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,15 @@
* @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.
* @property Recurly_CustomFieldList $custom_fields Optional custom fields for the adjustment.
*/
class Recurly_Adjustment extends Recurly_Resource
{
public function __construct($href = null, $client = null) {
parent::__construct($href, $client);
$this->custom_fields = new Recurly_CustomFieldList();
}

public static function get($adjustment_uuid, $client = null) {
return Recurly_Base::_get(self::_safeUri(Recurly_Client::PATH_ADJUSTMENTS, $adjustment_uuid), $client);
}
Expand Down Expand Up @@ -122,7 +128,7 @@ protected function getWriteableAttributes() {
'currency', 'unit_amount_in_cents', 'quantity', 'quantity_decimal', 'description',
'accounting_code', 'tax_exempt', 'tax_inclusive', 'tax_code', 'start_date', 'end_date',
'revenue_schedule_type', 'origin', 'product_code', 'credit_reason_code',
'shipping_address', 'shipping_address_id', 'item_code', 'external_sku'
'shipping_address', 'shipping_address_id', 'item_code', 'external_sku', 'custom_fields'
);
}
}