processPayment method

Future<ProcessPaymentResponse> processPayment({
  1. required PaymentInput paymentInput,
  2. required String paymentInstrumentId,
  3. required String paymentManagerArn,
  4. required String paymentSessionId,
  5. required PaymentType paymentType,
  6. String? agentName,
  7. String? clientToken,
  8. String? userId,
})

Processes a payment using a payment instrument within a payment session.

May throw AccessDeniedException. May throw ConflictException. May throw InternalServerException. May throw ServiceQuotaExceededException. May throw ThrottlingException. May throw ValidationException.

Parameter paymentInput : The payment input details specific to the payment type.

Parameter paymentInstrumentId : The ID of the payment instrument to use.

Parameter paymentManagerArn : The ARN of the payment manager.

Parameter paymentSessionId : The ID of the payment session.

Parameter paymentType : The type of payment to process.

Parameter agentName : The agent name associated with this request, used for observability.

Parameter clientToken : A unique, case-sensitive identifier that you provide to ensure the idempotency of the request.

Parameter userId : The user ID associated with this payment.

Implementation

Future<ProcessPaymentResponse> processPayment({
  required PaymentInput paymentInput,
  required String paymentInstrumentId,
  required String paymentManagerArn,
  required String paymentSessionId,
  required PaymentType paymentType,
  String? agentName,
  String? clientToken,
  String? userId,
}) async {
  final headers = <String, String>{
    if (agentName != null)
      'X-Amzn-Bedrock-AgentCore-Payments-Agent-Name': agentName.toString(),
    if (userId != null)
      'X-Amzn-Bedrock-AgentCore-Payments-User-Id': userId.toString(),
  };
  final $payload = <String, dynamic>{
    'paymentInput': paymentInput,
    'paymentInstrumentId': paymentInstrumentId,
    'paymentManagerArn': paymentManagerArn,
    'paymentSessionId': paymentSessionId,
    'paymentType': paymentType.value,
    'clientToken': clientToken ?? _s.generateIdempotencyToken(),
  };
  final response = await _protocol.send(
    payload: $payload,
    method: 'POST',
    requestUri: '/payments/processPayment',
    headers: headers,
    exceptionFnMap: _exceptionFns,
  );
  return ProcessPaymentResponse.fromJson(response);
}