Skip to content

Commit 07abcda

Browse files
committed
Adding tax_service_opt_out to Gift Cards
1 parent cbe3858 commit 07abcda

File tree

6 files changed

+333
-8
lines changed

6 files changed

+333
-8
lines changed

recurly/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,8 @@ class GiftCard(Resource):
792792
'billing_info',
793793
'liability_gl_account_id',
794794
'revenue_gl_account_id',
795-
'performance_obligation_id'
795+
'performance_obligation_id',
796+
'tax_service_opt_out'
796797
)
797798
_classes_for_nodename = {'recipient_account': Account,'gifter_account':
798799
Account, 'delivery': Delivery}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
POST https://api.recurly.com/v2/gift_cards HTTP/1.1
2+
X-Api-Version: {api-version}
3+
Accept: application/xml
4+
Authorization: Basic YXBpa2V5Og==
5+
User-Agent: {user-agent}
6+
Content-Type: application/xml; charset=utf-8
7+
8+
<?xml version="1.0" encoding="UTF-8"?>
9+
<gift_card>
10+
<currency>USD</currency>
11+
<delivery>
12+
<address>
13+
<address1>400 Alabama St</address1>
14+
<city>San Francisco</city>
15+
<country>US</country>
16+
<state>CA</state>
17+
<zip>94110</zip>
18+
</address>
19+
<email_address>john@email.com</email_address>
20+
<first_name>John</first_name>
21+
<last_name>Smith</last_name>
22+
<method>email</method>
23+
</delivery>
24+
<gifter_account>
25+
<account_code>e0004e3c-216c-4254-8767-9be605cd0b03</account_code>
26+
<email>verena@example.com</email>
27+
<first_name>Verena</first_name>
28+
<last_name>Example</last_name>
29+
<billing_info>
30+
<country>US</country>
31+
<currency>USD</currency>
32+
<first_name>Verena</first_name>
33+
<last_name>Example</last_name>
34+
<month type="integer">11</month>
35+
<number>4111-1111-1111-1111</number>
36+
<verification_value>123</verification_value>
37+
<year type="integer">2019</year>
38+
</billing_info>
39+
</gifter_account>
40+
<product_code>test_gift_card</product_code>
41+
<tax_service_opt_out type="boolean">false</tax_service_opt_out>
42+
<unit_amount_in_cents type="integer">2000</unit_amount_in_cents>
43+
</gift_card>
44+

45+
HTTP/1.1 201 Created
46+
Content-Type: application/xml; charset=utf-8
47+
Location: https://api.recurly.com/v2/gift_cards/2018434791876074812
48+
49+
<?xml version="1.0" encoding="UTF-8"?>
50+
<gift_card href="https://api.recurly.com/v2/gift_cards/2018434791876074812">
51+
<gifter_account href="https://api.recurly.com/v2/accounts/e0004e3c-216c-4254-8767-9be605cd0b03"/>
52+
<invoice href="https://api.recurly.com/v2/invoices/2096"/>
53+
<id type="integer">2018434791876074812</id>
54+
<redemption_code>9FC359369CD3892E</redemption_code>
55+
<product_code>test_gift_card</product_code>
56+
<unit_amount_in_cents type="integer">2000</unit_amount_in_cents>
57+
<currency>USD</currency>
58+
<delivery>
59+
<method>email</method>
60+
<email_address>john@email.com</email_address>
61+
<deliver_at nil="nil"></deliver_at>
62+
<first_name nil="nil"></first_name>
63+
<last_name nil="nil"></last_name>
64+
<address>
65+
<address1>400 Alabama St</address1>
66+
<address2 nil="nil"></address2>
67+
<city>San Francisco</city>
68+
<state>CA</state>
69+
<zip>94110</zip>
70+
<country>US</country>
71+
<phone nil="nil"></phone>
72+
</address>
73+
<gifter_name nil="nil"></gifter_name>
74+
<personal_message nil="nil"></personal_message>
75+
</delivery>
76+
<created_at type="datetime">2016-08-16T21:49:37Z</created_at>
77+
<updated_at type="datetime">2016-08-16T21:49:37Z</updated_at>
78+
<delivered_at nil="nil"></delivered_at>
79+
<redeemed_at nil="nil"></redeemed_at>
80+
<canceled_at nil="nil"></canceled_at>
81+
<a name="redeem" href="https://api.recurly.com/v2/gift_cards/9FC359369CD3892E/redeem" method="post"/>
82+
</gift_card>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
POST https://api.recurly.com/v2/gift_cards HTTP/1.1
2+
X-Api-Version: {api-version}
3+
Accept: application/xml
4+
Authorization: Basic YXBpa2V5Og==
5+
User-Agent: {user-agent}
6+
Content-Type: application/xml; charset=utf-8
7+
8+
<?xml version="1.0" encoding="UTF-8"?>
9+
<gift_card>
10+
<currency>USD</currency>
11+
<delivery>
12+
<address>
13+
<address1>400 Alabama St</address1>
14+
<city>San Francisco</city>
15+
<country>US</country>
16+
<state>CA</state>
17+
<zip>94110</zip>
18+
</address>
19+
<email_address>john@email.com</email_address>
20+
<first_name>John</first_name>
21+
<last_name>Smith</last_name>
22+
<method>email</method>
23+
</delivery>
24+
<gifter_account>
25+
<account_code>e0004e3c-216c-4254-8767-9be605cd0b03</account_code>
26+
<email>verena@example.com</email>
27+
<first_name>Verena</first_name>
28+
<last_name>Example</last_name>
29+
<billing_info>
30+
<country>US</country>
31+
<currency>USD</currency>
32+
<first_name>Verena</first_name>
33+
<last_name>Example</last_name>
34+
<month type="integer">11</month>
35+
<number>4111-1111-1111-1111</number>
36+
<verification_value>123</verification_value>
37+
<year type="integer">2019</year>
38+
</billing_info>
39+
</gifter_account>
40+
<product_code>test_gift_card</product_code>
41+
<tax_service_opt_out>invalid</tax_service_opt_out>
42+
<unit_amount_in_cents type="integer">2000</unit_amount_in_cents>
43+
</gift_card>
44+

45+
HTTP/1.1 422 Unprocessable Entity
46+
Content-Type: application/xml; charset=utf-8
47+
48+
<?xml version="1.0" encoding="UTF-8"?>
49+
<error>
50+
<symbol>tax_service_opt_out</symbol>
51+
<description>Allowed values: true, false</description>
52+
</error>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
POST https://api.recurly.com/v2/gift_cards HTTP/1.1
2+
X-Api-Version: {api-version}
3+
Accept: application/xml
4+
Authorization: Basic YXBpa2V5Og==
5+
User-Agent: {user-agent}
6+
Content-Type: application/xml; charset=utf-8
7+
8+
<?xml version="1.0" encoding="UTF-8"?>
9+
<gift_card>
10+
<currency>USD</currency>
11+
<delivery>
12+
<address>
13+
<address1>400 Alabama St</address1>
14+
<city>San Francisco</city>
15+
<country>US</country>
16+
<state>CA</state>
17+
<zip>94110</zip>
18+
</address>
19+
<email_address>john@email.com</email_address>
20+
<first_name>John</first_name>
21+
<last_name>Smith</last_name>
22+
<method>email</method>
23+
</delivery>
24+
<gifter_account>
25+
<account_code>e0004e3c-216c-4254-8767-9be605cd0b03</account_code>
26+
<email>verena@example.com</email>
27+
<first_name>Verena</first_name>
28+
<last_name>Example</last_name>
29+
<billing_info>
30+
<country>US</country>
31+
<currency>USD</currency>
32+
<first_name>Verena</first_name>
33+
<last_name>Example</last_name>
34+
<month type="integer">11</month>
35+
<number>4111-1111-1111-1111</number>
36+
<verification_value>123</verification_value>
37+
<year type="integer">2019</year>
38+
</billing_info>
39+
</gifter_account>
40+
<product_code>test_gift_card</product_code>
41+
<tax_service_opt_out type="boolean">true</tax_service_opt_out>
42+
<unit_amount_in_cents type="integer">2000</unit_amount_in_cents>
43+
</gift_card>
44+

45+
HTTP/1.1 422 Unprocessable Entity
46+
Content-Type: application/xml; charset=utf-8
47+
48+
<?xml version="1.0" encoding="UTF-8"?>
49+
<error>
50+
<symbol>tax_service_opt_out</symbol>
51+
<description>Not supported for legacy invoices</description>
52+
</error>
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
POST https://api.recurly.com/v2/gift_cards HTTP/1.1
2+
X-Api-Version: {api-version}
3+
Accept: application/xml
4+
Authorization: Basic YXBpa2V5Og==
5+
User-Agent: {user-agent}
6+
Content-Type: application/xml; charset=utf-8
7+
8+
<?xml version="1.0" encoding="UTF-8"?>
9+
<gift_card>
10+
<currency>USD</currency>
11+
<delivery>
12+
<address>
13+
<address1>400 Alabama St</address1>
14+
<city>San Francisco</city>
15+
<country>US</country>
16+
<state>CA</state>
17+
<zip>94110</zip>
18+
</address>
19+
<email_address>john@email.com</email_address>
20+
<first_name>John</first_name>
21+
<last_name>Smith</last_name>
22+
<method>email</method>
23+
</delivery>
24+
<gifter_account>
25+
<account_code>e0004e3c-216c-4254-8767-9be605cd0b03</account_code>
26+
<email>verena@example.com</email>
27+
<first_name>Verena</first_name>
28+
<last_name>Example</last_name>
29+
<billing_info>
30+
<country>US</country>
31+
<currency>USD</currency>
32+
<first_name>Verena</first_name>
33+
<last_name>Example</last_name>
34+
<month type="integer">11</month>
35+
<number>4111-1111-1111-1111</number>
36+
<verification_value>123</verification_value>
37+
<year type="integer">2019</year>
38+
</billing_info>
39+
</gifter_account>
40+
<product_code>test_gift_card</product_code>
41+
<tax_service_opt_out type="boolean">true</tax_service_opt_out>
42+
<unit_amount_in_cents type="integer">2000</unit_amount_in_cents>
43+
</gift_card>
44+

45+
HTTP/1.1 201 Created
46+
Content-Type: application/xml; charset=utf-8
47+
Location: https://api.recurly.com/v2/gift_cards/2018434791876074812
48+
49+
<?xml version="1.0" encoding="UTF-8"?>
50+
<gift_card href="https://api.recurly.com/v2/gift_cards/2018434791876074812">
51+
<gifter_account href="https://api.recurly.com/v2/accounts/e0004e3c-216c-4254-8767-9be605cd0b03"/>
52+
<invoice href="https://api.recurly.com/v2/invoices/2096"/>
53+
<id type="integer">2018434791876074812</id>
54+
<redemption_code>9FC359369CD3892E</redemption_code>
55+
<product_code>test_gift_card</product_code>
56+
<unit_amount_in_cents type="integer">2000</unit_amount_in_cents>
57+
<currency>USD</currency>
58+
<delivery>
59+
<method>email</method>
60+
<email_address>john@email.com</email_address>
61+
<deliver_at nil="nil"></deliver_at>
62+
<first_name nil="nil"></first_name>
63+
<last_name nil="nil"></last_name>
64+
<address>
65+
<address1>400 Alabama St</address1>
66+
<address2 nil="nil"></address2>
67+
<city>San Francisco</city>
68+
<state>CA</state>
69+
<zip>94110</zip>
70+
<country>US</country>
71+
<phone nil="nil"></phone>
72+
</address>
73+
<gifter_name nil="nil"></gifter_name>
74+
<personal_message nil="nil"></personal_message>
75+
</delivery>
76+
<created_at type="datetime">2016-08-16T21:49:37Z</created_at>
77+
<updated_at type="datetime">2016-08-16T21:49:37Z</updated_at>
78+
<delivered_at nil="nil"></delivered_at>
79+
<redeemed_at nil="nil"></redeemed_at>
80+
<canceled_at nil="nil"></canceled_at>
81+
<a name="redeem" href="https://api.recurly.com/v2/gift_cards/9FC359369CD3892E/redeem" method="post"/>
82+
</gift_card>

tests/test_resources.py

Lines changed: 63 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -570,16 +570,16 @@ def test_charge_with_vertex_transaction_type(self):
570570
type='charge',
571571
vertex_transaction_type='sale'
572572
)
573-
573+
574574
with self.mock_request('adjustment/charged-with-vertex-transaction-type.xml'):
575575
account.charge(charge)
576-
576+
577577
# Verify the charge was created with vertex_transaction_type
578578
self.assertEqual(charge.vertex_transaction_type, 'sale')
579579

580580
def test_purchase_with_invoice_override_vertex_transaction_type(self):
581581
"""Test that invoice-level vertex_transaction_type overrides adjustment-level values.
582-
582+
583583
This demonstrates the override behavior where an invoice can have its own
584584
vertex_transaction_type that takes precedence over the individual adjustment values.
585585
"""
@@ -596,16 +596,16 @@ def test_purchase_with_invoice_override_vertex_transaction_type(self):
596596
],
597597
vertex_transaction_type='rental' # Invoice-level value (should override)
598598
)
599-
599+
600600
with self.mock_request('purchase/invoiced-with-invoice-override-vertex-type.xml'):
601601
invoice_collection = purchase.invoice()
602-
602+
603603
invoice = invoice_collection.charge_invoice
604604
adjustments = invoice.line_items
605-
605+
606606
# Verify the invoice has the invoice-level vertex_transaction_type
607607
self.assertEqual(invoice.vertex_transaction_type, 'rental')
608-
608+
609609
# The adjustment still has its own value (API preserves both)
610610
# but the invoice-level value is what gets used for tax calculation
611611
self.assertEqual(adjustments[0].vertex_transaction_type, 'sale')
@@ -3454,6 +3454,62 @@ def test_gift_cards_purchase(self):
34543454
self.assertTrue(gift_card.delivery is not None)
34553455
self.assertTrue(gift_card.canceled_at is None)
34563456

3457+
def test_gift_cards_purchase_with_tax_service_opt_out_true(self):
3458+
gift_card = self._build_gift_card()
3459+
gift_card.tax_service_opt_out = True
3460+
3461+
self.assertFalse('_url' in gift_card.attributes)
3462+
3463+
with self.mock_request('gift_cards/created-with-tax-service-opt-out-true.xml'):
3464+
gift_card.save()
3465+
3466+
self.assertTrue(gift_card._url is not None)
3467+
self.assertTrue(gift_card.delivery is not None)
3468+
self.assertTrue(gift_card.canceled_at is None)
3469+
3470+
def test_gift_cards_purchase_with_tax_service_opt_out_false(self):
3471+
gift_card = self._build_gift_card()
3472+
gift_card.tax_service_opt_out = False
3473+
3474+
self.assertFalse('_url' in gift_card.attributes)
3475+
3476+
with self.mock_request('gift_cards/created-with-tax-service-opt-out-false.xml'):
3477+
gift_card.save()
3478+
3479+
self.assertTrue(gift_card._url is not None)
3480+
self.assertTrue(gift_card.delivery is not None)
3481+
self.assertTrue(gift_card.canceled_at is None)
3482+
3483+
def test_gift_cards_purchase_with_tax_service_opt_out_invalid(self):
3484+
gift_card = self._build_gift_card()
3485+
gift_card.tax_service_opt_out = 'invalid'
3486+
3487+
self.assertFalse('_url' in gift_card.attributes)
3488+
3489+
with self.mock_request('gift_cards/created-with-tax-service-opt-out-invalid.xml'):
3490+
try:
3491+
gift_card.save()
3492+
except ValidationError as exc:
3493+
error = exc
3494+
else:
3495+
self.fail('Creating a gift card with invalid tax_service_opt_out did not raise a ValidationError')
3496+
self.assertEqual(error.symbol, 'tax_service_opt_out')
3497+
self.assertIn('Allowed values: true, false', error.message)
3498+
3499+
def test_gift_cards_purchase_with_tax_service_opt_out_legacy_site(self):
3500+
gift_card = self._build_gift_card()
3501+
gift_card.tax_service_opt_out = True
3502+
3503+
with self.mock_request('gift_cards/created-with-tax-service-opt-out-legacy-site.xml'):
3504+
try:
3505+
gift_card.save()
3506+
except ValidationError as exc:
3507+
error = exc
3508+
else:
3509+
self.fail('Creating a gift card with tax_service_opt_out on legacy site did not raise a ValidationError')
3510+
self.assertEqual(error.symbol, 'tax_service_opt_out')
3511+
self.assertIn('Not supported for legacy invoices', error.message)
3512+
34573513
def test_gift_cards_preview(self):
34583514
gift_card = self._build_gift_card()
34593515

0 commit comments

Comments
 (0)