-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ARB data types and request support.
- Loading branch information
Showing
17 changed files
with
584 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace CommerceGuys\AuthNet; | ||
|
||
use GuzzleHttp\Client; | ||
use CommerceGuys\AuthNet\DataTypes\Paging; | ||
use CommerceGuys\AuthNet\DataTypes\Sorting; | ||
use CommerceGuys\AuthNet\Request\RequestInterface; | ||
|
||
/** | ||
* Use this method to cancel subscriptions using Automated Recurring Billing. | ||
*/ | ||
class ARBCancelSubscriptionRequest extends ARBSubscriptionRequest | ||
{ | ||
protected $subscriptionId; | ||
|
||
public function __construct( | ||
Configuration $configuration, | ||
Client $client, | ||
$subscriptionId | ||
) { | ||
parent::__construct($configuration, $client); | ||
$this->subscriptionId = $subscriptionId; | ||
} | ||
|
||
protected function attachData(RequestInterface $request) | ||
{ | ||
$request->addData('subscriptionId', $this->subscriptionId); | ||
} | ||
} |
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,39 @@ | ||
<?php | ||
|
||
namespace CommerceGuys\AuthNet; | ||
|
||
use GuzzleHttp\Client; | ||
use CommerceGuys\AuthNet\DataTypes\Subscription; | ||
use CommerceGuys\AuthNet\Request\RequestInterface; | ||
|
||
/** | ||
* Use this method to create subscriptions using Automated Recurring Billing. | ||
*/ | ||
class ARBCreateSubscriptionRequest extends ARBSubscriptionRequest | ||
{ | ||
protected $subscription; | ||
|
||
public function __construct( | ||
Configuration $configuration, | ||
Client $client, | ||
Subscription $subscription = null | ||
) { | ||
parent::__construct($configuration, $client); | ||
$this->subscription = $subscription; | ||
} | ||
|
||
/** | ||
* @param \CommerceGuys\AuthNet\DataTypes\Subscription $subscription | ||
* @return $this | ||
*/ | ||
public function setSubscription(Subscription $subscription) | ||
{ | ||
$this->subscription = $subscription; | ||
return $this; | ||
} | ||
|
||
protected function attachData(RequestInterface $request) | ||
{ | ||
$request->addDataType($this->subscription); | ||
} | ||
} |
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,60 @@ | ||
<?php | ||
|
||
namespace CommerceGuys\AuthNet; | ||
|
||
use GuzzleHttp\Client; | ||
use CommerceGuys\AuthNet\DataTypes\Paging; | ||
use CommerceGuys\AuthNet\DataTypes\Sorting; | ||
use CommerceGuys\AuthNet\Request\RequestInterface; | ||
|
||
/** | ||
* Use this method to get subscriptions using Automated Recurring Billing. | ||
*/ | ||
class ARBGetSubscriptionListRequest extends ARBSubscriptionRequest | ||
{ | ||
protected $searchType; | ||
|
||
protected $sorting; | ||
|
||
protected $paging; | ||
|
||
public function __construct( | ||
Configuration $configuration, | ||
Client $client, | ||
$searchType | ||
) { | ||
parent::__construct($configuration, $client); | ||
$this->searchType = $searchType; | ||
} | ||
|
||
/** | ||
* @param \CommerceGuys\AuthNet\DataTypes\Sorting $sorting | ||
* @return $this | ||
*/ | ||
public function setSorting(Sorting $sorting) | ||
{ | ||
$this->sorting = $sorting; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @param \CommerceGuys\AuthNet\DataTypes\Paging $paging | ||
* @return $this | ||
*/ | ||
public function setPaging(Paging $paging) | ||
{ | ||
$this->paging = $paging; | ||
return $this; | ||
} | ||
|
||
protected function attachData(RequestInterface $request) | ||
{ | ||
$request->addData('searchType', $this->searchType); | ||
if ($this->sorting) { | ||
$request->addDataType($this->sorting); | ||
} | ||
if ($this->paging) { | ||
$request->addDataType($this->paging); | ||
} | ||
} | ||
} |
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,34 @@ | ||
<?php | ||
|
||
namespace CommerceGuys\AuthNet; | ||
|
||
use GuzzleHttp\Client; | ||
use CommerceGuys\AuthNet\DataTypes\Paging; | ||
use CommerceGuys\AuthNet\DataTypes\Sorting; | ||
use CommerceGuys\AuthNet\Request\RequestInterface; | ||
|
||
/** | ||
* Use this method to get a subscription using Automated Recurring Billing. | ||
*/ | ||
class ARBGetSubscriptionRequest extends ARBSubscriptionRequest | ||
{ | ||
protected $subscriptionId; | ||
protected $includeTransactions; | ||
|
||
public function __construct( | ||
Configuration $configuration, | ||
Client $client, | ||
$subscriptionId, | ||
$includeTransactions = false | ||
) { | ||
parent::__construct($configuration, $client); | ||
$this->subscriptionId = $subscriptionId; | ||
$this->includeTransactions = filter_var($includeTransactions, FILTER_VALIDATE_BOOLEAN) ? 'true' : 'false'; | ||
} | ||
|
||
protected function attachData(RequestInterface $request) | ||
{ | ||
$request->addData('subscriptionId', $this->subscriptionId); | ||
$request->addData('includeTransactions', $this->includeTransactions); | ||
} | ||
} |
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,30 @@ | ||
<?php | ||
|
||
namespace CommerceGuys\AuthNet; | ||
|
||
use GuzzleHttp\Client; | ||
use CommerceGuys\AuthNet\DataTypes\Paging; | ||
use CommerceGuys\AuthNet\DataTypes\Sorting; | ||
use CommerceGuys\AuthNet\Request\RequestInterface; | ||
|
||
/** | ||
* Use this method to get a subscription using Automated Recurring Billing. | ||
*/ | ||
class ARBGetSubscriptionStatusRequest extends ARBSubscriptionRequest | ||
{ | ||
protected $subscriptionId; | ||
|
||
public function __construct( | ||
Configuration $configuration, | ||
Client $client, | ||
$subscriptionId | ||
) { | ||
parent::__construct($configuration, $client); | ||
$this->subscriptionId = $subscriptionId; | ||
} | ||
|
||
protected function attachData(RequestInterface $request) | ||
{ | ||
$request->addData('subscriptionId', $this->subscriptionId); | ||
} | ||
} |
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,22 @@ | ||
<?php | ||
|
||
namespace CommerceGuys\AuthNet; | ||
|
||
use GuzzleHttp\Client; | ||
use CommerceGuys\AuthNet\DataTypes\Paging; | ||
use CommerceGuys\AuthNet\DataTypes\Sorting; | ||
use CommerceGuys\AuthNet\Request\RequestInterface; | ||
|
||
/** | ||
* Use this method to create subscriptions using Automated Recurring Billing. | ||
* | ||
* @link https://developer.authorize.net/api/reference/#recurring-billing | ||
*/ | ||
abstract class ARBSubscriptionRequest extends BaseApiRequest | ||
{ | ||
|
||
public function getType() | ||
{ | ||
return (new \ReflectionClass($this))->getShortName(); | ||
} | ||
} |
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,29 @@ | ||
<?php | ||
|
||
namespace CommerceGuys\AuthNet; | ||
|
||
use GuzzleHttp\Client; | ||
use CommerceGuys\AuthNet\DataTypes\Subscription; | ||
use CommerceGuys\AuthNet\Request\RequestInterface; | ||
|
||
/** | ||
* Use this method to update subscriptions using Automated Recurring Billing. | ||
*/ | ||
class ARBUpdateSubscriptionRequest extends ARBCreateSubscriptionRequest | ||
{ | ||
protected $subscriptionId; | ||
|
||
public function __construct( | ||
Configuration $configuration, | ||
Client $client, | ||
$subscriptionId | ||
) { | ||
parent::__construct($configuration, $client); | ||
$this->subscriptionId = $subscription; | ||
} | ||
|
||
protected function attachData(RequestInterface $request) | ||
{ | ||
$request->addData('subscriptionId', $this->subscriptionId); | ||
} | ||
} |
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 @@ | ||
<?php | ||
|
||
namespace CommerceGuys\AuthNet\DataTypes; | ||
|
||
class CustomerPaymentProfileBase extends BaseDataType | ||
{ | ||
|
||
protected $propertyMap = [ | ||
'customerType', | ||
'billTo', | ||
]; | ||
|
||
public function addBillTo(BillTo $billTo) | ||
{ | ||
$this->addDataType($billTo); | ||
} | ||
} |
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 | ||
|
||
namespace CommerceGuys\AuthNet\DataTypes; | ||
|
||
class CustomerProfileId extends BaseDataType | ||
{ | ||
|
||
protected $propertyMap = [ | ||
'customerProfileId', | ||
'customerPaymentProfileId', | ||
'customerAddressId', | ||
]; | ||
} |
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 | ||
|
||
namespace CommerceGuys\AuthNet\DataTypes; | ||
|
||
class Interval extends BaseDataType | ||
{ | ||
protected $propertyMap = [ | ||
'length', | ||
'unit', | ||
]; | ||
|
||
/** | ||
* Allows child classes to validate incoming values. | ||
* | ||
* @param array $values | ||
*/ | ||
protected function validate(array $values) | ||
{ | ||
if (!isset($values['length'])) { | ||
throw new \InvalidArgumentException('Interval must have a length.'); | ||
} | ||
if (!isset($values['unit'])) { | ||
throw new \InvalidArgumentException('Interval must have a unit.'); | ||
} | ||
if (!array_intersect(['days', 'months'], (array) $values['unit'])) { | ||
throw new \InvalidArgumentException('Interval unit must be days or months.'); | ||
} | ||
switch ($values['unit']) { | ||
case 'days': | ||
if ($values['length'] < 7 || $values['length'] > 365) { | ||
$message = 'Interval length for days must be between 7 and 365, inclusive.'; | ||
throw new \InvalidArgumentException($message); | ||
} | ||
break; | ||
|
||
case 'months': | ||
if ($values['length'] < 1 || $values['length'] > 12) { | ||
$message = 'Interval length for months must be between 1 and 12, inclusive.'; | ||
throw new \InvalidArgumentException($message); | ||
} | ||
break; | ||
} | ||
} | ||
} |
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,12 @@ | ||
<?php | ||
|
||
namespace CommerceGuys\AuthNet\DataTypes; | ||
|
||
class Paging extends BaseDataType | ||
{ | ||
|
||
protected $propertyMap = [ | ||
'limit', | ||
'offset', | ||
]; | ||
} |
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,18 @@ | ||
<?php | ||
|
||
namespace CommerceGuys\AuthNet\DataTypes; | ||
|
||
class PaymentSchedule extends BaseDataType | ||
{ | ||
protected $propertyMap = [ | ||
'interval', | ||
'startDate', | ||
'totalOccurrences', | ||
'trialOccurrences', | ||
]; | ||
|
||
public function addInterval(Interval $interval) | ||
{ | ||
$this->properties['interval'] = $interval->toArray(); | ||
} | ||
} |
Oops, something went wrong.