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
fix(core/payouts): Fix payouts void logic and response handling for wallets (#10630)
Vani Gupta7864ee21e80d
diff --git a/api-reference/v1/openapi_spec_v1.json b/api-reference/v1/openapi_spec_v1.jsonindex dbbe2a4031..7ac75949d8 100644--- a/api-reference/v1/openapi_spec_v1.json+++ b/api-reference/v1/openapi_spec_v1.json@@ -35405,27 +35405,74 @@}},"PaypalAdditionalData": {- "type": "object",- "description": "Masked payout method details for paypal wallet payout method",- "properties": {- "email": {- "type": "string",+ "oneOf": [+ {+ "type": "object","description": "Email linked with paypal account",- "example": "[email protected]",- "nullable": true- },- "telephone_number": {- "type": "string",- "description": "mobile number linked to paypal account",- "example": "******* 3349",- "nullable": true+ "required": [+ "email",+ "field_type"+ ],+ "properties": {+ "email": {+ "type": "string",+ "description": "Email linked with paypal account",+ "example": "[email protected]"+ },+ "field_type": {+ "type": "string",+ "enum": [+ "email"+ ]+ }+ }},- "paypal_id": {- "type": "string",+ {+ "type": "object","description": "id of the paypal account",- "example": "G83K ***** HCQ2",- "nullable": true+ "required": [+ "paypal_id",+ "field_type"+ ],+ "properties": {+ "paypal_id": {+ "type": "string",+ "description": "id of the paypal account",+ "example": "G83K*****HCQ2"+ },+ "field_type": {+ "type": "string",+ "enum": [+ "paypal_id"+ ]+ }+ }+ },+ {+ "type": "object",+ "description": "mobile number linked to paypal account",+ "required": [+ "field_type"+ ],+ "properties": {+ "telephone_number": {+ "type": "string",+ "description": "mobile number linked to paypal account",+ "example": "G83K ***** HCQ2",+ "nullable": true+ },+ "field_type": {+ "type": "string",+ "enum": [+ "telephone_number"+ ]+ }+ }}+ ],+ "description": "Masked payout method details for paypal wallet payout method",+ "discriminator": {+ "propertyName": "field_type"}},"PaypalFlow": {@@ -42291,13 +42338,13 @@"WalletAdditionalData": {"oneOf": [{- "$ref": "#/components/schemas/PaypalAdditionalData"+ "$ref": "#/components/schemas/ApplePayDecryptAdditionalData"},{- "$ref": "#/components/schemas/VenmoAdditionalData"+ "$ref": "#/components/schemas/PaypalAdditionalData"},{- "$ref": "#/components/schemas/ApplePayDecryptAdditionalData"+ "$ref": "#/components/schemas/VenmoAdditionalData"}],"description": "Masked payout method details for wallet payout method"diff --git a/api-reference/v2/openapi_spec_v2.json b/api-reference/v2/openapi_spec_v2.jsonindex 3c5e521822..1e9c056811 100644--- a/api-reference/v2/openapi_spec_v2.json+++ b/api-reference/v2/openapi_spec_v2.json@@ -25776,27 +25776,74 @@}},"PaypalAdditionalData": {- "type": "object",- "description": "Masked payout method details for paypal wallet payout method",- "properties": {- "email": {- "type": "string",+ "oneOf": [+ {+ "type": "object","description": "Email linked with paypal account",- "example": "[email protected]",- "nullable": true- },- "telephone_number": {- "type": "string",- "description": "mobile number linked to paypal account",- "example": "******* 3349",- "nullable": true+ "required": [+ "email",+ "field_type"+ ],+ "properties": {+ "email": {+ "type": "string",+ "description": "Email linked with paypal account",+ "example": "[email protected]"+ },+ "field_type": {+ "type": "string",+ "enum": [+ "email"+ ]+ }+ }},- "paypal_id": {- "type": "string",+ {+ "type": "object","description": "id of the paypal account",- "example": "G83K ***** HCQ2",- "nullable": true+ "required": [+ "paypal_id",+ "field_type"+ ],+ "properties": {+ "paypal_id": {+ "type": "string",+ "description": "id of the paypal account",+ "example": "G83K*****HCQ2"+ },+ "field_type": {+ "type": "string",+ "enum": [+ "paypal_id"+ ]+ }+ }+ },+ {+ "type": "object",+ "description": "mobile number linked to paypal account",+ "required": [+ "field_type"+ ],+ "properties": {+ "telephone_number": {+ "type": "string",+ "description": "mobile number linked to paypal account",+ "example": "G83K ***** HCQ2",+ "nullable": true+ },+ "field_type": {+ "type": "string",+ "enum": [+ "telephone_number"+ ]+ }+ }}+ ],+ "description": "Masked payout method details for paypal wallet payout method",+ "discriminator": {+ "propertyName": "field_type"}},"PaypalFlow": {@@ -31835,13 +31882,13 @@"WalletAdditionalData": {"oneOf": [{- "$ref": "#/components/schemas/PaypalAdditionalData"+ "$ref": "#/components/schemas/ApplePayDecryptAdditionalData"},{- "$ref": "#/components/schemas/VenmoAdditionalData"+ "$ref": "#/components/schemas/PaypalAdditionalData"},{- "$ref": "#/components/schemas/ApplePayDecryptAdditionalData"+ "$ref": "#/components/schemas/VenmoAdditionalData"}],"description": "Masked payout method details for wallet payout method"diff --git a/crates/api_models/src/payouts.rs b/crates/api_models/src/payouts.rsindex ae7598ab04..d220845823 100644--- a/crates/api_models/src/payouts.rs+++ b/crates/api_models/src/payouts.rs@@ -1243,11 +1243,22 @@ impl From<Wallet> for payout_method_utils::WalletAdditionalData {email,telephone_number,paypal_id,- }) => Self::Paypal(Box::new(payout_method_utils::PaypalAdditionalData {- email: email.map(ForeignFrom::foreign_from),- telephone_number: telephone_number.map(From::from),- paypal_id: paypal_id.map(From::from),- })),+ }) => {+ let paypal_additional_data = if let Some(e) = email {+ payout_method_utils::PaypalAdditionalData::Email {+ email: ForeignFrom::foreign_from(e),+ }+ } else if let Some(id) = paypal_id {+ payout_method_utils::PaypalAdditionalData::PaypalId {+ paypal_id: From::from(id),+ }+ } else {+ payout_method_utils::PaypalAdditionalData::TelephoneNumber {+ telephone_number: telephone_number.map(From::from),+ }+ };+ Self::Paypal(Box::new(paypal_additional_data))+ }Wallet::Venmo(Venmo { telephone_number }) => {Self::Venmo(Box::new(payout_method_utils::VenmoAdditionalData {telephone_number: telephone_number.map(From::from),diff --git a/crates/common_utils/src/payout_method_utils.rs b/crates/common_utils/src/payout_method_utils.rsindex 491ea57c77..0f1eccf443 100644--- a/crates/common_utils/src/payout_method_utils.rs+++ b/crates/common_utils/src/payout_method_utils.rs@@ -228,31 +228,40 @@ pub struct TrustlyBankTransferAdditionalData {#[diesel(sql_type = Jsonb)]#[serde(untagged)]pub enum WalletAdditionalData {+ /// Additional data for Apple pay decrypt wallet payout method+ ApplePayDecrypt(Box<ApplePayDecryptAdditionalData>),/// Additional data for paypal wallet payout methodPaypal(Box<PaypalAdditionalData>),/// Additional data for venmo wallet payout methodVenmo(Box<VenmoAdditionalData>),- /// Additional data for Apple pay decrypt wallet payout method- ApplePayDecrypt(Box<ApplePayDecryptAdditionalData>),}/// Masked payout method details for paypal wallet payout method#[derive(- Default, Eq, PartialEq, Clone, Debug, Deserialize, Serialize, FromSqlRow, AsExpression, ToSchema,+ Eq, PartialEq, Clone, Debug, Deserialize, Serialize, FromSqlRow, AsExpression, ToSchema,)]#[diesel(sql_type = Jsonb)]-pub struct PaypalAdditionalData {+#[serde(tag = "field_type", rename_all = "snake_case")]+pub enum PaypalAdditionalData {+ // Exactly one of the three identifiers will always be present/// Email linked with paypal account- #[schema(value_type = Option<String>, example = "[email protected]")]- pub email: Option<MaskedEmail>,-- /// mobile number linked to paypal account- #[schema(value_type = Option<String>, example = "******* 3349")]- pub telephone_number: Option<MaskedPhoneNumber>,-+ Email {+ /// Email linked with paypal account+ #[schema(value_type = String, example = "[email protected]")]+ email: MaskedEmail,+ },/// id of the paypal account- #[schema(value_type = Option<String>, example = "G83K ***** HCQ2")]- pub paypal_id: Option<MaskedBankAccount>,+ PaypalId {+ /// id of the paypal account+ #[schema(value_type = String, example = "G83K*****HCQ2")]+ paypal_id: MaskedBankAccount,+ },+ /// mobile number linked to paypal account+ TelephoneNumber {+ /// mobile number linked to paypal account+ #[schema(value_type = Option<String>, example = "G83K ***** HCQ2")]+ telephone_number: Option<MaskedPhoneNumber>, // Keeping this optional does not affect serialization because the enum is tagged with `field_type`, so the correct variant is chosen explicitly+ },}/// Masked payout method details for venmo wallet payout methoddiff --git a/crates/router/src/core/payouts.rs b/crates/router/src/core/payouts.rsindex 2b35bf5c41..42c27c997f 100644--- a/crates/router/src/core/payouts.rs+++ b/crates/router/src/core/payouts.rs@@ -9,6 +9,7 @@ pub mod transformers;pub mod validator;use std::{collections::{HashMap, HashSet},+ str::FromStr,vec::IntoIter,};@@ -619,6 +620,11 @@ pub async fn payouts_cancel_core(let payout_attempt = payout_data.payout_attempt.to_owned();let status = payout_attempt.status;+ let connector_name = payout_attempt+ .connector+ .as_deref()+ .and_then(|connector| common_enums::connector_enums::Connector::from_str(connector).ok());+// Verify if cancellation can be triggeredif helpers::is_payout_terminal_state(status) {return Err(report!(errors::ApiErrorResponse::InvalidRequestData {@@ -629,7 +635,12 @@ pub async fn payouts_cancel_core(}));// Make local cancellation- } else if helpers::is_eligible_for_local_payout_cancellation(status) {+ } else if helpers::is_eligible_for_local_payout_cancellation(status)+ && connector_name+ .as_ref()+ .map(|name| name.supports_instant_payout(payout_data.payouts.payout_type))+ .unwrap_or(true)+ {let status = storage_enums::PayoutStatus::Cancelled;let updated_payout_attempt = storage::PayoutAttemptUpdate::StatusUpdate {connector_payout_id: payout_attempt.connector_payout_id.to_owned(),diff --git a/crates/router/src/core/payouts/helpers.rs b/crates/router/src/core/payouts/helpers.rsindex 4ac099adc5..1282a2f3fd 100644--- a/crates/router/src/core/payouts/helpers.rs+++ b/crates/router/src/core/payouts/helpers.rs@@ -1284,6 +1284,7 @@ pub fn is_eligible_for_local_payout_cancellation(status: api_enums::PayoutStatus| api_enums::PayoutStatus::RequiresConfirmation| api_enums::PayoutStatus::RequiresPayoutMethodData| api_enums::PayoutStatus::RequiresVendorAccountCreation+ | api_enums::PayoutStatus::RequiresFulfillment)}