Skip to content

Commit 09c14b5

Browse files
author
sunny
committed
Adds tax_service_opt_out to gift cards
1 parent 70513fe commit 09c14b5

File tree

5 files changed

+187
-1
lines changed

5 files changed

+187
-1
lines changed

Tests/Recurly/GiftCard_Test.php

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,126 @@ public function testRedeemGiftCard() {
5959
$this->assertInstanceOf('Recurly_Stub', $giftCard->gifter_account);
6060
$this->assertInstanceOf('Recurly_Delivery', $giftCard->delivery);
6161
}
62+
63+
// AC1: GIVEN I am creating a gift card purchase via the v2 /gift_cards endpoint
64+
// WHEN I pass in a value of true for tax_service_opt_out attribute
65+
// THEN I bypass the tax integration.
66+
public function testCreateGiftCardWithTaxServiceOptOutTrue() {
67+
$this->client->addResponse('POST', '/gift_cards', 'gift_cards/create-with-tax-opt-out-201.xml');
68+
69+
$giftCard = new Recurly_GiftCard(null, $this->client);
70+
$giftCard->product_code = 'gift_card';
71+
$giftCard->unit_amount_in_cents = 3000;
72+
$giftCard->currency = 'USD';
73+
$giftCard->tax_service_opt_out = true;
74+
75+
$delivery = new Recurly_Delivery();
76+
$delivery->method = 'email';
77+
$delivery->email_address = 'recipient2@example.com';
78+
$delivery->first_name = 'Bob';
79+
$delivery->last_name = 'Smith';
80+
$delivery->gifter_name = 'Alice Gifter';
81+
$giftCard->delivery = $delivery;
82+
83+
$gifterAccount = new Recurly_Stub('gifter_account', 'https://api.recurly.com/v2/accounts/gifter456');
84+
$giftCard->gifter_account = $gifterAccount;
85+
86+
$giftCard->create();
87+
88+
$this->assertInstanceOf('Recurly_GiftCard', $giftCard);
89+
$this->assertEquals($giftCard->redemption_code, 'BYPASS123CODE89');
90+
$this->assertEquals($giftCard->unit_amount_in_cents, '3000');
91+
}
92+
93+
// AC2: GIVEN I am creating a gift card purchase via the v2 /gift_cards endpoint
94+
// WHEN I pass in a value of false for tax_service_opt_out attribute
95+
// THEN send to the tax integration.
96+
public function testCreateGiftCardWithTaxServiceOptOutFalse() {
97+
$this->client->addResponse('POST', '/gift_cards', 'gift_cards/create-201.xml');
98+
99+
$giftCard = new Recurly_GiftCard(null, $this->client);
100+
$giftCard->product_code = 'gift_card';
101+
$giftCard->unit_amount_in_cents = 5000;
102+
$giftCard->currency = 'USD';
103+
$giftCard->tax_service_opt_out = false;
104+
105+
$delivery = new Recurly_Delivery();
106+
$delivery->method = 'email';
107+
$delivery->email_address = 'recipient@example.com';
108+
$delivery->first_name = 'Jane';
109+
$delivery->last_name = 'Doe';
110+
$delivery->gifter_name = 'John Gifter';
111+
$giftCard->delivery = $delivery;
112+
113+
$gifterAccount = new Recurly_Stub('gifter_account', 'https://api.recurly.com/v2/accounts/gifter123');
114+
$giftCard->gifter_account = $gifterAccount;
115+
116+
$giftCard->create();
117+
118+
$this->assertInstanceOf('Recurly_GiftCard', $giftCard);
119+
$this->assertEquals($giftCard->redemption_code, 'TEST123CODE4567');
120+
$this->assertEquals($giftCard->unit_amount_in_cents, '5000');
121+
}
122+
123+
// AC3: GIVEN I am creating a gift card via the v2 /gift_cards endpoint
124+
// WHEN I don't pass a value for tax_service_opt_out attribute
125+
// THEN send to the tax integration.
126+
public function testCreateGiftCardWithoutTaxServiceOptOut() {
127+
$this->client->addResponse('POST', '/gift_cards', 'gift_cards/create-201.xml');
128+
129+
$giftCard = new Recurly_GiftCard(null, $this->client);
130+
$giftCard->product_code = 'gift_card';
131+
$giftCard->unit_amount_in_cents = 5000;
132+
$giftCard->currency = 'USD';
133+
// Not setting tax_service_opt_out - should default to sending to tax integration
134+
135+
$delivery = new Recurly_Delivery();
136+
$delivery->method = 'email';
137+
$delivery->email_address = 'recipient@example.com';
138+
$delivery->first_name = 'Jane';
139+
$delivery->last_name = 'Doe';
140+
$delivery->gifter_name = 'John Gifter';
141+
$giftCard->delivery = $delivery;
142+
143+
$gifterAccount = new Recurly_Stub('gifter_account', 'https://api.recurly.com/v2/accounts/gifter123');
144+
$giftCard->gifter_account = $gifterAccount;
145+
146+
$giftCard->create();
147+
148+
$this->assertInstanceOf('Recurly_GiftCard', $giftCard);
149+
$this->assertEquals($giftCard->redemption_code, 'TEST123CODE4567');
150+
}
151+
152+
// AC4: GIVEN I am creating a gift card purchase via the v2 /gift_cards endpoint
153+
// WHEN I pass in a tax_service_opt_out value that isn't accepted
154+
// THEN I receive an API error response.
155+
public function testCreateGiftCardWithInvalidTaxServiceOptOut() {
156+
$this->client->addResponse('POST', '/gift_cards', 'gift_cards/create-invalid-tax-opt-out-422.xml');
157+
158+
$giftCard = new Recurly_GiftCard(null, $this->client);
159+
$giftCard->product_code = 'gift_card';
160+
$giftCard->unit_amount_in_cents = 5000;
161+
$giftCard->currency = 'USD';
162+
// Note: In PHP, the client lib will convert to boolean before sending,
163+
// but this test validates server-side error handling
164+
165+
$delivery = new Recurly_Delivery();
166+
$delivery->method = 'email';
167+
$delivery->email_address = 'recipient@example.com';
168+
$delivery->first_name = 'Jane';
169+
$delivery->last_name = 'Doe';
170+
$giftCard->delivery = $delivery;
171+
172+
$gifterAccount = new Recurly_Stub('gifter_account', 'https://api.recurly.com/v2/accounts/gifter123');
173+
$giftCard->gifter_account = $gifterAccount;
174+
175+
try {
176+
$giftCard->create();
177+
$this->fail("Expected Recurly_ValidationError");
178+
}
179+
catch (Recurly_ValidationError $e) {
180+
$this->assertEquals($e->errors[0]->symbol, 'invalid_value');
181+
}
182+
}
62183
}
184+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
HTTP/1.1 201 Created
2+
Content-Type: application/xml; charset=utf-8
3+
Location: https://api.recurly.com/v2/gift_cards/2038694498638568564.xml
4+
5+
<?xml version="1.0" encoding="UTF-8"?>
6+
<gift_card href="https://api.recurly.com/v2/gift_cards/2038694498638568564">
7+
<gifter_account href="https://api.recurly.com/v2/accounts/gifter123" />
8+
<invoice href="https://api.recurly.com/v2/invoices/2001" />
9+
<id type="integer">2038694498638568564</id>
10+
<redemption_code>TEST123CODE4567</redemption_code>
11+
<product_code>gift_card</product_code>
12+
<unit_amount_in_cents type="integer">5000</unit_amount_in_cents>
13+
<currency>USD</currency>
14+
<delivery>
15+
<method>email</method>
16+
<deliver_at nil="nil"></deliver_at>
17+
<email_address>recipient@example.com</email_address>
18+
<first_name>Jane</first_name>
19+
<last_name>Doe</last_name>
20+
<gifter_name>John Gifter</gifter_name>
21+
<personal_message>Enjoy your gift!</personal_message>
22+
</delivery>
23+
<created_at type="datetime">2023-12-01T10:00:00Z</created_at>
24+
<updated_at type="datetime">2023-12-01T10:00:00Z</updated_at>
25+
<delivered_at nil="nil"></delivered_at>
26+
<redeemed_at nil="nil"></redeemed_at>
27+
<canceled_at nil="nil"></canceled_at>
28+
</gift_card>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
HTTP/1.1 422 Unprocessable Entity
2+
Content-Type: application/xml; charset=utf-8
3+
4+
<?xml version="1.0" encoding="UTF-8"?>
5+
<errors>
6+
<error field="gift_card.tax_service_opt_out" symbol="invalid_value">is not a valid boolean value</error>
7+
</errors>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
HTTP/1.1 201 Created
2+
Content-Type: application/xml; charset=utf-8
3+
Location: https://api.recurly.com/v2/gift_cards/2038694498638568565.xml
4+
5+
<?xml version="1.0" encoding="UTF-8"?>
6+
<gift_card href="https://api.recurly.com/v2/gift_cards/2038694498638568565">
7+
<gifter_account href="https://api.recurly.com/v2/accounts/gifter456" />
8+
<invoice href="https://api.recurly.com/v2/invoices/2002" />
9+
<id type="integer">2038694498638568565</id>
10+
<redemption_code>BYPASS123CODE89</redemption_code>
11+
<product_code>gift_card</product_code>
12+
<unit_amount_in_cents type="integer">3000</unit_amount_in_cents>
13+
<currency>USD</currency>
14+
<delivery>
15+
<method>email</method>
16+
<deliver_at nil="nil"></deliver_at>
17+
<email_address>recipient2@example.com</email_address>
18+
<first_name>Bob</first_name>
19+
<last_name>Smith</last_name>
20+
<gifter_name>Alice Gifter</gifter_name>
21+
<personal_message>Special gift for you!</personal_message>
22+
</delivery>
23+
<created_at type="datetime">2023-12-01T11:00:00Z</created_at>
24+
<updated_at type="datetime">2023-12-01T11:00:00Z</updated_at>
25+
<delivered_at nil="nil"></delivered_at>
26+
<redeemed_at nil="nil"></redeemed_at>
27+
<canceled_at nil="nil"></canceled_at>
28+
</gift_card>

lib/recurly/gift_card.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* @property string $revenue_gl_account_id The ID of the revenue general ledger account associated with the gift card product.
1919
* @property string $performance_obligation_id The ID of the performance obligation associated with the gift card product.
2020
* @property Recurly_Delivery $delivery Block of delivery information.
21+
* @property boolean $tax_service_opt_out Optional. If true, bypasses the tax integration for this gift card purchase. If false or omitted, the purchase is sent to the tax integration.
2122
* @property DateTime $created_at The date and time the gift card was created in Recurly.
2223
* @property DateTime $updated_at The date and time the gift card was last updated.
2324
* @property DateTime $delivered_at When the gift card was sent to the recipient by Recurly via email, if method was email and the "Gift Card Delivery" email template was enabled. This will be empty for post delivery or email delivery where the email template was disabled.
@@ -88,7 +89,7 @@ protected function getWriteableAttributes() {
8889
return array(
8990
'product_code','unit_amount_in_cents','delivery',
9091
'gifter_account','currency',
91-
'billing_info'
92+
'billing_info','tax_service_opt_out'
9293
);
9394
}
9495
}

0 commit comments

Comments
 (0)