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
2 changes: 1 addition & 1 deletion src/Model/Request/AmountType.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static function createGross(): self
public function toArray(): array
{
return [
'amount_type' => $this->value,
'amountType' => $this->value,
];
}
}
2 changes: 1 addition & 1 deletion src/Model/Request/PhoneNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function __construct(string $value)
public function toArray(): array
{
return [
'phone_number' => $this->value,
'phoneNumber' => $this->value,
];
}
}
14 changes: 7 additions & 7 deletions src/Model/Response/DirectBillingTransaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class DirectBillingTransaction
public ?Operator $operator;
public DirectBillingTransactionNotify $notify;
public \DateTimeImmutable $createdAt;
public \DateTimeImmutable $updatedAt;
public ?\DateTimeImmutable $updatedAt;

private function __construct(
string $id,
Expand All @@ -27,7 +27,7 @@ private function __construct(
?Operator $operator,
DirectBillingTransactionNotify $notify,
\DateTimeImmutable $createdAt,
\DateTimeImmutable $updatedAt
?\DateTimeImmutable $updatedAt
) {
$this->id = $id;
$this->status = $status;
Expand All @@ -46,14 +46,14 @@ public static function createFromResponse(array $data): self
return new self(
$data['id'],
$data['status'],
$data['phone_number'],
$data['control'],
$data['phoneNumber'] ?? null,
$data['control'] ?? null,
$data['value'],
$data['value_netto'],
new Operator($data['operator']),
$data['value_net'],
null !== ($data['operator'] ?? null) ? new Operator($data['operator']) : null,
DirectBillingTransactionNotify::createFromResponse($data['notify']),
new \DateTimeImmutable($data['created_at']),
new \DateTimeImmutable($data['updated_at']),
null !== ($data['updated_at'] ?? null) ? new \DateTimeImmutable($data['updated_at']) : null,
);
}
}
2 changes: 1 addition & 1 deletion src/Model/Response/DirectBillingTransactionCreate.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ private function __construct(string $transactionId, string $redirectUrl)

public static function createFromResponse(array $data): self
{
return new self($data['transaction_id'], $data['redirect_url'],);
return new self($data['transactionId'], $data['redirectUrl'],);
}
}
14 changes: 7 additions & 7 deletions src/Model/Response/DirectBillingTransactionList.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ class DirectBillingTransactionList
public string $status;
public float $value;
public float $valueNetto;
public string $operator;
public ?string $operator;
public \DateTimeImmutable $createdAt;
public \DateTimeImmutable $updatedAt;
public ?\DateTimeImmutable $updatedAt;

private function __construct(
string $id,
string $status,
float $value,
float $valueNetto,
string $operator,
?string $operator,
\DateTimeImmutable $createdAt,
\DateTimeImmutable $updatedAt
?\DateTimeImmutable $updatedAt
) {
$this->id = $id;
$this->status = $status;
Expand All @@ -38,10 +38,10 @@ public static function createFromResponse(array $data): self
$data['id'],
$data['status'],
$data['value'],
$data['value_netto'],
$data['operator'],
$data['value_net'],
$data['operator'] ?? null,
new \DateTimeImmutable($data['created_at']),
new \DateTimeImmutable($data['updated_at']),
null !== ($data['updated_at'] ?? null) ? new \DateTimeImmutable($data['updated_at']) : null,
);
}
}
6 changes: 3 additions & 3 deletions src/Model/Response/DirectBillingTransactionNotify.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ class DirectBillingTransactionNotify
{
public bool $isSend;
public \DateTimeImmutable $lastSendAt;
public int $count;
public ?int $count;

private function __construct(bool $isSend, \DateTimeImmutable $lastSendAt, int $count)
private function __construct(bool $isSend, \DateTimeImmutable $lastSendAt, ?int $count)
{
$this->isSend = $isSend;
$this->lastSendAt = $lastSendAt;
Expand All @@ -19,6 +19,6 @@ private function __construct(bool $isSend, \DateTimeImmutable $lastSendAt, int $

public static function createFromResponse(array $data): self
{
return new self($data['is_send'], new \DateTimeImmutable($data['last_send_at']), $data['count'],);
return new self($data['is_send'], new \DateTimeImmutable($data['last_send_at']), $data['count'] ?? null,);
}
}
70 changes: 59 additions & 11 deletions tests/DirectBillingTransactionApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ private function mockDirectBillingTransactionsApiResponse(string $serviceId): vo
'id' => 'dc261d4f-31ef-4728-bfd6-97bbe2a5ef0a',
'status' => 'transaction_db_payed',
'value' => 0.34,
'value_netto' => 0.24,
'value_net' => 0.24,
'operator' => 'test_operator',
'created_at' => '2023-02-16T14:52:11+01:00',
'updated_at' => '2023-02-16T14:52:11+01:00',
Expand Down Expand Up @@ -196,7 +196,7 @@ private function mockDirectBillingTransactionsWithFiltersApiResponse(string $ser
'query' => [
'filter' => [
'status' => 'transaction_db_new',
'phone_number' => '48123456789',
'phoneNumber' => '48123456789',
'control' => 'test_control',
],
],
Expand All @@ -210,7 +210,7 @@ private function mockDirectBillingTransactionsWithFiltersApiResponse(string $ser
'id' => 'dc261d4f-31ef-4728-bfd6-97bbe2a5ef0a',
'status' => 'transaction_db_new',
'value' => 0.34,
'value_netto' => 0.24,
'value_net' => 0.24,
'operator' => 'test_operator',
'created_at' => '2023-02-16T14:52:11+01:00',
'updated_at' => '2023-02-16T14:52:11+01:00',
Expand Down Expand Up @@ -248,13 +248,61 @@ private function mockDirectBillingTransactionNecessary(string $serviceId): void
[
'success' => true,
'data' => [
'transaction_id' => '1d87a1b3-18f8-4146-bcb1-c0c9f293b04f',
'redirect_url' => 'https://db.simpay.pl/1d87a1b3-18f8-4146-bcb1-c0c9f293b04f',
'transactionId' => '1d87a1b3-18f8-4146-bcb1-c0c9f293b04f',
'redirectUrl' => 'https://db.simpay.pl/1d87a1b3-18f8-4146-bcb1-c0c9f293b04f',
],
],
));
}

/**
* @test
*/
public function should_return_new_direct_billing_transaction_with_empty_fields(): void
{
//GIVEN
$serviceId = 'd151e4f9';
$transactionId = '4c6aa6ba-4518-473c-a30f-1376138e699c';
$this->client->expects($this->once())
->method('request')
->with('GET', \sprintf('directbilling/%s/transactions/%s', $serviceId, $transactionId),)
->willReturn($this->mockResponse(
[
'success' => true,
'data' => [
'id' => $transactionId,
'status' => 'transaction_db_new',
'phoneNumber' => null,
'control' => null,
'value' => 0,
'value_net' => 0,
'value_created' => 5.34,
'value_created_type' => 'NET',
'operator' => null,
'notify' => [
'is_send' => false,
'last_send_at' => '1970-01-01T01:00:00+01:00',
'count' => null,
],
'score' => null,
'created_at' => '2023-02-16T14:52:11+01:00',
'updated_at' => null,
],
],
));
$api = new DirectBillingTransactionApi($this->factory);

//WHEN
$response = $api->directBillingTransaction(new ServiceId($serviceId), new PaymentTransactionId($transactionId));

//THEN
$this->assertSame('transaction_db_new', $response->status);
$this->assertNull($response->phoneNumber);
$this->assertNull($response->operator);
$this->assertNull($response->notify->count);
$this->assertNull($response->updatedAt);
}

private function mockCreateDirectBillingTransaction(string $serviceId): void
{
$this->client->expects($this->once())
Expand All @@ -265,10 +313,10 @@ private function mockCreateDirectBillingTransaction(string $serviceId): void
[
'json' => [
'amount' => 19.99,
'amount_type' => 'required',
'amountType' => 'required',
'description' => 'test description',
'control' => '96125f23d5494bfca845b781b5f1ad03',
'phone_number' => '48123456789',
'phoneNumber' => '48123456789',
'returns' => [
'success' => 'https://www.simpay.pl/success',
'failure' => 'https://www.simpay.pl/failure',
Expand All @@ -281,8 +329,8 @@ private function mockCreateDirectBillingTransaction(string $serviceId): void
[
'success' => true,
'data' => [
'transaction_id' => '1d87a1b3-18f8-4146-bcb1-c0c9f293b04f',
'redirect_url' => 'https://db.simpay.pl/1d87a1b3-18f8-4146-bcb1-c0c9f293b04f',
'transactionId' => '1d87a1b3-18f8-4146-bcb1-c0c9f293b04f',
'redirectUrl' => 'https://db.simpay.pl/1d87a1b3-18f8-4146-bcb1-c0c9f293b04f',
],
],
));
Expand All @@ -299,10 +347,10 @@ private function mockDirectBillingTransactionResponse(string $serviceId, string
'data' => [
'id' => $transactionId,
'status' => 'transaction_db_payed',
'phone_number' => null,
'phoneNumber' => null,
'control' => '1d87a1b3-18f8-4146-bcb1-c0c9f293b04f',
'value' => 16.67,
'value_netto' => 10,
'value_net' => 10,
'operator' => 't-mobile',
'notify' => [
'is_send' => false,
Expand Down
Loading