diff --git a/doc/installation.md b/doc/installation.md
index 2440142c..936f038e 100644
--- a/doc/installation.md
+++ b/doc/installation.md
@@ -932,3 +932,42 @@ If you are missing translations, just clear the cache:
```bash
php bin/console cache:clear
```
+
+# Sylius API
+In order to create Mollie payment with Sylius API, the following steps must be followed:
+
+- send the following request to the Sylius API in order to retrieve Mollie payment method configuration: /api/v2/shop/orders/{tokenValue}/payments/{paymentId}/configuration
+- tokenValue represents order token which is saved in the sylius_order DB table
+- response from this endpoint should be in the following format:
+
+```json
+{
+ "method": "ideal",
+ "issuer": "ideal_ABNANL2A",
+ "cardToken": null,
+ "amount": {"value":"18.75","currency":"EUR"},
+ "customerId": null,
+ "description": "000000157",
+ "redirectUrl": "{redirect_url}",
+ "webhookUrl": "{webhook_url}",
+ "metadata": {"order_id":170,"customer_id":22,"molliePaymentMethods":"ideal","cartToken":null,"saveCardInfo":null,"useSavedCards":null,"selected_issuer":"ideal_ABNANL2A","methodType":"Payments API","refund_token":"{token}"},
+ "locale": "en_US"
+}
+```
+- create the payment on Mollie, using Mollie API. Response from the above-mentioned step should be put in the request body.
+Request should be sent to the POST: https://api.mollie.com/v2/payments. Bearer token should be sent in the request authorization header.
+Token can be copied from the Mollie admin configuration page.
+
+- after payment has been created, API response will contain checkout field. User should enter this url in the browser.
+
+```json
+{
+ "checkout":
+ {
+ "href": "https://www.mollie.com/checkout/test-mode?method=ideal&token=6.voklib",
+ "type": "text/html"
+}}
+```
+- open checkout url in the browser and complete the payment
+
+
diff --git a/src/Action/ApiPlatform/MolliePayment.php b/src/Action/ApiPlatform/MolliePayment.php
new file mode 100644
index 00000000..0499af46
--- /dev/null
+++ b/src/Action/ApiPlatform/MolliePayment.php
@@ -0,0 +1,79 @@
+urlGenerator = $urlGenerator;
+ }
+
+ /**
+ * @param PaymentMethodInterface $paymentMethod
+ *
+ * @return bool
+ */
+ public function supports(PaymentMethodInterface $paymentMethod): bool
+ {
+ /** @var GatewayConfigInterface $gatewayConfig */
+ $gatewayConfig = $paymentMethod->getGatewayConfig();
+
+ return $gatewayConfig->getFactoryName() === self::MOLLIE_PAYMENT_METHOD_NAME;
+ }
+
+ /**
+ * @param PaymentInterface $payment
+ *
+ * @return array
+ */
+ public function provideConfiguration(PaymentInterface $payment): array
+ {
+ /** @var OrderInterface $order */
+ $order = $payment->getOrder();
+
+ $details = $payment->getDetails();
+ $methodName = $details['molliePaymentMethods'] ?? null;
+
+ if (!$methodName) {
+ if (isset($details['metadata']['molliePaymentMethods'])) {
+ $methodName = $details['metadata']['molliePaymentMethods'];
+ }
+ }
+
+ $redirectUrl = $this->urlGenerator->generate('sylius_mollie_plugin_payum', [], UrlGeneratorInterface::ABSOLUTE_URL);
+ $webhookUrl = $this->urlGenerator->generate('sylius_mollie_plugin_payment_webhook', [], UrlGeneratorInterface::ABSOLUTE_URL);
+ $redirectUrl .= '?orderId=' . $order->getId();
+ $webhookUrl .= '?orderId=' . $order->getId();
+
+ return [
+ "method" => $methodName,
+ "issuer" => isset($details['selected_issuer']) ? $details['selected_issuer'] : null,
+ "cardToken" => isset($details['metadata']['cartToken']) ? $details['metadata']['cartToken'] : null,
+ "amount" => isset($details['amount']) ? $details['amount'] : null,
+ "customerId" => isset($details['customerId']) ? $details['customerId'] : null,
+ "description" => isset($details['description']) ? $details['description'] : null,
+ "redirectUrl" => $redirectUrl,
+ "webhookUrl" => $webhookUrl,
+ "metadata" => isset($details['metadata']) ? $details['metadata'] : null,
+ "locale" => isset($details['locale']) ? $details['locale'] : null
+ ];
+ }
+}
diff --git a/src/Action/ConvertMolliePaymentAction.php b/src/Action/ConvertMolliePaymentAction.php
index f4c7d354..e795e630 100644
--- a/src/Action/ConvertMolliePaymentAction.php
+++ b/src/Action/ConvertMolliePaymentAction.php
@@ -108,9 +108,9 @@ public function execute($request): void
$useSavedCards = $paymentOptions['metadata']['useSavedCards'];
} else {
$paymentMethod = $paymentOptions['molliePaymentMethods'] ?? null;
- $cartToken = $paymentOptions['cartToken'];
- $saveCardInfo = $paymentOptions['saveCardInfo'];
- $useSavedCards = $paymentOptions['useSavedCards'];
+ $cartToken = $paymentOptions['cartToken'] ?? null;
+ $saveCardInfo = $paymentOptions['saveCardInfo'] ?? null;
+ $useSavedCards = $paymentOptions['useSavedCards'] ?? null;
}
/** @var MollieGatewayConfigInterface $method */
diff --git a/src/Repository/MollieSubscriptionRepository.php b/src/Repository/MollieSubscriptionRepository.php
index 4826707e..6ded5f1a 100644
--- a/src/Repository/MollieSubscriptionRepository.php
+++ b/src/Repository/MollieSubscriptionRepository.php
@@ -13,14 +13,18 @@ final class MollieSubscriptionRepository extends EntityRepository implements Mol
{
public function findOneByOrderId(int $orderId): ?MollieSubscriptionInterface
{
- $qb = $this->createQueryBuilder('q');
-
- $qb->leftJoin('q.orders', 'o');
- $qb->andWhere('o.id = :orderId');
- $qb->setParameter('orderId', $orderId);
-
- return $qb->getQuery()->getOneOrNullResult()
- ;
+ try {
+ $qb = $this->createQueryBuilder('q');
+
+ $qb->leftJoin('q.orders', 'o');
+ $qb->andWhere('o.id = :orderId');
+ $qb->setParameter('orderId', $orderId);
+
+ return $qb->getQuery()->getOneOrNullResult()
+ ;
+ } catch (\Exception $exception) {
+ return null;
+ }
}
public function findByOrderId(int $orderId): array
diff --git a/src/Resources/config/services/action.xml b/src/Resources/config/services/action.xml
index cf5034ba..e6a384d5 100644
--- a/src/Resources/config/services/action.xml
+++ b/src/Resources/config/services/action.xml
@@ -17,6 +17,10 @@
+
+
+
+