refactor(core): make sessions token resposne enum (#135)

This commit is contained in:
Narayan Bhat
2022-12-13 18:50:52 +05:30
committed by GitHub
parent 9fe3f7d904
commit 16cc0a4b38
6 changed files with 35 additions and 34 deletions

View File

@ -657,22 +657,29 @@ pub struct PaymentsRetrieveRequest {
pub connector: Option<String>,
}
#[derive(Debug, Clone, serde::Serialize)]
pub struct ConnectorSessionToken {
pub connector_name: String,
pub session_token: String,
pub session_id: Option<String>,
}
#[derive(Default, Debug, serde::Deserialize, Clone)]
pub struct PaymentsSessionRequest {
pub payment_id: String,
pub client_secret: String,
}
#[derive(Debug, Clone, serde::Serialize)]
#[serde(tag = "connector_name")]
#[serde(rename_all = "lowercase")]
pub enum SessionToken {
Gpay {},
Klarna {
session_token: String,
session_id: String,
},
Paypal {
session_token: String,
},
}
#[derive(Default, Debug, serde::Serialize, Clone)]
pub struct PaymentsSessionResponse {
pub session_token: Vec<ConnectorSessionToken>,
pub session_token: Vec<SessionToken>,
}
#[derive(Default, Debug, serde::Deserialize, serde::Serialize, Clone)]

View File

@ -177,8 +177,9 @@ impl<F, T>
) -> Result<Self, Self::Error> {
Ok(types::RouterData {
response: Ok(types::PaymentsResponseData::SessionResponse {
session_token: types::api::SessionToken::Paypal {
session_token: item.response.client_token.value.authorization_fingerprint,
session_id: None,
},
}),
..item.data
})

View File

@ -54,8 +54,10 @@ impl TryFrom<types::PaymentsSessionResponseRouterData<KlarnaSessionResponse>>
let response = &item.response;
Ok(types::RouterData {
response: Ok(types::PaymentsResponseData::SessionResponse {
session_id: Some(response.session_id.clone()),
session_token: types::api::SessionToken::Klarna {
session_token: response.client_token.clone(),
session_id: response.session_id.clone(),
},
}),
..item.data
})

View File

@ -406,18 +406,10 @@ where
let connector_name = connector.connector_name.to_string();
match connector_res?.response {
Ok(connector_response) => {
if let types::PaymentsResponseData::SessionResponse {
session_token,
session_id,
} = connector_response
if let types::PaymentsResponseData::SessionResponse { session_token } =
connector_response
{
payment_data
.sessions_token
.push(api::ConnectorSessionToken {
session_id,
connector_name,
session_token,
});
payment_data.sessions_token.push(session_token);
}
}
@ -471,7 +463,7 @@ where
pub force_sync: Option<bool>,
pub payment_method_data: Option<api::PaymentMethod>,
pub refunds: Vec<storage::Refund>,
pub sessions_token: Vec<api::ConnectorSessionToken>,
pub sessions_token: Vec<api::SessionToken>,
pub card_cvc: Option<Secret<String>>,
}

View File

@ -167,8 +167,7 @@ pub enum PaymentsResponseData {
mandate_reference: Option<String>,
},
SessionResponse {
session_token: String,
session_id: Option<String>,
session_token: api::SessionToken,
},
}

View File

@ -1,14 +1,14 @@
use api_models::payments;
pub use api_models::payments::{
AcceptanceType, Address, AddressDetails, Amount, AuthenticationForStartResponse, CCard,
ConnectorSessionToken, CustomerAcceptance, MandateData, MandateTxnType, MandateType,
MandateValidationFields, NextAction, NextActionType, OnlineMandate, PayLaterData,
PaymentIdType, PaymentListConstraints, PaymentListResponse, PaymentMethod,
PaymentMethodDataResponse, PaymentOp, PaymentRetrieveBody, PaymentsCancelRequest,
PaymentsCaptureRequest, PaymentsRedirectRequest, PaymentsRedirectionResponse, PaymentsRequest,
PaymentsResponse, PaymentsResponseForm, PaymentsRetrieveRequest, PaymentsSessionRequest,
PaymentsSessionResponse, PaymentsStartRequest, PgRedirectResponse, PhoneDetails,
RedirectionResponse, UrlDetails, VerifyRequest, VerifyResponse, WalletData,
CustomerAcceptance, MandateData, MandateTxnType, MandateType, MandateValidationFields,
NextAction, NextActionType, OnlineMandate, PayLaterData, PaymentIdType, PaymentListConstraints,
PaymentListResponse, PaymentMethod, PaymentMethodDataResponse, PaymentOp, PaymentRetrieveBody,
PaymentsCancelRequest, PaymentsCaptureRequest, PaymentsRedirectRequest,
PaymentsRedirectionResponse, PaymentsRequest, PaymentsResponse, PaymentsResponseForm,
PaymentsRetrieveRequest, PaymentsSessionRequest, PaymentsSessionResponse, PaymentsStartRequest,
PgRedirectResponse, PhoneDetails, RedirectionResponse, SessionToken, UrlDetails, VerifyRequest,
VerifyResponse, WalletData,
};
use error_stack::{IntoReport, ResultExt};
use masking::PeekInterface;