Skip to content

Commit

Permalink
Rename billingAnchor into invoiceTimeShift
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrofimov committed Oct 24, 2019
1 parent a596d3c commit 6547c9f
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 52 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Security - in case of vulnerabilities.
- [x] Added new properties to `Transaction`: `requestAmount`, `requestCurrency`, `purchaseAmount`, `purchaseCurrency`, `isProcessedOutside`
- [x] Added field `additionalCriteria` into `GatewayAccount` object
- [x] Added field `dueTimeShift` into `BillingAnchor` object
- [x] Renamed field `billingAnchor` into `invoiceTimeShift` in `Subscription` object

### Deprecated
- [x] Deprecated `Transaction` entity method: `getPaymentCardId`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,24 @@ public function setUnit($value)
return $this->setAttribute('unit', $value);
}

/**
* @return string
*/
public function getChronology()
{
return $this->getAttribute('chronology');
}

/**
* @param string $value
*
* @return $this
*/
public function setChronology($value)
{
return $this->setAttribute('chronology', $value);
}

/**
* {@inheritdoc}
*/
Expand Down
20 changes: 10 additions & 10 deletions src/Entities/Subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace Rebilly\Entities;

use DomainException;
use Rebilly\Entities\Subscriptions\BillingAnchor;
use Rebilly\Entities\Subscriptions\InvoiceTimeShift;
use Rebilly\Entities\Subscriptions\RecurringInterval;
use Rebilly\Entities\Subscriptions\SubscriptionTrial;
use Rebilly\Rest\Entity;
Expand Down Expand Up @@ -418,31 +418,31 @@ function (array $item) {
}

/**
* @return BillingAnchor
* @return InvoiceTimeShift
*/
public function getBillingAnchor()
public function getInvoiceTimeShift()
{
return $this->getAttribute('billingAnchor');
return $this->getAttribute('invoiceTimeShift');
}

/**
* @param array|BillingAnchor $value
* @param array|InvoiceTimeShift $value
*
* @return $this
*/
public function setBillingAnchor($value)
public function setInvoiceTimeShift($value)
{
return $this->setAttribute('billingAnchor', $value);
return $this->setAttribute('invoiceTimeShift', $value);
}

/**
* @param array $data
*
* @return BillingAnchor
* @return InvoiceTimeShift
*/
public function createBillingAnchor(array $data)
public function createInvoiceTimeShift(array $data)
{
return new BillingAnchor($data);
return new InvoiceTimeShift($data);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,29 @@

namespace Rebilly\Entities\Subscriptions;

use Rebilly\Entities\PaymentRetryInstructions\ScheduleInstruction;
use Rebilly\Entities\PaymentRetryInstructions\ScheduleInstructionTypes\DateIntervalType;
use Rebilly\Rest\Resource;

final class BillingAnchor extends Resource
final class InvoiceTimeShift extends Resource
{
public function getChronology()
{
return $this->getAttribute('chronology');
}

public function setChronology($value)
{
return $this->setAttribute('chronology', $value);
}

/**
* @return ScheduleInstruction
* @return DateIntervalType
*/
public function getBillingAnchorInstruction()
public function getIssueTimeShift()
{
return $this->getAttribute('billingAnchorInstruction');
return $this->getAttribute('issueTimeShift');
}

public function setBillingAnchorInstruction($value)
public function setIssueTimeShift($value)
{
return $this->setAttribute('billingAnchorInstruction', $value);
return $this->setAttribute('issueTimeShift', $value);
}

public function createBillingAnchorInstruction(array $data)
public function createIssueTimeShift(array $data)
{
return ScheduleInstruction::createFromData($data);
$data['method'] = DateIntervalType::DATE_INTERVAL;

return DateIntervalType::createFromData($data);
}

/**
Expand Down
46 changes: 25 additions & 21 deletions tests/Entities/Subscriptions/SubscriptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use Rebilly\Entities\PaymentRetryInstructions\ScheduleInstruction;
use Rebilly\Entities\PaymentRetryInstructions\ScheduleInstructionTypes\DateIntervalType;
use Rebilly\Entities\Subscription;
use Rebilly\Entities\Subscriptions\BillingAnchor;
use Rebilly\Entities\Subscriptions\InvoiceTimeShift;
use Rebilly\Entities\Subscriptions\PlanItem;
use Rebilly\Entities\Website;
use Rebilly\Tests\TestCase;
Expand Down Expand Up @@ -64,10 +64,10 @@ private static function getDefaultData()
['planId' => 'plan-2', 'quantity' => null],
['planId' => 'plan-3'],
],
'billingAnchor' => [
'chronology' => 'before',
'billingAnchorInstruction' => [
'invoiceTimeShift' => [
'issueTimeShift' => [
'method' => ScheduleInstruction::DATE_INTERVAL,
'chronology' => 'before',
'duration' => 7,
'unit' => 'days',
],
Expand Down Expand Up @@ -103,18 +103,18 @@ public function buildObjectUsingSetterToSendToServer()
$value->setRiskMetadata($data['riskMetadata']);
$value->setItems($data['items']);

$billingAnchor = new BillingAnchor();
$billingAnchor->setChronology($data['billingAnchor']['chronology']);
$invoiceTimeShift = new InvoiceTimeShift();
$instruction = new DateIntervalType();
$instruction->setDuration($data['billingAnchor']['billingAnchorInstruction']['duration']);
$instruction->setUnit($data['billingAnchor']['billingAnchorInstruction']['unit']);
$billingAnchor->setBillingAnchorInstruction($instruction);
$instruction->setChronology($data['invoiceTimeShift']['issueTimeShift']['chronology']);
$instruction->setDuration($data['invoiceTimeShift']['issueTimeShift']['duration']);
$instruction->setUnit($data['invoiceTimeShift']['issueTimeShift']['unit']);
$invoiceTimeShift->setIssueTimeShift($instruction);
$dueTimeShift = new DateIntervalType();
$dueTimeShift->setDuration($data['billingAnchor']['dueTimeShift']['duration']);
$dueTimeShift->setUnit($data['billingAnchor']['dueTimeShift']['unit']);
$billingAnchor->setDueTimeShift($dueTimeShift);
$dueTimeShift->setDuration($data['invoiceTimeShift']['dueTimeShift']['duration']);
$dueTimeShift->setUnit($data['invoiceTimeShift']['dueTimeShift']['unit']);
$invoiceTimeShift->setDueTimeShift($dueTimeShift);

$value->setBillingAnchor($billingAnchor);
$value->setInvoiceTimeShift($invoiceTimeShift);

$expectedJson = $data;
// Unset read-only properties which we not set.
Expand Down Expand Up @@ -188,17 +188,21 @@ public function populatePlanFromArrayReceivedFromServer()
self::assertInstanceOf(Customer::class, $value->getCustomer());
self::assertInstanceOf(LeadSource::class, $value->getLeadSource());

$billingAnchor = $value->getBillingAnchor();
self::assertInstanceOf(BillingAnchor::class, $billingAnchor);
self::assertSame($data['billingAnchor']['chronology'], $billingAnchor->getChronology());
$instructionData = $data['billingAnchor']['billingAnchorInstruction'];
$instruction = $billingAnchor->getBillingAnchorInstruction();
$invoiceTimeShift = $value->getInvoiceTimeShift();
self::assertInstanceOf(InvoiceTimeShift::class, $invoiceTimeShift);
self::assertSame(
$data['invoiceTimeShift']['issueTimeShift']['chronology'],
$invoiceTimeShift->getIssueTimeShift()->getChronology()
);
$instructionData = $data['invoiceTimeShift']['issueTimeShift'];
$instruction = $invoiceTimeShift->getIssueTimeShift();
self::assertInstanceOf(DateIntervalType::class, $instruction);
self::assertSame($instructionData['chronology'], $instruction->getChronology());
self::assertSame($instructionData['duration'], $instruction->getDuration());
self::assertSame($instructionData['unit'], $instruction->getUnit());
self::assertTrue($billingAnchor->hasDueTimeShift());
$dueTimeShiftData = $data['billingAnchor']['dueTimeShift'];
$dueTimeShift = $billingAnchor->getDueTimeShift();
self::assertTrue($invoiceTimeShift->hasDueTimeShift());
$dueTimeShiftData = $data['invoiceTimeShift']['dueTimeShift'];
$dueTimeShift = $invoiceTimeShift->getDueTimeShift();
self::assertInstanceOf(DateIntervalType::class, $dueTimeShift);
self::assertSame($dueTimeShiftData['duration'], $dueTimeShift->getDuration());
self::assertSame($dueTimeShiftData['unit'], $dueTimeShift->getUnit());
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -694,8 +694,8 @@ protected function getFakeValue($attribute, $class)
'path' => '/transaction/websiteId',
'value' => 'website-1',
];
case 'billingAnchor':
return new Entities\Subscriptions\BillingAnchor(['billingAnchorInstruction' => ['method' => 'immediately']]);
case 'invoiceTimeShift':
return new Entities\Subscriptions\InvoiceTimeShift();
default:
throw new InvalidArgumentException(
sprintf('Cannot generate fake value for "%s :: %s"', $class, $attribute)
Expand Down

0 comments on commit 6547c9f

Please sign in to comment.