mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-30 09:38:33 +08:00
feat(connector): [Adyen] Add support for PayPal wallet mandates (#1686)
This commit is contained in:
@ -19,6 +19,7 @@ use crate::{
|
|||||||
api::{self, enums as api_enums},
|
api::{self, enums as api_enums},
|
||||||
storage::enums as storage_enums,
|
storage::enums as storage_enums,
|
||||||
transformers::ForeignFrom,
|
transformers::ForeignFrom,
|
||||||
|
PaymentsAuthorizeData,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1054,6 +1055,21 @@ impl<'a> TryFrom<&api::Card> for AdyenPaymentMethod<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl TryFrom<&storage_enums::PaymentMethodType> for PaymentType {
|
||||||
|
type Error = Error;
|
||||||
|
fn try_from(item: &storage_enums::PaymentMethodType) -> Result<Self, Self::Error> {
|
||||||
|
match item {
|
||||||
|
storage_enums::PaymentMethodType::Credit | storage_enums::PaymentMethodType::Debit => {
|
||||||
|
Ok(Self::Scheme)
|
||||||
|
}
|
||||||
|
storage_enums::PaymentMethodType::Paypal => Ok(Self::Paypal),
|
||||||
|
_ => Err(errors::ConnectorError::NotImplemented(
|
||||||
|
"Payment Method Type".to_string(),
|
||||||
|
))?,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl TryFrom<&utils::CardIssuer> for CardBrand {
|
impl TryFrom<&utils::CardIssuer> for CardBrand {
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
fn try_from(card_issuer: &utils::CardIssuer) -> Result<Self, Self::Error> {
|
fn try_from(card_issuer: &utils::CardIssuer) -> Result<Self, Self::Error> {
|
||||||
@ -1302,10 +1318,15 @@ impl<'a>
|
|||||||
let browser_info = get_browser_info(item)?;
|
let browser_info = get_browser_info(item)?;
|
||||||
let additional_data = get_additional_data(item);
|
let additional_data = get_additional_data(item);
|
||||||
let return_url = item.request.get_return_url()?;
|
let return_url = item.request.get_return_url()?;
|
||||||
|
let payment_method_type = item
|
||||||
|
.request
|
||||||
|
.payment_method_type
|
||||||
|
.as_ref()
|
||||||
|
.ok_or(errors::ConnectorError::MissingPaymentMethodType)?;
|
||||||
let payment_method = match mandate_ref_id {
|
let payment_method = match mandate_ref_id {
|
||||||
payments::MandateReferenceId::ConnectorMandateId(connector_mandate_ids) => {
|
payments::MandateReferenceId::ConnectorMandateId(connector_mandate_ids) => {
|
||||||
let adyen_mandate = AdyenMandate {
|
let adyen_mandate = AdyenMandate {
|
||||||
payment_type: PaymentType::Scheme,
|
payment_type: PaymentType::try_from(payment_method_type)?,
|
||||||
stored_payment_method_id: connector_mandate_ids.get_connector_mandate_id()?,
|
stored_payment_method_id: connector_mandate_ids.get_connector_mandate_id()?,
|
||||||
};
|
};
|
||||||
Ok::<AdyenPaymentMethod<'_>, Self::Error>(AdyenPaymentMethod::Mandate(Box::new(
|
Ok::<AdyenPaymentMethod<'_>, Self::Error>(AdyenPaymentMethod::Mandate(Box::new(
|
||||||
@ -1521,6 +1542,24 @@ fn get_sofort_extra_details(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_shopper_email(
|
||||||
|
item: &PaymentsAuthorizeData,
|
||||||
|
is_mandate_payment: bool,
|
||||||
|
) -> errors::CustomResult<Option<Email>, errors::ConnectorError> {
|
||||||
|
if is_mandate_payment {
|
||||||
|
let payment_method_type = item
|
||||||
|
.payment_method_type
|
||||||
|
.as_ref()
|
||||||
|
.ok_or(errors::ConnectorError::MissingPaymentMethodType)?;
|
||||||
|
match payment_method_type {
|
||||||
|
storage_enums::PaymentMethodType::Paypal => Ok(Some(item.get_email()?)),
|
||||||
|
_ => Ok(item.email.clone()),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Ok(item.email.clone())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'a> TryFrom<(&types::PaymentsAuthorizeRouterData, &api::WalletData)>
|
impl<'a> TryFrom<(&types::PaymentsAuthorizeRouterData, &api::WalletData)>
|
||||||
for AdyenPaymentRequest<'a>
|
for AdyenPaymentRequest<'a>
|
||||||
{
|
{
|
||||||
@ -1538,6 +1577,7 @@ impl<'a> TryFrom<(&types::PaymentsAuthorizeRouterData, &api::WalletData)>
|
|||||||
let (recurring_processing_model, store_payment_method, shopper_reference) =
|
let (recurring_processing_model, store_payment_method, shopper_reference) =
|
||||||
get_recurring_processing_model(item)?;
|
get_recurring_processing_model(item)?;
|
||||||
let return_url = item.request.get_return_url()?;
|
let return_url = item.request.get_return_url()?;
|
||||||
|
let shopper_email = get_shopper_email(&item.request, store_payment_method.is_some())?;
|
||||||
Ok(AdyenPaymentRequest {
|
Ok(AdyenPaymentRequest {
|
||||||
amount,
|
amount,
|
||||||
merchant_account: auth_type.merchant_account,
|
merchant_account: auth_type.merchant_account,
|
||||||
@ -1550,7 +1590,7 @@ impl<'a> TryFrom<(&types::PaymentsAuthorizeRouterData, &api::WalletData)>
|
|||||||
additional_data,
|
additional_data,
|
||||||
telephone_number: None,
|
telephone_number: None,
|
||||||
shopper_name: None,
|
shopper_name: None,
|
||||||
shopper_email: None,
|
shopper_email,
|
||||||
shopper_locale: None,
|
shopper_locale: None,
|
||||||
billing_address: None,
|
billing_address: None,
|
||||||
delivery_address: None,
|
delivery_address: None,
|
||||||
|
|||||||
@ -308,6 +308,8 @@ pub enum ConnectorError {
|
|||||||
FileValidationFailed { reason: String },
|
FileValidationFailed { reason: String },
|
||||||
#[error("Missing 3DS redirection payload: {field_name}")]
|
#[error("Missing 3DS redirection payload: {field_name}")]
|
||||||
MissingConnectorRedirectionPayload { field_name: &'static str },
|
MissingConnectorRedirectionPayload { field_name: &'static str },
|
||||||
|
#[error("Payment Method Type not found")]
|
||||||
|
MissingPaymentMethodType,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, thiserror::Error)]
|
#[derive(Debug, thiserror::Error)]
|
||||||
|
|||||||
Reference in New Issue
Block a user