Skip to content
Open
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
18 changes: 14 additions & 4 deletions src/Factories/CreateSessionRequestFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,29 @@

namespace Mollie\Api\Factories;

use Mollie\Api\Http\Data\Address;
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->payload('redirectUrl'),
$this->transformFromPayload(
'lines',
fn ($items) => OrderLineCollectionFactory::new($items)->create()
),
$this->payload('cancelUrl'),
$this->transformFromPayload('billingAddress', fn ($item) => Address::fromArray($item)),
$this->transformFromPayload('shippingAddress', fn ($item) => Address::fromArray($item)),
$this->payload('customerId'),
$this->payload('sequenceType'),
$this->payload('metadata'),
$this->payload('webhookUrl', null, 'payment.'),
$this->payload('profileId')
);
}
}
8 changes: 4 additions & 4 deletions src/Factories/RequestFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ public function withQuery(array $query)
return $this;
}

protected function payload(?string $key = null, $default = null)
protected function payload(?string $key = null, $default = null, $backupKey = 'payment.')
{
return $this->get($key, $default, $this->payload);
return $this->get($key, $default, $this->payload, $backupKey);
}

protected function query(?string $key = null, $default = null)
protected function query(?string $key = null, $default = null, $backupKey = 'filters.')
{
return $this->get($key, $default, $this->query);
return $this->get($key, $default, $this->query, $backupKey);
}

protected function payloadIncludes(string $key, $value)
Expand Down
41 changes: 25 additions & 16 deletions src/Fake/Responses/session.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,40 @@
{
"resource": "session",
"id": "{{ RESOURCE_ID }}",
"clientAccessToken": "dddiweodh23973yo23d2h...",
"status": "open",
"mode": "live",
"status": "created",
"amount": {
"value": "10.00",
"currency": "EUR"
"currency": "EUR",
"value": "10.00"
},
"description": "Order #12345",
"method": "paypal",
"methodDetails": {
"checkoutFlow": "express"
"redirectUrl": "https://example.com/redirect",
"cancelUrl": "https://example.com/cancel",
"metadata": {
"orderId": "12345"
},
"nextAction": "redirect",
"createdAt": "2024-01-10T12:06:28+00:00",
"payment": {
"webhookUrl": "https://webshop.example.org/payments/webhook"
},
"lines": [
{
"description": "Product A",
"quantity": 1,
"unitPrice": {
"currency": "EUR",
"value": "10.00"
},
"totalAmount": {
"currency": "EUR",
"value": "10.00"
}
}
],
"_links": {
"self": {
"href": "https://api.mollie.com/v2/sessions/{{ RESOURCE_ID }}",
"type": "application/hal+json"
},
"redirect": {
"href": "https://paypalc.com/order/dghjfidf;gj",
"type": "application/hal+json"
},
"documentation": {
"href": "...",
"type": "text/html"
}
}
}
76 changes: 57 additions & 19 deletions src/Http/Requests/CreateSessionRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,57 +3,95 @@
namespace Mollie\Api\Http\Requests;

use Mollie\Api\Contracts\HasPayload;
use Mollie\Api\Contracts\SupportsTestmodeInPayload;
use Mollie\Api\Http\Data\Address;
use Mollie\Api\Http\Data\DataCollection;
use Mollie\Api\Http\Data\Money;
use Mollie\Api\Http\Data\OrderLine;
use Mollie\Api\Resources\Session;
use Mollie\Api\Traits\HasJsonPayload;
use Mollie\Api\Types\CheckoutFlow;
use Mollie\Api\Types\Method;

class CreateSessionRequest extends ResourceHydratableRequest implements HasPayload
class CreateSessionRequest extends ResourceHydratableRequest implements HasPayload, SupportsTestmodeInPayload
{
use HasJsonPayload;

protected static string $method = Method::POST;

protected $hydratableResource = Session::class;

private Money $amount;

private string $description;

private string $redirectUrl;

private string $cancelUrl;
/**
* @var DataCollection<OrderLine>
*/
private DataCollection $lines;

private Money $amount;
private ?string $cancelUrl;

private string $description;
private ?Address $billingAddress;

private ?Address $shippingAddress;

private ?string $customerId;

private ?string $sequenceType;

private ?array $metadata;

private string $paymentMethod;
private ?string $paymentWebhook;

private string $checkoutFlow;
private ?string $profileId;

public function __construct(
string $redirectUrl,
string $cancelUrl,
Money $amount,
string $description,
string $method,
?string $checkoutFlow = null
string $redirectUrl,
DataCollection $lines,
?string $cancelUrl = null,
?Address $billingAddress = null,
?Address $shippingAddress = null,
?string $customerId = null,
?string $sequenceType = null,
?array $metadata = null,
?string $paymentWebhook = null,
?string $profileId = null
) {
$this->redirectUrl = $redirectUrl;
$this->cancelUrl = $cancelUrl;
$this->amount = $amount;
$this->description = $description;
$this->paymentMethod = $method;
$this->checkoutFlow = $checkoutFlow ?? CheckoutFlow::EXPRESS;
$this->redirectUrl = $redirectUrl;
$this->lines = $lines;
$this->cancelUrl = $cancelUrl;
$this->billingAddress = $billingAddress;
$this->shippingAddress = $shippingAddress;
$this->customerId = $customerId;
$this->sequenceType = $sequenceType;
$this->metadata = $metadata;
$this->paymentWebhook = $paymentWebhook;
$this->profileId = $profileId;
}

protected function defaultPayload(): array
{
return [
'redirectUrl' => $this->redirectUrl,
'cancelUrl' => $this->cancelUrl,
'amount' => $this->amount,
'description' => $this->description,
'method' => $this->paymentMethod,
'checkoutFlow' => $this->checkoutFlow,
'redirectUrl' => $this->redirectUrl,
'lines' => $this->lines,
'cancelUrl' => $this->cancelUrl,
'billingAddress' => $this->billingAddress,
'shippingAddress' => $this->shippingAddress,
'customerId' => $this->customerId,
'sequenceType' => $this->sequenceType,
'metadata' => $this->metadata,
'profileId' => $this->profileId,
'payment' => $this->paymentWebhook !== null ? [
'webhookUrl' => $this->paymentWebhook,
] : null,
];
}

Expand Down
80 changes: 38 additions & 42 deletions src/Resources/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,11 @@ class Session extends BaseResource
public $status;

/**
* UTC datetime indicating the time at which the Session failed in ISO-8601 format.
*
* @example "2013-12-25T10:30:54+00:00"
*
* @var string|null
*/
public $failedAt;

/**
* Unique identifier to record the Userʼs authentication with a method
* Client access token for the session.
*
* @var string
*/
public $authenticationId;

/**
* Indicates the next action to take in the payment preparation flow.
*
* @var string
*/
public $nextAction;
public $clientAccessToken;

/**
* The URL the buyer will be redirected to in case the
Expand Down Expand Up @@ -85,36 +69,53 @@ class Session extends BaseResource
public $description;

/**
* Payment method currently selected by the shopper.
* The person and the address the payment is shipped to.
*
* @var string
* @var \stdClass|null
*/
public $method;
public $shippingAddress;

/**
* All additional information relating to the selected method.
* The person and the address the payment is billed to.
*
* @var \stdClass
* @var \stdClass|null
*/
public $methodDetails;
public $billingAddress;

/**
* The person and the address the payment is shipped to.
* ID of the customer the session is created for.
*
* @var string|null
*/
public $customerId;

/**
* Sequence type for recurring payments.
*
* @deprecated
* @var string|null
*/
public $sequenceType;

/**
* Metadata associated with the session.
*
* @var \stdClass
* @var object|array|null
*/
public $shippingAddress;
public $metadata;

/**
* The person and the address the payment is billed to.
* Payment settings for the session.
*
* @deprecated
* @var \stdClass|null
*/
public $payment;

/**
* Order lines for the session.
*
* @var \stdClass
* @var array|object[]|null
*/
public $billingAddress;
public $lines;

/**
* An object with several URL objects relevant to the customer. Every URL object will contain an href and a type field.
Expand All @@ -123,24 +124,19 @@ class Session extends BaseResource
*/
public $_links;

public function isCreated()
public function isOpen()
{
return $this->status === SessionStatus::STATUS_CREATED;
return $this->status === SessionStatus::OPEN;
}

public function isReadyForProcessing()
public function isExpired()
{
return $this->status === SessionStatus::STATUS_READY_FOR_PROCESSING;
return $this->status === SessionStatus::EXPIRED;
}

public function isCompleted()
{
return $this->status === SessionStatus::STATUS_COMPLETED;
}

public function hasFailed()
{
return $this->status === SessionStatus::STATUS_FAILED;
return $this->status === SessionStatus::COMPLETED;
}

/**
Expand Down
8 changes: 0 additions & 8 deletions src/Types/CheckoutFlow.php

This file was deleted.

15 changes: 5 additions & 10 deletions src/Types/SessionStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,17 @@
class SessionStatus
{
/**
* The session has just been created.
* The session is open.
*/
public const STATUS_CREATED = 'created';
public const OPEN = 'open';

/**
* The session has been paid.
* The session has expired.
*/
public const STATUS_READY_FOR_PROCESSING = 'ready_for_processing';
public const EXPIRED = 'expired';

/**
* The session is completed.
*/
public const STATUS_COMPLETED = 'completed';

/**
* The session has failed.
*/
public const STATUS_FAILED = 'failed';
public const COMPLETED = 'completed';
}
Loading