| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <?php
- namespace App\Data\Pagarme\Response;
- use App\Data\Pagarme\PagarmeResponseData;
- final readonly class BulkAnticipationResponseData extends PagarmeResponseData
- {
- public function __construct(
- public ?string $id,
- public ?string $status,
- public ?int $amount,
- public ?int $fee,
- public ?int $fraudCoverageFee,
- public ?int $anticipationFee,
- public ?bool $automaticTransfer,
- public ?string $type,
- public ?string $timeframe,
- public ?string $paymentDate,
- public ?string $createdAt = null,
- public ?string $updatedAt = null,
- public mixed $anticipationTax = null,
- ) {}
- public function requireId(): string
- {
- if (! $this->id) {
- throw new \RuntimeException('Pagar.me bulk anticipation creation returned an empty id.');
- }
- return $this->id;
- }
- public static function fromArray(array $payload): static
- {
- return new self(
- id: static::arrString($payload, 'id'),
- status: static::arrString($payload, 'status'),
- amount: static::arrInt($payload, 'amount'),
- fee: static::arrInt($payload, 'fee'),
- fraudCoverageFee: static::arrInt($payload, 'fraud_coverage_fee'),
- anticipationFee: static::arrInt($payload, 'anticipation_fee'),
- automaticTransfer: static::arrBool($payload, 'automatic_transfer'),
- type: static::arrString($payload, 'type'),
- timeframe: static::arrString($payload, 'timeframe'),
- paymentDate: static::arrString($payload, 'payment_date'),
- createdAt: static::arrString($payload, 'created_at'),
- updatedAt: static::arrString($payload, 'updated_at'),
- anticipationTax: static::arrGet($payload, 'anticipation_tax'),
- );
- }
- public function toArray(): array
- {
- return array_filter([
- 'id' => $this->id,
- 'status' => $this->status,
- 'amount' => $this->amount,
- 'fee' => $this->fee,
- 'fraud_coverage_fee' => $this->fraudCoverageFee,
- 'anticipation_fee' => $this->anticipationFee,
- 'automatic_transfer' => $this->automaticTransfer,
- 'type' => $this->type,
- 'timeframe' => $this->timeframe,
- 'payment_date' => $this->paymentDate,
- 'created_at' => $this->createdAt,
- 'updated_at' => $this->updatedAt,
- 'anticipation_tax' => $this->anticipationTax,
- ], static fn ($v) => $v !== null);
- }
- }
|