Skip to content

Commit

Permalink
adjust metered billing and three d secure endpoints and added test
Browse files Browse the repository at this point in the history
  • Loading branch information
adamaltman committed Jan 15, 2014
1 parent 8d52946 commit 233ea21
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 35 deletions.
12 changes: 6 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 5 additions & 8 deletions lib/RebillyMeteredBilling.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
*/
class RebillyMeteredBilling extends RebillyRequest
{
const URL = 'meteredBilling/';
const TYPE_DEBIT = 'debit';
const TYPE_CREDIT = 'credit';

/**
* @var string $itemId the id assigned to the item by the Merchant
*/
public $itemId;
/**
* @var string $type Can be 'DEBIT' or 'CREDIT'
Expand Down Expand Up @@ -39,13 +43,6 @@ public function __construct($attributes)
}
}

public function retrieve()
{
$this->setApiController(self::URL . $this->itemId);

return $this->sendGetRequest();
}

/**
* Return all the property of this class
* @param $class
Expand Down
24 changes: 6 additions & 18 deletions lib/RebillySubscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*/
class RebillySubscription extends RebillyRequest
{

const SUBSCRIPTION_URL = 'subscriptions/';
/**
* @var string $websiteId unique id for each website
*/
Expand Down Expand Up @@ -83,27 +85,13 @@ public function __construct($id = null)
}

/**
* Send POST request to Rebilly
* @return RebillyResponse response from Rebilly
*/
public function createThreeDSecure()
{
$this->setApiController(RebillyThreeDSecure::THREE_D_SECURE_URL);

$data = $this->buildRequest($this);

return $this->sendPostRequest($data, get_class());
}

/**
* Create Metered Billing
* @return RebillyResponse
* Sends the request to Rebilly's endpoint and returns the prepared response.
* @return array the api prepared response
*/
public function createMeteredBilling()
public function create()
{
$this->setApiController(RebillyMeteredBilling::URL);
$this->setApiController(self::SUBSCRIPTION_URL);
$data = $this->buildRequest($this);

return $this->sendPostRequest($data);
}

Expand Down
2 changes: 0 additions & 2 deletions lib/RebillyThreeDSecure.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
*/
class RebillyThreeDSecure
{

const THREE_D_SECURE_URL = 'threeDSecure/';
/**
* @var string
*/
Expand Down
21 changes: 21 additions & 0 deletions tests/unit/RebillyMeteredBillingTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

class RebillyMeteredBilling extends \Codeception\TestCase\Test
{
public function testMeteredBillingPost()
{
$subscription = new RebillySubscription('subscriptionId123');
$subscription->setApiKey('apiKey');
$meteredBilling = new RebillyMeteredBilling();
$meteredBilling->itemId = 'abc1';
$meteredBilling->type = 'debit';
$meteredBilling->amount = '9.99';
$meteredBilling->quantity = 1;
$meteredBilling->description = 'Test widget';

$subscription->meteredBilling = array($meteredBilling);

expect($subscription->buildRequest($subscription))
->equals('{"lookupSubscriptionId":"subscriptionId123","meteredBilling":[{"itemId":"abc1","type":"debit","amount":"9.99","quantity":1,"description":"Test widget"}]}');
}
}
1 change: 0 additions & 1 deletion tests/unit/RebillyThreeDSecureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ class RebillyThreeDSecureTest extends \Codeception\TestCase\Test
public function testCreateThreeDSecure()
{
$subscription = new RebillySubscription('subscriptionId');
$subscription->setEnvironment(RebillyRequest::ENV_STAGING);
$subscription->setApiKey('apiKey');
$threeDSecure = new RebillyThreeDSecure();
$threeDSecure->amount = '10.00';
Expand Down

0 comments on commit 233ea21

Please sign in to comment.