def passes()

in support-frontend/app/utils/CheckoutValidationRules.scala [349:382]


  def passes(createSupportWorkersRequest: CreateSupportWorkersRequest, fulfilmentOptions: FulfilmentOptions): Result = {

    val maybeValid: Either[Result, Result] = for {
      address <- createSupportWorkersRequest.deliveryAddress.toRight(Invalid("missing delivery address"))
      postCode <- address.postCode.toRight(Invalid("missing post code"))
    } yield {

      val hasDeliveryAddressInUKAndPaidInGbp =
        deliveredToUkAndPaidInGbp(address.country, createSupportWorkersRequest.product.currency)
      val deliveryAddressHasAddressLine1AndCity = hasAddressLine1AndCity(address)
      val validPostcode = fulfilmentOptions match {
        case NationalDelivery => Valid // checked separately
        case HomeDelivery => postcodeIsWithinHomeDeliveryArea(postCode)
        case Collection => Valid
        case Domestic => Invalid("domestic is not valid for paper")
        case RestOfWorld => Invalid("rest of world is not valid for paper")
        case NoFulfilmentOptions => Invalid("no fulfilment options is not valid for paper")
      }

      PaidProductValidation.passes(createSupportWorkersRequest) and
        hasDeliveryAddressInUKAndPaidInGbp and
        createSupportWorkersRequest.firstDeliveryDate.nonEmpty.otherwise("first delivery date is missing") and
        hasAddressLine1AndCity(createSupportWorkersRequest.billingAddress) and
        deliveryAddressHasAddressLine1AndCity and
        validPostcode and hasValidPostcodeLength(address.postCode, "Delivery") and hasValidPostcodeLength(
          createSupportWorkersRequest.billingAddress.postCode,
          "Billing",
        )

    }

    maybeValid.merge // since we have Either[Result, Result] we can .merge it into a Result

  }