Browse Source

fix(core): Add check on order PaymentSettled transition

Michael Bromley 5 years ago
parent
commit
141d650904

+ 1 - 0
packages/core/src/i18n/messages/en.json

@@ -69,6 +69,7 @@
     "PAYMENT_DECLINED_ERROR": "The payment was declined",
     "PAYMENT_FAILED_ERROR": "The payment failed",
     "PAYMENT_ORDER_MISMATCH_ERROR": "The Payment and OrderLines do not belong to the same Order",
+    "PAYMENT_STATE_TRANSITION_ERROR": "Cannot transition Payment from \"{ fromState }\" to \"{ toState }\"",
     "PRODUCT_OPTION_IN_USE_ERROR": "Cannot remove ProductOptionGroup \"{ optionGroupCode }\" as it is used by {productVariantCount, plural, one {1 ProductVariant} other {# ProductVariants}}",
     "QUANTITY_TOO_GREAT_ERROR": "The specified quantity is greater than the available OrderItems",
     "REFUND_ORDER_STATE_ERROR": "Cannot refund an Order in the \"{ orderState }\" state",

+ 5 - 1
packages/core/src/service/services/order.service.ts

@@ -650,7 +650,11 @@ export class OrderService {
             this.eventBus.publish(
                 new PaymentStateTransitionEvent(fromState, toState, ctx, payment, payment.order),
             );
-            if (payment.amount === payment.order.total) {
+            const orderTotalSettled = payment.amount === payment.order.total;
+            if (
+                orderTotalSettled &&
+                this.orderStateMachine.canTransition(payment.order.state, 'PaymentSettled')
+            ) {
                 const orderTransitionResult = await this.transitionToState(
                     ctx,
                     payment.order.id,