diff --git a/src/Controller/Api/Controller/OrderController.php b/src/Controller/Api/Controller/OrderController.php
new file mode 100644
index 000000000..e32647f15
--- /dev/null
+++ b/src/Controller/Api/Controller/OrderController.php
@@ -0,0 +1,125 @@
+baseController = $baseController;
+ $this->shippingController = $shippingController;
+ $this->requestBagFactory = $requestBagFactory;
+ $this->orderController = $orderController;
+ $this->cancelLineController = $cancelLineController;
+ $this->orderRepository = $orderRepository;
+ }
+
+ /**
+ * Requires orderId, salesChannelId and mollieOrderId to be set in the request.
+ */
+ public function getOrderDetails(Request $request, Context $context): JsonResponse
+ {
+ $orderId = $request->get('orderId');
+ $scId = $this->getSalesChannelId($orderId, $context);
+ $mollieOrderId = $this->getMollieOrderId($orderId, $context);
+
+ $request->request->set('mollieOrderId', $mollieOrderId);
+ $request->request->set('salesChannelId', $scId);
+
+ $config = $this->baseController->getRefundManagerConfig($request, $context);
+ $shipping = $this->shippingController->total($this->requestBagFactory->createForShipping($request), $context);
+ $payment = $this->orderController->paymentUrl($request, $context);
+ $cancelStatus = $this->cancelLineController->statusAction($request, $context);
+
+ $result = [
+ 'config' => $config->getContent(),
+ 'shipping' => $shipping->getContent(),
+ 'payment' => $payment->getContent(),
+ 'cancelStatus' => $cancelStatus->getContent(),
+ ];
+
+ foreach ($result as &$item) {
+ if (is_string($item)) {
+ $item = json_decode($item);
+ }
+ }
+
+ return new JsonResponse(array_merge(['success' => true,], $result));
+ }
+
+ private function getSalesChannelId(string $orderId, Context $context): string
+ {
+ $orders = $this->orderRepository->search(new Criteria([$orderId]), $context);
+
+ if ($orders->count() === 0) {
+ throw new \RuntimeException('Order not found');
+ }
+
+ $order = $orders->first();
+
+ return $order->getSalesChannelId();
+ }
+
+ private function getMollieOrderId(string $orderId, Context $context): string
+ {
+ $orders = $this->orderRepository->search(new Criteria([$orderId]), $context);
+
+ if ($orders->count() === 0) {
+ throw new \RuntimeException('Order not found');
+ }
+
+ $order = $orders->first();
+
+ $customFields = $order->getCustomFieldsValue('mollie_payments');
+
+ return $customFields['order_id'];
+ }
+}
diff --git a/src/Controller/Api/Controller/RequestBagFactory.php b/src/Controller/Api/Controller/RequestBagFactory.php
new file mode 100644
index 000000000..facd5547b
--- /dev/null
+++ b/src/Controller/Api/Controller/RequestBagFactory.php
@@ -0,0 +1,18 @@
+set('orderId', $request->get('orderId'));
+
+ return $result;
+ }
+}
diff --git a/src/Resources/app/administration/src/core/service/api/mollie-payments-config.service.js b/src/Resources/app/administration/src/core/service/api/mollie-payments-config.service.js
index 30abc3966..73590ad9b 100644
--- a/src/Resources/app/administration/src/core/service/api/mollie-payments-config.service.js
+++ b/src/Resources/app/administration/src/core/service/api/mollie-payments-config.service.js
@@ -1,7 +1,10 @@
+
+import MolliePaymentsRefundBundleRepositoryService from './mollie-payments-refund-bundle-repository.service';
// eslint-disable-next-line no-undef
const ApiService = Shopware.Classes.ApiService;
export default class MolliePaymentsConfigService extends ApiService {
+ repository;
/**
@@ -78,19 +81,11 @@ export default class MolliePaymentsConfigService extends ApiService {
* @returns {*}
*/
getRefundManagerConfig(salesChannelId, orderId) {
- return this.httpClient
- .post(
- `_action/${this.getApiBasePath()}/config/refund-manager`,
- {
- 'salesChannelId': salesChannelId,
- 'orderId': orderId,
- },
- {
- headers: this.getBasicHeaders(),
- }
- ).then((response) => {
- return ApiService.handleResponse(response);
- });
+ MolliePaymentsRefundBundleRepositoryService.setOrderId(orderId);
+ MolliePaymentsRefundBundleRepositoryService.setClient(this.httpClient);
+ MolliePaymentsRefundBundleRepositoryService.setHeaders(this.getBasicHeaders());
+
+ return MolliePaymentsRefundBundleRepositoryService.fetch()
}
}
diff --git a/src/Resources/app/administration/src/core/service/api/mollie-payments-order.service.js b/src/Resources/app/administration/src/core/service/api/mollie-payments-order.service.js
index 40e2d80bb..8242c0a15 100644
--- a/src/Resources/app/administration/src/core/service/api/mollie-payments-order.service.js
+++ b/src/Resources/app/administration/src/core/service/api/mollie-payments-order.service.js
@@ -1,3 +1,5 @@
+
+import MolliePaymentsRefundBundleRepositoryService from './mollie-payments-refund-bundle-repository.service';
// eslint-disable-next-line no-undef
const ApiService = Shopware.Classes.ApiService;
@@ -9,17 +11,13 @@ class MolliePaymentsOrderService extends ApiService {
getPaymentUrl(data = {orderId: null}) {
const headers = this.getBasicHeaders();
- return this.httpClient
- .post(
- `_action/${this.getApiBasePath()}/order/payment-url`,
- JSON.stringify(data),
- {
- headers: headers,
- }
- )
- .then((response) => {
- return ApiService.handleResponse(response);
- });
+ MolliePaymentsRefundBundleRepositoryService.setOrderId(data.orderId);
+ MolliePaymentsRefundBundleRepositoryService.setHeaders(headers);
+ MolliePaymentsRefundBundleRepositoryService.setClient(this.httpClient);
+
+ return MolliePaymentsRefundBundleRepositoryService.fetch().then((response) => {
+ return ApiService.handleResponse(response.data.payment);
+ });
}
}
diff --git a/src/Resources/app/administration/src/core/service/api/mollie-payments-refund-bundle-repository.service.js b/src/Resources/app/administration/src/core/service/api/mollie-payments-refund-bundle-repository.service.js
new file mode 100644
index 000000000..dcf951157
--- /dev/null
+++ b/src/Resources/app/administration/src/core/service/api/mollie-payments-refund-bundle-repository.service.js
@@ -0,0 +1,53 @@
+// eslint-disable-next-line no-undef
+const ApiService = Shopware.Classes.ApiService;
+
+export default class MolliePaymentsRefundBundleRepositoryService extends ApiService {
+ static response = null;
+ static orderId = null;
+ static headers = null
+ static client = null;
+
+ static setOrderId(orderId) {
+ if (orderId !== null) {
+ MolliePaymentsRefundBundleRepositoryService.orderId = orderId;
+ }
+ }
+
+ static setHeaders(headers) {
+ if (headers !== null) {
+ MolliePaymentsRefundBundleRepositoryService.headers = headers;
+ }
+ }
+
+ static setClient(client) {
+ if (client !== null) {
+ MolliePaymentsRefundBundleRepositoryService.client = client;
+ }
+ }
+
+ static fetch() {
+ if (!MolliePaymentsRefundBundleRepositoryService.client) {
+ throw new Error('Client not set. Please set the client using setClient() method.');
+ }
+
+ if (!MolliePaymentsRefundBundleRepositoryService.orderId) {
+ throw new Error('orderId not set. Please set the orderId using setOrderId() method.');
+ }
+
+ if (MolliePaymentsRefundBundleRepositoryService.response !== null) {
+ return MolliePaymentsRefundBundleRepositoryService.response;
+ }
+
+ MolliePaymentsRefundBundleRepositoryService.response = MolliePaymentsRefundBundleRepositoryService.client.post(
+ '_action/mollie/refund-manager/bundled',
+ {
+ orderId: MolliePaymentsRefundBundleRepositoryService.orderId,
+ },
+ {
+ headers: MolliePaymentsRefundBundleRepositoryService.headers,
+ }
+ );
+
+ return MolliePaymentsRefundBundleRepositoryService.response;
+ }
+}
diff --git a/src/Resources/app/administration/src/module/mollie-payments/components/mollie-refund-manager/RefundManager.js b/src/Resources/app/administration/src/module/mollie-payments/components/mollie-refund-manager/RefundManager.js
index 722c5c348..c6e145ad4 100644
--- a/src/Resources/app/administration/src/module/mollie-payments/components/mollie-refund-manager/RefundManager.js
+++ b/src/Resources/app/administration/src/module/mollie-payments/components/mollie-refund-manager/RefundManager.js
@@ -24,9 +24,10 @@ export default class RefundManager {
let refundManagerPossible = false;
- await this._configService.getRefundManagerConfig(salesChannelId, orderId).then((response) => {
- refundManagerPossible = response.enabled;
- });
+ await this._configService.getRefundManagerConfig(salesChannelId, orderId)
+ .then((response) => {
+ refundManagerPossible = response.data.config.enabled;
+ });
return refundManagerPossible;
}
diff --git a/src/Resources/app/administration/src/module/mollie-payments/extension/sw-order/component/sw-order-user-card/index.js b/src/Resources/app/administration/src/module/mollie-payments/extension/sw-order/component/sw-order-user-card/index.js
index 50d63561e..3398faeda 100644
--- a/src/Resources/app/administration/src/module/mollie-payments/extension/sw-order/component/sw-order-user-card/index.js
+++ b/src/Resources/app/administration/src/module/mollie-payments/extension/sw-order/component/sw-order-user-card/index.js
@@ -128,7 +128,7 @@ Component.override('sw-order-user-card', {
this.MolliePaymentsOrderService.getPaymentUrl({orderId: this.currentOrder.id})
.then(response => {
- this.molliePaymentUrl = (response.url !== null) ? response.url : '';
+ this.molliePaymentUrl = (response.data.payment.url !== null) ? response.data.payment.url : '';
})
.finally(() => {
this.isMolliePaymentUrlLoading = false;
diff --git a/src/Resources/app/administration/src/module/mollie-payments/extension/sw-order/view/sw-order-detail-general/index.js b/src/Resources/app/administration/src/module/mollie-payments/extension/sw-order/view/sw-order-detail-general/index.js
index 413006563..69354d314 100644
--- a/src/Resources/app/administration/src/module/mollie-payments/extension/sw-order/view/sw-order-detail-general/index.js
+++ b/src/Resources/app/administration/src/module/mollie-payments/extension/sw-order/view/sw-order-detail-general/index.js
@@ -4,6 +4,8 @@ import OrderAttributes from '../../../../../../core/models/OrderAttributes';
import RefundManager from '../../../../components/mollie-refund-manager/RefundManager';
import MollieShipping from '../../../../components/mollie-ship-order/MollieShipping';
import MollieShippingEvents from '../../../../components/mollie-ship-order/MollieShippingEvents';
+import MolliePaymentsRefundBundleRepositoryService
+from '../../../../../../core/service/api/mollie-payments-refund-bundle-repository.service';
// eslint-disable-next-line no-undef
const {Component, Mixin, Filter} = Shopware;
@@ -259,8 +261,9 @@ Component.override('sw-order-detail-general', {
this.molliePaymentUrl = (response.url !== null) ? response.url : '';
});
- this.shippingManagerService.isShippingPossible(this.order).then((enabled) => {
- this.isShippingPossible = enabled;
+ MolliePaymentsRefundBundleRepositoryService.setOrderId(this.order.id);
+ MolliePaymentsRefundBundleRepositoryService.fetch().then((response) => {
+ this.isShippingPossible = response.data.shipping;
});
this.refundedManagerService.isRefundManagerAvailable(this.order.salesChannelId, this.order.id).then((possible)=>{
diff --git a/src/Resources/config/routes/admin-api/config.xml b/src/Resources/config/routes/admin-api/config.xml
index cdd230d5c..7ee8b2cd2 100644
--- a/src/Resources/config/routes/admin-api/config.xml
+++ b/src/Resources/config/routes/admin-api/config.xml
@@ -32,7 +32,7 @@
true
-
Kiener\MolliePayments\Controller\Api\PluginConfig\ConfigControllerBase::getRefundManagerConfig
@@ -41,6 +41,15 @@
true
+
+ Kiener\MolliePayments\Controller\Api\Controller\OrderController::getOrderDetails
+ api
+ true
+ true
+
+
diff --git a/src/Resources/config/services/controller.xml b/src/Resources/config/services/controller.xml
index de45570b5..e8ef55a90 100644
--- a/src/Resources/config/services/controller.xml
+++ b/src/Resources/config/services/controller.xml
@@ -17,6 +17,21 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+