Skip to content

Commit

Permalink
Merge pull request #164 from Flambe/master
Browse files Browse the repository at this point in the history
  • Loading branch information
drewish committed Jul 2, 2015
2 parents 656ed24 + 8cb3652 commit 72cc4cb
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Tests/Recurly/Coupon_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ public function testRedeemCoupon() {
$this->assertInstanceOf('Recurly_CouponRedemption', $redemption);
}

public function testGetCouponRedemptions() {
$this->client->addResponse('GET', 'https://api.recurly.com/v2/coupons/special/redemptions', 'coupons/show-redemptions-200.xml');

$coupon = Recurly_Coupon::get('special', $this->client);
$redemptions = $coupon->redemptions->get();

$this->assertInstanceOf('Recurly_CouponRedemptionList', $redemptions);
$this->assertEquals(2, $redemptions->count());
}

public function testRedeemCouponExpired() {
$this->client->addResponse('GET', '/coupons/expired', 'coupons/show-200-expired.xml');

Expand Down
25 changes: 25 additions & 0 deletions Tests/fixtures/coupons/show-redemptions-200.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
HTTP/1.1 200 OK
Content-Type: application/xml; charset=utf-8
Location: https://api.recurly.com/v2/coupons/special/redemptions

<?xml version="1.0" encoding="UTF-8"?>
<redemptions type="array">
<redemption href="https://api.recurly.com/v2/accounts/with_address/redemption">
<coupon href="https://api.recurly.com/v2/coupons/special"/>
<account href="https://api.recurly.com/v2/accounts/abcdef1234567890"/>
<single_use type="boolean">false</single_use>
<total_discounted_in_cents type="integer">0</total_discounted_in_cents>
<currency>USD</currency>
<state>active</state>
<created_at type="datetime">2014-01-06T19:06:35Z</created_at>
</redemption>
<redemption href="https://api.recurly.com/v2/accounts/with_address/redemption">
<coupon href="https://api.recurly.com/v2/coupons/special"/>
<account href="https://api.recurly.com/v2/accounts/1234567890abcdef"/>
<single_use type="boolean">false</single_use>
<total_discounted_in_cents type="integer">1238</total_discounted_in_cents>
<currency>USD</currency>
<state>active</state>
<created_at type="datetime">2014-01-14T13:27:53Z</created_at>
</redemption>
</redemptions>
1 change: 1 addition & 0 deletions lib/recurly.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
require_once(dirname(__FILE__) . '/recurly/plan.php');
require_once(dirname(__FILE__) . '/recurly/plan_list.php');
require_once(dirname(__FILE__) . '/recurly/redemption.php');
require_once(dirname(__FILE__) . '/recurly/redemption_list.php');
require_once(dirname(__FILE__) . '/recurly/subscription.php');
require_once(dirname(__FILE__) . '/recurly/subscription_list.php');
require_once(dirname(__FILE__) . '/recurly/subscription_addon.php');
Expand Down
1 change: 1 addition & 0 deletions lib/recurly/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ private function addLink($name, $href, $method){
'plan_codes' => 'array',
'pending_subscription' => 'Recurly_Subscription',
'redemption' => 'Recurly_CouponRedemption',
'redemptions' => 'Recurly_CouponRedemptionList',
'setup_fee_in_cents' => 'Recurly_CurrencyList',
'subscription' => 'Recurly_Subscription',
'subscriptions' => 'Recurly_SubscriptionList',
Expand Down
1 change: 1 addition & 0 deletions lib/recurly/client.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class Recurly_Client
const PATH_BILLING_INFO = '/billing_info';
const PATH_COUPON = '/coupon';
const PATH_COUPON_REDEMPTION = '/redemption';
const PATH_COUPON_REDEMPTIONS = '/redemptions';
const PATH_COUPONS = '/coupons';
const PATH_INVOICES = '/invoices';
const PATH_NOTES = '/notes';
Expand Down
15 changes: 15 additions & 0 deletions lib/recurly/redemption_list.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

class Recurly_CouponRedemptionList extends Recurly_Pager
{
public static function get($params = null, $client = null)
{
$list = new Recurly_CouponRedemptionList(Recurly_Client::PATH_COUPON_REDEMPTIONS, $client);
$list->_loadFrom(Recurly_Client::PATH_COUPON_REDEMPTIONS, $params);
return $list;
}

protected function getNodeName() {
return 'redemptions';
}
}

0 comments on commit 72cc4cb

Please sign in to comment.