diff --git a/src/Model/Response/PaymentServiceTransaction.php b/src/Model/Response/PaymentServiceTransaction.php index 0b3425d..998de01 100644 --- a/src/Model/Response/PaymentServiceTransaction.php +++ b/src/Model/Response/PaymentServiceTransaction.php @@ -9,9 +9,9 @@ class PaymentServiceTransaction public string $id; public PaymentServiceTransactionStatus $status; public float $amount; - public string $control; - public string $channel; - public \DateTimeImmutable $paidAt; + public ?string $control; + public ?string $channel; + public ?\DateTimeImmutable $paidAt; public \DateTimeImmutable $createdAt; public \DateTimeImmutable $updatedAt; @@ -19,9 +19,9 @@ private function __construct( string $id, PaymentServiceTransactionStatus $status, float $amount, - string $control, - string $channel, - \DateTimeImmutable $paidAt, + ?string $control, + ?string $channel, + ?\DateTimeImmutable $paidAt, \DateTimeImmutable $createdAt, \DateTimeImmutable $updatedAt ) { @@ -40,10 +40,10 @@ public static function createFromResponse(array $data): self return new self( $data['id'], new PaymentServiceTransactionStatus($data['status']), - $data['amount'], - $data['control'], - $data['channel'], - new \DateTimeImmutable($data['paid_at']), + (float) $data['amount'], + $data['control'] ?? null, + $data['channel'] ?? null, + empty($data['paid_at']) ? null : new \DateTimeImmutable($data['paid_at']), new \DateTimeImmutable($data['created_at']), new \DateTimeImmutable($data['updated_at']), ); diff --git a/src/Model/Response/PaymentServiceTransactionStatus.php b/src/Model/Response/PaymentServiceTransactionStatus.php index 9e1fb2e..9270aec 100644 --- a/src/Model/Response/PaymentServiceTransactionStatus.php +++ b/src/Model/Response/PaymentServiceTransactionStatus.php @@ -10,8 +10,12 @@ class PaymentServiceTransactionStatus public const CONFIRMED = 'transaction_confirmed'; public const GENERATED = 'transaction_generated'; public const PAID = 'transaction_paid'; - public const FAILED = 'transaction_failed'; + public const FAILED = 'transaction_failure'; public const EXPIRED = 'transaction_expired'; + public const REFUNDED = 'transaction_refunded'; + public const FRAUD = 'transaction_fraud'; + public const FRAUD_POSSIBILITY = 'transaction_fraud_possibility'; + /** @deprecated The API never returns this status. */ public const CANCELED = 'transaction_canceled'; public string $value; diff --git a/src/Model/Response/PaymentTransactionAmount.php b/src/Model/Response/PaymentTransactionAmount.php index ccbf728..2f699cd 100644 --- a/src/Model/Response/PaymentTransactionAmount.php +++ b/src/Model/Response/PaymentTransactionAmount.php @@ -19,6 +19,6 @@ private function __construct(float $value, string $currency, float $commission) public static function createFromResponse(array $data): self { - return new self($data['value'], $data['currency'], $data['commission']); + return new self((float) $data['value'], $data['currency'], (float) $data['commission']); } } diff --git a/tests/PaymentApiTest.php b/tests/PaymentApiTest.php index d10c8a1..39219f2 100644 --- a/tests/PaymentApiTest.php +++ b/tests/PaymentApiTest.php @@ -72,6 +72,10 @@ public function should_return_service_transactions(): void $this->assertSame('test', $response->data[0]->control); $this->assertSame('test', $response->data[0]->channel); $this->assertSame('2021-11-08T18:19:16+01:00', $response->data[0]->paidAt->format(\DateTimeInterface::ATOM)); + $this->assertNull($response->data[1]->paidAt); + $this->assertNull($response->data[1]->control); + $this->assertNull($response->data[1]->channel); + $this->assertSame(5.0, $response->data[1]->amount); $this->assertSame('2021-11-08T18:19:16+01:00', $response->data[0]->createdAt->format(\DateTimeInterface::ATOM)); $this->assertSame('2021-11-08T18:19:16+01:00', $response->data[0]->updatedAt->format(\DateTimeInterface::ATOM)); @@ -248,6 +252,16 @@ private function mockPaymentTransactions(string $serviceId): void 'created_at' => '2021-11-08T18:19:16+01:00', 'updated_at' => '2021-11-08T18:19:16+01:00', ], + [ + 'id' => 'e262f5a0', + 'status' => 'transaction_new', + 'amount' => 5, + 'control' => null, + 'channel' => null, + 'paid_at' => null, + 'created_at' => '2021-11-08T18:19:16+01:00', + 'updated_at' => '2021-11-08T18:19:16+01:00', + ], ], 'pagination' => [ 'total' => 1, @@ -398,7 +412,7 @@ private function mockSinglePaymentTransactionResponse(string $serviceId, string 'amount' => [ 'value' => 19.99, 'currency' => 'PLN', - 'commission' => 0.98, + 'commission' => '0.98', ], 'channel' => 'nest', 'control' => 'test_control',