def createSubscription()

in support-frontend/app/services/stepfunctions/SupportWorkersClient.scala [130:202]


  def createSubscription(
      request: Request[CreateSupportWorkersRequest],
      user: User,
      requestId: UUID,
  ): EitherT[Future, String, StatusResponse] = {
    for {
      giftRecipient <- EitherT.fromEither[Future](
        request.body.giftRecipient.map(getGiftRecipient(_, request.body.product)).sequence,
      )
      createPaymentMethodState = CreatePaymentMethodState(
        requestId = requestId,
        user = user,
        giftRecipient = giftRecipient,
        product = request.body.product,
        analyticsInfo = AnalyticsInfo(
          giftRecipient.isDefined,
          PaymentProvider.fromPaymentFields(request.body.paymentFields),
        ),
        paymentFields = request.body.paymentFields,
        acquisitionData = Some(
          AcquisitionData(
            ophanIds = request.body.ophanIds,
            referrerAcquisitionData = referrerAcquisitionDataWithGAFields(request),
            supportAbTests = request.body.supportAbTests,
          ),
        ),
        appliedPromotion = request.body.appliedPromotion,
        csrUsername = request.body.csrUsername,
        salesforceCaseId = request.body.salesforceCaseId,
        firstDeliveryDate = request.body.firstDeliveryDate,
        userAgent = request.headers.get("user-agent").getOrElse("Unknown"),
        ipAddress =
          request.headers.get("X-Forwarded-For").flatMap(_.split(',').headOption).getOrElse(request.remoteAddress),
        similarProductsConsent = request.body.similarProductsConsent,
      )
      isExistingAccount = createPaymentMethodState.paymentFields match {
        case _: ExistingPaymentFields => true
        case _ => false
      }
      name =
        (if (user.isTestUser) "TestUser-" else "") +
          createPaymentMethodState.product.describe + "-" +
          createPaymentMethodState.paymentFields.describe
      executionResult <- underlying
        .triggerExecution(createPaymentMethodState, user.isTestUser, isExistingAccount, name)
        .bimap(
          { error =>
            logger.error(scrub"[$requestId] Failed to trigger Step Function execution for ${user.id} - $error")
            StateMachineFailure.toString
          },
          { success =>
            logger.info(s"[$requestId] Successfully triggered Step Function execution for ${user.id} ($success)")
            underlying.jobIdFromArn(success.arn).map { jobId =>
              StatusResponse(
                status = Status.Pending,
                trackingUri = supportUrl + statusCall(jobId).url,
              )
            } getOrElse {
              logger.error(
                scrub"[$requestId] Failed to parse ${success.arn} to a jobId after triggering Step Function execution for ${user.id} $request",
              )
              StatusResponse(
                status = Status.Failure,
                trackingUri = "",
                failureReason = Some(CheckoutFailureReasons.Unknown),
              )
            }

          },
        )
    } yield executionResult

  }