refactor(core): Add 'redirect_response' field to CompleteAuthorizeData (#1222)

Signed-off-by: chikke srujan <121822803+srujanchikke@users.noreply.github.com>
This commit is contained in:
chikke srujan
2023-05-30 13:13:15 +05:30
committed by GitHub
parent 3af3a3cb39
commit 77e60c82fa
17 changed files with 66 additions and 30 deletions

View File

@ -1575,15 +1575,21 @@ pub struct Metadata {
#[serde(flatten)]
pub data: pii::SecretSerdeValue,
/// Payload coming in request as a metadata field
#[schema(value_type = Option<Object>)]
pub payload: Option<pii::SecretSerdeValue>,
/// Redirection response coming in request as metadata field only for redirection scenarios
pub redirect_response: Option<RedirectResponse>,
/// Allowed payment method types for a payment intent
#[schema(value_type = Option<Vec<PaymentMethodType>>)]
pub allowed_payment_method_types: Option<Vec<api_enums::PaymentMethodType>>,
}
#[derive(Default, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
pub struct RedirectResponse {
pub param: Option<Secret<String>>,
#[schema(value_type = Option<Object>)]
pub json_payload: Option<pii::SecretSerdeValue>,
}
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
pub struct PaymentsSessionRequest {
/// The identifier for the payment

View File

@ -1,3 +1,5 @@
use error_stack::{IntoReport, ResultExt};
use masking::PeekInterface;
use serde::{Deserialize, Serialize};
use time::PrimitiveDateTime;
use url::Url;
@ -166,9 +168,18 @@ impl TryFrom<&types::PaymentsCompleteAuthorizeRouterData> for AirwallexCompleteR
three_ds: AirwallexThreeDsData {
acs_response: item
.request
.payload
.redirect_response
.as_ref()
.map(|data| Secret::new(serde_json::Value::to_string(data))),
.map(|f| f.payload.to_owned())
.ok_or(errors::ConnectorError::MissingRequiredField {
field_name: "redirect_response.payload",
})?
.as_ref()
.map(|data| serde_json::to_string(data.peek()))
.transpose()
.into_report()
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?
.map(Secret::new),
},
three_ds_type: AirwallexThreeDsType::ThreeDSContinue,
})

View File

@ -80,10 +80,11 @@ impl TryFrom<&types::CompleteAuthorizeData> for BamboraThreedsContinueRequest {
type Error = error_stack::Report<errors::ConnectorError>;
fn try_from(value: &types::CompleteAuthorizeData) -> Result<Self, Self::Error> {
let card_response: CardResponse = value
.payload
.clone()
.redirect_response
.as_ref()
.and_then(|f| f.payload.to_owned())
.ok_or(errors::ConnectorError::MissingRequiredField {
field_name: "payload",
field_name: "redirect_response.payload",
})?
.parse_value("CardResponse")
.change_context(errors::ConnectorError::ParsingFailed)?;

View File

@ -339,10 +339,11 @@ impl TryFrom<&types::PaymentsCompleteAuthorizeRouterData> for BluesnapPaymentsRe
fn try_from(item: &types::PaymentsCompleteAuthorizeRouterData) -> Result<Self, Self::Error> {
let redirection_response: BluesnapRedirectionResponse = item
.request
.payload
.clone()
.redirect_response
.as_ref()
.and_then(|res| res.payload.to_owned())
.ok_or(errors::ConnectorError::MissingConnectorRedirectionPayload {
field_name: "request.payload",
field_name: "request.redirect_response.payload",
})?
.parse_value("BluesnapRedirectionResponse")
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;

View File

@ -361,7 +361,10 @@ impl PaymentRedirectFlow for PaymentRedirectCompleteAuthorize {
routing_parameters: None,
order_details: None,
data: masking::Secret::new("{}".into()),
payload: Some(req.json_payload.unwrap_or(serde_json::json!({})).into()),
redirect_response: Some(api_models::payments::RedirectResponse {
param: req.param.map(Secret::new),
json_payload: Some(req.json_payload.unwrap_or(serde_json::json!({})).into()),
}),
allowed_payment_method_types: None,
}),
..Default::default()
@ -950,6 +953,7 @@ where
pub pm_token: Option<String>,
pub connector_customer_id: Option<String>,
pub ephemeral_key: Option<ephemeral_key::EphemeralKey>,
pub redirect_response: Option<api_models::payments::RedirectResponse>,
}
#[derive(Debug, Default)]

View File

@ -152,6 +152,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsCancelRequest>
pm_token: None,
connector_customer_id: None,
ephemeral_key: None,
redirect_response: None,
},
None,
))

View File

@ -158,6 +158,7 @@ impl<F: Send + Clone> GetTracker<F, payments::PaymentData<F>, api::PaymentsCaptu
pm_token: None,
connector_customer_id: None,
ephemeral_key: None,
redirect_response: None,
},
None,
))

View File

@ -2,7 +2,6 @@ use std::marker::PhantomData;
use async_trait::async_trait;
use error_stack::ResultExt;
use masking::ExposeOptionInterface;
use router_derive::PaymentOperation;
use router_env::{instrument, tracing};
@ -146,7 +145,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Co
)
.await?;
let mut connector_response = db
let connector_response = db
.find_connector_response_by_payment_id_merchant_id_attempt_id(
&payment_attempt.payment_id,
&payment_attempt.merchant_id,
@ -156,12 +155,10 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Co
.await
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;
connector_response.encoded_data = request.metadata.clone().and_then(|secret_metadata| {
secret_metadata
.payload
.expose_option()
.map(|exposed_payload| exposed_payload.to_string())
});
let redirect_response = request
.metadata
.as_ref()
.and_then(|secret_metadata| secret_metadata.redirect_response.to_owned());
payment_intent.shipping_address_id = shipping_address.clone().map(|i| i.address_id);
payment_intent.billing_address_id = billing_address.clone().map(|i| i.address_id);
@ -205,6 +202,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Co
pm_token: None,
connector_customer_id: None,
ephemeral_key: None,
redirect_response,
},
Some(CustomerDetails {
customer_id: request.customer_id.clone(),

View File

@ -245,6 +245,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
pm_token: None,
connector_customer_id: None,
ephemeral_key: None,
redirect_response: None,
},
Some(CustomerDetails {
customer_id: request.customer_id.clone(),

View File

@ -250,6 +250,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
pm_token: None,
connector_customer_id: None,
ephemeral_key,
redirect_response: None,
},
Some(CustomerDetails {
customer_id: request.customer_id.clone(),

View File

@ -179,6 +179,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::VerifyRequest> for Paym
pm_token: None,
connector_customer_id: None,
ephemeral_key: None,
redirect_response: None,
},
Some(payments::CustomerDetails {
customer_id: request.customer_id.clone(),

View File

@ -171,6 +171,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsSessionRequest>
pm_token: None,
connector_customer_id: None,
ephemeral_key: None,
redirect_response: None,
},
Some(customer_details),
))

View File

@ -143,6 +143,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsStartRequest> f
pm_token: None,
connector_customer_id: None,
ephemeral_key: None,
redirect_response: None,
},
Some(customer_details),
))

View File

@ -291,6 +291,7 @@ async fn get_tracker_for_sync<
pm_token: None,
connector_customer_id: None,
ephemeral_key: None,
redirect_response: None,
},
None,
))

View File

@ -304,6 +304,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
pm_token: None,
connector_customer_id: None,
ephemeral_key: None,
redirect_response: None,
},
Some(CustomerDetails {
customer_id: request.customer_id.clone(),

View File

@ -1,7 +1,7 @@
use std::{fmt::Debug, marker::PhantomData};
use common_utils::fp_utils;
use error_stack::{IntoReport, ResultExt};
use error_stack::ResultExt;
use router_env::{instrument, tracing};
use storage_models::ephemeral_key;
@ -836,13 +836,13 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::CompleteAuthoriz
field_name: "browser_info",
})?;
let json_payload = payment_data
.connector_response
.encoded_data
.map(|s| serde_json::from_str::<serde_json::Value>(&s))
.transpose()
.into_report()
.change_context(errors::ApiErrorResponse::InternalServerError)?;
let redirect_response = payment_data.redirect_response.map(|redirect| {
types::CompleteAuthorizeRedirectResponse {
params: redirect.param,
payload: redirect.json_payload,
}
});
Ok(Self {
setup_future_usage: payment_data.payment_intent.setup_future_usage,
mandate_id: payment_data.mandate_id.clone(),
@ -857,7 +857,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::CompleteAuthoriz
email: payment_data.email,
payment_method_data: payment_data.payment_method_data,
connector_transaction_id: payment_data.connector_response.connector_transaction_id,
payload: json_payload,
redirect_response,
connector_meta: payment_data.payment_attempt.connector_metadata,
})
}

View File

@ -284,12 +284,18 @@ pub struct CompleteAuthorizeData {
pub mandate_id: Option<api_models::payments::MandateIds>,
pub off_session: Option<bool>,
pub setup_mandate_details: Option<payments::MandateData>,
pub payload: Option<serde_json::Value>,
pub redirect_response: Option<CompleteAuthorizeRedirectResponse>,
pub browser_info: Option<BrowserInformation>,
pub connector_transaction_id: Option<String>,
pub connector_meta: Option<serde_json::Value>,
}
#[derive(Debug, Clone)]
pub struct CompleteAuthorizeRedirectResponse {
pub params: Option<Secret<String>>,
pub payload: Option<pii::SecretSerdeValue>,
}
#[derive(Debug, Default, Clone)]
pub struct PaymentsSyncData {
//TODO : add fields based on the connector requirements