1: <?php
2:
3: namespace IPay\Builders;
4:
5: use IPay\Enums\TransactionType;
6: use IPay\ValueObjects\Transaction;
7:
8: /**
9: * @psalm-import-type ParametersType from RequestBodyBuilder
10: *
11: * @implements \IteratorAggregate<int,Transaction>
12: */
13: final class TransactionBuilder implements \IteratorAggregate
14: {
15: /** @var \Closure(ParametersType):\Traversable<Transaction> */
16: private \Closure $resolver;
17:
18: /** @var ParametersType */
19: private array $parameters = [];
20:
21: public function between(
22: \DateTimeInterface $from,
23: \DateTimeInterface $to,
24: ): self {
25: $this->parameters['startDate'] = $from->format('Y-m-d');
26: $this->parameters['endDate'] = $to->format('Y-m-d');
27:
28: return $this;
29: }
30:
31: public function today(): self
32: {
33: $today = new \DateTimeImmutable();
34: $this->between($today, $today);
35:
36: return $this;
37: }
38:
39: public function type(TransactionType $type): self
40: {
41: $this->parameters['tranType'] = $type->value;
42:
43: return $this;
44: }
45:
46: public function getIterator(): \Traversable
47: {
48: return ($this->resolver)($this->parameters);
49: }
50: }
51: