Skip to content
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
3 changes: 2 additions & 1 deletion recurly/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,8 @@ class GiftCard(Resource):
'billing_info',
'liability_gl_account_id',
'revenue_gl_account_id',
'performance_obligation_id'
'performance_obligation_id',
'tax_service_opt_out'
)
_classes_for_nodename = {'recipient_account': Account,'gifter_account':
Account, 'delivery': Delivery}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
POST https://api.recurly.com/v2/gift_cards 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

<?xml version="1.0" encoding="UTF-8"?>
<gift_card>
<currency>USD</currency>
<delivery>
<address>
<address1>400 Alabama St</address1>
<city>San Francisco</city>
<country>US</country>
<state>CA</state>
<zip>94110</zip>
</address>
<email_address>john@email.com</email_address>
<first_name>John</first_name>
<last_name>Smith</last_name>
<method>email</method>
</delivery>
<gifter_account>
<account_code>e0004e3c-216c-4254-8767-9be605cd0b03</account_code>
<email>verena@example.com</email>
<first_name>Verena</first_name>
<last_name>Example</last_name>
<billing_info>
<country>US</country>
<currency>USD</currency>
<first_name>Verena</first_name>
<last_name>Example</last_name>
<month type="integer">11</month>
<number>4111-1111-1111-1111</number>
<verification_value>123</verification_value>
<year type="integer">2019</year>
</billing_info>
</gifter_account>
<product_code>test_gift_card</product_code>
<tax_service_opt_out type="boolean">false</tax_service_opt_out>
<unit_amount_in_cents type="integer">2000</unit_amount_in_cents>
</gift_card>

HTTP/1.1 201 Created
Content-Type: application/xml; charset=utf-8
Location: https://api.recurly.com/v2/gift_cards/2018434791876074812

<?xml version="1.0" encoding="UTF-8"?>
<gift_card href="https://api.recurly.com/v2/gift_cards/2018434791876074812">
<gifter_account href="https://api.recurly.com/v2/accounts/e0004e3c-216c-4254-8767-9be605cd0b03"/>
<invoice href="https://api.recurly.com/v2/invoices/2096"/>
<id type="integer">2018434791876074812</id>
<redemption_code>9FC359369CD3892E</redemption_code>
<product_code>test_gift_card</product_code>
<unit_amount_in_cents type="integer">2000</unit_amount_in_cents>
<currency>USD</currency>
<delivery>
<method>email</method>
<email_address>john@email.com</email_address>
<deliver_at nil="nil"></deliver_at>
<first_name nil="nil"></first_name>
<last_name nil="nil"></last_name>
<address>
<address1>400 Alabama St</address1>
<address2 nil="nil"></address2>
<city>San Francisco</city>
<state>CA</state>
<zip>94110</zip>
<country>US</country>
<phone nil="nil"></phone>
</address>
<gifter_name nil="nil"></gifter_name>
<personal_message nil="nil"></personal_message>
</delivery>
<created_at type="datetime">2016-08-16T21:49:37Z</created_at>
<updated_at type="datetime">2016-08-16T21:49:37Z</updated_at>
<delivered_at nil="nil"></delivered_at>
<redeemed_at nil="nil"></redeemed_at>
<canceled_at nil="nil"></canceled_at>
<a name="redeem" href="https://api.recurly.com/v2/gift_cards/9FC359369CD3892E/redeem" method="post"/>
</gift_card>
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
POST https://api.recurly.com/v2/gift_cards 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

<?xml version="1.0" encoding="UTF-8"?>
<gift_card>
<currency>USD</currency>
<delivery>
<address>
<address1>400 Alabama St</address1>
<city>San Francisco</city>
<country>US</country>
<state>CA</state>
<zip>94110</zip>
</address>
<email_address>john@email.com</email_address>
<first_name>John</first_name>
<last_name>Smith</last_name>
<method>email</method>
</delivery>
<gifter_account>
<account_code>e0004e3c-216c-4254-8767-9be605cd0b03</account_code>
<email>verena@example.com</email>
<first_name>Verena</first_name>
<last_name>Example</last_name>
<billing_info>
<country>US</country>
<currency>USD</currency>
<first_name>Verena</first_name>
<last_name>Example</last_name>
<month type="integer">11</month>
<number>4111-1111-1111-1111</number>
<verification_value>123</verification_value>
<year type="integer">2019</year>
</billing_info>
</gifter_account>
<product_code>test_gift_card</product_code>
<tax_service_opt_out>invalid</tax_service_opt_out>
<unit_amount_in_cents type="integer">2000</unit_amount_in_cents>
</gift_card>

HTTP/1.1 422 Unprocessable Entity
Content-Type: application/xml; charset=utf-8

<?xml version="1.0" encoding="UTF-8"?>
<error>
<symbol>tax_service_opt_out</symbol>
<description>Allowed values: true, false</description>
</error>
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
POST https://api.recurly.com/v2/gift_cards 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

<?xml version="1.0" encoding="UTF-8"?>
<gift_card>
<currency>USD</currency>
<delivery>
<address>
<address1>400 Alabama St</address1>
<city>San Francisco</city>
<country>US</country>
<state>CA</state>
<zip>94110</zip>
</address>
<email_address>john@email.com</email_address>
<first_name>John</first_name>
<last_name>Smith</last_name>
<method>email</method>
</delivery>
<gifter_account>
<account_code>e0004e3c-216c-4254-8767-9be605cd0b03</account_code>
<email>verena@example.com</email>
<first_name>Verena</first_name>
<last_name>Example</last_name>
<billing_info>
<country>US</country>
<currency>USD</currency>
<first_name>Verena</first_name>
<last_name>Example</last_name>
<month type="integer">11</month>
<number>4111-1111-1111-1111</number>
<verification_value>123</verification_value>
<year type="integer">2019</year>
</billing_info>
</gifter_account>
<product_code>test_gift_card</product_code>
<tax_service_opt_out type="boolean">true</tax_service_opt_out>
<unit_amount_in_cents type="integer">2000</unit_amount_in_cents>
</gift_card>

HTTP/1.1 422 Unprocessable Entity
Content-Type: application/xml; charset=utf-8

<?xml version="1.0" encoding="UTF-8"?>
<error>
<symbol>tax_service_opt_out</symbol>
<description>Not supported for legacy invoices</description>
</error>
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
POST https://api.recurly.com/v2/gift_cards 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

<?xml version="1.0" encoding="UTF-8"?>
<gift_card>
<currency>USD</currency>
<delivery>
<address>
<address1>400 Alabama St</address1>
<city>San Francisco</city>
<country>US</country>
<state>CA</state>
<zip>94110</zip>
</address>
<email_address>john@email.com</email_address>
<first_name>John</first_name>
<last_name>Smith</last_name>
<method>email</method>
</delivery>
<gifter_account>
<account_code>e0004e3c-216c-4254-8767-9be605cd0b03</account_code>
<email>verena@example.com</email>
<first_name>Verena</first_name>
<last_name>Example</last_name>
<billing_info>
<country>US</country>
<currency>USD</currency>
<first_name>Verena</first_name>
<last_name>Example</last_name>
<month type="integer">11</month>
<number>4111-1111-1111-1111</number>
<verification_value>123</verification_value>
<year type="integer">2019</year>
</billing_info>
</gifter_account>
<product_code>test_gift_card</product_code>
<tax_service_opt_out type="boolean">true</tax_service_opt_out>
<unit_amount_in_cents type="integer">2000</unit_amount_in_cents>
</gift_card>

HTTP/1.1 201 Created
Content-Type: application/xml; charset=utf-8
Location: https://api.recurly.com/v2/gift_cards/2018434791876074812

<?xml version="1.0" encoding="UTF-8"?>
<gift_card href="https://api.recurly.com/v2/gift_cards/2018434791876074812">
<gifter_account href="https://api.recurly.com/v2/accounts/e0004e3c-216c-4254-8767-9be605cd0b03"/>
<invoice href="https://api.recurly.com/v2/invoices/2096"/>
<id type="integer">2018434791876074812</id>
<redemption_code>9FC359369CD3892E</redemption_code>
<product_code>test_gift_card</product_code>
<unit_amount_in_cents type="integer">2000</unit_amount_in_cents>
<currency>USD</currency>
<delivery>
<method>email</method>
<email_address>john@email.com</email_address>
<deliver_at nil="nil"></deliver_at>
<first_name nil="nil"></first_name>
<last_name nil="nil"></last_name>
<address>
<address1>400 Alabama St</address1>
<address2 nil="nil"></address2>
<city>San Francisco</city>
<state>CA</state>
<zip>94110</zip>
<country>US</country>
<phone nil="nil"></phone>
</address>
<gifter_name nil="nil"></gifter_name>
<personal_message nil="nil"></personal_message>
</delivery>
<created_at type="datetime">2016-08-16T21:49:37Z</created_at>
<updated_at type="datetime">2016-08-16T21:49:37Z</updated_at>
<delivered_at nil="nil"></delivered_at>
<redeemed_at nil="nil"></redeemed_at>
<canceled_at nil="nil"></canceled_at>
<a name="redeem" href="https://api.recurly.com/v2/gift_cards/9FC359369CD3892E/redeem" method="post"/>
</gift_card>
70 changes: 63 additions & 7 deletions tests/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,16 +570,16 @@ def test_charge_with_vertex_transaction_type(self):
type='charge',
vertex_transaction_type='sale'
)

with self.mock_request('adjustment/charged-with-vertex-transaction-type.xml'):
account.charge(charge)

# Verify the charge was created with vertex_transaction_type
self.assertEqual(charge.vertex_transaction_type, 'sale')

def test_purchase_with_invoice_override_vertex_transaction_type(self):
"""Test that invoice-level vertex_transaction_type overrides adjustment-level values.

This demonstrates the override behavior where an invoice can have its own
vertex_transaction_type that takes precedence over the individual adjustment values.
"""
Expand All @@ -596,16 +596,16 @@ def test_purchase_with_invoice_override_vertex_transaction_type(self):
],
vertex_transaction_type='rental' # Invoice-level value (should override)
)

with self.mock_request('purchase/invoiced-with-invoice-override-vertex-type.xml'):
invoice_collection = purchase.invoice()

invoice = invoice_collection.charge_invoice
adjustments = invoice.line_items

# Verify the invoice has the invoice-level vertex_transaction_type
self.assertEqual(invoice.vertex_transaction_type, 'rental')

# The adjustment still has its own value (API preserves both)
# but the invoice-level value is what gets used for tax calculation
self.assertEqual(adjustments[0].vertex_transaction_type, 'sale')
Expand Down Expand Up @@ -3454,6 +3454,62 @@ def test_gift_cards_purchase(self):
self.assertTrue(gift_card.delivery is not None)
self.assertTrue(gift_card.canceled_at is None)

def test_gift_cards_purchase_with_tax_service_opt_out_true(self):
gift_card = self._build_gift_card()
gift_card.tax_service_opt_out = True

self.assertFalse('_url' in gift_card.attributes)

with self.mock_request('gift_cards/created-with-tax-service-opt-out-true.xml'):
gift_card.save()

self.assertTrue(gift_card._url is not None)
self.assertTrue(gift_card.delivery is not None)
self.assertTrue(gift_card.canceled_at is None)

def test_gift_cards_purchase_with_tax_service_opt_out_false(self):
gift_card = self._build_gift_card()
gift_card.tax_service_opt_out = False

self.assertFalse('_url' in gift_card.attributes)

with self.mock_request('gift_cards/created-with-tax-service-opt-out-false.xml'):
gift_card.save()

self.assertTrue(gift_card._url is not None)
self.assertTrue(gift_card.delivery is not None)
self.assertTrue(gift_card.canceled_at is None)

def test_gift_cards_purchase_with_tax_service_opt_out_invalid(self):
gift_card = self._build_gift_card()
gift_card.tax_service_opt_out = 'invalid'

self.assertFalse('_url' in gift_card.attributes)

with self.mock_request('gift_cards/created-with-tax-service-opt-out-invalid.xml'):
try:
gift_card.save()
except ValidationError as exc:
error = exc
else:
self.fail('Creating a gift card with invalid tax_service_opt_out did not raise a ValidationError')
self.assertEqual(error.symbol, 'tax_service_opt_out')
self.assertIn('Allowed values: true, false', error.message)

def test_gift_cards_purchase_with_tax_service_opt_out_legacy_site(self):
gift_card = self._build_gift_card()
gift_card.tax_service_opt_out = True

with self.mock_request('gift_cards/created-with-tax-service-opt-out-legacy-site.xml'):
try:
gift_card.save()
except ValidationError as exc:
error = exc
else:
self.fail('Creating a gift card with tax_service_opt_out on legacy site did not raise a ValidationError')
self.assertEqual(error.symbol, 'tax_service_opt_out')
self.assertIn('Not supported for legacy invoices', error.message)

def test_gift_cards_preview(self):
gift_card = self._build_gift_card()

Expand Down