Skip to content

Commit

Permalink
[API V2] Client Library and Doc Update - PHP
Browse files Browse the repository at this point in the history
Description:
Created CurrencyPercentageTier and PercentageTier resources.
Created test cases to new resources.
Updated test cases of Addon and Subscription.
  • Loading branch information
paulorbpinho-fullstacklabs committed Apr 25, 2022
1 parent e9ba50f commit a308f0f
Show file tree
Hide file tree
Showing 11 changed files with 537 additions and 33 deletions.
68 changes: 66 additions & 2 deletions Tests/Recurly/Addon_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ public function testCreateXmlItemBackedAddOn() {
$addon->item_code = $item->item_code;
$addon->unit_amount_in_cents->addCurrency('USD', 400);

$this->assertEquals("<?xml version=\"1.0\"?>\n<add_on><item_code>little_llama</item_code><unit_amount_in_cents><USD>400</USD></unit_amount_in_cents></add_on>\n", $addon->xml());
$this->assertXmlStringEqualsXmlString("
<add_on>
<item_code>little_llama</item_code>
<unit_amount_in_cents>
<USD>400</USD>
</unit_amount_in_cents>
</add_on>", $addon->xml());
}

public function testCreateXmlTieredAddOn() {
Expand All @@ -57,6 +63,64 @@ public function testCreateXmlTieredAddOn() {

$addon->tiers = array($tier1, $tier2);

$this->assertEquals("<?xml version=\"1.0\"?>\n<add_on><add_on_code>little_llama</add_on_code><tier_type>tiered</tier_type><tiers><tier><unit_amount_in_cents><USD>400</USD></unit_amount_in_cents><ending_quantity>800</ending_quantity></tier><tier><unit_amount_in_cents><USD>200</USD></unit_amount_in_cents></tier></tiers></add_on>\n", $addon->xml());
$this->assertXmlStringEqualsXmlString("
<add_on>
<add_on_code>little_llama</add_on_code>
<tier_type>tiered</tier_type>
<tiers>
<tier>
<unit_amount_in_cents>
<USD>400</USD>
</unit_amount_in_cents>
<ending_quantity>800</ending_quantity>
</tier>
<tier>
<unit_amount_in_cents>
<USD>200</USD>
</unit_amount_in_cents>
</tier>
</tiers>
</add_on>", $addon->xml());
}

public function testCreateXmlPercentageTieredAddOn() {
$item = new Recurly_Item();
$addon = new Recurly_Addon();
$addon->plan_code = 'gold';
$addon->add_on_code = 'little_llama';
$addon->tier_type = 'tiered';

$percentage_tier = new Recurly_PercentageTier();
$percentage_tier->currency = 'USD';
$tier = new Recurly_CurrencyPercentageTier();
$tier->ending_amount_in_cents = 100;
$tier->usage_percentage = '10.0';
$tier2 = new Recurly_CurrencyPercentageTier();
$tier2->ending_amount_in_cents = null;
$tier2->usage_percentage = '20.0';
$percentage_tier->tiers = array($tier, $tier2);

$addon->percentage_tiers = array($percentage_tier);

$this->assertXmlStringEqualsXmlString("
<add_on>
<add_on_code>little_llama</add_on_code>
<tier_type>tiered</tier_type>
<percentage_tiers>
<percentage_tier>
<currency>USD</currency>
<tiers>
<tier>
<ending_amount_in_cents>100</ending_amount_in_cents>
<usage_percentage>10.0</usage_percentage>
</tier>
<tier>
<ending_amount_in_cents nil=\"nil\"></ending_amount_in_cents>
<usage_percentage>20.0</usage_percentage>
</tier>
</tiers>
</percentage_tier>
</percentage_tiers>
</add_on>\n", $addon->xml());
}
}
36 changes: 36 additions & 0 deletions Tests/Recurly/Currency_Percentage_Tier_Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php


class Recurly_CurrencyPercentageTierTest extends Recurly_TestCase
{
public function testCreateXml() {
$percentageTierByCurrency = new Recurly_CurrencyPercentageTier();
$percentageTierByCurrency->ending_amount_in_cents = 100;
$percentageTierByCurrency->usage_percentage = '10.0';

$doc = new DOMDocument("1.0");
$root = $doc->appendChild($doc->createElement('tiers'));
$percentageTierByCurrency->populateXmlDoc($doc, $root, $percentageTierByCurrency);

$this->assertXmlStringEqualsXmlString(
"<tiers>
<tier>
<ending_amount_in_cents>100</ending_amount_in_cents>
<usage_percentage>10.0</usage_percentage>
</tier>
</tiers>", $doc->saveXml());
}

public function testCreateXml_EmptyCreatesNoElement() {
$percentageTierByCurrency = new Recurly_CurrencyPercentageTier();

$doc = new DOMDocument("1.0");
$root = $doc->appendChild($doc->createElement('wrapper'));
$percentageTierByCurrency->populateXmlDoc($doc, $root, $percentageTierByCurrency);

$this->assertEquals(
"<?xml version=\"1.0\"?>\n<wrapper/>\n",
$doc->saveXml()
);
}
}
51 changes: 51 additions & 0 deletions Tests/Recurly/Percentage_Tier_Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php


class Recurly_PercentageTierTest extends Recurly_TestCase
{
public function testCreateXml() {
$percentageTier = new Recurly_PercentageTier();
$percentageTier->currency = 'USD';
$percentageTierByCurrency = new Recurly_CurrencyPercentageTier();
$percentageTierByCurrency->ending_amount_in_cents = 100;
$percentageTierByCurrency->usage_percentage = '10.0';
$percentageTierByCurrency2 = new Recurly_CurrencyPercentageTier();
$percentageTierByCurrency2->ending_amount_in_cents = null;
$percentageTierByCurrency2->usage_percentage = '20.0';
$percentageTier->tiers = array($percentageTierByCurrency, $percentageTierByCurrency2);

$doc = new DOMDocument("1.0");
$root = $doc->appendChild($doc->createElement('percentage_tiers'));
$percentageTier->populateXmlDoc($doc, $root, $percentageTier);

$this->assertXmlStringEqualsXmlString(
"<percentage_tiers>
<percentage_tier>
<currency>USD</currency>
<tiers>
<tier>
<ending_amount_in_cents>100</ending_amount_in_cents>
<usage_percentage>10.0</usage_percentage>
</tier>
<tier>
<ending_amount_in_cents nil=\"nil\"/>
<usage_percentage>20.0</usage_percentage>
</tier>
</tiers>
</percentage_tier>
</percentage_tiers>", $doc->saveXml());
}

public function testCreateXml_EmptyCreatesNoElement() {
$percentageTier = new Recurly_PercentageTier();

$doc = new DOMDocument("1.0");
$root = $doc->appendChild($doc->createElement('wrapper'));
$percentageTier->populateXmlDoc($doc, $root, $percentageTier);

$this->assertEquals(
"<?xml version=\"1.0\"?>\n<wrapper/>\n",
$doc->saveXml()
);
}
}
Loading

0 comments on commit a308f0f

Please sign in to comment.