From 7bca167e97f576414e179969e4510fe8f37178a9 Mon Sep 17 00:00:00 2001 From: Christian Dangl Date: Mon, 16 Oct 2023 17:48:45 +0200 Subject: [PATCH] MOL-1244: fix refund manager for swag commercial plugin --- .../Api/Order/ShippingControllerBase.php | 26 +- .../src/core/models/OrderAttributes.js | 50 ++- .../mollie-refund-manager/RefundManager.js | 31 ++ .../components/mollie-refund-manager/index.js | 1 - .../mollie-ship-order/MollieShipping.js | 94 ++++++ .../mollie-ship-order/MollieShippingEvents.js | 11 + .../components/mollie-ship-order/index.js | 149 +++++++-- .../mollie-ship-order.html.twig | 29 +- .../sw-order-line-items-grid/index.js | 207 ++++++------- .../sw-order-line-items-grid.html.twig | 110 +++---- .../component/sw-order-user-card/index.js | 118 ++++--- .../sw-order-user-card.html.twig | 21 +- .../view/sw-order-detail-base/index.js | 109 +++++-- .../sw-order-detail-base.html.twig | 54 ++-- .../view/sw-order-detail-general/index.js | 202 +++++++----- .../sw-order-detail-general.html.twig | 287 ++++++++++-------- .../app/administration/src/snippet/de-DE.json | 4 +- .../app/administration/src/snippet/en-GB.json | 4 +- .../app/administration/src/snippet/nl-NL.json | 4 +- .../FullShippingRepository.js | 2 +- 20 files changed, 959 insertions(+), 554 deletions(-) create mode 100644 src/Resources/app/administration/src/module/mollie-payments/components/mollie-refund-manager/RefundManager.js create mode 100644 src/Resources/app/administration/src/module/mollie-payments/components/mollie-ship-order/MollieShipping.js create mode 100644 src/Resources/app/administration/src/module/mollie-payments/components/mollie-ship-order/MollieShippingEvents.js diff --git a/src/Controller/Api/Order/ShippingControllerBase.php b/src/Controller/Api/Order/ShippingControllerBase.php index 0f6fe31b7..2ed3cdcce 100644 --- a/src/Controller/Api/Order/ShippingControllerBase.php +++ b/src/Controller/Api/Order/ShippingControllerBase.php @@ -4,6 +4,7 @@ use Exception; use Kiener\MolliePayments\Facade\MollieShipment; +use Kiener\MolliePayments\Traits\Api\ApiTrait; use Mollie\Api\Resources\OrderLine; use Mollie\Api\Resources\Shipment; use Psr\Log\LoggerInterface; @@ -18,6 +19,8 @@ class ShippingControllerBase extends AbstractController { + use ApiTrait; + /** * @var MollieShipment */ @@ -83,8 +86,8 @@ public function shipOrderApi(QueryDataBag $query, Context $context): JsonRespons * * @param QueryDataBag $query * @param Context $context - * @throws \Exception * @return JsonResponse + * @throws \Exception */ public function shipItemApi(QueryDataBag $query, Context $context): JsonResponse { @@ -225,13 +228,8 @@ public function shipOrderLegacy(RequestDataBag $data, Context $context): JsonRes * @param Context $context * @return JsonResponse */ - public function getShipOrderResponse( - string $orderId, - string $trackingCarrier, - string $trackingCode, - string $trackingUrl, - Context $context - ): JsonResponse { + public function getShipOrderResponse(string $orderId, string $trackingCarrier, string $trackingCode, string $trackingUrl, Context $context): JsonResponse + { try { if (empty($orderId)) { throw new \InvalidArgumentException('Missing Argument for Order ID!'); @@ -247,14 +245,7 @@ public function getShipOrderResponse( return $this->shipmentToJson($shipment); } catch (\Exception $e) { - $data = [ - 'orderId' => $orderId, - 'trackingCarrier' => $trackingCarrier, - 'trackingCode' => $trackingCode, - 'trackingUrl' => $trackingUrl, - ]; - - return $this->exceptionToJson($e, $data); + return $this->buildErrorResponse($e->getMessage()); } } @@ -316,7 +307,8 @@ public function getShipItemResponse( string $trackingCode, string $trackingUrl, Context $context - ): JsonResponse { + ): JsonResponse + { try { if (empty($orderId)) { throw new \InvalidArgumentException('Missing Argument for Order ID!'); diff --git a/src/Resources/app/administration/src/core/models/OrderAttributes.js b/src/Resources/app/administration/src/core/models/OrderAttributes.js index 540980d30..626e047a6 100644 --- a/src/Resources/app/administration/src/core/models/OrderAttributes.js +++ b/src/Resources/app/administration/src/core/models/OrderAttributes.js @@ -12,29 +12,39 @@ export default class OrderAttributes { this._paymentId = ''; this._swSubscriptionId = ''; this._creditCardAttributes = null; + this._paymentRef = null; if (orderEntity === null) { return; } - const customFields = orderEntity.customFields; + this.customFields = orderEntity.customFields; - if (customFields === null || customFields === undefined) { + if (this.customFields === null || this.customFields === undefined) { return; } - if (customFields.mollie_payments === undefined || customFields.mollie_payments === null) { + if (this.customFields.mollie_payments === undefined || this.customFields.mollie_payments === null) { return; } - const mollieData = customFields.mollie_payments; + const mollieData = this.customFields.mollie_payments; this._orderId = this._convertString(mollieData['order_id']); this._paymentId = this._convertString(mollieData['payment_id']); this._swSubscriptionId = this._convertString(mollieData['swSubscriptionId']); + this._paymentRef = this._convertString(mollieData['third_party_payment_id']); this._creditCardAttributes = new CreditcardAttributes(mollieData); } + /** + * + * @returns {boolean} + */ + isMollieOrder() { + return (this.customFields !== null && 'mollie_payments' in this.customFields); + } + /** * * @returns {null|CreditcardAttributes|*} @@ -59,6 +69,30 @@ export default class OrderAttributes { return this._paymentId; } + /** + * + * @returns {string|*|null} + */ + getMollieID() { + if (this.getOrderId() !== '') { + return this.getOrderId(); + } + + if (this.getPaymentId() !== '') { + return this.getPaymentId(); + } + + return null; + } + + /** + * + * @returns {boolean} + */ + isSubscription() { + return (this.getSwSubscriptionId() !== ''); + } + /** * * @returns {string|*} @@ -67,6 +101,14 @@ export default class OrderAttributes { return this._swSubscriptionId; } + /** + * + * @returns {string} + */ + getPaymentRef() { + return this._paymentRef; + } + /** * * @param value 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 new file mode 100644 index 000000000..df52402b6 --- /dev/null +++ b/src/Resources/app/administration/src/module/mollie-payments/components/mollie-refund-manager/RefundManager.js @@ -0,0 +1,31 @@ +export default class RefundManager { + + /** + * + * @param configService + * @param acl + */ + constructor(configService, acl) { + this._configService = configService; + this._acl = acl; + } + + /** + * Gets if the refund manager is available + * @returns {boolean} + */ + async isRefundManagerAvailable(salesChannelId) { + let refundManagerPossible = false; + + await this._configService.getRefundManagerConfig(salesChannelId).then((response) => { + refundManagerPossible = response.enabled; + }); + + if (!refundManagerPossible) { + return false; + } + + return this._acl.can('mollie_refund_manager:read'); + } + +} \ No newline at end of file diff --git a/src/Resources/app/administration/src/module/mollie-payments/components/mollie-refund-manager/index.js b/src/Resources/app/administration/src/module/mollie-payments/components/mollie-refund-manager/index.js index a4a4ea0d9..33a22ed5e 100644 --- a/src/Resources/app/administration/src/module/mollie-payments/components/mollie-refund-manager/index.js +++ b/src/Resources/app/administration/src/module/mollie-payments/components/mollie-refund-manager/index.js @@ -160,7 +160,6 @@ Component.register('mollie-refund-manager', { } }, - // --------------------------------------------------------------------------------------------------------- // // --------------------------------------------------------------------------------------------------------- diff --git a/src/Resources/app/administration/src/module/mollie-payments/components/mollie-ship-order/MollieShipping.js b/src/Resources/app/administration/src/module/mollie-payments/components/mollie-ship-order/MollieShipping.js new file mode 100644 index 000000000..3266e9c0f --- /dev/null +++ b/src/Resources/app/administration/src/module/mollie-payments/components/mollie-ship-order/MollieShipping.js @@ -0,0 +1,94 @@ +import OrderAttributes from '../../../../core/models/OrderAttributes'; + +export default class MollieShipping { + + + /** + * + * @param shippingService + */ + constructor(shippingService) { + this._shippingService = shippingService; + } + + /** + * + * @param order + * @returns {boolean} + */ + async isShippingPossible(order) { + + const orderAttributes = new OrderAttributes(order); + + // this can happen on subscription renewals...they have no order id + // and therefore the order cannot be shipped + if (orderAttributes.getOrderId() === '') { + return false; + } + + const items = await this.getShippableItems(order); + + for (let i = 0; i < items.length; i++) { + const lineItem = items[i]; + + if (lineItem.quantity > 0) { + return true; + } + } + + return false; + } + + /** + * + * @param order + * @returns {Promise<{quantity: *, label: *}[]>} + */ + async getShippableItems(order) { + // load the already shipped items + // so that we can calculate what is left to be shipped + await this._shippingService + .status({ + orderId: order.id, + }) + .then((response) => { + this.shippedLineItems = response; + }); + + const finalItems = []; + + for (let i = 0; i < order.lineItems.length; i++) { + const lineItem = order.lineItems[i]; + + finalItems.push({ + label: lineItem.label, + quantity: this._shippableQuantity(lineItem), + }); + } + + return finalItems; + + } + + /** + * + * @param item + * @returns {*|number} + * @private + */ + _shippableQuantity(item) { + + if (this.shippedLineItems === null || this.shippedLineItems === undefined) { + return 0; + } + + const itemShippingStatus = this.shippedLineItems[item.id]; + + if (itemShippingStatus === null || itemShippingStatus === undefined) { + return 0; + } + + return itemShippingStatus.quantityShippable; + } + +} diff --git a/src/Resources/app/administration/src/module/mollie-payments/components/mollie-ship-order/MollieShippingEvents.js b/src/Resources/app/administration/src/module/mollie-payments/components/mollie-ship-order/MollieShippingEvents.js new file mode 100644 index 000000000..0862b58b3 --- /dev/null +++ b/src/Resources/app/administration/src/module/mollie-payments/components/mollie-ship-order/MollieShippingEvents.js @@ -0,0 +1,11 @@ +export default class MollieShippingEvents { + + /** + * + * @returns {string} + */ + static get EventShippedOrder() { + return 'mollie-shipped-order'; + } + +} diff --git a/src/Resources/app/administration/src/module/mollie-payments/components/mollie-ship-order/index.js b/src/Resources/app/administration/src/module/mollie-payments/components/mollie-ship-order/index.js index 4b760e361..ebd15e265 100644 --- a/src/Resources/app/administration/src/module/mollie-payments/components/mollie-ship-order/index.js +++ b/src/Resources/app/administration/src/module/mollie-payments/components/mollie-ship-order/index.js @@ -1,49 +1,160 @@ import template from './mollie-ship-order.html.twig'; +import MollieShippingEvents from "./MollieShippingEvents"; // eslint-disable-next-line no-undef -const {Component} = Shopware; +const {Component, Mixin} = Shopware; Component.register('mollie-ship-order', { template, - props: { - shippableLineItems: { - type: Array, - }, - order:{ + mixins: [ + Mixin.getByName('notification'), + ], + + inject: [ + 'MolliePaymentsShippingService', + 'MolliePaymentsConfigService', + 'acl', + ], + + props: { + order: { type: Object, + required: true, }, - tracking: { - carrier: '', - code: '', - url: '', - }, - showTrackingInfo:false, + }, + + data() { + return { + shippableLineItems: [], + shippedLineItems: [], + showTrackingInfo: false, + tracking: { + carrier: '', + code: '', + url: '', + }, + }; + }, + + + /** + * + */ + created() { + this.createdComponent(); }, computed: { + getShipOrderColumns() { return [ { property: 'label', label: this.$tc('mollie-payments.modals.shipping.order.itemHeader'), - }, - { + }, { property: 'quantity', label: this.$tc('mollie-payments.modals.shipping.order.quantityHeader'), }, ]; }, - shippableLineItems1() { - return this.orderLineItems - .filter((item) => this.shippableQuantity(item)) + + }, + + methods: { + + /** + * + */ + async createdComponent() { + + this.showTrackingInfo = false; + + this.tracking = { + carrier: '', + code: '', + url: '', + }; + + + // load the already shipped items + // so that we can calculate what is left to be shipped + await this.MolliePaymentsShippingService + .status({ + orderId: this.order.id, + }) + .then((response) => { + this.shippedLineItems = response; + }); + + this.shippableLineItems = this.order.lineItems .map((item) => { return { label: item.label, - quantity: this.shippableQuantity(item), + quantity: this._shippableQuantity(item), } }); + + + // if we have at least 1 tracking code in the order + // then try to prefill our tracking information + // also automatically enable the tracking data (it can be turned off again by the merchant) + if (this.order.deliveries.length) { + const delivery = this.order.deliveries.first(); + this.showTrackingInfo = (delivery.trackingCodes.length >= 1); + } }, + + /** + * + */ + onShipOrder() { + + const params = { + orderId: this.order.id, + trackingCarrier: this.tracking.carrier, + trackingCode: this.tracking.code, + trackingUrl: this.tracking.url, + }; + + this.MolliePaymentsShippingService.shipOrder(params) + .then(() => { + // send global event + this.$root.$emit(MollieShippingEvents.EventShippedOrder); + this.createNotificationSuccess({ + message: this.$tc('mollie-payments.modals.shipping.item.success'), + }); + }) + .catch((response) => { + const msg = (response.response.data.message) ? response.response.data.message : response.response.data.errors[0]; + this.createNotificationError({ + message: msg, + }); + }); + }, + + /** + * + * @param item + * @returns {*|number} + * @private + */ + _shippableQuantity(item) { + + if (this.shippedLineItems === null || this.shippedLineItems === undefined) { + return 0; + } + + const itemShippingStatus = this.shippedLineItems[item.id]; + + if (itemShippingStatus === null || itemShippingStatus === undefined) { + return 0; + } + + return itemShippingStatus.quantityShippable; + }, + }, -}); \ No newline at end of file + +}); diff --git a/src/Resources/app/administration/src/module/mollie-payments/components/mollie-ship-order/mollie-ship-order.html.twig b/src/Resources/app/administration/src/module/mollie-payments/components/mollie-ship-order/mollie-ship-order.html.twig index d72639e06..344b541ab 100644 --- a/src/Resources/app/administration/src/module/mollie-payments/components/mollie-ship-order/mollie-ship-order.html.twig +++ b/src/Resources/app/administration/src/module/mollie-payments/components/mollie-ship-order/mollie-ship-order.html.twig @@ -1,14 +1,24 @@

{{ $tc('mollie-payments.modals.shipping.order.description') }}

- - + {% block sw_order_line_items_grid_grid_mollie_ship_item_modal_items %} + + + {% endblock %} + + + {{ $tc('mollie-payments.modals.shipping.confirmButton') }} + {% block sw_order_line_items_grid_grid_mollie_ship_item_modal_tracking %} {% endblock %} -
\ No newline at end of file + + diff --git a/src/Resources/app/administration/src/module/mollie-payments/extension/sw-order/component/sw-order-line-items-grid/index.js b/src/Resources/app/administration/src/module/mollie-payments/extension/sw-order/component/sw-order-line-items-grid/index.js index a649356db..f03df8a27 100644 --- a/src/Resources/app/administration/src/module/mollie-payments/extension/sw-order/component/sw-order-line-items-grid/index.js +++ b/src/Resources/app/administration/src/module/mollie-payments/extension/sw-order/component/sw-order-line-items-grid/index.js @@ -1,6 +1,9 @@ import template from './sw-order-line-items-grid.html.twig'; import './sw-order-line-items-grid.scss'; 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"; // eslint-disable-next-line no-undef const {Component, Mixin} = Shopware; @@ -36,7 +39,11 @@ Component.override('sw-order-line-items-grid', { // --------------------------------- configShowRefundManager: true, showRefundModal: false, + isRefundManagerPossible: false, // --------------------------------- + isShippingPossible: false, + showShipOrderModal: false, + isShipOrderLoading: false, isShipItemLoading: false, shipQuantity: 0, @@ -47,12 +54,18 @@ Component.override('sw-order-line-items-grid', { code: '', url: '', }, - showShipOrderModal: false, showTrackingInfo: false, + + EVENT_TOGGLE_REFUND_MANAGER: 'toggle-refund-manager-modal', }; }, computed: { + + /** + * + * @returns {*} + */ getLineItemColumns() { const columnDefinitions = this.$super('getLineItemColumns'); @@ -70,49 +83,13 @@ Component.override('sw-order-line-items-grid', { return columnDefinitions; }, - shippableLineItems() { - return this.orderLineItems - .filter((item) => this.shippableQuantity(item)) - .map((item) => { - return { - label: item.label, - quantity: this.shippableQuantity(item), - } - }); - }, - - isMollieOrder() { - return (this.order.customFields !== null && 'mollie_payments' in this.order.customFields); - }, - - isShippingPossible() { - - if (!this.isMollieOrder) { - return false; - } - - const orderAttributes = new OrderAttributes(this.order); - - // this can happen on subscription renewals...they have no order id - // and therefore the order cannot be shipped - if (orderAttributes.getOrderId() === '') { - return false; - } - - return this.shippableLineItems.length > 0; - }, - /** * * @returns {boolean} */ - isRefundManagerPossible() { - - if (!this.configShowRefundManager) { - return; - } - - return this.acl.can('mollie_refund_manager:read'); + isMollieOrder() { + const attr = new OrderAttributes(this.order); + return attr.isMollieOrder(); }, /** @@ -137,121 +114,122 @@ Component.override('sw-order-line-items-grid', { created() { this.createdComponent(); }, - watch: { - showShipOrderModal(showShipOrderModal) { - if (showShipOrderModal) { - this.updateTrackingPrefilling(); - } else { - this.isShipOrderLoading = false; - this.resetTracking(); - } - }, - }, methods: { + /** + * + * @returns {Promise} + */ async createdComponent() { - // Do not attempt to load the shipping status if this isn't a Mollie order, - // or it will trigger an exception in the API. - let refundManagerPossible = false; + if (!this.isMollieOrder) { + return; + } - if (this.isMollieOrder) { - await this.getShippingStatus(); + // hook into our shipping events + // we close our modals if shipping happened + this.$root.$on(MollieShippingEvents.EventShippedOrder, () => { + this.onCloseShipOrderModal(); + }); - const me = this; + this.refundedManagerService = new RefundManager(this.MolliePaymentsConfigService, this.acl); + this.shippingManagerService = new MollieShipping(this.MolliePaymentsShippingService); - this.MolliePaymentsConfigService.getRefundManagerConfig(this.order.salesChannelId).then((response) => { - me.configShowRefundManager = response.enabled; - }); - refundManagerPossible = this.isRefundManagerPossible; + this.reloadData(); + }, + + /** + * + */ + async reloadData() { + this.shippingManagerService.isShippingPossible(this.order).then((enabled) => { + this.isShippingPossible = enabled; + }); - } - this.$emit('refund-manager-possible', refundManagerPossible) - this.$emit('shipping-possible', this.isShippingPossible) - }, + this.isRefundManagerPossible = this.refundedManagerService.isRefundManagerAvailable(this.order.salesChannelId); + await this.loadMollieShippingStatus(); + }, // ==============================================================================================// // REFUND MANAGER + /** + * + */ onOpenRefundManager() { this.showRefundModal = true; - this.$emit('toggle-refund-manager-modal', this.showRefundModal); }, + /** + * + */ onCloseRefundManager() { this.showRefundModal = false; - this.$emit('toggle-refund-manager-modal', this.showRefundModal); }, //==== Shipping =============================================================================================// - async getShippingStatus() { - await this.MolliePaymentsShippingService - .status({ - orderId: this.order.id, - }) - .then((response) => { - this.shippingStatus = response; - }); - }, - + /** + * + */ onOpenShipOrderModal() { this.showShipOrderModal = true; }, + /** + * + */ onCloseShipOrderModal() { this.showShipOrderModal = false; + this.reloadData(); }, - onConfirmShipOrder() { - if (this.showTrackingInfo && !this.validateTracking()) { - this.createNotificationError({ - message: this.$tc('mollie-payments.modals.shipping.tracking.invalid'), - }); - return; - } - - this.isShipOrderLoading = true; - - this.MolliePaymentsShippingService - .shipOrder({ - orderId: this.order.id, - trackingCarrier: this.tracking.carrier, - trackingCode: this.tracking.code, - trackingUrl: this.tracking.url, - }) - .then(() => { - this.onCloseShipOrderModal(); - }) - .then(async () => { - this.$emit('ship-item-success'); - await this.getShippingStatus(); - this.$emit('shipping-possible', this.isShippingPossible) - }) - .catch((response) => { - this.createNotificationError({ - message: response.message, - }); - }); - }, + //==== Shipping Line Item =============================================================================================// + // unfortunately too tightly integrated in here + /** + * + * @param item + */ onOpenShipItemModal(item) { this.showShipItemModal = item.id; - this.updateTrackingPrefilling(); }, + /** + * + */ onCloseShipItemModal() { this.isShipItemLoading = false; this.showShipItemModal = false; this.shipQuantity = 0; this.resetTracking(); + + this.reloadData(); + }, + + /** + * + * @returns {Promise} + */ + async loadMollieShippingStatus() { + await this.MolliePaymentsShippingService + .status({ + orderId: this.order.id, + }) + .then((response) => { + this.shippingStatus = response; + }); }, + /** + * + * @param item + */ onConfirmShipItem(item) { if (this.shipQuantity === 0) { this.createNotificationError({ @@ -283,13 +261,15 @@ Component.override('sw-order-line-items-grid', { message: this.$tc('mollie-payments.modals.shipping.item.success'), }); this.onCloseShipItemModal(); + // send global event + this.$root.$emit(MollieShippingEvents.EventShippedOrder); }) .then(() => { this.$emit('ship-item-success'); }) .catch((response) => { this.createNotificationError({ - message: response.message, + message: response.response.data.message, }); }); }, @@ -344,6 +324,11 @@ Component.override('sw-order-line-items-grid', { } }, + validateTracking() { + return !string.isEmptyOrSpaces(this.tracking.carrier) + && !string.isEmptyOrSpaces(this.tracking.code) + }, + resetTracking() { this.showTrackingInfo = false; this.tracking = { @@ -353,9 +338,5 @@ Component.override('sw-order-line-items-grid', { }; }, - validateTracking() { - return !string.isEmptyOrSpaces(this.tracking.carrier) - && !string.isEmptyOrSpaces(this.tracking.code) - }, }, }); diff --git a/src/Resources/app/administration/src/module/mollie-payments/extension/sw-order/component/sw-order-line-items-grid/sw-order-line-items-grid.html.twig b/src/Resources/app/administration/src/module/mollie-payments/extension/sw-order/component/sw-order-line-items-grid/sw-order-line-items-grid.html.twig index a38d2e57e..e266c0b09 100644 --- a/src/Resources/app/administration/src/module/mollie-payments/extension/sw-order/component/sw-order-line-items-grid/sw-order-line-items-grid.html.twig +++ b/src/Resources/app/administration/src/module/mollie-payments/extension/sw-order/component/sw-order-line-items-grid/sw-order-line-items-grid.html.twig @@ -1,17 +1,25 @@ + {% block sw_order_line_items_grid_actions %} {% parent %} - - + class="sw-order-line-items-grid__actions-container" + columns="1fr auto" + gap="16px"> {% block sw_order_line_items_grid_line_item_filter %} {% parent %} {% endblock %} - {# =================================================================================================================== MOLLIE ACTIONS @@ -59,54 +67,45 @@ {% endblock %} - - {# style="background-color: #f0f2f5 !important;" - =================================================================================================================== - REFUND MANAGER - =================================================================================================================== - #} - - - - - - - {# - =================================================================================================================== - SHIPPING - =================================================================================================================== - #} - - - - - + + {# + =================================================================================================================== + REFUND MANAGER + =================================================================================================================== + #} + + + + + + {# + =================================================================================================================== + SHIPPING + =================================================================================================================== + #} + + + + + + {% endblock %} @@ -191,7 +190,10 @@ {{ $tc('mollie-payments.modals.shipping.cancelButton') }} - {{ $tc('mollie-payments.modals.shipping.confirmButton') }} 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 11b198054..50d63561e 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 @@ -2,7 +2,6 @@ import template from './sw-order-user-card.html.twig'; import './sw-order-user-card.scss'; import OrderAttributes from '../../../../../../core/models/OrderAttributes'; - // eslint-disable-next-line no-undef const {Component} = Shopware; @@ -20,6 +19,24 @@ Component.override('sw-order-user-card', { }, computed: { + + /** + * + * @returns {boolean} + */ + isMollieOrder() { + const attr = new OrderAttributes(this.currentOrder); + return attr.isMollieOrder(); + }, + + /** + * + * @returns {*} + */ + hasCreditCardData() { + return this._creditCardData().hasCreditCardData(); + }, + /** * * @returns {string|*} @@ -49,30 +66,17 @@ Component.override('sw-order-user-card', { * @returns {null|string|*} */ mollieOrderId() { - const orderAttributes = new OrderAttributes(this.currentOrder); - - if (orderAttributes.getOrderId() !== '') { - return orderAttributes.getOrderId(); - } - - if (orderAttributes.getPaymentId() !== '') { - return orderAttributes.getPaymentId(); - } - - return null; + return orderAttributes.getMollieID(); }, - mollieThirdPartyPaymentId() { - if ( - !!this.currentOrder - && !!this.currentOrder.customFields - && !!this.currentOrder.customFields.mollie_payments - && !!this.currentOrder.customFields.mollie_payments.third_party_payment_id - ) { - return this.currentOrder.customFields.mollie_payments.third_party_payment_id; - } - return null; + /** + * + * @returns {string} + */ + mollieThirdPartyPaymentId() { + const orderAttributes = new OrderAttributes(this.currentOrder); + return orderAttributes.getPaymentRef(); }, /** @@ -81,7 +85,7 @@ Component.override('sw-order-user-card', { */ isSubscription() { const orderAttributes = new OrderAttributes(this.currentOrder); - return (orderAttributes.getSwSubscriptionId() !== ''); + return orderAttributes.isSubscription(); }, /** @@ -101,10 +105,6 @@ Component.override('sw-order-user-card', { return this.molliePaymentUrl !== ''; }, - hasCreditCardData() { - return this._creditCardData().hasCreditCardData(); - }, - }, created() { @@ -114,61 +114,51 @@ Component.override('sw-order-user-card', { methods: { /** * - * @returns {CreditcardAttributes|*} */ - _creditCardData() { - const orderAttributes = new OrderAttributes(this.currentOrder); - return orderAttributes.getCreditCardAttributes(); - }, - createdComponent() { this.$super('createdComponent'); this.molliePaymentUrl = ''; - if (this.mollieOrderId) { - this.isMolliePaymentUrlLoading = true; - - this.MolliePaymentsOrderService.getPaymentUrl({orderId: this.currentOrder.id}) - .then(response => { - this.molliePaymentUrl = (response.url !== null) ? response.url : ''; - }) - .finally(() => { - this.isMolliePaymentUrlLoading = false; - }); + if (!this.mollieOrderId) { + return; } + + this.isMolliePaymentUrlLoading = true; + + this.MolliePaymentsOrderService.getPaymentUrl({orderId: this.currentOrder.id}) + .then(response => { + this.molliePaymentUrl = (response.url !== null) ? response.url : ''; + }) + .finally(() => { + this.isMolliePaymentUrlLoading = false; + }); + }, + + /** + * + * @returns {CreditcardAttributes|*} + */ + _creditCardData() { + const orderAttributes = new OrderAttributes(this.currentOrder); + return orderAttributes.getCreditCardAttributes(); }, + /** + * + */ copyPaymentUrlToClipboard() { // eslint-disable-next-line no-undef Shopware.Utils.dom.copyToClipboard(this.molliePaymentUrl); this.molliePaymentUrlCopied = true; }, - onMolliePaymentUrlProcessFinished(value) { - this.molliePaymentUrlCopied = value; - }, - /** * - * @returns {{voucher_type: *}|*|null} + * @param value */ - getMollieData() { - if (this.currentOrder === undefined || this.currentOrder === null) { - return null; - } - - if (this.currentOrder.customFields === undefined || this.currentOrder.customFields === null) { - return null; - } - - const customFields = this.currentOrder.customFields; - - if (customFields.mollie_payments === undefined || customFields.mollie_payments === null) { - return null; - } - - return customFields.mollie_payments; + onMolliePaymentUrlProcessFinished(value) { + this.molliePaymentUrlCopied = value; }, }, diff --git a/src/Resources/app/administration/src/module/mollie-payments/extension/sw-order/component/sw-order-user-card/sw-order-user-card.html.twig b/src/Resources/app/administration/src/module/mollie-payments/extension/sw-order/component/sw-order-user-card/sw-order-user-card.html.twig index 0b31d72bd..3d1227b02 100644 --- a/src/Resources/app/administration/src/module/mollie-payments/extension/sw-order/component/sw-order-user-card/sw-order-user-card.html.twig +++ b/src/Resources/app/administration/src/module/mollie-payments/extension/sw-order/component/sw-order-user-card/sw-order-user-card.html.twig @@ -1,11 +1,24 @@ + {% block sw_order_detail_base_secondary_info_payment %} {% parent %} -