Skip to content

Commit

Permalink
feat: add action dto
Browse files Browse the repository at this point in the history
  • Loading branch information
kajetan-nobel committed Oct 3, 2023
1 parent 539532d commit ff8d6c2
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/DTO/Casts/ActionDto.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace Routegroup\Imoje\Payment\DTO\Casts;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Routegroup\Imoje\Payment\DTO\BaseDto;
use Routegroup\Imoje\Payment\Factories\Casts\ActionDtoFactory;
use Routegroup\Imoje\Payment\Types\ActionType;

/**
* @property-read ActionType $type
* @property-read string $url
* @property-read string $method
* @property-read string $contentType
* @property-read string $contentBodyRaw
* @property-read string|null $ban
*/
class ActionDto extends BaseDto
{
use HasFactory;

protected array $casts = [
'type' => ActionType::class,
'url' => 'string',
'method' => 'string',
'contentType' => 'string',
'contentBodyRaw' => 'string',
];

protected static function newFactory(): ActionDtoFactory
{
return ActionDtoFactory::new();
}
}
3 changes: 3 additions & 0 deletions src/DTO/Notifications/Paywall/TransactionNotificationDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Routegroup\Imoje\Payment\DTO\BaseDto;
use Routegroup\Imoje\Payment\DTO\Casts\ActionDto;
use Routegroup\Imoje\Payment\DTO\Casts\PaymentDto;
use Routegroup\Imoje\Payment\DTO\Casts\TransactionDto;
use Routegroup\Imoje\Payment\Factories\Notifications\Paywall\TransactionNotificationDtoFactory;

/**
* @property-read TransactionDto $transaction
* @property-read PaymentDto $payment
* @property-read ActionDto $action
*/
class TransactionNotificationDto extends BaseDto
{
Expand All @@ -21,6 +23,7 @@ class TransactionNotificationDto extends BaseDto
protected array $casts = [
'transaction' => TransactionDto::class,
'payment' => PaymentDto::class,
'action' => ActionDto::class,
];

protected static function newFactory(): TransactionNotificationDtoFactory
Expand Down
32 changes: 32 additions & 0 deletions src/Factories/Casts/ActionDtoFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace Routegroup\Imoje\Payment\Factories\Casts;

use Routegroup\Imoje\Payment\DTO\Casts\ActionDto;
use Routegroup\Imoje\Payment\Factories\Factory;
use Routegroup\Imoje\Payment\Types\ActionType;

class ActionDtoFactory extends Factory
{
protected $model = ActionDto::class;

public function definition(): array
{
return [
'type' => ActionType::TRANSFER,
'url' => '',
'method' => 'GET',
'contentType' => '',
'contentBodyRaw' => '',
];
}

public function wireTransfer(): static
{
return $this->state([
'iban' => $this->faker->iban,
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Routegroup\Imoje\Payment\Factories\Notifications\Paywall;

use Routegroup\Imoje\Payment\DTO\Casts\ActionDto;
use Routegroup\Imoje\Payment\DTO\Casts\PaymentDto;
use Routegroup\Imoje\Payment\DTO\Casts\TransactionDto;
use Routegroup\Imoje\Payment\DTO\Notifications\Paywall\TransactionNotificationDto;
Expand All @@ -18,6 +19,7 @@ public function definition(): array
return [
'transaction' => TransactionDto::factory(),
'payment' => PaymentDto::factory(),
'action' => ActionDto::factory(),
];
}
}
9 changes: 9 additions & 0 deletions src/Types/ActionType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Routegroup\Imoje\Payment\Types;

enum ActionType: string
{
case REDIRECT = 'redirect';
case TRANSFER = 'transfer';
}

0 comments on commit ff8d6c2

Please sign in to comment.