From a122e30ae600b65fb433e125fcfd0ac72dfeec54 Mon Sep 17 00:00:00 2001 From: Russel Anthony Date: Wed, 2 Sep 2020 09:23:45 -0400 Subject: [PATCH 1/3] changes to ARB subscription update so that it works, additional functions on ARB data types --- src/ARBUpdateSubscriptionRequest.php | 10 +++++++--- src/DataTypes/Interval.php | 12 +++++++++++- src/DataTypes/PaymentSchedule.php | 5 +++++ src/DataTypes/Subscription.php | 19 +++++++++++++++++++ 4 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/ARBUpdateSubscriptionRequest.php b/src/ARBUpdateSubscriptionRequest.php index 32c0054..e5bb726 100644 --- a/src/ARBUpdateSubscriptionRequest.php +++ b/src/ARBUpdateSubscriptionRequest.php @@ -16,14 +16,18 @@ class ARBUpdateSubscriptionRequest extends ARBCreateSubscriptionRequest public function __construct( Configuration $configuration, Client $client, - $subscriptionId + Subscription $subscription, + string $subscriptionId ) { - parent::__construct($configuration, $client); - $this->subscriptionId = $subscription; + $this->subscriptionId = $subscriptionId; + // Authnet does not allow an interval to be updated + $subscription->removeInterval(); + parent::__construct($configuration, $client, $subscription); } protected function attachData(RequestInterface $request) { $request->addData('subscriptionId', $this->subscriptionId); + parent::attachData($request); } } diff --git a/src/DataTypes/Interval.php b/src/DataTypes/Interval.php index dd0e341..63a945e 100644 --- a/src/DataTypes/Interval.php +++ b/src/DataTypes/Interval.php @@ -23,7 +23,7 @@ protected function validate(array $values) 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.'); + throw new \InvalidArgumentException('Interval unit must be days or months.' . $values['unit']); } switch ($values['unit']) { case 'days': @@ -41,4 +41,14 @@ protected function validate(array $values) break; } } + + public function addLength(int $length): void + { + $this->propertyMap['length'] = $length; + } + + public function addUnit(String $unit): void + { + $this->propertyMap['unit'] = $unit; + } } diff --git a/src/DataTypes/PaymentSchedule.php b/src/DataTypes/PaymentSchedule.php index 9b33f66..8409636 100644 --- a/src/DataTypes/PaymentSchedule.php +++ b/src/DataTypes/PaymentSchedule.php @@ -15,4 +15,9 @@ public function addInterval(Interval $interval) { $this->properties['interval'] = $interval->toArray(); } + + public function addTotalOccurrences(String $totalOccurrences) + { + $this->properties['totalOccurrences'] = $totalOccurrences; + } } diff --git a/src/DataTypes/Subscription.php b/src/DataTypes/Subscription.php index 133263b..c82def1 100644 --- a/src/DataTypes/Subscription.php +++ b/src/DataTypes/Subscription.php @@ -45,4 +45,23 @@ public function addProfile(CustomerProfileId $profile) { $this->properties['profile'] = $profile->toArray(); } + + public function addAmount(String $amount) + { + $this->properties['amount'] = $amount; + } + + public function getAmount() + { + return $this->properties['amount']; + } + + public function getInterval() { + return $this->properties['paymentSchedule']['interval']; + } + + public function removeInterval() + { + unset($this->properties['paymentSchedule']['interval']); + } } From 4b9816b950a60f077605973caaf063031a5fb69e Mon Sep 17 00:00:00 2001 From: Russel Anthony Date: Fri, 9 Oct 2020 15:05:47 -0400 Subject: [PATCH 2/3] DataType for an Arb Transaction --- src/DataTypes/ArbTransaction.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/DataTypes/ArbTransaction.php diff --git a/src/DataTypes/ArbTransaction.php b/src/DataTypes/ArbTransaction.php new file mode 100644 index 0000000..3196fce --- /dev/null +++ b/src/DataTypes/ArbTransaction.php @@ -0,0 +1,13 @@ + Date: Fri, 9 Oct 2020 15:06:29 -0400 Subject: [PATCH 3/3] Add some helper functions for ARB --- src/DataTypes/Interval.php | 4 +-- src/DataTypes/PaymentSchedule.php | 4 +++ src/DataTypes/Subscription.php | 51 +++++++++++++++++++++++++++++-- 3 files changed, 55 insertions(+), 4 deletions(-) diff --git a/src/DataTypes/Interval.php b/src/DataTypes/Interval.php index 63a945e..9b00cdd 100644 --- a/src/DataTypes/Interval.php +++ b/src/DataTypes/Interval.php @@ -42,12 +42,12 @@ protected function validate(array $values) } } - public function addLength(int $length): void + public function addLength(int $length) { $this->propertyMap['length'] = $length; } - public function addUnit(String $unit): void + public function addUnit(String $unit) { $this->propertyMap['unit'] = $unit; } diff --git a/src/DataTypes/PaymentSchedule.php b/src/DataTypes/PaymentSchedule.php index 8409636..d0f9baa 100644 --- a/src/DataTypes/PaymentSchedule.php +++ b/src/DataTypes/PaymentSchedule.php @@ -20,4 +20,8 @@ public function addTotalOccurrences(String $totalOccurrences) { $this->properties['totalOccurrences'] = $totalOccurrences; } + + public function addStartDate(string $startDate) { + $this->properties['startDate'] = $startDate; + } } diff --git a/src/DataTypes/Subscription.php b/src/DataTypes/Subscription.php index c82def1..834a7ae 100644 --- a/src/DataTypes/Subscription.php +++ b/src/DataTypes/Subscription.php @@ -46,7 +46,7 @@ public function addProfile(CustomerProfileId $profile) $this->properties['profile'] = $profile->toArray(); } - public function addAmount(String $amount) + public function addAmount(string $amount) { $this->properties['amount'] = $amount; } @@ -57,11 +57,58 @@ public function getAmount() } public function getInterval() { - return $this->properties['paymentSchedule']['interval']; + if(is_array($this->properties['paymentSchedule'])) { + return $this->properties['paymentSchedule']['interval']; + } + return $this->properties['paymentSchedule']->interval; + } + + public function getPaymentSchedule() { + return $this->properties['paymentSchedule']; } public function removeInterval() { unset($this->properties['paymentSchedule']['interval']); } + + public function getStartDate() + { + if(is_array($this->properties['paymentSchedule'])) { + return $this->properties['paymentSchedule']['startDate']; + } + return $this->properties['paymentSchedule']->startDate; + } + + public function addStartDate(string $startDate) + { + if(is_object($this->properties['paymentSchedule'])) { + $this->properties['paymentSchedule']->startDate = $startDate; + } + $this->properties['paymentSchedule']['startDate'] = $startDate; + } + + public function removeStartDate() { + unset($this->properties['paymentSchedule']['startDate']); + } + + public function getArbTransactions() { + return $this->properties['arbTransactions']; + } + + public function addArbTransactions($arbTransactions) { + if( is_array($arbTransactions)) { + $arbTransactions = $arbTransactions['arbTransaction']; + } + else { + $arbTransactions = $arbTransactions->arbTransaction; + } + foreach( $arbTransactions as $arbTransaction ) { + $this->properties['arbTransactions']['arbTransaction'][] = (array) $arbTransaction; + } + } + + public function addArbTransaction(ArbTransaction $arbTransaction) { + $this->properties['arbTransactions']['arbTransaction'][] = $arbTransaction->toArray(); + } }