Skip to content

Commit

Permalink
Merge pull request #638 from recurly/Client-Lib-Updates-V2-For-Dunnin…
Browse files Browse the repository at this point in the history
…g-Campaigns

Client lib updates for v2 dunning campaigns
  • Loading branch information
judith committed Oct 27, 2021
2 parents da24837 + f7bc8ff commit 9877c92
Show file tree
Hide file tree
Showing 24 changed files with 429 additions and 12 deletions.
4 changes: 3 additions & 1 deletion Tests/Recurly/Account_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public function testGetAccount() {
$this->assertEquals($account->cc_emails, 'cheryl.hines@example.com,richard.lewis@example.com');
$this->assertEquals($account->has_paused_subscription, false);
$this->assertEquals($account->preferred_locale, 'en-US');
$this->assertEquals($account->dunning_campaign_id, '1234abcd');

$this->assertInstanceOf('Recurly_CustomFieldList', $account->custom_fields);
$this->assertCount(2, $account->custom_fields);
Expand Down Expand Up @@ -103,6 +104,7 @@ public function testXml() {
$account->exemption_certificate = 'Some Certificate';
$account->entity_use_code = 'I';
$account->preferred_locale = 'en-US';
$account->dunning_campaign_id = '1234abcd';

$account_acquisition = new Recurly_AccountAcquisition();
$account_acquisition->cost_in_cents = 599;
Expand Down Expand Up @@ -145,7 +147,7 @@ public function testXml() {
$account->custom_fields[] = new Recurly_CustomField("serial_number", "4567-8900-1234");

$this->assertEquals(
"<?xml version=\"1.0\"?>\n<account><account_code>act123</account_code><first_name>Verena</first_name><address><address1>123 Main St.</address1></address><tax_exempt>false</tax_exempt><entity_use_code>I</entity_use_code><shipping_addresses><shipping_address><address1>123 Main St.</address1><city>San Francisco</city><state>CA</state><zip>94110</zip><country>US</country><phone>555-555-5555</phone><email>verena@example.com</email><nickname>Work</nickname><first_name>Verena</first_name><last_name>Example</last_name><company>Recurly Inc.</company></shipping_address><shipping_address><address1>123 Dolores St.</address1><city>San Francisco</city><state>CA</state><zip>94110</zip><country>US</country><phone>555-555-5555</phone><email>verena@example.com</email><nickname>Home</nickname><first_name>Verena</first_name><last_name>Example</last_name></shipping_address></shipping_addresses><preferred_locale>en-US</preferred_locale><custom_fields><custom_field><name>serial_number</name><value>4567-8900-1234</value></custom_field></custom_fields><account_acquisition><cost_in_cents>599</cost_in_cents><currency>USD</currency><channel>marketing_content</channel><subchannel>pickle sticks blog post</subchannel><campaign>mailchimp67a904de95.0914d8f4b4</campaign></account_acquisition><exemption_certificate>Some Certificate</exemption_certificate></account>\n",
"<?xml version=\"1.0\"?>\n<account><account_code>act123</account_code><first_name>Verena</first_name><address><address1>123 Main St.</address1></address><tax_exempt>false</tax_exempt><entity_use_code>I</entity_use_code><shipping_addresses><shipping_address><address1>123 Main St.</address1><city>San Francisco</city><state>CA</state><zip>94110</zip><country>US</country><phone>555-555-5555</phone><email>verena@example.com</email><nickname>Work</nickname><first_name>Verena</first_name><last_name>Example</last_name><company>Recurly Inc.</company></shipping_address><shipping_address><address1>123 Dolores St.</address1><city>San Francisco</city><state>CA</state><zip>94110</zip><country>US</country><phone>555-555-5555</phone><email>verena@example.com</email><nickname>Home</nickname><first_name>Verena</first_name><last_name>Example</last_name></shipping_address></shipping_addresses><preferred_locale>en-US</preferred_locale><custom_fields><custom_field><name>serial_number</name><value>4567-8900-1234</value></custom_field></custom_fields><account_acquisition><cost_in_cents>599</cost_in_cents><currency>USD</currency><channel>marketing_content</channel><subchannel>pickle sticks blog post</subchannel><campaign>mailchimp67a904de95.0914d8f4b4</campaign></account_acquisition><exemption_certificate>Some Certificate</exemption_certificate><dunning_campaign_id>1234abcd</dunning_campaign_id></account>\n",
$account->xml()
);
}
Expand Down
16 changes: 16 additions & 0 deletions Tests/Recurly/DunningCampaign_List_Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

class RecurlyDunningCampaignListTest extends Recurly_TestCase
{
function defaultResponses() {
return array(
array('GET', '/dunning_campaigns', 'dunning_campaigns/index-200.xml')
);
}

public function testLoad() {
$dunning_campaigns = Recurly_DunningCampaignList::get(null, $this->client);

$this->assertInstanceOf('Recurly_DunningCampaignList', $dunning_campaigns);
}
}
49 changes: 49 additions & 0 deletions Tests/Recurly/DunningCampaign_Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

class Recurly_DunningCampaignTest extends Recurly_TestCase
{
function defaultResponses() {
return array(
array('GET', '/dunning_campaigns/1234abcd', 'dunning_campaigns/show-200.xml'),
);
}

public function testGetSingleDunningCampaign() {
$dunning_campaign = Recurly_DunningCampaign::get('1234abcd', $this->client);

$this->assertInstanceOf('Recurly_DunningCampaign', $dunning_campaign);
$this->assertEquals(3, $dunning_campaign->dunning_cycles[0]->intervals[0]->days);
}

public function testBulkUpdateSuccess() {
$this->client->addResponse('PUT', '/dunning_campaigns/1234abcd/bulk_update', 'dunning_campaigns/update-204.xml');

$dunning_campaign = Recurly_DunningCampaign::get('1234abcd', $this->client);

$plan_1 = new Recurly_Plan();
$plan_1->plan_code = 'platinum';
$plan_1->name = 'Platinum & Gold Plan';
$plan_1->unit_amount_in_cents->addCurrency('USD', 1500);
$plan_1->unit_amount_in_cents->addCurrency('EUR', 1200);
$plan_1->setup_fee_in_cents->addCurrency('EUR', 500);
$plan_1->trial_requires_billing_info = false;
$plan_1->total_billing_cycles = 6;
$plan_1->auto_renew = false;

$bulk_update_response = $dunning_campaign->bulkUpdate([$plan_1->plan_code]);

$this->assertNull($bulk_update_response);
}

public function testBulkUpdateFailure() {
$this->client->addResponse('PUT', '/dunning_campaigns/1234abcd/bulk_update', 'dunning_campaigns/update-404.xml');

$dunning_campaign = Recurly_DunningCampaign::get('1234abcd', $this->client);

try {
$bulk_update_response = $dunning_campaign->bulkUpdate(['foo']);
} catch (Exception $e) {
$this->assertInstanceOf('Recurly_NotFoundError', $e);
}
}
}
1 change: 1 addition & 0 deletions Tests/Recurly/Invoice_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public function testGetInvoice() {
$this->assertEquals($invoice->customer_notes, 'Some Customer Notes');
$this->assertEquals($invoice->vat_reverse_charge_notes, 'Some VAT Notes');
$this->assertEquals($invoice->invoice_number_prefix, '');
$this->assertEquals($invoice->dunning_campaign_id, '1234abcd');
$this->assertEquals($invoice->invoiceNumberWithPrefix(), '1001');
}

Expand Down
7 changes: 5 additions & 2 deletions Tests/Recurly/Plan_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function testGetPlan() {
$this->assertEquals(500, $plan->setup_fee_in_cents['USD']->amount_in_cents);
$this->assertEquals(400, $plan->setup_fee_in_cents['EUR']->amount_in_cents);
$this->assertTrue($plan->tax_exempt);
$this->assertEquals('1234abcd', $plan->dunning_campaign_id);
}

public function testDeletePlan() {
Expand All @@ -60,9 +61,10 @@ public function testCreateXml() {
$plan->trial_requires_billing_info = false;
$plan->total_billing_cycles = 6;
$plan->auto_renew = false;
$plan->dunning_campaign_id = '1234abcd';

$this->assertEquals(
"<?xml version=\"1.0\"?>\n<plan><plan_code>platinum</plan_code><name>Platinum &amp; Gold Plan</name><unit_amount_in_cents><USD>1500</USD><EUR>1200</EUR></unit_amount_in_cents><setup_fee_in_cents><EUR>500</EUR></setup_fee_in_cents><total_billing_cycles>6</total_billing_cycles><trial_requires_billing_info>false</trial_requires_billing_info><auto_renew>false</auto_renew></plan>\n",
"<?xml version=\"1.0\"?>\n<plan><plan_code>platinum</plan_code><name>Platinum &amp; Gold Plan</name><unit_amount_in_cents><USD>1500</USD><EUR>1200</EUR></unit_amount_in_cents><setup_fee_in_cents><EUR>500</EUR></setup_fee_in_cents><total_billing_cycles>6</total_billing_cycles><trial_requires_billing_info>false</trial_requires_billing_info><auto_renew>false</auto_renew><dunning_campaign_id>1234abcd</dunning_campaign_id></plan>\n",
$plan->xml()
);
}
Expand All @@ -78,9 +80,10 @@ public function testUpdateXml() {
$plan->tax_exempt = false;
$plan->trial_requires_billing_info = false;
$plan->tax_code = 'fake-tax-code';
$plan->dunning_campaign_id = '1234abcd';

$this->assertEquals(
"<?xml version=\"1.0\"?>\n<plan><plan_code>platinum</plan_code><name>Platinum Plan</name><unit_amount_in_cents><USD>1500</USD><EUR>1200</EUR></unit_amount_in_cents><setup_fee_in_cents><USD>500</USD><EUR>500</EUR></setup_fee_in_cents><total_billing_cycles nil=\"nil\"></total_billing_cycles><tax_exempt>false</tax_exempt><tax_code>fake-tax-code</tax_code><trial_requires_billing_info>false</trial_requires_billing_info></plan>\n",
"<?xml version=\"1.0\"?>\n<plan><plan_code>platinum</plan_code><name>Platinum Plan</name><unit_amount_in_cents><USD>1500</USD><EUR>1200</EUR></unit_amount_in_cents><setup_fee_in_cents><USD>500</USD><EUR>500</EUR></setup_fee_in_cents><total_billing_cycles nil=\"nil\"></total_billing_cycles><tax_exempt>false</tax_exempt><tax_code>fake-tax-code</tax_code><trial_requires_billing_info>false</trial_requires_billing_info><dunning_campaign_id>1234abcd</dunning_campaign_id></plan>\n",
$plan->xml()
);
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/Recurly/Purchase_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public function mockPurchase() {
$purchase->account->address->country = "US";
$purchase->account->billing_info = new Recurly_BillingInfo();
$purchase->account->billing_info->token_id = '7z6furn4jvb9';
$purchase->account->dunning_campaign_id = '1234abcd';

$shipping_address = new Recurly_ShippingAddress();
$shipping_address->first_name = 'Dolores';
Expand Down Expand Up @@ -62,7 +63,7 @@ public function testXml() {
$purchase = $this->mockPurchase();

$this->assertEquals(
"<?xml version=\"1.0\"?>\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></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\"?>\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",
$purchase->xml()
);
}
Expand Down Expand Up @@ -153,4 +154,3 @@ public function testTransactionError() {
}
}
}

9 changes: 5 additions & 4 deletions Tests/Recurly/Subscription_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public function testCreateSubscriptionXml() {
$account->last_name = 'Example';
$account->email = 'verena@example.com';
$account->accept_language = 'en-US';
$account->dunning_campaign_id = '1234abcd';

$billing_info = new Recurly_BillingInfo();
$billing_info->first_name = 'Verena';
Expand Down Expand Up @@ -116,7 +117,7 @@ public function testCreateSubscriptionXml() {
$subscription->renewal_billing_cycles = 1;

$this->assertEquals(
"<?xml version=\"1.0\"?>\n<subscription><account><account_code>account_code</account_code><username>username</username><first_name>Verena</first_name><last_name>Example</last_name><email>verena@example.com</email><accept_language>en-US</accept_language><billing_info><first_name>Verena</first_name><last_name>Example</last_name><ip_address>192.168.0.1</ip_address><number>4111-1111-1111-1111</number><month>11</month><year>2015</year><verification_value>123</verification_value></billing_info></account><plan_code>gold</plan_code><quantity>1</quantity><currency>USD</currency><subscription_add_ons></subscription_add_ons><bulk>true</bulk><terms_and_conditions>Some Terms and Conditions</terms_and_conditions><customer_notes>Some Customer Notes</customer_notes><shipping_address><address1>123 Main St.</address1><city>San Francisco</city><state>CA</state><zip>94110</zip><country>US</country><phone>555-555-5555</phone><email>verena@example.com</email><nickname>Work</nickname><first_name>Verena</first_name><last_name>Example</last_name><company>Recurly Inc.</company></shipping_address><custom_fields><custom_field><name>serial_number</name><value>4567-8900-1234</value></custom_field></custom_fields><auto_renew>false</auto_renew><renewal_billing_cycles>1</renewal_billing_cycles></subscription>\n",
"<?xml version=\"1.0\"?>\n<subscription><account><account_code>account_code</account_code><username>username</username><first_name>Verena</first_name><last_name>Example</last_name><email>verena@example.com</email><accept_language>en-US</accept_language><billing_info><first_name>Verena</first_name><last_name>Example</last_name><ip_address>192.168.0.1</ip_address><number>4111-1111-1111-1111</number><month>11</month><year>2015</year><verification_value>123</verification_value></billing_info><dunning_campaign_id>1234abcd</dunning_campaign_id></account><plan_code>gold</plan_code><quantity>1</quantity><currency>USD</currency><subscription_add_ons></subscription_add_ons><bulk>true</bulk><terms_and_conditions>Some Terms and Conditions</terms_and_conditions><customer_notes>Some Customer Notes</customer_notes><shipping_address><address1>123 Main St.</address1><city>San Francisco</city><state>CA</state><zip>94110</zip><country>US</country><phone>555-555-5555</phone><email>verena@example.com</email><nickname>Work</nickname><first_name>Verena</first_name><last_name>Example</last_name><company>Recurly Inc.</company></shipping_address><custom_fields><custom_field><name>serial_number</name><value>4567-8900-1234</value></custom_field></custom_fields><auto_renew>false</auto_renew><renewal_billing_cycles>1</renewal_billing_cycles></subscription>\n",
$subscription->xml()
);
}
Expand Down Expand Up @@ -332,7 +333,7 @@ public function testPostponeSubscription() {
$subscription = Recurly_Subscription::get('012345678901234567890123456789ab', $this->client);

$subscription->postpone(date('c', strtotime('2019-12-31Z')));

$this->assertEquals(new DateTime('2019-12-31Z'), $subscription->current_period_ends_at);
}

Expand All @@ -355,10 +356,10 @@ public function testConvertTrialWith3DSToken() {
public function testConvertTrialWithout3DSToken() {
$this->client->addResponse('GET', '/subscriptions/012345678901234567890123456789ab', 'subscriptions/show-200-trial.xml');
$this->client->addResponse('PUT', 'https://api.recurly.com/v2/subscriptions/012345678901234567890123456789ab/convert_trial', 'subscriptions/convert-trial-200.xml');
$subscription = Recurly_Subscription::get('012345678901234567890123456789ab', $this->client);
$subscription = Recurly_Subscription::get('012345678901234567890123456789ab', $this->client);
$subscription->convertTrial();
$this->assertEquals($subscription->trial_ends_at, $subscription->current_period_started_at);
}


}
}
1 change: 1 addition & 0 deletions Tests/fixtures/accounts/show-200.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ Content-Type: application/xml; charset=utf-8
<has_past_due_invoice type="boolean">false</has_past_due_invoice>
<has_paused_subscription type="boolean">false</has_paused_subscription>
<vat_location_valid type="boolean">true</vat_location_valid>
<dunning_campaign_id>1234abcd</dunning_campaign_id>
</account>
Loading

0 comments on commit 9877c92

Please sign in to comment.