-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: add dedicated create, get and delete requests for sessions
- Loading branch information
Showing
10 changed files
with
185 additions
and
31 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Upgrading | ||
****# Upgrading | ||
|
||
## From v2 to v3 | ||
|
||
|
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,20 @@ | ||
<?php | ||
|
||
namespace Mollie\Api\Factories; | ||
|
||
use Mollie\Api\Http\Requests\CreateSessionRequest; | ||
|
||
class CreateSessionRequestFactory extends RequestFactory | ||
{ | ||
public function create(): CreateSessionRequest | ||
{ | ||
return new CreateSessionRequest( | ||
$this->payload('redirectUrl'), | ||
$this->payload('cancelUrl'), | ||
MoneyFactory::new($this->payload('amount'))->create(), | ||
$this->payload('description'), | ||
$this->payload('method'), | ||
$this->payload('checkoutFlow') | ||
); | ||
} | ||
} |
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,25 @@ | ||
<?php | ||
|
||
namespace Mollie\Api\Http\Requests; | ||
|
||
use Mollie\Api\Types\Method; | ||
use Mollie\Api\Resources\Session; | ||
|
||
class CancelSessionRequest extends ResourceHydratableRequest | ||
{ | ||
protected static string $method = Method::DELETE; | ||
|
||
protected $hydratableResource = Session::class; | ||
|
||
private string $sessionId; | ||
|
||
public function __construct(string $sessionId) | ||
{ | ||
$this->sessionId = $sessionId; | ||
} | ||
|
||
public function resolveResourcePath(): string | ||
{ | ||
return "sessions/{$this->sessionId}"; | ||
} | ||
} |
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,64 @@ | ||
<?php | ||
|
||
namespace Mollie\Api\Http\Requests; | ||
|
||
use Mollie\Api\Contracts\HasPayload; | ||
use Mollie\Api\Http\Data\Money; | ||
use Mollie\Api\Traits\HasJsonPayload; | ||
use Mollie\Api\Types\Method; | ||
use Mollie\Api\Resources\Session; | ||
use Mollie\Api\Types\CheckoutFlow; | ||
|
||
class CreateSessionRequest extends ResourceHydratableRequest implements HasPayload | ||
{ | ||
use HasJsonPayload; | ||
|
||
protected static string $method = Method::POST; | ||
|
||
protected $hydratableResource = Session::class; | ||
|
||
private string $redirectUrl; | ||
|
||
private string $cancelUrl; | ||
|
||
private Money $amount; | ||
|
||
private string $description; | ||
|
||
private string $paymentMethod; | ||
|
||
private string $checkoutFlow; | ||
|
||
public function __construct( | ||
string $redirectUrl, | ||
string $cancelUrl, | ||
Money $amount, | ||
string $description, | ||
string $method, | ||
?string $checkoutFlow = null | ||
) { | ||
$this->redirectUrl = $redirectUrl; | ||
$this->cancelUrl = $cancelUrl; | ||
$this->amount = $amount; | ||
$this->description = $description; | ||
$this->paymentMethod = $method; | ||
$this->checkoutFlow = $checkoutFlow ?? CheckoutFlow::EXPRESS; | ||
} | ||
|
||
protected function defaultPayload(): array | ||
{ | ||
return [ | ||
'redirectUrl' => $this->redirectUrl, | ||
'cancelUrl' => $this->cancelUrl, | ||
'amount' => $this->amount, | ||
'description' => $this->description, | ||
'method' => $this->paymentMethod, | ||
'checkoutFlow' => $this->checkoutFlow, | ||
]; | ||
} | ||
|
||
public function resolveResourcePath(): string | ||
{ | ||
return 'sessions'; | ||
} | ||
} |
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,25 @@ | ||
<?php | ||
|
||
namespace Mollie\Api\Http\Requests; | ||
|
||
use Mollie\Api\Resources\Session; | ||
use Mollie\Api\Types\Method; | ||
|
||
class GetSessionRequest extends ResourceHydratableRequest | ||
{ | ||
protected static string $method = Method::GET; | ||
|
||
protected $hydratableResource = Session::class; | ||
|
||
private string $id; | ||
|
||
public function __construct(string $id) | ||
{ | ||
$this->id = $id; | ||
} | ||
|
||
public function resolveResourcePath(): string | ||
{ | ||
return 'sessions/' . $this->id; | ||
} | ||
} |
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,8 @@ | ||
<?php | ||
|
||
namespace Mollie\Api\Types; | ||
|
||
class CheckoutFlow | ||
{ | ||
public const EXPRESS = 'express'; | ||
} |
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