Skip to content

Commit

Permalink
Add transaction allocations to credit memo (#571)
Browse files Browse the repository at this point in the history
* Add transaction allocations to credit memo

* Remove getCreditMemoId

* Remove useless getters and setters

* Update changelog

* Add factory methods for creating instances

* Check if item is already an object

* Remove incorrect typehint
  • Loading branch information
Boyd Bueno de Mesquita committed Oct 10, 2022
1 parent 6cd1f9b commit f3265ed
Show file tree
Hide file tree
Showing 5 changed files with 177 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Security - in case of vulnerabilities.
## [Unreleased]

- [x] Added new property to `Subscription`: `paymentInstrumentId`
- [x] Added new property to `CreditMemo`: `allocations`

## [2.19.0] 2022-06-22

Expand Down
64 changes: 64 additions & 0 deletions src/Entities/AllocationCollection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php
/**
* This source file is proprietary and part of Rebilly.
*
* (c) Rebilly SRL
* Rebilly Ltd.
* Rebilly Inc.
*
* @see https://www.rebilly.com
*/

namespace Rebilly\Entities;

use Rebilly\Rest\Entity;

/**
* Class AllocationCollection.
*/
final class AllocationCollection extends Entity
{
/**
* @param array $data
*
* @return AllocationCollection
*/
public static function createFromData(array $data)
{
return new self($data);
}

/**
* @return TransactionAllocation[]
*/
public function getTransactions()
{
return $this->getAttribute('transactions');
}

/**
* @param TransactionAllocation[] $value
*
* @return $this
*/
public function setTransactions($value)
{
return $this->setAttribute('transactions', $value);
}

/**
* @param array $data
*
* @return array|TransactionAllocation[]
*/
public function createTransactions(array $data)
{
return array_map(function ($item) {
if ($item instanceof TransactionAllocation) {
return $item;
}

return new TransactionAllocation($item);
}, $data);
}
}
28 changes: 28 additions & 0 deletions src/Entities/CreditMemo.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,34 @@ public function getUnusedAmount()
return $this->getAttribute('unusedAmount');
}

/**
* @return AllocationCollection
*/
public function getAllocations()
{
return $this->getAttribute('allocations');
}

/**
* @param AllocationCollection|array $value
*
* @return $this
*/
public function setAllocations($value)
{
return $this->setAttribute('allocations', $value);
}

/**
* @param array $data
*
* @return AllocationCollection
*/
public function createAllocations(array $data)
{
return AllocationCollection::createFromData($data);
}

/**
* @return int
*/
Expand Down
80 changes: 80 additions & 0 deletions src/Entities/TransactionAllocation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php
/**
* This source file is proprietary and part of Rebilly.
*
* (c) Rebilly SRL
* Rebilly Ltd.
* Rebilly Inc.
*
* @see https://www.rebilly.com
*/

namespace Rebilly\Entities;

use Rebilly\Rest\Entity;

/**
* Class TransactionAllocation.
*/
final class TransactionAllocation extends Entity
{
/**
* @return string
*/
public function getTransactionId()
{
return $this->getAttribute('transactionId');
}

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

/**
* @return float
*/
public function getAmount()
{
return $this->getAttribute('amount');
}

/**
* @param float $value
*
* @return $this
*/
public function setAmount($value)
{
return $this->setAttribute('amount', $value);
}

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

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

/**
* @return string
*/
public function getUpdatedTime()
{
return $this->getAttribute('updatedTime');
}
}
4 changes: 4 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,10 @@ protected function getFakeValue($attribute, $class)
sprintf('Cannot generate fake value for "%s :: %s"', $class, $attribute)
);
}
case 'allocations':
return new Entities\AllocationCollection(['transactions' => [new Entities\TransactionAllocation([
'transactionId' => 'transaction-1',
])]]);
}
}

Expand Down

0 comments on commit f3265ed

Please sign in to comment.