diff --git a/recurly/__init__.py b/recurly/__init__.py
index d9e04bc9..74743b3e 100644
--- a/recurly/__init__.py
+++ b/recurly/__init__.py
@@ -927,9 +927,14 @@ class Adjustment(Resource):
'shipping_address',
'shipping_address_id',
'refundable_total_in_cents',
+ 'custom_fields',
)
xml_attribute_attributes = ('type',)
- _classes_for_nodename = {'tax_detail': TaxDetail, 'shipping_address': ShippingAddress}
+ _classes_for_nodename = {
+ 'tax_detail': TaxDetail,
+ 'shipping_address': ShippingAddress,
+ 'custom_field': CustomField,
+ }
# This can be removed when the `original_adjustment_uuid` is moved to a link
def __getattr__(self, name):
diff --git a/tests/README.md b/tests/README.md
index 01b114aa..a07a55ee 100644
--- a/tests/README.md
+++ b/tests/README.md
@@ -4,6 +4,10 @@ To run these tests in Python 2.7, use the `unittest` test runner:
$ python -m unittest discover -s tests
+To run a specific test, pass the name of the file and the test name prefixed with test class:
+
+ $ python tests/test_resources.py TestResources.test_purchase
+
Under Python 2.6 or earlier, install the `unittest2` distribution and use it
instead:
diff --git a/tests/fixtures/purchase-with-custom-fields-on-adjustments/authorized.xml b/tests/fixtures/purchase-with-custom-fields-on-adjustments/authorized.xml
new file mode 100644
index 00000000..0d98209b
--- /dev/null
+++ b/tests/fixtures/purchase-with-custom-fields-on-adjustments/authorized.xml
@@ -0,0 +1,214 @@
+POST https://api.recurly.com/v2/purchases/authorize HTTP/1.1
+X-Api-Version: {api-version}
+Accept: application/xml
+Authorization: Basic YXBpa2V5Og==
+User-Agent: {user-agent}
+Content-Type: application/xml; charset=utf-8
+
+
+
+
+ testmock
+
+
+
+
+
+ adjustment-size
+ large
+
+
+ adjustment-color
+ blue
+
+
+ Item 1
+ 1
+ 1000
+
+
+ Item 2
+ 2
+ 2000
+
+
+ manual
+ USD
+ aBcD1234
+
+
+HTTP/1.1 200 OK
+Content-Type: application/xml; charset=utf-8
+Location: https://api.recurly.com/v2/invoices/1021
+
+
+
+
+
+
+ 123 Main St
+
+ New Orleans
+ LA
+ 70114
+ US
+
+
+
+ 40625fdaa006a398c444204ae5bd42a3
+ processing
+
+ 1021
+
+
+ 6000
+ 0
+ 6000
+ 6000
+ USD
+ 2023-01-16T12:20:37Z
+ 2023-01-16T12:20:37Z
+
+ 2023-01-16T12:20:37Z
+
+
+
+ 0
+ automatic
+
+
+
+
+ 40625fda8b836c4ff51e764ef795fb87
+ invoiced
+ Item 1
+
+
+ debit
+ 1000
+ 1
+ 0
+ 0
+ 1000
+ USD
+ false
+ 2023-01-06T12:20:37Z
+
+ 2023-01-16T12:20:37Z
+ 2023-01-16T12:20:37Z
+
+
+
+ adjustment-size
+ large
+
+
+ adjustment-color
+ blue
+
+
+
+
+
+
+
+ 40625fda8ea4dbb77b2b8d4a5d8a9ac2
+ invoiced
+ Item 2
+
+
+
+ debit
+ 2000
+ 2
+ 0
+ 0
+
+ 4000
+ USD
+ false
+ 2023-01-06T12:20:37Z
+
+
+ 2023-01-16T12:20:37Z
+ 2023-01-16T12:20:37Z
+
+
+ 123
+ Main St
+
+ New Orleans
+ LA
+ 70114
+ US
+ Work
+
+
+
+
+
+
+
+
+
+
+ 40625fdb0d71f87624a285476ba7d73d
+ authorization
+ 6000
+ 0
+ USD
+ success
+ credit_card
+ 3523411
+ subscription
+ false
+ true
+ true
+ true
+
+ test
+ api
+
+ Successful test transaction
+
+
+
+ Match
+ Street address and postal code match.
+
+
+ 2023-01-16T12:20:37Z
+ 2023-01-16T12:20:37Z
+ 2023-01-16T12:20:37Z
+
+
+ 03f2dad7-e0d3-4856-acbb-fa7a7ce26683
+
+
+
+
+
+ Verena
+ Example
+ 123 Main St
+
+ New Orleans
+ LA
+ 70114
+ US
+
+
+ Visa
+ 2020
+ 11
+ 411111
+ 1111
+
+
+
+
+
+
+
+
+
diff --git a/tests/fixtures/purchase-with-custom-fields-on-adjustments/cancelled.xml b/tests/fixtures/purchase-with-custom-fields-on-adjustments/cancelled.xml
new file mode 100644
index 00000000..ec3d0d6e
--- /dev/null
+++ b/tests/fixtures/purchase-with-custom-fields-on-adjustments/cancelled.xml
@@ -0,0 +1,183 @@
+POST https://api.recurly.com/v2/purchases/transaction-uuid-40625fdb0d71f87624a285476ba7d73d/cancel HTTP/1.1
+X-Api-Version: {api-version}
+Accept: application/xml
+Authorization: Basic YXBpa2V5Og==
+User-Agent: {user-agent}
+Content-Length: 0
+
+
+HTTP/1.1 200 OK
+Content-Type: application/xml; charset=utf-8
+Location: https://api.recurly.com/v2/invoices/1021
+
+
+
+
+
+
+ 123 Main St
+
+ New Orleans
+ LA
+ 70114
+ US
+
+
+
+ 40625fdaa006a398c444204ae5bd42a3
+ paid
+
+ 1021
+
+
+ 6000
+ 0
+ 6000
+ 6000
+ USD
+ 2023-01-16T12:20:37Z
+ 2023-01-16T12:20:37Z
+
+ 2023-01-16T12:20:37Z
+
+
+
+ 0
+ automatic
+
+
+
+
+ 40625fda8b836c4ff51e764ef795fb87
+ invoiced
+ Item 1
+
+
+ debit
+ 1000
+ 1
+ 0
+ 0
+ 1000
+ USD
+ false
+ 2023-01-06T12:20:37Z
+
+ 2023-01-16T12:20:37Z
+ 2023-01-16T12:20:37Z
+
+
+
+ adjustment-size
+ large
+
+
+ adjustment-color
+ blue
+
+
+
+
+
+
+
+ 40625fda8ea4dbb77b2b8d4a5d8a9ac2
+ invoiced
+ Item 2
+
+
+
+ debit
+ 2000
+ 2
+ 0
+ 0
+
+ 4000
+ USD
+ false
+ 2023-01-06T12:20:37Z
+
+
+ 2023-01-16T12:20:37Z
+ 2023-01-16T12:20:37Z
+
+
+ 123
+ Main St
+
+ New Orleans
+ LA
+ 70114
+ US
+ Work
+
+
+
+
+
+
+
+
+
+
+ 40625fdb0d71f87624a285476ba7d73d
+ purchase
+ 6000
+ 0
+ USD
+ success
+ credit_card
+ 3523411
+ subscription
+ false
+ true
+ true
+ true
+
+ test
+ api
+
+ Successful test transaction
+
+
+
+ Match
+ Street address and postal code match.
+
+
+ 2023-01-16T12:20:37Z
+ 2023-01-16T12:20:37Z
+ 2023-01-16T12:20:37Z
+
+
+ 03f2dad7-e0d3-4856-acbb-fa7a7ce26683
+
+
+
+
+
+ Verena
+ Example
+ 123 Main St
+
+ New Orleans
+ LA
+ 70114
+ US
+
+
+ Visa
+ 2020
+ 11
+ 411111
+ 1111
+
+
+
+
+
+
+
+
+
diff --git a/tests/fixtures/purchase-with-custom-fields-on-adjustments/captured.xml b/tests/fixtures/purchase-with-custom-fields-on-adjustments/captured.xml
new file mode 100644
index 00000000..2d507401
--- /dev/null
+++ b/tests/fixtures/purchase-with-custom-fields-on-adjustments/captured.xml
@@ -0,0 +1,183 @@
+POST https://api.recurly.com/v2/purchases/transaction-uuid-40625fdb0d71f87624a285476ba7d73d/capture HTTP/1.1
+X-Api-Version: {api-version}
+Accept: application/xml
+Authorization: Basic YXBpa2V5Og==
+User-Agent: {user-agent}
+Content-Length: 0
+
+
+HTTP/1.1 200 OK
+Content-Type: application/xml; charset=utf-8
+Location: https://api.recurly.com/v2/invoices/1021
+
+
+
+
+
+
+ 123 Main St
+
+ New Orleans
+ LA
+ 70114
+ US
+
+
+
+ 40625fdaa006a398c444204ae5bd42a3
+ paid
+
+ 1021
+
+
+ 6000
+ 0
+ 6000
+ 6000
+ USD
+ 2023-01-16T12:20:37Z
+ 2023-01-16T12:20:37Z
+
+ 2023-01-16T12:20:37Z
+
+
+
+ 0
+ automatic
+
+
+
+
+ 40625fda8b836c4ff51e764ef795fb87
+ invoiced
+ Item 1
+
+
+ debit
+ 1000
+ 1
+ 0
+ 0
+ 1000
+ USD
+ false
+ 2023-01-06T12:20:37Z
+
+ 2023-01-16T12:20:37Z
+ 2023-01-16T12:20:37Z
+
+
+
+ adjustment-size
+ large
+
+
+ adjustment-color
+ blue
+
+
+
+
+
+
+
+ 40625fda8ea4dbb77b2b8d4a5d8a9ac2
+ invoiced
+ Item 2
+
+
+
+ debit
+ 2000
+ 2
+ 0
+ 0
+
+ 4000
+ USD
+ false
+ 2023-01-06T12:20:37Z
+
+
+ 2023-01-16T12:20:37Z
+ 2023-01-16T12:20:37Z
+
+
+ 123
+ Main St
+
+ New Orleans
+ LA
+ 70114
+ US
+ Work
+
+
+
+
+
+
+
+
+
+
+ 40625fdb0d71f87624a285476ba7d73d
+ purchase
+ 6000
+ 0
+ USD
+ success
+ credit_card
+ 3523411
+ subscription
+ false
+ true
+ true
+ true
+
+ test
+ api
+
+ Successful test transaction
+
+
+
+ Match
+ Street address and postal code match.
+
+
+ 2023-01-16T12:20:37Z
+ 2023-01-16T12:20:37Z
+ 2023-01-16T12:20:37Z
+
+
+ 03f2dad7-e0d3-4856-acbb-fa7a7ce26683
+
+
+
+
+
+ Verena
+ Example
+ 123 Main St
+
+ New Orleans
+ LA
+ 70114
+ US
+
+
+ Visa
+ 2020
+ 11
+ 411111
+ 1111
+
+
+
+
+
+
+
+
+
diff --git a/tests/fixtures/purchase-with-custom-fields-on-adjustments/invoiced.xml b/tests/fixtures/purchase-with-custom-fields-on-adjustments/invoiced.xml
new file mode 100644
index 00000000..a453cdfc
--- /dev/null
+++ b/tests/fixtures/purchase-with-custom-fields-on-adjustments/invoiced.xml
@@ -0,0 +1,214 @@
+POST https://api.recurly.com/v2/purchases HTTP/1.1
+X-Api-Version: {api-version}
+Accept: application/xml
+Authorization: Basic YXBpa2V5Og==
+User-Agent: {user-agent}
+Content-Type: application/xml; charset=utf-8
+
+
+
+
+ testmock
+
+
+
+
+
+ adjustment-size
+ large
+
+
+ adjustment-color
+ blue
+
+
+ Item 1
+ 1
+ 1000
+
+
+ Item 2
+ 2
+ 2000
+
+
+ manual
+ USD
+ aBcD1234
+
+
+HTTP/1.1 201 Created
+Content-Type: application/xml; charset=utf-8
+Location: https://api.recurly.com/v2/invoices/1021
+
+
+
+
+
+
+ 123 Main St
+
+ New Orleans
+ LA
+ 70114
+ US
+
+
+
+ 40625fdaa006a398c444204ae5bd42a3
+ paid
+
+ 1021
+
+
+ 6000
+ 0
+ 6000
+ 6000
+ USD
+ 2023-01-16T12:20:37Z
+ 2023-01-16T12:20:37Z
+
+ 2023-01-16T12:20:37Z
+
+
+
+ 0
+ automatic
+
+
+
+
+ 40625fda8b836c4ff51e764ef795fb87
+ invoiced
+ Item 1
+
+
+ debit
+ 1000
+ 1
+ 0
+ 0
+ 1000
+ USD
+ false
+ 2023-01-06T12:20:37Z
+
+ 2023-01-16T12:20:37Z
+ 2023-01-16T12:20:37Z
+
+
+
+ adjustment-size
+ large
+
+
+ adjustment-color
+ blue
+
+
+
+
+
+
+
+ 40625fda8ea4dbb77b2b8d4a5d8a9ac2
+ invoiced
+ Item 2
+
+
+
+ debit
+ 2000
+ 2
+ 0
+ 0
+
+ 4000
+ USD
+ false
+ 2023-01-06T12:20:37Z
+
+
+ 2023-01-16T12:20:37Z
+ 2023-01-16T12:20:37Z
+
+
+ 123
+ Main St
+
+ New Orleans
+ LA
+ 70114
+ US
+ Work
+
+
+
+
+
+
+
+
+
+
+ 40625fdb0d71f87624a285476ba7d73d
+ purchase
+ 6000
+ 0
+ USD
+ success
+ credit_card
+ 3523411
+ subscription
+ false
+ true
+ true
+ true
+
+ test
+ api
+
+ Successful test transaction
+
+
+
+ Match
+ Street address and postal code match.
+
+
+ 2023-01-16T12:20:37Z
+ 2023-01-16T12:20:37Z
+ 2023-01-16T12:20:37Z
+
+
+ 03f2dad7-e0d3-4856-acbb-fa7a7ce26683
+
+
+
+
+
+ Verena
+ Example
+ 123 Main St
+
+ New Orleans
+ LA
+ 70114
+ US
+
+
+ Visa
+ 2020
+ 11
+ 411111
+ 1111
+
+
+
+
+
+
+
+
+
diff --git a/tests/fixtures/purchase-with-custom-fields-on-adjustments/pending.xml b/tests/fixtures/purchase-with-custom-fields-on-adjustments/pending.xml
new file mode 100644
index 00000000..95e8712c
--- /dev/null
+++ b/tests/fixtures/purchase-with-custom-fields-on-adjustments/pending.xml
@@ -0,0 +1,214 @@
+POST https://api.recurly.com/v2/purchases/pending HTTP/1.1
+X-Api-Version: {api-version}
+Accept: application/xml
+Authorization: Basic YXBpa2V5Og==
+User-Agent: {user-agent}
+Content-Type: application/xml; charset=utf-8
+
+
+
+
+ testmock
+
+
+
+
+
+ adjustment-size
+ large
+
+
+ adjustment-color
+ blue
+
+
+ Item 1
+ 1
+ 1000
+
+
+ Item 2
+ 2
+ 2000
+
+
+ manual
+ USD
+ aBcD1234
+
+
+HTTP/1.1 200 OK
+Content-Type: application/xml; charset=utf-8
+Location: https://api.recurly.com/v2/invoices/1021
+
+
+
+
+
+
+ 123 Main St
+
+ New Orleans
+ LA
+ 70114
+ US
+
+
+
+ 40625fdaa006a398c444204ae5bd42a3
+ paid
+
+ 1021
+
+
+ 6000
+ 0
+ 6000
+ 6000
+ USD
+ 2023-01-16T12:20:37Z
+ 2023-01-16T12:20:37Z
+
+ 2023-01-16T12:20:37Z
+
+
+
+ 0
+ automatic
+
+
+
+
+ 40625fda8b836c4ff51e764ef795fb87
+ invoiced
+ Item 1
+
+
+ debit
+ 1000
+ 1
+ 0
+ 0
+ 1000
+ USD
+ false
+ 2023-01-06T12:20:37Z
+
+ 2023-01-16T12:20:37Z
+ 2023-01-16T12:20:37Z
+
+
+
+ adjustment-size
+ large
+
+
+ adjustment-color
+ blue
+
+
+
+
+
+
+
+ 40625fda8ea4dbb77b2b8d4a5d8a9ac2
+ invoiced
+ Item 2
+
+
+
+ debit
+ 2000
+ 2
+ 0
+ 0
+
+ 4000
+ USD
+ false
+ 2023-01-06T12:20:37Z
+
+
+ 2023-01-16T12:20:37Z
+ 2023-01-16T12:20:37Z
+
+
+ 123
+ Main St
+
+ New Orleans
+ LA
+ 70114
+ US
+ Work
+
+
+
+
+
+
+
+
+
+
+ 40625fdb0d71f87624a285476ba7d73d
+ purchase
+ 6000
+ 0
+ USD
+ success
+ credit_card
+ 3523411
+ subscription
+ false
+ true
+ true
+ true
+
+ test
+ api
+
+ Successful test transaction
+
+
+
+ Match
+ Street address and postal code match.
+
+
+ 2023-01-16T12:20:37Z
+ 2023-01-16T12:20:37Z
+ 2023-01-16T12:20:37Z
+
+
+ 03f2dad7-e0d3-4856-acbb-fa7a7ce26683
+
+
+
+
+
+ Verena
+ Example
+ 123 Main St
+
+ New Orleans
+ LA
+ 70114
+ US
+
+
+ Visa
+ 2020
+ 11
+ 411111
+ 1111
+
+
+
+
+
+
+
+
+
diff --git a/tests/fixtures/purchase-with-custom-fields-on-adjustments/previewed.xml b/tests/fixtures/purchase-with-custom-fields-on-adjustments/previewed.xml
new file mode 100644
index 00000000..ca182206
--- /dev/null
+++ b/tests/fixtures/purchase-with-custom-fields-on-adjustments/previewed.xml
@@ -0,0 +1,153 @@
+POST https://api.recurly.com/v2/purchases/preview HTTP/1.1
+X-Api-Version: {api-version}
+Accept: application/xml
+Authorization: Basic YXBpa2V5Og==
+User-Agent: {user-agent}
+Content-Type: application/xml; charset=utf-8
+
+
+
+
+ testmock
+
+
+
+
+
+ adjustment-size
+ large
+
+
+ adjustment-color
+ blue
+
+
+ Item 1
+ 1
+ 1000
+
+
+ Item 2
+ 2
+ 2000
+
+
+ manual
+ USD
+ aBcD1234
+
+
+HTTP/1.1 200 OK
+Content-Type: application/xml; charset=utf-8
+Location: https://api.recurly.com/v2/invoices/1021
+
+
+
+
+
+
+ 123 Main St
+
+ New Orleans
+ LA
+ 70114
+ US
+
+
+
+ 40625fdaa006a398c444204ae5bd42a3
+ paid
+
+ 1021
+
+
+ 6000
+ 0
+ 6000
+ 6000
+ USD
+ 2023-01-16T12:20:37Z
+ 2023-01-16T12:20:37Z
+
+ 2023-01-16T12:20:37Z
+
+
+
+ 0
+ automatic
+
+
+
+
+ 40625fda8b836c4ff51e764ef795fb87
+ invoiced
+ Item 1
+
+
+ debit
+ 1000
+ 1
+ 0
+ 0
+ 1000
+ USD
+ false
+ 2023-01-06T12:20:37Z
+
+ 2023-01-16T12:20:37Z
+ 2023-01-16T12:20:37Z
+
+
+
+ adjustment-size
+ large
+
+
+ adjustment-color
+ blue
+
+
+
+
+
+
+
+ 40625fda8ea4dbb77b2b8d4a5d8a9ac2
+ invoiced
+ Item 2
+
+
+
+ debit
+ 2000
+ 2
+ 0
+ 0
+
+ 4000
+ USD
+ false
+ 2023-01-06T12:20:37Z
+
+
+ 2023-01-16T12:20:37Z
+ 2023-01-16T12:20:37Z
+
+
+ 123
+ Main St
+
+ New Orleans
+ LA
+ 70114
+ US
+ Work
+
+
+
+
+
+
+
+
+
diff --git a/tests/test_resources.py b/tests/test_resources.py
index c022b00f..c708c836 100644
--- a/tests/test_resources.py
+++ b/tests/test_resources.py
@@ -155,6 +155,71 @@ def create_purchase():
self.assertIsInstance(collection.charge_invoice, Invoice)
self.assertEqual(purchase.billing_info_uuid, 'uniqueUuid')
+ def test_purchase_with_custom_fields_on_adjustments(self):
+ account_code = 'test%s' % self.test_id
+ def create_purchase():
+ return Purchase(
+ currency = 'USD',
+ gateway_code = 'aBcD1234',
+ collection_method = 'manual',
+ account = Account(
+ account_code = account_code,
+ ),
+ adjustments = [
+ recurly.Adjustment(
+ unit_amount_in_cents=1000,
+ description='Item 1',
+ quantity=1,
+ custom_fields=[
+ recurly.CustomField(
+ name='adjustment-size',
+ value='large'
+ ),
+ recurly.CustomField(
+ name='adjustment-color',
+ value='blue'
+ ),
+ ]
+ ),
+ recurly.Adjustment(
+ unit_amount_in_cents=2000,
+ description='Item 2',
+ quantity=2
+ ),
+ ]
+ )
+ def assert_custom_fields_on_charges():
+ self.assertIsInstance(collection.charge_invoice.line_items[0].custom_fields[0], CustomField)
+ self.assertEqual(collection.charge_invoice.line_items[0].custom_fields[0].name, 'adjustment-size')
+ self.assertEqual(collection.charge_invoice.line_items[0].custom_fields[0].value, 'large')
+ self.assertEqual(collection.charge_invoice.line_items[0].custom_fields[1].name, 'adjustment-color')
+ self.assertEqual(collection.charge_invoice.line_items[0].custom_fields[1].value, 'blue')
+ self.assertEqual(collection.charge_invoice.line_items[1].custom_fields, [])
+
+ with self.mock_request('purchase-with-custom-fields-on-adjustments/invoiced.xml'):
+ collection = create_purchase().invoice()
+ assert_custom_fields_on_charges()
+
+ with self.mock_request('purchase-with-custom-fields-on-adjustments/previewed.xml'):
+ collection = create_purchase().preview()
+ assert_custom_fields_on_charges()
+
+ with self.mock_request('purchase-with-custom-fields-on-adjustments/authorized.xml'):
+ collection = create_purchase().authorize()
+ assert_custom_fields_on_charges()
+
+ with self.mock_request('purchase-with-custom-fields-on-adjustments/pending.xml'):
+ collection = create_purchase().pending()
+ assert_custom_fields_on_charges()
+
+ with self.mock_request('purchase-with-custom-fields-on-adjustments/captured.xml'):
+ collection = create_purchase().capture('40625fdb0d71f87624a285476ba7d73d')
+ assert_custom_fields_on_charges()
+
+ with self.mock_request('purchase-with-custom-fields-on-adjustments/cancelled.xml'):
+ collection = create_purchase().cancel('40625fdb0d71f87624a285476ba7d73d')
+ assert_custom_fields_on_charges()
+
def test_purchase_with_ramp_plan(self):
account_code = 'test%s' % self.test_id
def create_purchase():