From 141d650904e327a0251dbce8f83542fe2e2f0602 Mon Sep 17 00:00:00 2001 From: Michael Bromley Date: Fri, 2 Oct 2020 14:15:37 +0200 Subject: [PATCH] fix(core): Add check on order PaymentSettled transition --- packages/core/src/i18n/messages/en.json | 1 + packages/core/src/service/services/order.service.ts | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/core/src/i18n/messages/en.json b/packages/core/src/i18n/messages/en.json index 854f9a8c40..bdb48bfac6 100644 --- a/packages/core/src/i18n/messages/en.json +++ b/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", diff --git a/packages/core/src/service/services/order.service.ts b/packages/core/src/service/services/order.service.ts index 538b1b79bb..a2db121f41 100644 --- a/packages/core/src/service/services/order.service.ts +++ b/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,