Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
fix(connector): [Iatapay] fix error response handling when payment is failed (#3197)
Prasunna Soppa716a74cf8449
diff --git a/crates/router/src/connector/iatapay/transformers.rs b/crates/router/src/connector/iatapay/transformers.rsindex b6d2dee4a0..e6ecc6da2f 100644--- a/crates/router/src/connector/iatapay/transformers.rs+++ b/crates/router/src/connector/iatapay/transformers.rs@@ -1,16 +1,20 @@use std::collections::HashMap;use api_models::enums::PaymentMethod;+use common_utils::errors::CustomResult;use masking::{Secret, SwitchStrategy};use serde::{Deserialize, Serialize};use crate::{connector::utils::{self, PaymentsAuthorizeRequestData, RefundsRequestData, RouterData},+ consts,core::errors,services,types::{self, api, storage::enums, PaymentsAuthorizeData},};+type Error = error_stack::Report<errors::ConnectorError>;+// Every access token will be valid for 5 minutes. It contains grant_type and scope for different type of access, but for our usecases it should be only 'client_credentials' and 'payment' resp(as per doc) for all type of api call.#[derive(Debug, Serialize)]pub struct IatapayAuthUpdateRequest {@@ -257,53 +261,85 @@ pub struct IatapayPaymentsResponse {pub bank_transfer_description: Option<String>,pub checkout_methods: Option<CheckoutMethod>,pub failure_code: Option<String>,+ pub failure_details: Option<String>,+}++fn get_iatpay_response(+ response: IatapayPaymentsResponse,+ status_code: u16,+) -> CustomResult<+ (+ enums::AttemptStatus,+ Option<types::ErrorResponse>,+ types::PaymentsResponseData,+ ),+ errors::ConnectorError,+> {+ let status = enums::AttemptStatus::from(response.status);+ let error = if status == enums::AttemptStatus::Failure {+ Some(types::ErrorResponse {+ code: response+ .failure_code+ .unwrap_or_else(|| consts::NO_ERROR_CODE.to_string()),+ message: response+ .failure_details+ .clone()+ .unwrap_or_else(|| consts::NO_ERROR_MESSAGE.to_string()),+ reason: response.failure_details,+ status_code,+ attempt_status: Some(status),+ connector_transaction_id: response.iata_payment_id.clone(),+ })+ } else {+ None+ };+ let form_fields = HashMap::new();+ let id = match response.iata_payment_id.clone() {+ Some(s) => types::ResponseId::ConnectorTransactionId(s),+ None => types::ResponseId::NoResponseId,+ };+ let connector_response_reference_id = response.merchant_payment_id.or(response.iata_payment_id);++ let payment_response_data = response.checkout_methods.map_or(+ types::PaymentsResponseData::TransactionResponse {+ resource_id: id.clone(),+ redirection_data: None,+ mandate_reference: None,+ connector_metadata: None,+ network_txn_id: None,+ connector_response_reference_id: connector_response_reference_id.clone(),+ incremental_authorization_allowed: None,+ },+ |checkout_methods| types::PaymentsResponseData::TransactionResponse {+ resource_id: id,+ redirection_data: Some(services::RedirectForm::Form {+ endpoint: checkout_methods.redirect.redirect_url,+ method: services::Method::Get,+ form_fields,+ }),+ mandate_reference: None,+ connector_metadata: None,+ network_txn_id: None,+ connector_response_reference_id: connector_response_reference_id.clone(),+ incremental_authorization_allowed: None,+ },+ );+ Ok((status, error, payment_response_data))}impl<F, T>TryFrom<types::ResponseRouterData<F, IatapayPaymentsResponse, T, types::PaymentsResponseData>>for types::RouterData<F, T, types::PaymentsResponseData>{- type Error = error_stack::Report<errors::ConnectorError>;+ type Error = Error;fn try_from(item: types::ResponseRouterData<F, IatapayPaymentsResponse, T, types::PaymentsResponseData>,) -> Result<Self, Self::Error> {- let form_fields = HashMap::new();- let id = match item.response.iata_payment_id.clone() {- Some(s) => types::ResponseId::ConnectorTransactionId(s),- None => types::ResponseId::NoResponseId,- };- let connector_response_reference_id = item- .response- .merchant_payment_id- .or(item.response.iata_payment_id);+ let (status, error, payment_response_data) =+ get_iatpay_response(item.response, item.http_code)?;Ok(Self {- status: enums::AttemptStatus::from(item.response.status),- response: item.response.checkout_methods.map_or(- Ok(types::PaymentsResponseData::TransactionResponse {- resource_id: id.clone(),- redirection_data: None,- mandate_reference: None,- connector_metadata: None,- network_txn_id: None,- connector_response_reference_id: connector_response_reference_id.clone(),- incremental_authorization_allowed: None,- }),- |checkout_methods| {- Ok(types::PaymentsResponseData::TransactionResponse {- resource_id: id,- redirection_data: Some(services::RedirectForm::Form {- endpoint: checkout_methods.redirect.redirect_url,- method: services::Method::Get,- form_fields,- }),- mandate_reference: None,- connector_metadata: None,- network_txn_id: None,- connector_response_reference_id: connector_response_reference_id.clone(),- incremental_authorization_allowed: None,- })- },- ),+ status,+ response: error.map_or_else(|| Ok(payment_response_data), Err),..item.data})}