mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-03 21:37:41 +08:00
refactor(connector): [Payme] Response Handling for Preprocessing (#2097)
This commit is contained in:
@ -1,6 +1,9 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use api_models::{enums::AuthenticationType, payments::PaymentMethodData};
|
||||
use api_models::{
|
||||
enums::{AuthenticationType, PaymentMethod},
|
||||
payments::PaymentMethodData,
|
||||
};
|
||||
use common_utils::pii;
|
||||
use error_stack::{IntoReport, ResultExt};
|
||||
use masking::{ExposeInterface, Secret};
|
||||
@ -454,8 +457,49 @@ impl<F>
|
||||
types::PaymentsResponseData,
|
||||
>,
|
||||
) -> Result<Self, Self::Error> {
|
||||
match item.data.auth_type {
|
||||
AuthenticationType::NoThreeDs => {
|
||||
match item.data.payment_method {
|
||||
PaymentMethod::Card => {
|
||||
match item.data.auth_type {
|
||||
AuthenticationType::NoThreeDs => {
|
||||
Ok(Self {
|
||||
// We don't get any status from payme, so defaulting it to pending
|
||||
// then move to authorize flow
|
||||
status: enums::AttemptStatus::Pending,
|
||||
preprocessing_id: Some(item.response.payme_sale_id.to_owned()),
|
||||
response: Ok(types::PaymentsResponseData::PreProcessingResponse {
|
||||
pre_processing_id:
|
||||
types::PreprocessingResponseId::ConnectorTransactionId(
|
||||
item.response.payme_sale_id,
|
||||
),
|
||||
connector_metadata: None,
|
||||
session_token: None,
|
||||
connector_response_reference_id: None,
|
||||
}),
|
||||
..item.data
|
||||
})
|
||||
}
|
||||
AuthenticationType::ThreeDs => Ok(Self {
|
||||
// We don't go to authorize flow in 3ds,
|
||||
// Response is send directly after preprocessing flow
|
||||
// redirection data is send to run script along
|
||||
// status is made authentication_pending to show redirection
|
||||
status: enums::AttemptStatus::AuthenticationPending,
|
||||
preprocessing_id: Some(item.response.payme_sale_id.to_owned()),
|
||||
response: Ok(types::PaymentsResponseData::TransactionResponse {
|
||||
resource_id: types::ResponseId::ConnectorTransactionId(
|
||||
item.response.payme_sale_id.to_owned(),
|
||||
),
|
||||
redirection_data: Some(services::RedirectForm::Payme),
|
||||
mandate_reference: None,
|
||||
connector_metadata: None,
|
||||
network_txn_id: None,
|
||||
connector_response_reference_id: None,
|
||||
}),
|
||||
..item.data
|
||||
}),
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
let currency_code = item.data.request.get_currency()?;
|
||||
let amount = item.data.request.get_amount()?;
|
||||
let amount_in_base_unit = utils::to_currency_base_unit(amount, currency_code)?;
|
||||
@ -514,21 +558,6 @@ impl<F>
|
||||
..item.data
|
||||
})
|
||||
}
|
||||
AuthenticationType::ThreeDs => Ok(Self {
|
||||
status: enums::AttemptStatus::AuthenticationPending,
|
||||
preprocessing_id: Some(item.response.payme_sale_id.to_owned()),
|
||||
response: Ok(types::PaymentsResponseData::TransactionResponse {
|
||||
resource_id: types::ResponseId::ConnectorTransactionId(
|
||||
item.response.payme_sale_id.to_owned(),
|
||||
),
|
||||
redirection_data: Some(services::RedirectForm::Payme),
|
||||
mandate_reference: None,
|
||||
connector_metadata: None,
|
||||
network_txn_id: None,
|
||||
connector_response_reference_id: None,
|
||||
}),
|
||||
..item.data
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -588,7 +617,7 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for PayRequest {
|
||||
}
|
||||
}
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct PaymePayloadData {
|
||||
pub struct PaymeRedirectResponseData {
|
||||
meta_data: String,
|
||||
}
|
||||
|
||||
@ -602,7 +631,7 @@ impl TryFrom<&types::PaymentsCompleteAuthorizeRouterData> for Pay3dsRequest {
|
||||
|
||||
let payload_data = item.request.get_redirect_response_payload()?.expose();
|
||||
|
||||
let jwt_data: PaymePayloadData = serde_json::from_value(payload_data)
|
||||
let jwt_data: PaymeRedirectResponseData = serde_json::from_value(payload_data)
|
||||
.into_report()
|
||||
.change_context(errors::ConnectorError::MissingConnectorRedirectionPayload {
|
||||
field_name: "meta_data_jwt",
|
||||
|
||||
Reference in New Issue
Block a user