generated from spatie/package-skeleton-laravel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3777713
commit 2f0d028
Showing
16 changed files
with
160 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Routegroup\Imoje\Payment\Client; | ||
|
||
use ArrayAccess; | ||
use Illuminate\Contracts\Support\Arrayable; | ||
use Illuminate\Http\Client\Response as OriginalResponse; | ||
use Routegroup\Imoje\Payment\DTO\BaseDto; | ||
use Routegroup\Imoje\Payment\Exceptions\InvalidDtoNameException; | ||
|
||
class Response implements Arrayable, ArrayAccess | ||
{ | ||
public function __construct( | ||
public readonly OriginalResponse $originalResponse, | ||
public readonly BaseDto $data | ||
) { | ||
} | ||
|
||
public static function resolve( | ||
OriginalResponse $clientResponse, | ||
string $dto, | ||
): Response { | ||
if (! is_subclass_of($dto, BaseDto::class)) { | ||
throw new InvalidDtoNameException(); | ||
} | ||
|
||
return new static( | ||
$clientResponse, | ||
new $dto($clientResponse->collect()->toArray()) | ||
); | ||
} | ||
|
||
public function toArray(): array | ||
{ | ||
return $this->data->toArray(); | ||
} | ||
|
||
public function offsetExists(mixed $offset): bool | ||
{ | ||
return isset($this->data[$offset]); | ||
} | ||
|
||
public function offsetGet(mixed $offset): mixed | ||
{ | ||
return $this->data->get($offset); | ||
} | ||
|
||
public function offsetSet(mixed $offset, mixed $value): void | ||
{ | ||
// | ||
} | ||
|
||
public function offsetUnset(mixed $offset): void | ||
{ | ||
unset($this->data[$offset]); | ||
} | ||
|
||
public function __get($key) | ||
{ | ||
return $this->data->get($key); | ||
} | ||
|
||
public function __isset(mixed $key) | ||
{ | ||
return $this->offsetExists($key); | ||
} | ||
|
||
public function __unset(mixed $key) | ||
{ | ||
$this->offsetUnset($key); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Routegroup\Imoje\Payment\DTO\Response; | ||
|
||
use Routegroup\Imoje\Payment\DTO\BaseDto; | ||
use Routegroup\Imoje\Payment\DTO\Response\Api\PaymentProfileResponseDto; | ||
|
||
/** | ||
* @property-read PaymentProfileResponseDto $transaction | ||
*/ | ||
class ProfileResponseDto extends BaseDto | ||
{ | ||
protected array $casts = [ | ||
'paymentProfile' => PaymentProfileResponseDto::class, | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Routegroup\Imoje\Payment\DTO\Response; | ||
|
||
use Routegroup\Imoje\Payment\DTO\BaseDto; | ||
use Routegroup\Imoje\Payment\DTO\Response\Api\TransactionResponseDto; | ||
|
||
/** | ||
* @property-read TransactionResponseDto $transaction | ||
*/ | ||
class RefundResponseDto extends BaseDto | ||
{ | ||
protected array $casts = [ | ||
'transaction' => TransactionResponseDto::class, | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Routegroup\Imoje\Payment\Exceptions; | ||
|
||
use InvalidArgumentException; | ||
|
||
class InvalidDtoNameException extends InvalidArgumentException | ||
{ | ||
protected $message = 'Given name is not a subclass of a DTO.'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters