Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
feat(payouts): Add Wallet to Payouts (#3502)
Sakil Mostak3af6aaf28e92
diff --git a/crates/api_models/src/payment_methods.rs b/crates/api_models/src/payment_methods.rsindex ef1812acf1..281da5066d 100644--- a/crates/api_models/src/payment_methods.rs+++ b/crates/api_models/src/payment_methods.rs@@ -60,6 +60,11 @@ pub struct PaymentMethodCreate {#[cfg(feature = "payouts")]#[schema(value_type = Option<Bank>)]pub bank_transfer: Option<payouts::Bank>,++ /// Payment method details from locker+ #[cfg(feature = "payouts")]+ #[schema(value_type = Option<Wallet>)]+ pub wallet: Option<payouts::Wallet>,}#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)]@@ -82,6 +87,11 @@ pub struct PaymentMethodUpdate {#[schema(value_type = Option<Bank>)]pub bank_transfer: Option<payouts::Bank>,+ /// Payment method details from locker+ #[cfg(feature = "payouts")]+ #[schema(value_type = Option<Wallet>)]+ pub wallet: Option<payouts::Wallet>,+/// You can specify up to 50 keys, with key names up to 40 characters long and values up to 500 characters long. Metadata is useful for storing additional, structured information on an object.#[schema(value_type = Option<Object>,example = json!({ "city": "NY", "unit": "245" }))]pub metadata: Option<pii::SecretSerdeValue>,diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rsindex a4f052549b..07a891efd3 100644--- a/crates/api_models/src/payments.rs+++ b/crates/api_models/src/payments.rs@@ -1649,7 +1649,11 @@ pub struct WeChatPayQr {}pub struct CashappQr {}#[derive(Eq, PartialEq, Clone, Debug, serde::Deserialize, serde::Serialize, ToSchema)]-pub struct PaypalRedirection {}+pub struct PaypalRedirection {+ /// paypal's email address+ #[schema(max_length = 255, value_type = Option<String>, example = "[email protected]")]+ pub email: Option<Email>,+}#[derive(Eq, PartialEq, Clone, Debug, serde::Deserialize, serde::Serialize, ToSchema)]pub struct AliPayQr {}diff --git a/crates/api_models/src/payouts.rs b/crates/api_models/src/payouts.rsindex 9e771b4712..b0d0cd75fa 100644--- a/crates/api_models/src/payouts.rs+++ b/crates/api_models/src/payouts.rs@@ -157,6 +157,7 @@ pub struct PayoutCreateRequest {pub enum PayoutMethodData {Card(Card),Bank(Bank),+ Wallet(Wallet),}impl Default for PayoutMethodData {@@ -262,6 +263,19 @@ pub struct SepaBankTransfer {pub bic: Option<Secret<String>>,}+#[derive(Eq, PartialEq, Clone, Debug, Deserialize, Serialize, ToSchema)]+#[serde(rename_all = "snake_case")]+pub enum Wallet {+ Paypal(Paypal),+}++#[derive(Default, Eq, PartialEq, Clone, Debug, Deserialize, Serialize, ToSchema)]+pub struct Paypal {+ /// Email linked with paypal account+ #[schema(value_type = String, example = "[email protected]")]+ pub email: Option<Email>,+}+#[derive(Debug, ToSchema, Clone, Serialize)]#[serde(deny_unknown_fields)]pub struct PayoutCreateResponse {diff --git a/crates/common_enums/src/enums.rs b/crates/common_enums/src/enums.rsindex 7330c0708d..82569579cf 100644--- a/crates/common_enums/src/enums.rs+++ b/crates/common_enums/src/enums.rs@@ -2012,6 +2012,7 @@ pub enum PayoutType {#[default]Card,Bank,+ Wallet,}#[derive(@@ -2038,6 +2039,7 @@ pub enum PayoutEntityType {Company,NonProfit,PublicSector,+ NaturalPerson,/// Wise#[strum(serialize = "lowercase")]diff --git a/crates/connector_configs/toml/development.toml b/crates/connector_configs/toml/development.tomlindex a8188323dc..693ea69ff4 100644--- a/crates/connector_configs/toml/development.toml+++ b/crates/connector_configs/toml/development.toml@@ -2504,6 +2504,8 @@ api_key="Api Key"payment_method_type = "bacs"[[adyen_payout.bank_transfer]]payment_method_type = "sepa"+[[adyen_payout.wallet]]+ payment_method_type = "paypal"[adyen_payout.connector_auth.SignatureKey]api_key = "Adyen API Key (Payout creation)"api_secret = "Adyen Key (Payout submission)"diff --git a/crates/connector_configs/toml/sandbox.toml b/crates/connector_configs/toml/sandbox.tomlindex 576cd47c6e..dbb6284fbe 100644--- a/crates/connector_configs/toml/sandbox.toml+++ b/crates/connector_configs/toml/sandbox.toml@@ -2506,6 +2506,8 @@ api_key="Api Key"payment_method_type = "bacs"[[adyen_payout.bank_transfer]]payment_method_type = "sepa"+[[adyen_payout.wallet]]+ payment_method_type = "paypal"[adyen_payout.connector_auth.SignatureKey]api_key = "Adyen API Key (Payout creation)"api_secret = "Adyen Key (Payout submission)"diff --git a/crates/openapi/src/openapi.rs b/crates/openapi/src/openapi.rsindex 3d4a1893ad..982072e8c0 100644--- a/crates/openapi/src/openapi.rs+++ b/crates/openapi/src/openapi.rs@@ -389,6 +389,8 @@ Never share your secret api keys. Keep them guarded and secure.api_models::payouts::PayoutCreateRequest,api_models::payments::Address,api_models::payouts::Card,+ api_models::payouts::Wallet,+ api_models::payouts::Paypal,api_models::payouts::AchBankTransfer,api_models::payouts::BacsBankTransfer,api_models::payouts::SepaBankTransfer,diff --git a/crates/router/src/connector/adyen.rs b/crates/router/src/connector/adyen.rsindex 32f14fd021..84db2675b0 100644--- a/crates/router/src/connector/adyen.rs+++ b/crates/router/src/connector/adyen.rs@@ -1164,7 +1164,8 @@ impl services::ConnectorIntegration<api::PoFulfill, types::PayoutsData, types::P"{}pal/servlet/Payout/v68/{}",connectors.adyen.secondary_base_url,match req.request.payout_type {- storage_enums::PayoutType::Bank => "confirmThirdParty".to_string(),+ storage_enums::PayoutType::Bank | storage_enums::PayoutType::Wallet =>+ "confirmThirdParty".to_string(),storage_enums::PayoutType::Card => "payout".to_string(),}))@@ -1186,7 +1187,7 @@ impl services::ConnectorIntegration<api::PoFulfill, types::PayoutsData, types::Plet mut api_key = vec![(headers::X_API_KEY.to_string(),match req.request.payout_type {- storage_enums::PayoutType::Bank => {+ storage_enums::PayoutType::Bank | storage_enums::PayoutType::Wallet => {auth.review_key.unwrap_or(auth.api_key).into_masked()}storage_enums::PayoutType::Card => auth.api_key.into_masked(),diff --git a/crates/router/src/connector/adyen/transformers.rs b/crates/router/src/connector/adyen/transformers.rsindex c228bfffe6..aeb343bf81 100644--- a/crates/router/src/connector/adyen/transformers.rs+++ b/crates/router/src/connector/adyen/transformers.rs@@ -3967,7 +3967,8 @@ pub struct AdyenPayoutCreateRequest {amount: Amount,recurring: RecurringContract,merchant_account: Secret<String>,- bank: PayoutBankDetails,+ #[serde(flatten)]+ payment_data: PayoutPaymentMethodData,reference: String,shopper_reference: String,shopper_email: Option<Email>,@@ -3978,6 +3979,50 @@ pub struct AdyenPayoutCreateRequest {billing_address: Option<Address>,}+#[cfg(feature = "payouts")]+#[derive(Debug, Clone, Serialize, Deserialize)]+#[serde(untagged)]+pub enum PayoutPaymentMethodData {+ PayoutBankData(PayoutBankData),+ PayoutWalletData(PayoutWalletData),+}++#[cfg(feature = "payouts")]+#[derive(Debug, Clone, Serialize, Deserialize)]+#[serde(rename_all = "camelCase")]+pub struct PayoutBankData {+ bank: PayoutBankDetails,+}++#[cfg(feature = "payouts")]+#[derive(Debug, Clone, Serialize, Deserialize)]+#[serde(rename_all = "camelCase")]+pub struct PayoutWalletData {+ selected_brand: PayoutBrand,+ additional_data: PayoutAdditionalData,+}++#[cfg(feature = "payouts")]+#[derive(Debug, Clone, Serialize, Deserialize)]+#[serde(rename_all = "camelCase")]+pub enum PayoutBrand {+ Paypal,+}++#[cfg(feature = "payouts")]+#[derive(Debug, Clone, Serialize, Deserialize)]+#[serde(rename_all = "camelCase")]+struct PayoutAdditionalData {+ token_data_type: PayoutTokenDataType,+ email_id: Email,+}++#[cfg(feature = "payouts")]+#[derive(Debug, Clone, Serialize, Deserialize)]+enum PayoutTokenDataType {+ PayPal,+}+#[cfg(feature = "payouts")]#[derive(Debug, Clone, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]@@ -4063,14 +4108,14 @@ pub enum PayoutEligibility {#[derive(Debug, Serialize, Deserialize)]#[serde(untagged)]pub enum AdyenPayoutFulfillRequest {- Bank(PayoutFulfillBankRequest),+ GenericFulfillRequest(PayoutFulfillGenericRequest),Card(Box<PayoutFulfillCardRequest>),}#[cfg(feature = "payouts")]#[derive(Debug, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]-pub struct PayoutFulfillBankRequest {+pub struct PayoutFulfillGenericRequest {merchant_account: Secret<String>,original_reference: String,}@@ -4208,6 +4253,7 @@ impl<F> TryFrom<&AdyenRouterData<&types::PayoutsRouterData<F>>> for AdyenPayoutCconnector: "Adyen",})?,};+ let bank_data = PayoutBankData { bank: bank_details };let address: &payments::AddressDetails = item.router_data.get_billing_address()?;Ok(Self {amount: Amount {@@ -4218,13 +4264,52 @@ impl<F> TryFrom<&AdyenRouterData<&types::PayoutsRouterData<F>>> for AdyenPayoutCcontract: Contract::Payout,},merchant_account,- bank: bank_details,+ payment_data: PayoutPaymentMethodData::PayoutBankData(bank_data),reference: item.router_data.request.payout_id.to_owned(),shopper_reference: item.router_data.merchant_id.to_owned(),shopper_email: customer_email,shopper_name: ShopperName {- first_name: address.get_first_name().ok().cloned(),- last_name: address.get_last_name().ok().cloned(),+ first_name: Some(address.get_first_name()?.to_owned()), // it is a required field for payouts+ last_name: Some(address.get_last_name()?.to_owned()), // it is a required field for payouts+ },+ date_of_birth: None,+ entity_type: Some(item.router_data.request.entity_type),+ nationality: get_country_code(item.router_data.address.billing.as_ref()),+ billing_address: get_address_info(item.router_data.address.billing.as_ref()),+ })+ }+ PayoutMethodData::Wallet(wallet_data) => {+ let additional_data = match wallet_data {+ api_models::payouts::Wallet::Paypal(paypal_data) => PayoutAdditionalData {+ token_data_type: PayoutTokenDataType::PayPal,+ email_id: paypal_data.email.clone().ok_or(+ errors::ConnectorError::MissingRequiredField {+ field_name: "email_address",+ },+ )?,+ },+ };+ let address: &payments::AddressDetails = item.router_data.get_billing_address()?;+ let payout_wallet = PayoutWalletData {+ selected_brand: PayoutBrand::Paypal,+ additional_data,+ };+ Ok(Self {+ amount: Amount {+ value: item.amount.to_owned(),+ currency: item.router_data.request.destination_currency,+ },+ recurring: RecurringContract {+ contract: Contract::Payout,+ },+ merchant_account,+ payment_data: PayoutPaymentMethodData::PayoutWalletData(payout_wallet),+ reference: item.router_data.request.payout_id.to_owned(),+ shopper_reference: item.router_data.merchant_id.to_owned(),+ shopper_email: customer_email,+ shopper_name: ShopperName {+ first_name: Some(address.get_first_name()?.to_owned()), // it is a required field for payouts+ last_name: Some(address.get_last_name()?.to_owned()), // it is a required field for payouts},date_of_birth: None,entity_type: Some(item.router_data.request.entity_type),@@ -4245,15 +4330,19 @@ impl<F> TryFrom<&AdyenRouterData<&types::PayoutsRouterData<F>>> for AdyenPayoutFlet payout_type = item.router_data.request.payout_type.to_owned();let merchant_account = auth_type.merchant_account;match payout_type {- storage_enums::PayoutType::Bank => Ok(Self::Bank(PayoutFulfillBankRequest {- merchant_account,- original_reference: item- .router_data- .request- .connector_payout_id- .clone()- .unwrap_or("".to_string()),- })),+ storage_enums::PayoutType::Bank | storage_enums::PayoutType::Wallet => {+ Ok(Self::GenericFulfillRequest(PayoutFulfillGenericRequest {+ merchant_account,+ original_reference: item+ .router_data+ .request+ .connector_payout_id+ .clone()+ .ok_or(errors::ConnectorError::MissingRequiredField {+ field_name: "connector_payout_id",+ })?,+ }))+ }storage_enums::PayoutType::Card => {let address = item.router_data.get_billing_address()?;Ok(Self::Card(Box::new(PayoutFulfillCardRequest {@@ -4266,8 +4355,8 @@ impl<F> TryFrom<&AdyenRouterData<&types::PayoutsRouterData<F>>> for AdyenPayoutFmerchant_account,reference: item.router_data.request.payout_id.clone(),shopper_name: ShopperName {- first_name: address.get_first_name().ok().cloned(),- last_name: address.get_last_name().ok().cloned(),+ first_name: Some(address.get_first_name()?.to_owned()), // it is a required field for payouts+ last_name: Some(address.get_last_name()?.to_owned()), // it is a required field for payouts},nationality: get_country_code(item.router_data.address.billing.as_ref()),entity_type: Some(item.router_data.request.entity_type),diff --git a/crates/router/src/connector/wise/transformers.rs b/crates/router/src/connector/wise/transformers.rsindex e0fc05c3c8..b213c62212 100644--- a/crates/router/src/connector/wise/transformers.rs+++ b/crates/router/src/connector/wise/transformers.rs@@ -370,9 +370,11 @@ impl<F> TryFrom<&types::PayoutsRouterData<F>> for WiseRecipientCreateRequest {}),}?;match request.payout_type.to_owned() {- storage_enums::PayoutType::Card => Err(errors::ConnectorError::NotImplemented(- utils::get_unimplemented_payment_method_error_message("Wise"),- ))?,+ storage_enums::PayoutType::Card | storage_enums::PayoutType::Wallet => {+ Err(errors::ConnectorError::NotImplemented(+ utils::get_unimplemented_payment_method_error_message("Wise"),+ ))?+ }storage_enums::PayoutType::Bank => {let account_holder_name = customer_details.ok_or(errors::ConnectorError::MissingRequiredField {@@ -430,9 +432,11 @@ impl<F> TryFrom<&types::PayoutsRouterData<F>> for WisePayoutQuoteRequest {target_currency: request.destination_currency.to_string(),pay_out: WisePayOutOption::default(),}),- storage_enums::PayoutType::Card => Err(errors::ConnectorError::NotImplemented(- utils::get_unimplemented_payment_method_error_message("Wise"),- ))?,+ storage_enums::PayoutType::Card | storage_enums::PayoutType::Wallet => {+ Err(errors::ConnectorError::NotImplemented(+ utils::get_unimplemented_payment_method_error_message("Wise"),+ ))?+ }}}}@@ -486,9 +490,11 @@ impl<F> TryFrom<&types::PayoutsRouterData<F>> for WisePayoutCreateRequest {details: wise_transfer_details,})}- storage_enums::PayoutType::Card => Err(errors::ConnectorError::NotImplemented(- utils::get_unimplemented_payment_method_error_message("Wise"),- ))?,+ storage_enums::PayoutType::Card | storage_enums::PayoutType::Wallet => {+ Err(errors::ConnectorError::NotImplemented(+ utils::get_unimplemented_payment_method_error_message("Wise"),+ ))?+ }}}}@@ -529,9 +535,11 @@ impl<F> TryFrom<&types::PayoutsRouterData<F>> for WisePayoutFulfillRequest {storage_enums::PayoutType::Bank => Ok(Self {fund_type: FundType::default(),}),- storage_enums::PayoutType::Card => Err(errors::ConnectorError::NotImplemented(- utils::get_unimplemented_payment_method_error_message("Wise"),- ))?,+ storage_enums::PayoutType::Card | storage_enums::PayoutType::Wallet => {+ Err(errors::ConnectorError::NotImplemented(+ utils::get_unimplemented_payment_method_error_message("Wise"),+ ))?+ }}}}@@ -578,7 +586,8 @@ impl ForeignFrom<PayoutEntityType> for LegalType {match entity_type {PayoutEntityType::Individual| PayoutEntityType::Personal- | PayoutEntityType::NonProfit => Self::Private,+ | PayoutEntityType::NonProfit+ | PayoutEntityType::NaturalPerson => Self::Private,PayoutEntityType::Company| PayoutEntityType::PublicSector| PayoutEntityType::Business => Self::Business,diff --git a/crates/router/src/core/locker_migration.rs b/crates/router/src/core/locker_migration.rsindex 4bd2555792..48ddaf333b 100644--- a/crates/router/src/core/locker_migration.rs+++ b/crates/router/src/core/locker_migration.rs@@ -113,6 +113,7 @@ pub async fn call_to_locker(payment_method_issuer: pm.payment_method_issuer,payment_method_issuer_code: pm.payment_method_issuer_code,card: Some(card_details.clone()),+ wallet: None,bank_transfer: None,metadata: pm.metadata,customer_id: Some(pm.customer_id),diff --git a/crates/router/src/core/payment_methods/cards.rs b/crates/router/src/core/payment_methods/cards.rsindex ba5fb0a2a8..cae116fdac 100644--- a/crates/router/src/core/payment_methods/cards.rs+++ b/crates/router/src/core/payment_methods/cards.rs@@ -238,6 +238,7 @@ pub async fn update_customer_payment_method(payment_method_issuer_code: pm.payment_method_issuer_code,bank_transfer: req.bank_transfer,card: req.card,+ wallet: req.wallet,metadata: req.metadata,customer_id: Some(pm.customer_id),card_network: req@@ -2962,6 +2963,10 @@ pub async fn get_bank_from_hs_locker(message: "Expected bank details, found card details instead".to_string(),}.into()),+ api::PayoutMethodData::Wallet(_) => Err(errors::ApiErrorResponse::InvalidRequestData {+ message: "Expected bank details, found wallet details instead".to_string(),+ }+ .into()),}}diff --git a/crates/router/src/core/payment_methods/vault.rs b/crates/router/src/core/payment_methods/vault.rsindex 5b783f1c5d..25bac8086d 100644--- a/crates/router/src/core/payment_methods/vault.rs+++ b/crates/router/src/core/payment_methods/vault.rs@@ -409,6 +409,62 @@ impl Vaultable for api::CardPayout {}}+#[cfg(feature = "payouts")]+impl Vaultable for api::WalletPayout {+ fn get_value1(&self, _customer_id: Option<String>) -> CustomResult<String, errors::VaultError> {+ let value1 = match self {+ Self::Paypal(paypal_data) => api::TokenizedWalletValue1 {+ data: api::WalletData::PaypalRedirect(api_models::payments::PaypalRedirection {+ email: paypal_data.email.clone(),+ }),+ },+ };++ utils::Encode::<api::TokenizedWalletValue1>::encode_to_string_of_json(&value1)+ .change_context(errors::VaultError::RequestEncodingFailed)+ .attach_printable("Failed to encode wallet value1")+ }++ fn get_value2(&self, customer_id: Option<String>) -> CustomResult<String, errors::VaultError> {+ let value2 = api::TokenizedWalletValue2 { customer_id };++ utils::Encode::<api::TokenizedWalletValue2>::encode_to_string_of_json(&value2)+ .change_context(errors::VaultError::RequestEncodingFailed)+ .attach_printable("Failed to encode wallet value2")+ }++ fn from_values(+ value1: String,+ value2: String,+ ) -> CustomResult<(Self, SupplementaryVaultData), errors::VaultError> {+ let value1: api::TokenizedWalletValue1 = value1+ .parse_struct("TokenizedWalletValue1")+ .change_context(errors::VaultError::ResponseDeserializationFailed)+ .attach_printable("Could not deserialize into wallet value1")?;++ let value2: api::TokenizedWalletValue2 = value2+ .parse_struct("TokenizedWalletValue2")+ .change_context(errors::VaultError::ResponseDeserializationFailed)+ .attach_printable("Could not deserialize into wallet value2")?;++ let wallet = match value1.data {+ api::WalletData::PaypalRedirect(paypal_data) => {+ Self::Paypal(api_models::payouts::Paypal {+ email: paypal_data.email,+ })+ }+ _ => Err(errors::VaultError::ResponseDeserializationFailed)?,+ };++ let supp_data = SupplementaryVaultData {+ customer_id: value2.customer_id,+ payment_method_id: None,+ };++ Ok((wallet, supp_data))+ }+}+#[derive(Debug, serde::Serialize, serde::Deserialize)]pub struct TokenizedBankSensitiveValues {pub bank_account_number: Option<masking::Secret<String>>,@@ -551,6 +607,7 @@ impl Vaultable for api::BankPayout {pub enum VaultPayoutMethod {Card(String),Bank(String),+ Wallet(String),}#[cfg(feature = "payouts")]@@ -559,6 +616,7 @@ impl Vaultable for api::PayoutMethodData {let value1 = match self {Self::Card(card) => VaultPayoutMethod::Card(card.get_value1(customer_id)?),Self::Bank(bank) => VaultPayoutMethod::Bank(bank.get_value1(customer_id)?),+ Self::Wallet(wallet) => VaultPayoutMethod::Wallet(wallet.get_value1(customer_id)?),};utils::Encode::<VaultPaymentMethod>::encode_to_string_of_json(&value1)@@ -570,6 +628,7 @@ impl Vaultable for api::PayoutMethodData {let value2 = match self {Self::Card(card) => VaultPayoutMethod::Card(card.get_value2(customer_id)?),Self::Bank(bank) => VaultPayoutMethod::Bank(bank.get_value2(customer_id)?),+ Self::Wallet(wallet) => VaultPayoutMethod::Wallet(wallet.get_value2(customer_id)?),};utils::Encode::<VaultPaymentMethod>::encode_to_string_of_json(&value2)@@ -600,6 +659,10 @@ impl Vaultable for api::PayoutMethodData {let (bank, supp_data) = api::BankPayout::from_values(mvalue1, mvalue2)?;Ok((Self::Bank(bank), supp_data))}+ (VaultPayoutMethod::Wallet(mvalue1), VaultPayoutMethod::Wallet(mvalue2)) => {+ let (wallet, supp_data) = api::WalletPayout::from_values(mvalue1, mvalue2)?;+ Ok((Self::Wallet(wallet), supp_data))+ }_ => Err(errors::VaultError::PayoutMethodNotSupported).into_report().attach_printable("Payout method not supported"),diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rsindex 5d801063e6..7ec1f5e921 100644--- a/crates/router/src/core/payments/helpers.rs+++ b/crates/router/src/core/payments/helpers.rs@@ -1097,6 +1097,7 @@ pub(crate) async fn get_payment_method_create_request(payment_method_issuer: card.card_issuer.clone(),payment_method_issuer_code: None,bank_transfer: None,+ wallet: None,card: Some(card_detail),metadata: None,customer_id: Some(customer_id),@@ -1114,6 +1115,7 @@ pub(crate) async fn get_payment_method_create_request(payment_method_issuer: None,payment_method_issuer_code: None,bank_transfer: None,+ wallet: None,card: None,metadata: None,customer_id: Some(customer.customer_id.to_owned()),diff --git a/crates/router/src/core/payouts.rs b/crates/router/src/core/payouts.rsindex debc9d1244..8741407d17 100644--- a/crates/router/src/core/payouts.rs+++ b/crates/router/src/core/payouts.rs@@ -523,6 +523,22 @@ pub async fn call_connector_payout(.await.attach_printable("Payout creation failed for given Payout request")?;}++ if payout_data.payouts.payout_type == storage_enums::PayoutType::Wallet+ && payout_data.payout_attempt.status == storage_enums::PayoutStatus::RequiresCreation+ {+ // Create payout flow+ *payout_data = create_payout(+ state,+ merchant_account,+ key_store,+ req,+ &connector_data,+ payout_data,+ )+ .await+ .attach_printable("Payout creation failed for given Payout request")?;+ }};// Auto fulfillment flowdiff --git a/crates/router/src/core/payouts/helpers.rs b/crates/router/src/core/payouts/helpers.rsindex 1ab24023bd..fe8f5c6297 100644--- a/crates/router/src/core/payouts/helpers.rs+++ b/crates/router/src/core/payouts/helpers.rs@@ -177,76 +177,91 @@ pub async fn save_payout_data_to_locker(merchant_account: &domain::MerchantAccount,key_store: &domain::MerchantKeyStore,) -> RouterResult<()> {- let (locker_req, card_details, bank_details, payment_method_type) = match payout_method_data {- api_models::payouts::PayoutMethodData::Card(card) => {- let card_detail = api::CardDetail {- card_number: card.card_number.to_owned(),- card_holder_name: card.card_holder_name.to_owned(),- card_exp_month: card.expiry_month.to_owned(),- card_exp_year: card.expiry_year.to_owned(),- nick_name: None,- card_issuing_country: None,- card_network: None,- card_issuer: None,- card_type: None,- };- let payload = StoreLockerReq::LockerCard(StoreCardReq {- merchant_id: &merchant_account.merchant_id,- merchant_customer_id: payout_attempt.customer_id.to_owned(),- card: transformers::Card {+ let (locker_req, card_details, bank_details, wallet_details, payment_method_type) =+ match payout_method_data {+ api_models::payouts::PayoutMethodData::Card(card) => {+ let card_detail = api::CardDetail {card_number: card.card_number.to_owned(),- name_on_card: card.card_holder_name.to_owned(),+ card_holder_name: card.card_holder_name.to_owned(),card_exp_month: card.expiry_month.to_owned(),card_exp_year: card.expiry_year.to_owned(),- card_brand: None,- card_isin: None,nick_name: None,- },- requestor_card_reference: None,- });- (- payload,- Some(card_detail),- None,- api_enums::PaymentMethodType::Debit,- )- }- api_models::payouts::PayoutMethodData::Bank(bank) => {- let key = key_store.key.get_inner().peek();- let enc_data = async {- serde_json::to_value(payout_method_data.to_owned())- .into_report()- .change_context(errors::ApiErrorResponse::InternalServerError)- .attach_printable("Unable to encode payout method data")- .ok()- .map(|v| {- let secret: Secret<String> = Secret::new(v.to_string());- secret- })- .async_lift(|inner| domain_types::encrypt_optional(inner, key))- .await+ card_issuing_country: None,+ card_network: None,+ card_issuer: None,+ card_type: None,+ };+ let payload = StoreLockerReq::LockerCard(StoreCardReq {+ merchant_id: &merchant_account.merchant_id,+ merchant_customer_id: payout_attempt.customer_id.to_owned(),+ card: transformers::Card {+ card_number: card.card_number.to_owned(),+ name_on_card: card.card_holder_name.to_owned(),+ card_exp_month: card.expiry_month.to_owned(),+ card_exp_year: card.expiry_year.to_owned(),+ card_brand: None,+ card_isin: None,+ nick_name: None,+ },+ requestor_card_reference: None,+ });+ (+ payload,+ Some(card_detail),+ None,+ None,+ api_enums::PaymentMethodType::Debit,+ )}- .await- .change_context(errors::ApiErrorResponse::InternalServerError)- .attach_printable("Failed to encrypt payout method data")?- .map(Encryption::from)- .map(|e| e.into_inner())- .map_or(Err(errors::ApiErrorResponse::InternalServerError), |e| {- Ok(hex::encode(e.peek()))- })?;- let payload = StoreLockerReq::LockerGeneric(StoreGenericReq {- merchant_id: &merchant_account.merchant_id,- merchant_customer_id: payout_attempt.customer_id.to_owned(),- enc_data,- });- (- payload,- None,- Some(bank.to_owned()),- api_enums::PaymentMethodType::foreign_from(bank.to_owned()),- )- }- };+ _ => {+ let key = key_store.key.get_inner().peek();+ let enc_data = async {+ serde_json::to_value(payout_method_data.to_owned())+ .into_report()+ .change_context(errors::ApiErrorResponse::InternalServerError)+ .attach_printable("Unable to encode payout method data")+ .ok()+ .map(|v| {+ let secret: Secret<String> = Secret::new(v.to_string());+ secret+ })+ .async_lift(|inner| domain_types::encrypt_optional(inner, key))+ .await+ }+ .await+ .change_context(errors::ApiErrorResponse::InternalServerError)+ .attach_printable("Failed to encrypt payout method data")?+ .map(Encryption::from)+ .map(|e| e.into_inner())+ .map_or(Err(errors::ApiErrorResponse::InternalServerError), |e| {+ Ok(hex::encode(e.peek()))+ })?;+ let payload = StoreLockerReq::LockerGeneric(StoreGenericReq {+ merchant_id: &merchant_account.merchant_id,+ merchant_customer_id: payout_attempt.customer_id.to_owned(),+ enc_data,+ });+ match payout_method_data {+ api_models::payouts::PayoutMethodData::Bank(bank) => (+ payload,+ None,+ Some(bank.to_owned()),+ None,+ api_enums::PaymentMethodType::foreign_from(bank.to_owned()),+ ),+ api_models::payouts::PayoutMethodData::Wallet(wallet) => (+ payload,+ None,+ None,+ Some(wallet.to_owned()),+ api_enums::PaymentMethodType::foreign_from(wallet.to_owned()),+ ),+ api_models::payouts::PayoutMethodData::Card(_) => {+ Err(errors::ApiErrorResponse::InternalServerError)?+ }+ }+ }+ };// Store payout method in lockerlet stored_resp = cards::call_to_locker_hs(state,@@ -343,6 +358,7 @@ pub async fn save_payout_data_to_locker(payment_method_issuer_code: None,bank_transfer: bank_details,card: card_details,+ wallet: wallet_details,metadata: None,customer_id: Some(payout_attempt.customer_id.to_owned()),card_network: None,diff --git a/crates/router/src/types/api/payouts.rs b/crates/router/src/types/api/payouts.rsindex dd118b0915..9d74fc620a 100644--- a/crates/router/src/types/api/payouts.rs+++ b/crates/router/src/types/api/payouts.rs@@ -1,7 +1,7 @@pub use api_models::payouts::{AchBankTransfer, BacsBankTransfer, Bank as BankPayout, Card as CardPayout, PayoutActionRequest,PayoutCreateRequest, PayoutCreateResponse, PayoutMethodData, PayoutRequest, PayoutRetrieveBody,- PayoutRetrieveRequest, SepaBankTransfer,+ PayoutRetrieveRequest, SepaBankTransfer, Wallet as WalletPayout,};#[cfg(feature = "payouts")]diff --git a/crates/router/src/types/transformers.rs b/crates/router/src/types/transformers.rsindex 3821654686..f9ba7f8e92 100644--- a/crates/router/src/types/transformers.rs+++ b/crates/router/src/types/transformers.rs@@ -871,11 +871,20 @@ impl ForeignFrom<api_models::payouts::Bank> for api_enums::PaymentMethodType {}}+impl ForeignFrom<api_models::payouts::Wallet> for api_enums::PaymentMethodType {+ fn foreign_from(value: api_models::payouts::Wallet) -> Self {+ match value {+ api_models::payouts::Wallet::Paypal(_) => Self::Paypal,+ }+ }+}+impl ForeignFrom<api_models::payouts::PayoutMethodData> for api_enums::PaymentMethod {fn foreign_from(value: api_models::payouts::PayoutMethodData) -> Self {match value {api_models::payouts::PayoutMethodData::Bank(_) => Self::BankTransfer,api_models::payouts::PayoutMethodData::Card(_) => Self::Card,+ api_models::payouts::PayoutMethodData::Wallet(_) => Self::Wallet,}}}@@ -885,6 +894,7 @@ impl ForeignFrom<api_models::enums::PayoutType> for api_enums::PaymentMethod {match value {api_models::enums::PayoutType::Bank => Self::BankTransfer,api_models::enums::PayoutType::Card => Self::Card,+ api_models::enums::PayoutType::Wallet => Self::Wallet,}}}diff --git a/crates/router/tests/connectors/adyen.rs b/crates/router/tests/connectors/adyen.rsindex 430ae0bac1..76e2a3052a 100644--- a/crates/router/tests/connectors/adyen.rs+++ b/crates/router/tests/connectors/adyen.rs@@ -71,6 +71,8 @@ impl AdyenTest {#[cfg(feature = "payouts")]fn get_payout_info(payout_type: enums::PayoutType) -> Option<PaymentInfo> {+ use common_utils::pii::Email;+Some(PaymentInfo {country: Some(api_models::enums::CountryAlpha2::NL),currency: Some(enums::Currency::EUR),@@ -107,6 +109,11 @@ impl AdyenTest {bank_city: Some("Amsterdam".to_string()),}),)),+ enums::PayoutType::Wallet => Some(api::PayoutMethodData::Wallet(+ api::payouts::WalletPayout::Paypal(api_models::payouts::Paypal {+ email: Email::from_str("[email protected]").ok(),+ }),+ )),},..Default::default()})diff --git a/migrations/2024-01-30-090815_alter_payout_type/down.sql b/migrations/2024-01-30-090815_alter_payout_type/down.sqlnew file mode 100644index 0000000000..c7c9cbeb40--- /dev/null+++ b/migrations/2024-01-30-090815_alter_payout_type/down.sql@@ -0,0 +1,2 @@+-- This file should undo anything in `up.sql`+SELECT 1;\ No newline at end of filediff --git a/migrations/2024-01-30-090815_alter_payout_type/up.sql b/migrations/2024-01-30-090815_alter_payout_type/up.sqlnew file mode 100644index 0000000000..0c5a946c20--- /dev/null+++ b/migrations/2024-01-30-090815_alter_payout_type/up.sql@@ -0,0 +1,2 @@+-- Your SQL goes here+ALTER TYPE "PayoutType" ADD VALUE IF NOT EXISTS 'wallet';\ No newline at end of filediff --git a/openapi/openapi_spec.json b/openapi/openapi_spec.jsonindex 1ec6dcacf3..7f234661b5 100644--- a/openapi/openapi_spec.json+++ b/openapi/openapi_spec.json@@ -11413,6 +11413,14 @@}],"nullable": true+ },+ "wallet": {+ "allOf": [+ {+ "$ref": "#/components/schemas/Wallet"+ }+ ],+ "nullable": true}}},@@ -11894,6 +11902,14 @@],"nullable": true},+ "wallet": {+ "allOf": [+ {+ "$ref": "#/components/schemas/Wallet"+ }+ ],+ "nullable": true+ },"metadata": {"type": "object","description": "You can specify up to 50 keys, with key names up to 40 characters long and values up to 500 characters long. Metadata is useful for storing additional, structured information on an object.",@@ -14485,6 +14501,7 @@"Company","NonProfit","PublicSector",+ "NaturalPerson","lowercase","Personal"]@@ -14512,6 +14529,17 @@"$ref": "#/components/schemas/Bank"}}+ },+ {+ "type": "object",+ "required": [+ "wallet"+ ],+ "properties": {+ "wallet": {+ "$ref": "#/components/schemas/Wallet"+ }+ }}]},@@ -14600,11 +14628,34 @@"type": "string","enum": ["card",- "bank"+ "bank",+ "wallet"]},+ "Paypal": {+ "type": "object",+ "required": [+ "email"+ ],+ "properties": {+ "email": {+ "type": "string",+ "description": "Email linked with paypal account",+ "example": "[email protected]"+ }+ }+ },"PaypalRedirection": {- "type": "object"+ "type": "object",+ "properties": {+ "email": {+ "type": "string",+ "description": "paypal's email address",+ "example": "[email protected]",+ "nullable": true,+ "maxLength": 255+ }+ }},"PaypalSessionTokenResponse": {"type": "object",@@ -16388,6 +16439,21 @@}]},+ "Wallet": {+ "oneOf": [+ {+ "type": "object",+ "required": [+ "paypal"+ ],+ "properties": {+ "paypal": {+ "$ref": "#/components/schemas/Paypal"+ }+ }+ }+ ]+ },"WalletData": {"oneOf": [{diff --git a/package.json b/package.jsonindex 45d2be3153..0766efdcc1 100644--- a/package.json+++ b/package.json@@ -6,4 +6,4 @@"devDependencies": {"newman": "git+ssh://[email protected]:knutties/newman.git#7106e194c15d49d066fa09d9a2f18b2238f3dba8"}-}\ No newline at end of file+}