mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-27 19:46:48 +08:00
refactor: removed the usage of wallet(payment method) for paypal (#23)
This commit is contained in:
committed by
GitHub
parent
32e7d34572
commit
b2e45e614c
@ -112,7 +112,7 @@ impl TryFrom<&types::PaymentsRouterData> for AciPaymentsRequest {
|
||||
account_holder: "xyz".to_string(),
|
||||
}),
|
||||
api::PaymentMethod::PayLater(_) => PaymentDetails::Klarna,
|
||||
api::PaymentMethod::Wallet => PaymentDetails::Wallet,
|
||||
api::PaymentMethod::Wallet(_) => PaymentDetails::Wallet,
|
||||
api::PaymentMethod::Paypal => PaymentDetails::Paypal,
|
||||
};
|
||||
|
||||
|
||||
@ -10,6 +10,7 @@ use crate::{
|
||||
pii::{PeekInterface, Secret},
|
||||
services,
|
||||
types::{self, api, storage::enums},
|
||||
utils::OptionExt,
|
||||
};
|
||||
|
||||
// Adyen Types Definition
|
||||
@ -94,7 +95,7 @@ pub struct AdyenThreeDS {
|
||||
#[serde(untagged)]
|
||||
pub enum AdyenPaymentResponse {
|
||||
AdyenResponse(AdyenResponse),
|
||||
AdyenRedirectResponse(AdyenWalletResponse),
|
||||
AdyenRedirectResponse(AdyenRedirectionResponse),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
@ -110,16 +111,16 @@ pub struct AdyenResponse {
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct AdyenWalletResponse {
|
||||
pub struct AdyenRedirectionResponse {
|
||||
result_code: String,
|
||||
action: AdyenWalletAction,
|
||||
action: AdyenRedirectionAction,
|
||||
refusal_reason: Option<String>,
|
||||
refusal_reason_code: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct AdyenWalletAction {
|
||||
pub struct AdyenRedirectionAction {
|
||||
payment_method_type: String,
|
||||
url: String,
|
||||
method: String,
|
||||
@ -135,10 +136,11 @@ pub struct Amount {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[serde(untagged)]
|
||||
#[serde(tag = "type")]
|
||||
pub enum AdyenPaymentMethod {
|
||||
AdyenCard(AdyenCard),
|
||||
AdyenWallet(AdyenWallet),
|
||||
AdyenPaypal(AdyenPaypal),
|
||||
Gpay(AdyenGPay),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
@ -170,11 +172,19 @@ pub struct AdyenCancelResponse {
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct AdyenWallet {
|
||||
pub struct AdyenPaypal {
|
||||
#[serde(rename = "type")]
|
||||
payment_type: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct AdyenGPay {
|
||||
#[serde(rename = "type")]
|
||||
payment_type: String,
|
||||
#[serde(rename = "googlePayToken")]
|
||||
google_pay_token: String,
|
||||
}
|
||||
|
||||
// Refunds Request and Response
|
||||
#[derive(Default, Debug, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
@ -240,10 +250,15 @@ impl TryFrom<&types::PaymentsRouterData> for AdyenPaymentRequest {
|
||||
};
|
||||
let ccard = match item.request.payment_method_data {
|
||||
api::PaymentMethod::Card(ref ccard) => Some(ccard),
|
||||
api::PaymentMethod::BankTransfer => None,
|
||||
api::PaymentMethod::Wallet => None,
|
||||
api::PaymentMethod::PayLater(_) => None,
|
||||
api::PaymentMethod::Paypal => None,
|
||||
api::PaymentMethod::BankTransfer
|
||||
| api::PaymentMethod::Wallet(_)
|
||||
| api::PaymentMethod::PayLater(_)
|
||||
| api::PaymentMethod::Paypal => None,
|
||||
};
|
||||
|
||||
let wallet_data = match item.request.payment_method_data {
|
||||
api::PaymentMethod::Wallet(ref wallet_data) => Some(wallet_data),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
let shopper_interaction = match item.request.off_session {
|
||||
@ -260,7 +275,12 @@ impl TryFrom<&types::PaymentsRouterData> for AdyenPaymentRequest {
|
||||
|
||||
let payment_type = match item.payment_method {
|
||||
types::storage::enums::PaymentMethodType::Card => "scheme".to_string(),
|
||||
types::storage::enums::PaymentMethodType::Wallet => "paypal".to_string(),
|
||||
types::storage::enums::PaymentMethodType::Paypal => "paypal".to_string(),
|
||||
types::storage::enums::PaymentMethodType::Wallet => wallet_data
|
||||
.get_required_value("issuer_name")
|
||||
.change_context(errors::ConnectorError::RequestEncodingFailed)?
|
||||
.issuer_name
|
||||
.to_string(),
|
||||
_ => "None".to_string(),
|
||||
};
|
||||
|
||||
@ -278,9 +298,29 @@ impl TryFrom<&types::PaymentsRouterData> for AdyenPaymentRequest {
|
||||
|
||||
Ok(AdyenPaymentMethod::AdyenCard(card))
|
||||
}
|
||||
enums::PaymentMethodType::Wallet => {
|
||||
let wallet = AdyenWallet { payment_type };
|
||||
Ok(AdyenPaymentMethod::AdyenWallet(wallet))
|
||||
enums::PaymentMethodType::Wallet => match wallet_data
|
||||
.get_required_value("issuer_name")
|
||||
.change_context(errors::ConnectorError::RequestEncodingFailed)?
|
||||
.issuer_name
|
||||
{
|
||||
enums::WalletIssuer::GooglePay => {
|
||||
let gpay_data = AdyenGPay {
|
||||
payment_type,
|
||||
google_pay_token: wallet_data
|
||||
.get_required_value("token")
|
||||
.change_context(errors::ConnectorError::RequestEncodingFailed)?
|
||||
.token
|
||||
.to_string(),
|
||||
};
|
||||
Ok(AdyenPaymentMethod::Gpay(gpay_data))
|
||||
}
|
||||
_ => Err(errors::ConnectorError::NotImplemented(
|
||||
"ApplePay".to_string(),
|
||||
)),
|
||||
},
|
||||
enums::PaymentMethodType::Paypal => {
|
||||
let wallet = AdyenPaypal { payment_type };
|
||||
Ok(AdyenPaymentMethod::AdyenPaypal(wallet))
|
||||
}
|
||||
_ => Err(errors::ConnectorError::MissingRequiredField {
|
||||
field_name: "payment_method".to_string(),
|
||||
@ -388,8 +428,8 @@ pub fn get_adyen_response(
|
||||
Ok((status, error, payments_response_data))
|
||||
}
|
||||
|
||||
pub fn get_wallet_response(
|
||||
response: AdyenWalletResponse,
|
||||
pub fn get_redirection_response(
|
||||
response: AdyenRedirectionResponse,
|
||||
) -> errors::CustomResult<
|
||||
(
|
||||
enums::AttemptStatus,
|
||||
@ -434,8 +474,9 @@ pub fn get_wallet_response(
|
||||
form_fields: response.action.data,
|
||||
};
|
||||
|
||||
// We don't get connector transaction id for redirections in Adyen.
|
||||
let payments_response_data = types::PaymentsResponseData {
|
||||
connector_transaction_id: "123".to_string(),
|
||||
connector_transaction_id: "".to_string(),
|
||||
redirection_data: Some(redirection_data),
|
||||
redirect: true,
|
||||
};
|
||||
@ -452,7 +493,9 @@ impl<F, Req>
|
||||
) -> Result<Self, Self::Error> {
|
||||
let (status, error, payment_response_data) = match item.response {
|
||||
AdyenPaymentResponse::AdyenResponse(response) => get_adyen_response(response)?,
|
||||
AdyenPaymentResponse::AdyenRedirectResponse(response) => get_wallet_response(response)?,
|
||||
AdyenPaymentResponse::AdyenRedirectResponse(response) => {
|
||||
get_redirection_response(response)?
|
||||
}
|
||||
};
|
||||
|
||||
Ok(types::RouterData {
|
||||
|
||||
@ -146,7 +146,7 @@ impl TryFrom<&types::PaymentsRouterData> for CreateTransactionRequest {
|
||||
account_number: "XXXXX".to_string(),
|
||||
}),
|
||||
api::PaymentMethod::PayLater(_) => PaymentDetails::Klarna,
|
||||
api::PaymentMethod::Wallet => PaymentDetails::Wallet,
|
||||
api::PaymentMethod::Wallet(_) => PaymentDetails::Wallet,
|
||||
api::PaymentMethod::Paypal => PaymentDetails::Paypal,
|
||||
};
|
||||
let authorization_indicator_type =
|
||||
@ -355,7 +355,7 @@ impl<F> TryFrom<&types::RefundsRouterData<F>> for CreateRefundRequest {
|
||||
account_number: "XXXXX".to_string(),
|
||||
}),
|
||||
api::PaymentMethod::PayLater(_) => PaymentDetails::Klarna,
|
||||
api::PaymentMethod::Wallet => PaymentDetails::Wallet,
|
||||
api::PaymentMethod::Wallet(_) => PaymentDetails::Wallet,
|
||||
api::PaymentMethod::Paypal => PaymentDetails::Paypal,
|
||||
};
|
||||
|
||||
|
||||
@ -72,10 +72,10 @@ impl TryFrom<&types::PaymentsRouterData> for PaymentsRequest {
|
||||
fn try_from(item: &types::PaymentsRouterData) -> Result<Self, Self::Error> {
|
||||
let ccard = match item.request.payment_method_data {
|
||||
api::PaymentMethod::Card(ref ccard) => Some(ccard),
|
||||
api::PaymentMethod::BankTransfer => None,
|
||||
api::PaymentMethod::Wallet => None,
|
||||
api::PaymentMethod::PayLater(_) => None,
|
||||
api::PaymentMethod::Paypal => None,
|
||||
api::PaymentMethod::BankTransfer
|
||||
| api::PaymentMethod::Wallet(_)
|
||||
| api::PaymentMethod::PayLater(_)
|
||||
| api::PaymentMethod::Paypal => None,
|
||||
};
|
||||
|
||||
let three_ds = match item.auth_type {
|
||||
|
||||
@ -160,7 +160,7 @@ impl TryFrom<&types::PaymentsRouterData> for PaymentIntentRequest {
|
||||
billing_country: klarna_data.country.clone(),
|
||||
})
|
||||
}
|
||||
api::PaymentMethod::Wallet => StripePaymentMethodData::Wallet,
|
||||
api::PaymentMethod::Wallet(_) => StripePaymentMethodData::Wallet,
|
||||
api::PaymentMethod::Paypal => StripePaymentMethodData::Paypal,
|
||||
};
|
||||
let shipping_address = match item.address.shipping.clone() {
|
||||
|
||||
@ -614,6 +614,7 @@ pub async fn make_pm_data<'a, F: Clone, R>(
|
||||
Ok(pm.to_owned())
|
||||
}
|
||||
(pm @ Some(api::PaymentMethod::PayLater(_)), _) => Ok(pm.to_owned()),
|
||||
(pm @ Some(api::PaymentMethod::Wallet(_)), _) => Ok(pm.to_owned()),
|
||||
_ => Ok(None),
|
||||
}?;
|
||||
|
||||
|
||||
@ -269,7 +269,7 @@ impl<F: Clone> TryFrom<PaymentData<F>> for types::PaymentsRequestData {
|
||||
.get_required_value("payment_method_type")?;
|
||||
|
||||
match payment_method_type {
|
||||
enums::PaymentMethodType::Wallet => api::PaymentMethod::Wallet,
|
||||
enums::PaymentMethodType::Paypal => api::PaymentMethod::Paypal,
|
||||
_ => payment_data
|
||||
.payment_method_data
|
||||
.get_required_value("payment_method_data")?,
|
||||
|
||||
@ -151,13 +151,20 @@ pub enum PaymentMethod {
|
||||
Card(CCard),
|
||||
#[serde(rename(deserialize = "bank_transfer"))]
|
||||
BankTransfer,
|
||||
Wallet,
|
||||
#[serde(rename(deserialize = "wallet"))]
|
||||
Wallet(WalletData),
|
||||
#[serde(rename(deserialize = "pay_later"))]
|
||||
PayLater(PayLaterData),
|
||||
#[serde(rename(deserialize = "paypal"))]
|
||||
Paypal,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
|
||||
pub struct WalletData {
|
||||
pub issuer_name: enums::WalletIssuer,
|
||||
pub token: String,
|
||||
}
|
||||
|
||||
#[derive(Eq, PartialEq, Clone, Debug, serde::Serialize)]
|
||||
pub struct CCardResponse {
|
||||
last4: String,
|
||||
@ -171,7 +178,7 @@ pub enum PaymentMethodDataResponse {
|
||||
Card(CCardResponse),
|
||||
#[serde(rename(deserialize = "bank_transfer"))]
|
||||
BankTransfer,
|
||||
Wallet,
|
||||
Wallet(WalletData),
|
||||
PayLater(PayLaterData),
|
||||
Paypal,
|
||||
}
|
||||
@ -544,7 +551,7 @@ impl From<PaymentMethod> for PaymentMethodDataResponse {
|
||||
PaymentMethod::PayLater(pay_later_data) => {
|
||||
PaymentMethodDataResponse::PayLater(pay_later_data)
|
||||
}
|
||||
PaymentMethod::Wallet => PaymentMethodDataResponse::Wallet,
|
||||
PaymentMethod::Wallet(wallet_data) => PaymentMethodDataResponse::Wallet(wallet_data),
|
||||
PaymentMethod::Paypal => PaymentMethodDataResponse::Paypal,
|
||||
}
|
||||
}
|
||||
|
||||
@ -473,6 +473,27 @@ pub enum PaymentMethodType {
|
||||
Paypal,
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Clone,
|
||||
Copy,
|
||||
Debug,
|
||||
Eq,
|
||||
Hash,
|
||||
PartialEq,
|
||||
router_derive::DieselEnum,
|
||||
serde::Deserialize,
|
||||
serde::Serialize,
|
||||
strum::Display,
|
||||
strum::EnumString,
|
||||
)]
|
||||
#[router_derive::diesel_enum]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
#[strum(serialize_all = "lowercase")]
|
||||
pub enum WalletIssuer {
|
||||
GooglePay,
|
||||
ApplePay,
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Clone,
|
||||
Copy,
|
||||
|
||||
Reference in New Issue
Block a user