Booking Amendment

This workflow handles the end-to-end amendment of a previously confirmed freight booking. It validates the amendment request, enforces a mandatory processing hold using a Wait state, then runs concurrent carrier capacity re-check and hazmat re-verification using a Parallel state before issuing a confirmed amendment or cancellation.

{
  "Comment": "Booking amendment workflow: re-validate an existing confirmed booking, hold for processing, re-check capacity and hazmat in parallel, then confirm or cancel",
  "StartAt": "SetAmendmentMeta",
  "States": {
    "SetAmendmentMeta": {
      "Type": "Pass",
      "Parameters": {
        "amendmentId.$": "States.Format('AMD-{}-{}', $.bookingId, $$.Execution.Name)",
        "amendmentStatus": "PENDING",
        "booking.$": "$"
      },
      "Next": "ValidateAmendedBooking"
    },
    "ValidateAmendedBooking": {
      "Type": "Task",
      "Resource": "${ValidateBookingFunctionArn}",
      "ResultPath": "$.validation",
      "Next": "IsAmendmentValid"
    },
    "IsAmendmentValid": {
      "Type": "Choice",
      "Choices": [
        {
          "Variable": "$.validation.Payload.isValid",
          "BooleanEquals": true,
          "Next": "AmendmentProcessingHold"
        }
      ],
      "Default": "CancelAmendment"
    },
    "AmendmentProcessingHold": {
      "Type": "Wait",
      "Seconds": 5,
      "Next": "CarrierAndHazmatReCheck"
    },
    "CarrierAndHazmatReCheck": {
      "Type": "Parallel",
      "Branches": [
        {
          "StartAt": "ReCheckCarrierCapacity",
          "States": {
            "ReCheckCarrierCapacity": {
              "Type": "Task",
              "Resource": "${CheckCarrierCapacityFunctionArn}",
              "End": true
            }
          }
        },
        {
          "StartAt": "ReVerifyHazmat",
          "States": {
            "ReVerifyHazmat": {
              "Type": "Task",
              "Resource": "${VerifyHazmatFunctionArn}",
              "End": true
            }
          }
        }
      ],
      "ResultPath": "$.reChecks",
      "Next": "IsAmendmentApproved"
    },
    "IsAmendmentApproved": {
      "Type": "Choice",
      "Choices": [
        {
          "And": [
            {
              "Variable": "$.reChecks[0].Payload.isCapacityAvailable",
              "BooleanEquals": true
            },
            {
              "Variable": "$.reChecks[1].Payload.isHazmatCompliant",
              "BooleanEquals": true
            }
          ],
          "Next": "ConfirmAmendedBooking"
        }
      ],
      "Default": "CancelAmendment"
    },
    "ConfirmAmendedBooking": {
      "Type": "Task",
      "Resource": "${ConfirmBookingFunctionArn}",
      "ResultPath": "$.confirmation",
      "Next": "AmendmentConfirmed"
    },
    "CancelAmendment": {
      "Type": "Task",
      "Resource": "${CancelBookingFunctionArn}",
      "Parameters": {
        "cancelReason": "Amendment could not be fulfilled",
        "cancelReasonCode": "AMENDMENT_REJECTED",
        "booking.$": "$.booking"
      },
      "ResultPath": "$.cancellation",
      "Next": "AmendmentRejected"
    },
    "AmendmentConfirmed": {
      "Type": "Succeed"
    },
    "AmendmentRejected": {
      "Type": "Succeed"
    }
  }
}
JSON
Expand
100%

Logistics teams can use patterns like this to build reliable, compliant, and scalable automation for payment systems and can test and refine these flows locally with Thrubit to reduce cloud cost and speed up iteration.

Free Trial