-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
118 additions
and
53 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
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
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,58 @@ | ||
<?php | ||
|
||
namespace IPay\Builder; | ||
|
||
use IPay\Api\AuthenticatedApi; | ||
use IPay\Enum\TransactionType; | ||
|
||
/** | ||
* @psalm-type ParametersType = array{ | ||
* accountNumber: string, | ||
* tranType?: value-of<TransactionType>, | ||
* startDate?: \DateTimeInterface, | ||
* endDate?: \DateTimeInterface, | ||
* } | ||
* | ||
* @implements \IteratorAggregate<int,\IPay\Entity\Transaction> | ||
*/ | ||
final class TransactionBuilder implements \IteratorAggregate | ||
{ | ||
/** | ||
* @param ParametersType $parameters | ||
*/ | ||
public function __construct( | ||
private array $parameters, | ||
private AuthenticatedApi $api, | ||
) { | ||
} | ||
|
||
public function between( | ||
\DateTimeInterface $from, | ||
\DateTimeInterface $to, | ||
): static { | ||
$this->parameters['startDate'] = $from; | ||
$this->parameters['endDate'] = $to; | ||
|
||
return $this; | ||
} | ||
|
||
public function today(): static | ||
{ | ||
$today = new \DateTimeImmutable(); | ||
$this->between($today, $today); | ||
|
||
return $this; | ||
} | ||
|
||
public function type(TransactionType $type): static | ||
{ | ||
$this->parameters['tranType'] = $type->value; | ||
|
||
return $this; | ||
} | ||
|
||
public function getIterator(): \Traversable | ||
{ | ||
return $this->api->historyTransactions($this->parameters); | ||
} | ||
} |
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,10 @@ | ||
<?php | ||
|
||
namespace IPay\Enum; | ||
|
||
enum TransactionType: string | ||
{ | ||
case CREDIT = 'Credit'; | ||
case DEBIT = 'Debit'; | ||
case ALL = ''; | ||
} |
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