Skip to content

Commit

Permalink
fix(core): Add check on order PaymentSettled transition
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbromley committed Oct 2, 2020
1 parent 460963a commit 141d650
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/core/src/i18n/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/service/services/order.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 141d650

Please sign in to comment.