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>, 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)] #[derive(Default, Debug, serde::Deserialize, Clone)]
pub struct PaymentsSessionRequest { pub struct PaymentsSessionRequest {
pub payment_id: String, pub payment_id: String,
pub client_secret: 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)] #[derive(Default, Debug, serde::Serialize, Clone)]
pub struct PaymentsSessionResponse { pub struct PaymentsSessionResponse {
pub session_token: Vec<ConnectorSessionToken>, pub session_token: Vec<SessionToken>,
} }
#[derive(Default, Debug, serde::Deserialize, serde::Serialize, Clone)] #[derive(Default, Debug, serde::Deserialize, serde::Serialize, Clone)]

View File

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

View File

@ -54,8 +54,10 @@ impl TryFrom<types::PaymentsSessionResponseRouterData<KlarnaSessionResponse>>
let response = &item.response; let response = &item.response;
Ok(types::RouterData { Ok(types::RouterData {
response: Ok(types::PaymentsResponseData::SessionResponse { 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_token: response.client_token.clone(),
session_id: response.session_id.clone(),
},
}), }),
..item.data ..item.data
}) })

View File

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

View File

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

View File

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