-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
341 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,4 +21,4 @@ public function testDelete() { | |
$this->assertInstanceOf('Recurly_Addon', $addon); | ||
$addon->delete(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
require_once(__DIR__ . '/../test_helpers.php'); | ||
|
||
class Recurly_MeasuredUnitListTest extends Recurly_TestCase | ||
{ | ||
public function testGetMeasuredUnits() { | ||
$this->client->addResponse('GET', '/measured_units', 'measured_units/index-200.xml'); | ||
|
||
$measured_units = Recurly_MeasuredUnitList::get(null, $this->client); | ||
|
||
$this->assertInstanceOf('Recurly_MeasuredUnitList', $measured_units); | ||
$this->assertEquals(2, $measured_units->count()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
require_once(__DIR__ . '/../test_helpers.php'); | ||
|
||
class Recurly_MeasuredUnitTest extends Recurly_TestCase | ||
{ | ||
public function testGetMeasuredUnit() { | ||
$this->client->addResponse('GET', '/measured_units/123456', 'measured_units/show-200.xml'); | ||
|
||
$measured_unit = Recurly_MeasuredUnit::get(123456, $this->client); | ||
|
||
$this->assertInstanceOf('Recurly_MeasuredUnit', $measured_unit); | ||
$this->assertEquals(123456, $measured_unit->id); | ||
$this->assertEquals('Marketing Emails', $measured_unit->name); | ||
$this->assertEquals('Email', $measured_unit->display_name); | ||
$this->assertEquals('A Marketing Email', $measured_unit->description); | ||
} | ||
|
||
public function testCreateMeasuredUnit() { | ||
$this->client->addResponse('POST', '/measured_units', 'measured_units/create-201.xml'); | ||
|
||
$measured_unit = new Recurly_MeasuredUnit(null, $this->client); | ||
|
||
$measured_unit->name = 'Marketing Emails'; | ||
$measured_unit->display_name = 'Emails'; | ||
$measured_unit->description = 'A Marketing Email'; | ||
|
||
$measured_unit->create(); | ||
|
||
$this->assertInstanceOf('Recurly_MeasuredUnit', $measured_unit); | ||
$this->assertEquals(123456, $measured_unit->id); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
require_once(__DIR__ . '/../test_helpers.php'); | ||
|
||
class Recurly_UsageTest extends Recurly_TestCase | ||
{ | ||
public function testGetUsage() { | ||
$this->client->addResponse('GET', '/subscriptions/012345678901234567890123456789ab/add_ons/marketing_emails/usage/123456', 'usage/show-200.xml'); | ||
|
||
$usage = Recurly_Usage::get('012345678901234567890123456789ab', 'marketing_emails', 123456, $this->client); | ||
|
||
$this->assertInstanceOf('Recurly_Usage', $usage); | ||
$this->assertInstanceOf('Recurly_Stub', $usage->measured_unit); | ||
$this->assertEquals(6, $usage->amount); | ||
$this->assertEquals('Order Number: #198349243975', $usage->merchant_tag); | ||
$this->assertEquals('PERCENTAGE', $usage->usage_type); | ||
$this->assertEquals(1.25, $usage->usage_percentage); | ||
} | ||
|
||
public function testCreateUsage() { | ||
$this->client->addResponse('POST', '/subscriptions/012345678901234567890123456789ab/add_ons/marketing_emails/usage', 'usage/create-201.xml'); | ||
|
||
$usage = Recurly_Usage::build('012345678901234567890123456789ab', 'marketing_emails', $this->client); | ||
|
||
$usage->create(); | ||
|
||
$this->assertInstanceOf('Recurly_Usage', $usage); | ||
$this->assertInstanceOf('Recurly_Stub', $usage->measured_unit); | ||
} | ||
|
||
public function testCreateUsageFromSubscription() { | ||
$this->client->addResponse('GET', '/subscriptions/012345678901234567890123456789ab', 'subscriptions/show-200.xml'); | ||
$this->client->addResponse('POST', '/subscriptions/012345678901234567890123456789ab/add_ons/marketing_emails/usage', 'usage/create-201.xml'); | ||
|
||
$subscription = Recurly_Subscription::get('012345678901234567890123456789ab', $this->client); | ||
$usage = $subscription->buildUsage('marketing_emails', $this->client); | ||
|
||
$usage->create(); | ||
|
||
$this->assertInstanceOf('Recurly_Usage', $usage); | ||
$this->assertInstanceOf('Recurly_Stub', $usage->measured_unit); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
HTTP/1.1 201 Created | ||
Content-Type: application/xml; charset=utf-8 | ||
|
||
<?xml version="1.0" encoding="UTF-8"?> | ||
<measured_unit href="https://api.recurly.com/v2/measured_units/123456"> | ||
<id type="integer">123456</id> | ||
<name>Marketing Emails</name> | ||
<display_name>Email</display_name> | ||
<description>A Marketing Email</description> | ||
</measured_unit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
HTTP/1.1 200 OK | ||
Content-Type: application/xml; charset=utf-8 | ||
X-Records: 2 | ||
|
||
<?xml version="1.0" encoding="UTF-8"?> | ||
<measured_units> | ||
<measured_unit href="https://api.recurly.com/v2/measured_units/123456"> | ||
<id type="integer">123456</id> | ||
<name>Marketing Emails</name> | ||
<display_name>Email</display_name> | ||
<description>A Marketing Email</description> | ||
</measured_unit> | ||
<measured_unit href="https://api.recurly.com/v2/measured_units/654321"> | ||
<id type="integer">654321</id> | ||
<name>Another Unit</name> | ||
<display_name>Another</display_name> | ||
<description>Another Measured Unit</description> | ||
</measured_unit> | ||
</measured_units> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
HTTP/1.1 200 OK | ||
Content-Type: application/xml; charset=utf-8 | ||
|
||
<?xml version="1.0" encoding="UTF-8"?> | ||
<measured_unit href="https://api.recurly.com/v2/measured_units/123456"> | ||
<id type="integer">123456</id> | ||
<name>Marketing Emails</name> | ||
<display_name>Email</display_name> | ||
<description>A Marketing Email</description> | ||
</measured_unit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
HTTP/1.1 201 Created | ||
Content-Type: application/xml; charset=utf-8 | ||
|
||
<?xml version="1.0" encoding="UTF-8"?> | ||
<usage href="https://api.recurly.com/v2/subscriptions/012345678901234567890123456789ab/add_ons/marketing_emails/usage/123456"> | ||
<measured_unit href="https://yoursubdomain.recurly.com/v2/measured_units/7610" /> | ||
<amount type="integer">6</amount> | ||
<merchant_tag>Order Number: #198349243975</merchant_tag> | ||
<recording_timestamp type="date">2016-03-15T23:17:15+00:00</recording_timestamp> | ||
<usage_timestamp type="date">2016-03-15T23:17:14+00:00</usage_timestamp> | ||
<created_at type="date">2016-03-15T23:18:12+00:00</created_at> | ||
<updated_at nil="nil"></updated_at> | ||
<billed_at nil="nil"></billed_at> | ||
<usage_type>percentage</usage_type> | ||
<unit_amount_in_cents nil="nil"></unit_amount_in_cents> | ||
<usage_percentage type="float">1.25</usage_percentage> | ||
</usage> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
HTTP/1.1 200 OK | ||
Content-Type: application/xml; charset=utf-8 | ||
|
||
<?xml version="1.0" encoding="UTF-8"?> | ||
<usage href="https://api.recurly.com/v2/subscriptions/012345678901234567890123456789ab/add_ons/marketing_emails/usage/123456"> | ||
<measured_unit href="https://yoursubdomain.recurly.com/v2/measured_units/7610" /> | ||
<amount type="integer">6</amount> | ||
<merchant_tag>Order Number: #198349243975</merchant_tag> | ||
<recording_timestamp type="date">2016-03-15T23:17:15+00:00</recording_timestamp> | ||
<usage_timestamp type="date">2016-03-15T23:17:14+00:00</usage_timestamp> | ||
<created_at type="date">2016-03-15T23:18:12+00:00</created_at> | ||
<updated_at nil="nil"></updated_at> | ||
<billed_at nil="nil"></billed_at> | ||
<usage_type>PERCENTAGE</usage_type> | ||
<unit_amount_in_cents nil="nil"></unit_amount_in_cents> | ||
<usage_percentage type="float">1.25</usage_percentage> | ||
</usage> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
class Recurly_MeasuredUnit extends Recurly_Resource | ||
{ | ||
protected static $_writeableAttributes; | ||
|
||
public static function init() | ||
{ | ||
Recurly_MeasuredUnit::$_writeableAttributes = array( | ||
'name','display_name','description' | ||
); | ||
} | ||
|
||
public function create() { | ||
$this->_save(Recurly_Client::POST, Recurly_Client::PATH_MEASURED_UNITS); | ||
} | ||
|
||
public static function get($id, $client = null) { | ||
return Recurly_Base::_get(Recurly_MeasuredUnit::uriForMeasuredUnit($id), $client); | ||
} | ||
|
||
protected function uri() { | ||
if (!empty($this->_href)) | ||
return $this->getHref(); | ||
else | ||
return Recurly_Addon::uriForMeasuredUnit($this->id); | ||
} | ||
protected static function uriForMeasuredUnit($id) { | ||
return Recurly_Client::PATH_MEASURED_UNITS . '/' . rawurlencode($id); | ||
} | ||
|
||
protected function getNodeName() { | ||
return 'measured_unit'; | ||
} | ||
protected function getWriteableAttributes() { | ||
return Recurly_MeasuredUnit::$_writeableAttributes; | ||
} | ||
protected function getRequiredAttributes() { | ||
return array(); | ||
} | ||
} | ||
|
||
Recurly_MeasuredUnit::init(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
class Recurly_MeasuredUnitList extends Recurly_Pager | ||
{ | ||
public static function get($params = null, $client = null) { | ||
$uri = self::_uriWithParams(Recurly_Client::PATH_MEASURED_UNITS, $params); | ||
return new self($uri, $client); | ||
} | ||
|
||
protected function getNodeName() { | ||
return 'measured_units'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.