Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/Model/Response/PaymentServiceTransaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ 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;

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
) {
Expand All @@ -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']),
);
Expand Down
6 changes: 5 additions & 1 deletion src/Model/Response/PaymentServiceTransactionStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Model/Response/PaymentTransactionAmount.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
}
16 changes: 15 additions & 1 deletion tests/PaymentApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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',
Expand Down
Loading