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 payout webhooks for Paypal and Wise (#8888)
Sakil Mostakfdc102de4750
diff --git a/crates/hyperswitch_connectors/src/connectors/paypal.rs b/crates/hyperswitch_connectors/src/connectors/paypal.rsindex f90ac021fb..996ec05fba 100644--- a/crates/hyperswitch_connectors/src/connectors/paypal.rs+++ b/crates/hyperswitch_connectors/src/connectors/paypal.rs@@ -637,9 +637,9 @@ impl ConnectorIntegration<PoSync, PayoutsData, PayoutsResponseData> for Paypal {event_builder: Option<&mut ConnectorEvent>,res: Response,) -> CustomResult<PayoutsRouterData<PoSync>, errors::ConnectorError> {- let response: paypal::PaypalFulfillResponse = res+ let response: paypal::PaypalPayoutSyncResponse = res.response- .parse_struct("PaypalFulfillResponse")+ .parse_struct("PaypalPayoutSyncResponse").change_context(errors::ConnectorError::ResponseDeserializationFailed)?;event_builder.map(|i| i.set_response_body(&response));@@ -2068,6 +2068,20 @@ impl IncomingWebhook for Paypal {),))}+ #[cfg(feature = "payouts")]+ paypal::PaypalResource::PaypalBatchPayoutWebhooks(resource) => {+ Ok(api_models::webhooks::ObjectReferenceId::PayoutId(+ api_models::webhooks::PayoutIdType::ConnectorPayoutId(+ resource.batch_header.payout_batch_id,+ ),+ ))+ }+ #[cfg(feature = "payouts")]+ paypal::PaypalResource::PaypalItemPayoutWebhooks(resource) => {+ Ok(api_models::webhooks::ObjectReferenceId::PayoutId(+ api_models::webhooks::PayoutIdType::PayoutAttemptId(resource.sender_batch_id),+ ))+ }}}@@ -2100,6 +2114,19 @@ impl IncomingWebhook for Paypal {| PaypalWebhookEventType::CheckoutOrderCompleted| PaypalWebhookEventType::CheckoutOrderProcessed| PaypalWebhookEventType::Unknown => None,+ #[cfg(feature = "payouts")]+ PaypalWebhookEventType::PayoutsBatchDenied+ | PaypalWebhookEventType::PayoutsBatchProcessing+ | PaypalWebhookEventType::PayoutsBatchSuccess+ | PaypalWebhookEventType::PayoutsItemBlocked+ | PaypalWebhookEventType::PayoutsItemCanceled+ | PaypalWebhookEventType::PayoutsItemDenied+ | PaypalWebhookEventType::PayoutsItemFailed+ | PaypalWebhookEventType::PayoutsItemHeld+ | PaypalWebhookEventType::PayoutsItemRefunded+ | PaypalWebhookEventType::PayoutsItemReturned+ | PaypalWebhookEventType::PayoutsItemSuccess+ | PaypalWebhookEventType::PayoutsItemUnclaimed => None,};Ok(transformers::get_payapl_webhooks_event(@@ -2128,6 +2155,14 @@ impl IncomingWebhook for Paypal {paypal::RefundSyncResponse::try_from((*resource, details.event_type))?,),paypal::PaypalResource::PaypalDisputeWebhooks(_) => Box::new(details),+ #[cfg(feature = "payouts")]+ paypal::PaypalResource::PaypalBatchPayoutWebhooks(resource) => {+ Box::new(paypal::PaypalPayoutSyncResponse::try_from(*resource)?)+ }+ #[cfg(feature = "payouts")]+ paypal::PaypalResource::PaypalItemPayoutWebhooks(resource) => Box::new(+ paypal::PaypalPayoutSyncResponse::try_from((*resource, details.event_type))?,+ ),})}@@ -2146,6 +2181,12 @@ impl IncomingWebhook for Paypal {Err(errors::ConnectorError::ResponseDeserializationFailed).attach_printable("Expected Dispute webhooks,but found other webhooks")?}+ #[cfg(feature = "payouts")]+ transformers::PaypalResource::PaypalBatchPayoutWebhooks(_)+ | transformers::PaypalResource::PaypalItemPayoutWebhooks(_) => {+ Err(errors::ConnectorError::ResponseDeserializationFailed)+ .attach_printable("Expected Dispute webhooks,but found other webhooks")?+ }transformers::PaypalResource::PaypalDisputeWebhooks(payload) => {let amt = connector_utils::convert_back_amount_to_minor_units(self.amount_converter,diff --git a/crates/hyperswitch_connectors/src/connectors/paypal/transformers.rs b/crates/hyperswitch_connectors/src/connectors/paypal/transformers.rsindex d5e66fa435..b106914e9a 100644--- a/crates/hyperswitch_connectors/src/connectors/paypal/transformers.rs+++ b/crates/hyperswitch_connectors/src/connectors/paypal/transformers.rs@@ -2566,8 +2566,22 @@ pub struct PaypalFulfillResponse {#[cfg(feature = "payouts")]#[derive(Debug, Deserialize, Serialize)]pub struct PaypalBatchResponse {- payout_batch_id: String,- batch_status: PaypalFulfillStatus,+ pub payout_batch_id: String,+ pub batch_status: PaypalFulfillStatus,+}++#[cfg(feature = "payouts")]+#[derive(Debug, Deserialize, Serialize)]+pub struct PaypalPayoutSyncResponse {+ batch_header: PaypalSyncBatchResponse,+}++#[cfg(feature = "payouts")]+#[derive(Debug, Deserialize, Serialize)]+pub struct PaypalSyncBatchResponse {+ pub payout_batch_id: Option<String>,+ pub sender_batch_id: Option<String>,+ pub batch_status: PaypalFulfillStatus,}#[cfg(feature = "payouts")]@@ -2579,17 +2593,25 @@ pub enum PaypalFulfillStatus {Processing,Success,Cancelled,+ Failed,+ Refunded,+ Returned,}#[cfg(feature = "payouts")]pub(crate) fn get_payout_status(status: PaypalFulfillStatus) -> storage_enums::PayoutStatus {match status {PaypalFulfillStatus::Success => storage_enums::PayoutStatus::Success,- PaypalFulfillStatus::Denied => storage_enums::PayoutStatus::Failed,+ PaypalFulfillStatus::Denied | PaypalFulfillStatus::Failed => {+ storage_enums::PayoutStatus::Failed+ }PaypalFulfillStatus::Cancelled => storage_enums::PayoutStatus::Cancelled,PaypalFulfillStatus::Pending | PaypalFulfillStatus::Processing => {storage_enums::PayoutStatus::Pending}+ PaypalFulfillStatus::Refunded | PaypalFulfillStatus::Returned => {+ storage_enums::PayoutStatus::Reversed+ }}}@@ -2613,6 +2635,57 @@ impl<F> TryFrom<PayoutsResponseRouterData<F, PaypalFulfillResponse>> for Payouts}}+#[cfg(feature = "payouts")]+impl<F> TryFrom<PayoutsResponseRouterData<F, PaypalPayoutSyncResponse>> for PayoutsRouterData<F> {+ type Error = error_stack::Report<errors::ConnectorError>;+ fn try_from(+ item: PayoutsResponseRouterData<F, PaypalPayoutSyncResponse>,+ ) -> Result<Self, Self::Error> {+ Ok(Self {+ response: Ok(PayoutsResponseData {+ status: Some(get_payout_status(item.response.batch_header.batch_status)),+ connector_payout_id: item.response.batch_header.payout_batch_id,+ payout_eligible: None,+ should_add_next_step_to_process_tracker: false,+ error_code: None,+ error_message: None,+ }),+ ..item.data+ })+ }+}++#[cfg(feature = "payouts")]+impl TryFrom<PaypalBatchPayoutWebhooks> for PaypalPayoutSyncResponse {+ type Error = error_stack::Report<errors::ConnectorError>;+ fn try_from(webhook_body: PaypalBatchPayoutWebhooks) -> Result<Self, Self::Error> {+ Ok(Self {+ batch_header: PaypalSyncBatchResponse {+ payout_batch_id: Some(webhook_body.batch_header.payout_batch_id),+ sender_batch_id: None,+ batch_status: webhook_body.batch_header.batch_status,+ },+ })+ }+}++#[cfg(feature = "payouts")]+impl TryFrom<(PaypalItemPayoutWebhooks, PaypalWebhookEventType)> for PaypalPayoutSyncResponse {+ type Error = error_stack::Report<errors::ConnectorError>;+ fn try_from(+ (webhook_body, webhook_event): (PaypalItemPayoutWebhooks, PaypalWebhookEventType),+ ) -> Result<Self, Self::Error> {+ Ok(Self {+ batch_header: PaypalSyncBatchResponse {+ payout_batch_id: None,+ sender_batch_id: Some(webhook_body.sender_batch_id),+ batch_status: PaypalFulfillStatus::try_from(webhook_event)+ .attach_printable("Could not find suitable webhook event")?,+ },+ })+ }+}+#[derive(Debug, Serialize)]pub struct PaypalPaymentsCaptureRequest {amount: OrderAmount,@@ -2940,6 +3013,42 @@ pub enum PaypalWebhookEventType {CustomerDisputedUpdated,#[serde(rename = "RISK.DISPUTE.CREATED")]RiskDisputeCreated,+ #[cfg(feature = "payouts")]+ #[serde(rename = "PAYMENT.PAYOUTSBATCH.SUCCESS")]+ PayoutsBatchSuccess,+ #[cfg(feature = "payouts")]+ #[serde(rename = "PAYMENT.PAYOUTSBATCH.PROCESSING")]+ PayoutsBatchProcessing,+ #[cfg(feature = "payouts")]+ #[serde(rename = "PAYMENT.PAYOUTSBATCH.DENIED")]+ PayoutsBatchDenied,+ #[cfg(feature = "payouts")]+ #[serde(rename = "PAYMENT.PAYOUTS-ITEM.SUCCEEDED")]+ PayoutsItemSuccess,+ #[cfg(feature = "payouts")]+ #[serde(rename = "PAYMENT.PAYOUTS-ITEM.FAILED")]+ PayoutsItemFailed,+ #[cfg(feature = "payouts")]+ #[serde(rename = "PAYMENT.PAYOUTS-ITEM.BLOCKED")]+ PayoutsItemBlocked,+ #[cfg(feature = "payouts")]+ #[serde(rename = "PAYMENT.PAYOUTS-ITEM.CANCELED")]+ PayoutsItemCanceled,+ #[cfg(feature = "payouts")]+ #[serde(rename = "PAYMENT.PAYOUTS-ITEM.DENIED")]+ PayoutsItemDenied,+ #[cfg(feature = "payouts")]+ #[serde(rename = "PAYMENT.PAYOUTS-ITEM.HELD")]+ PayoutsItemHeld,+ #[cfg(feature = "payouts")]+ #[serde(rename = "PAYMENT.PAYOUTS-ITEM.REFUNDED")]+ PayoutsItemRefunded,+ #[cfg(feature = "payouts")]+ #[serde(rename = "PAYMENT.PAYOUTS-ITEM.RETURNED")]+ PayoutsItemReturned,+ #[cfg(feature = "payouts")]+ #[serde(rename = "PAYMENT.PAYOUTS-ITEM.UNCLAIMED")]+ PayoutsItemUnclaimed,#[serde(other)]Unknown,}@@ -2951,6 +3060,23 @@ pub enum PaypalResource {PaypalRedirectsWebhooks(Box<PaypalRedirectsWebhooks>),PaypalRefundWebhooks(Box<PaypalRefundWebhooks>),PaypalDisputeWebhooks(Box<PaypalDisputeWebhooks>),+ #[cfg(feature = "payouts")]+ PaypalBatchPayoutWebhooks(Box<PaypalBatchPayoutWebhooks>),+ #[cfg(feature = "payouts")]+ PaypalItemPayoutWebhooks(Box<PaypalItemPayoutWebhooks>),+}++#[cfg(feature = "payouts")]+#[derive(Deserialize, Debug, Serialize)]+pub struct PaypalBatchPayoutWebhooks {+ pub batch_header: PaypalBatchResponse,+}++#[cfg(feature = "payouts")]+#[derive(Deserialize, Debug, Serialize)]+pub struct PaypalItemPayoutWebhooks {+ pub sender_batch_id: String,+ pub transaction_status: PaypalFulfillStatus,}#[derive(Deserialize, Debug, Serialize)]@@ -3091,6 +3217,23 @@ pub(crate) fn get_payapl_webhooks_event(| PaypalWebhookEventType::CheckoutOrderApproved| PaypalWebhookEventType::CustomerDisputedUpdated| PaypalWebhookEventType::Unknown => IncomingWebhookEvent::EventNotSupported,+ #[cfg(feature = "payouts")]+ PaypalWebhookEventType::PayoutsBatchSuccess+ | PaypalWebhookEventType::PayoutsItemSuccess => IncomingWebhookEvent::PayoutSuccess,+ #[cfg(feature = "payouts")]+ PaypalWebhookEventType::PayoutsBatchProcessing+ | PaypalWebhookEventType::PayoutsItemHeld+ | PaypalWebhookEventType::PayoutsItemUnclaimed => IncomingWebhookEvent::PayoutProcessing,+ #[cfg(feature = "payouts")]+ PaypalWebhookEventType::PayoutsBatchDenied+ | PaypalWebhookEventType::PayoutsItemDenied+ | PaypalWebhookEventType::PayoutsItemBlocked+ | PaypalWebhookEventType::PayoutsItemCanceled => IncomingWebhookEvent::PayoutCancelled,+ #[cfg(feature = "payouts")]+ PaypalWebhookEventType::PayoutsItemFailed => IncomingWebhookEvent::PayoutFailure,+ #[cfg(feature = "payouts")]+ PaypalWebhookEventType::PayoutsItemRefunded+ | PaypalWebhookEventType::PayoutsItemReturned => IncomingWebhookEvent::PayoutReversed,}}@@ -3242,6 +3385,21 @@ impl TryFrom<PaypalWebhookEventType> for PaypalPaymentStatus {| PaypalWebhookEventType::Unknown => {Err(errors::ConnectorError::WebhookEventTypeNotFound.into())}+ #[cfg(feature = "payouts")]+ PaypalWebhookEventType::PayoutsBatchDenied+ | PaypalWebhookEventType::PayoutsBatchProcessing+ | PaypalWebhookEventType::PayoutsBatchSuccess+ | PaypalWebhookEventType::PayoutsItemBlocked+ | PaypalWebhookEventType::PayoutsItemCanceled+ | PaypalWebhookEventType::PayoutsItemDenied+ | PaypalWebhookEventType::PayoutsItemFailed+ | PaypalWebhookEventType::PayoutsItemHeld+ | PaypalWebhookEventType::PayoutsItemRefunded+ | PaypalWebhookEventType::PayoutsItemReturned+ | PaypalWebhookEventType::PayoutsItemSuccess+ | PaypalWebhookEventType::PayoutsItemUnclaimed => {+ Err(errors::ConnectorError::WebhookEventTypeNotFound.into())+ }}}}@@ -3266,6 +3424,58 @@ impl TryFrom<PaypalWebhookEventType> for RefundStatus {| PaypalWebhookEventType::Unknown => {Err(errors::ConnectorError::WebhookEventTypeNotFound.into())}+ #[cfg(feature = "payouts")]+ PaypalWebhookEventType::PayoutsBatchDenied+ | PaypalWebhookEventType::PayoutsBatchProcessing+ | PaypalWebhookEventType::PayoutsBatchSuccess+ | PaypalWebhookEventType::PayoutsItemBlocked+ | PaypalWebhookEventType::PayoutsItemCanceled+ | PaypalWebhookEventType::PayoutsItemDenied+ | PaypalWebhookEventType::PayoutsItemFailed+ | PaypalWebhookEventType::PayoutsItemHeld+ | PaypalWebhookEventType::PayoutsItemRefunded+ | PaypalWebhookEventType::PayoutsItemReturned+ | PaypalWebhookEventType::PayoutsItemSuccess+ | PaypalWebhookEventType::PayoutsItemUnclaimed => {+ Err(errors::ConnectorError::WebhookEventTypeNotFound.into())+ }+ }+ }+}++#[cfg(feature = "payouts")]+impl TryFrom<PaypalWebhookEventType> for PaypalFulfillStatus {+ type Error = error_stack::Report<errors::ConnectorError>;+ fn try_from(event: PaypalWebhookEventType) -> Result<Self, Self::Error> {+ match event {+ PaypalWebhookEventType::PayoutsBatchSuccess+ | PaypalWebhookEventType::PayoutsItemSuccess => Ok(Self::Success),+ PaypalWebhookEventType::PayoutsBatchProcessing => Ok(Self::Processing),+ PaypalWebhookEventType::PayoutsItemHeld+ | PaypalWebhookEventType::PayoutsItemUnclaimed => Ok(Self::Pending),+ PaypalWebhookEventType::PayoutsItemBlocked+ | PaypalWebhookEventType::PayoutsItemCanceled => Ok(Self::Cancelled),+ PaypalWebhookEventType::PayoutsBatchDenied+ | PaypalWebhookEventType::PayoutsItemDenied => Ok(Self::Denied),+ PaypalWebhookEventType::PayoutsItemFailed => Ok(Self::Failed),+ PaypalWebhookEventType::PayoutsItemRefunded => Ok(Self::Refunded),+ PaypalWebhookEventType::PayoutsItemReturned => Ok(Self::Returned),+ PaypalWebhookEventType::PaymentCaptureRefunded+ | PaypalWebhookEventType::PaymentAuthorizationCreated+ | PaypalWebhookEventType::PaymentAuthorizationVoided+ | PaypalWebhookEventType::PaymentCaptureDeclined+ | PaypalWebhookEventType::PaymentCaptureCompleted+ | PaypalWebhookEventType::PaymentCapturePending+ | PaypalWebhookEventType::CheckoutOrderApproved+ | PaypalWebhookEventType::CheckoutOrderCompleted+ | PaypalWebhookEventType::CheckoutOrderProcessed+ | PaypalWebhookEventType::CustomerDisputeCreated+ | PaypalWebhookEventType::CustomerDisputeResolved+ | PaypalWebhookEventType::CustomerDisputedUpdated+ | PaypalWebhookEventType::RiskDisputeCreated+ | PaypalWebhookEventType::Unknown => {+ Err(errors::ConnectorError::WebhookEventTypeNotFound.into())+ }}}}@@ -3290,6 +3500,21 @@ impl TryFrom<PaypalWebhookEventType> for PaypalOrderStatus {| PaypalWebhookEventType::Unknown => {Err(errors::ConnectorError::WebhookEventTypeNotFound.into())}+ #[cfg(feature = "payouts")]+ PaypalWebhookEventType::PayoutsBatchDenied+ | PaypalWebhookEventType::PayoutsBatchProcessing+ | PaypalWebhookEventType::PayoutsBatchSuccess+ | PaypalWebhookEventType::PayoutsItemBlocked+ | PaypalWebhookEventType::PayoutsItemCanceled+ | PaypalWebhookEventType::PayoutsItemDenied+ | PaypalWebhookEventType::PayoutsItemFailed+ | PaypalWebhookEventType::PayoutsItemHeld+ | PaypalWebhookEventType::PayoutsItemRefunded+ | PaypalWebhookEventType::PayoutsItemReturned+ | PaypalWebhookEventType::PayoutsItemSuccess+ | PaypalWebhookEventType::PayoutsItemUnclaimed => {+ Err(errors::ConnectorError::WebhookEventTypeNotFound.into())+ }}}}diff --git a/crates/hyperswitch_connectors/src/connectors/wise.rs b/crates/hyperswitch_connectors/src/connectors/wise.rsindex 1041a6e7b2..7280ad0a92 100644--- a/crates/hyperswitch_connectors/src/connectors/wise.rs+++ b/crates/hyperswitch_connectors/src/connectors/wise.rs@@ -6,7 +6,9 @@ use common_utils::request::{Method, RequestBuilder, RequestContent};#[cfg(feature = "payouts")]use common_utils::types::{AmountConvertor, MinorUnit, MinorUnitForConnector};use common_utils::{errors::CustomResult, ext_traits::ByteSliceExt, request::Request};-use error_stack::{report, ResultExt};+#[cfg(not(feature = "payouts"))]+use error_stack::report;+use error_stack::ResultExt;use hyperswitch_domain_models::{router_data::{AccessToken, ConnectorAuthType, ErrorResponse, RouterData},router_flow_types::{@@ -22,14 +24,16 @@ use hyperswitch_domain_models::{};#[cfg(feature = "payouts")]use hyperswitch_domain_models::{- router_flow_types::{PoCancel, PoCreate, PoEligibility, PoFulfill, PoQuote, PoRecipient},+ router_flow_types::{+ PoCancel, PoCreate, PoEligibility, PoFulfill, PoQuote, PoRecipient, PoSync,+ },types::{PayoutsData, PayoutsResponseData, PayoutsRouterData},};#[cfg(feature = "payouts")]use hyperswitch_interfaces::types::PayoutQuoteType;#[cfg(feature = "payouts")]use hyperswitch_interfaces::types::{- PayoutCancelType, PayoutCreateType, PayoutFulfillType, PayoutRecipientType,+ PayoutCancelType, PayoutCreateType, PayoutFulfillType, PayoutRecipientType, PayoutSyncType,};use hyperswitch_interfaces::{api::{@@ -225,6 +229,8 @@ impl api::PayoutQuote for Wise {}impl api::PayoutRecipient for Wise {}#[cfg(feature = "payouts")]impl api::PayoutFulfill for Wise {}+#[cfg(feature = "payouts")]+impl api::PayoutSync for Wise {}#[cfg(feature = "payouts")]impl ConnectorIntegration<PoCancel, PayoutsData, PayoutsResponseData> for Wise {@@ -409,6 +415,78 @@ impl ConnectorIntegration<PoQuote, PayoutsData, PayoutsResponseData> for Wise {}}+#[cfg(feature = "payouts")]+impl ConnectorIntegration<PoSync, PayoutsData, PayoutsResponseData> for Wise {+ fn get_url(+ &self,+ req: &PayoutsRouterData<PoSync>,+ connectors: &Connectors,+ ) -> CustomResult<String, ConnectorError> {+ let transfer_id = req.request.connector_payout_id.to_owned().ok_or(+ ConnectorError::MissingRequiredField {+ field_name: "transfer_id",+ },+ )?;+ Ok(format!(+ "{}/v1/transfers/{}",+ connectors.wise.base_url, transfer_id+ ))+ }++ fn get_headers(+ &self,+ req: &PayoutsRouterData<PoSync>,+ connectors: &Connectors,+ ) -> CustomResult<Vec<(String, Maskable<String>)>, ConnectorError> {+ self.build_headers(req, connectors)+ }++ fn build_request(+ &self,+ req: &PayoutsRouterData<PoSync>,+ connectors: &Connectors,+ ) -> CustomResult<Option<Request>, ConnectorError> {+ let request = RequestBuilder::new()+ .method(Method::Get)+ .url(&PayoutSyncType::get_url(self, req, connectors)?)+ .attach_default_headers()+ .headers(PayoutSyncType::get_headers(self, req, connectors)?)+ .build();++ Ok(Some(request))+ }++ #[instrument(skip_all)]+ fn handle_response(+ &self,+ data: &PayoutsRouterData<PoSync>,+ event_builder: Option<&mut ConnectorEvent>,+ res: Response,+ ) -> CustomResult<PayoutsRouterData<PoSync>, ConnectorError> {+ let response: wise::WisePayoutSyncResponse = res+ .response+ .parse_struct("WisePayoutSyncResponse")+ .change_context(ConnectorError::ResponseDeserializationFailed)?;++ event_builder.map(|i| i.set_response_body(&response));+ router_env::logger::info!(connector_response=?response);++ RouterData::try_from(ResponseRouterData {+ response,+ data: data.clone(),+ http_code: res.status_code,+ })+ }++ fn get_error_response(+ &self,+ res: Response,+ event_builder: Option<&mut ConnectorEvent>,+ ) -> CustomResult<ErrorResponse, ConnectorError> {+ self.build_error_response(res, event_builder)+ }+}+#[cfg(feature = "payouts")]impl ConnectorIntegration<PoRecipient, PayoutsData, PayoutsResponseData> for Wise {fn get_url(@@ -676,23 +754,68 @@ impl ConnectorIntegration<RSync, RefundsData, RefundsResponseData> for Wise {}impl IncomingWebhook for Wise {fn get_webhook_object_reference_id(&self,- _request: &IncomingWebhookRequestDetails<'_>,+ #[cfg(feature = "payouts")] request: &IncomingWebhookRequestDetails<'_>,+ #[cfg(not(feature = "payouts"))] _request: &IncomingWebhookRequestDetails<'_>,) -> CustomResult<api_models::webhooks::ObjectReferenceId, ConnectorError> {- Err(report!(ConnectorError::WebhooksNotImplemented))+ #[cfg(feature = "payouts")]+ {+ let payload: wise::WisePayoutsWebhookBody = request+ .body+ .parse_struct("WisePayoutsWebhookBody")+ .change_context(ConnectorError::WebhookReferenceIdNotFound)?;++ Ok(api_models::webhooks::ObjectReferenceId::PayoutId(+ api_models::webhooks::PayoutIdType::ConnectorPayoutId(+ payload.data.resource.id.to_string(),+ ),+ ))+ }+ #[cfg(not(feature = "payouts"))]+ {+ Err(report!(ConnectorError::WebhooksNotImplemented))+ }}fn get_webhook_event_type(&self,- _request: &IncomingWebhookRequestDetails<'_>,+ #[cfg(feature = "payouts")] request: &IncomingWebhookRequestDetails<'_>,+ #[cfg(not(feature = "payouts"))] _request: &IncomingWebhookRequestDetails<'_>,) -> CustomResult<IncomingWebhookEvent, ConnectorError> {- Err(report!(ConnectorError::WebhooksNotImplemented))+ #[cfg(feature = "payouts")]+ {+ let payload: wise::WisePayoutsWebhookBody = request+ .body+ .parse_struct("WisePayoutsWebhookBody")+ .change_context(ConnectorError::WebhookReferenceIdNotFound)?;++ Ok(transformers::get_wise_webhooks_event(+ payload.data.current_state,+ ))+ }+ #[cfg(not(feature = "payouts"))]+ {+ Err(report!(ConnectorError::WebhooksNotImplemented))+ }}fn get_webhook_resource_object(&self,- _request: &IncomingWebhookRequestDetails<'_>,+ #[cfg(feature = "payouts")] request: &IncomingWebhookRequestDetails<'_>,+ #[cfg(not(feature = "payouts"))] _request: &IncomingWebhookRequestDetails<'_>,) -> CustomResult<Box<dyn masking::ErasedMaskSerialize>, ConnectorError> {- Err(report!(ConnectorError::WebhooksNotImplemented))+ #[cfg(feature = "payouts")]+ {+ let payload: wise::WisePayoutsWebhookBody = request+ .body+ .parse_struct("WisePayoutsWebhookBody")+ .change_context(ConnectorError::WebhookReferenceIdNotFound)?;++ Ok(Box::new(wise::WisePayoutSyncResponse::from(payload.data)))+ }+ #[cfg(not(feature = "payouts"))]+ {+ Err(report!(ConnectorError::WebhooksNotImplemented))+ }}}diff --git a/crates/hyperswitch_connectors/src/connectors/wise/transformers.rs b/crates/hyperswitch_connectors/src/connectors/wise/transformers.rsindex f89e19f78c..1e0c383d35 100644--- a/crates/hyperswitch_connectors/src/connectors/wise/transformers.rs+++ b/crates/hyperswitch_connectors/src/connectors/wise/transformers.rs@@ -598,7 +598,7 @@ impl<F> TryFrom<PayoutsResponseRouterData<F, WiseFulfillResponse>> for PayoutsRoimpl From<WiseStatus> for PayoutStatus {fn from(wise_status: WiseStatus) -> Self {match wise_status {- WiseStatus::Completed => Self::Success,+ WiseStatus::Completed => Self::Initiated,WiseStatus::Rejected => Self::Failed,WiseStatus::Cancelled => Self::Cancelled,WiseStatus::Pending | WiseStatus::Processing | WiseStatus::IncomingPaymentWaiting => {@@ -638,3 +638,119 @@ impl TryFrom<PayoutMethodData> for RecipientType {}}}++#[cfg(feature = "payouts")]+#[derive(Debug, Deserialize, Serialize)]+pub struct WisePayoutSyncResponse {+ id: u64,+ status: WiseSyncStatus,+}++#[cfg(feature = "payouts")]+#[derive(Debug, Deserialize, Serialize)]+#[serde(rename_all = "snake_case")]+pub enum WiseSyncStatus {+ IncomingPaymentWaiting,+ IncomingPaymentInitiated,+ Processing,+ FundsConverted,+ OutgoingPaymentSent,+ Cancelled,+ FundsRefunded,+ BouncedBack,+ ChargedBack,+ Unknown,+}++#[cfg(feature = "payouts")]+impl<F> TryFrom<PayoutsResponseRouterData<F, WisePayoutSyncResponse>> for PayoutsRouterData<F> {+ type Error = Error;+ fn try_from(+ item: PayoutsResponseRouterData<F, WisePayoutSyncResponse>,+ ) -> Result<Self, Self::Error> {+ Ok(Self {+ response: Ok(PayoutsResponseData {+ status: Some(PayoutStatus::from(item.response.status)),+ connector_payout_id: Some(item.response.id.to_string()),+ payout_eligible: None,+ should_add_next_step_to_process_tracker: false,+ error_code: None,+ error_message: None,+ }),+ ..item.data+ })+ }+}++#[cfg(feature = "payouts")]+impl From<WiseSyncStatus> for PayoutStatus {+ fn from(status: WiseSyncStatus) -> Self {+ match status {+ WiseSyncStatus::IncomingPaymentWaiting => Self::Pending,+ WiseSyncStatus::IncomingPaymentInitiated => Self::Pending,+ WiseSyncStatus::Processing => Self::Pending,+ WiseSyncStatus::FundsConverted => Self::Pending,+ WiseSyncStatus::OutgoingPaymentSent => Self::Success,+ WiseSyncStatus::Cancelled => Self::Cancelled,+ WiseSyncStatus::FundsRefunded => Self::Reversed,+ WiseSyncStatus::BouncedBack => Self::Pending,+ WiseSyncStatus::ChargedBack => Self::Reversed,+ WiseSyncStatus::Unknown => Self::Ineligible,+ }+ }+}++#[cfg(feature = "payouts")]+#[derive(Debug, Deserialize, Serialize)]+pub struct WisePayoutsWebhookBody {+ pub data: WisePayoutsWebhookData,+}++#[cfg(feature = "payouts")]+#[derive(Debug, Deserialize, Serialize)]+pub struct WisePayoutsWebhookData {+ pub resource: WisePayoutsWebhookResource,+ pub current_state: WiseSyncStatus,+}++#[cfg(feature = "payouts")]+#[derive(Debug, Deserialize, Serialize)]+pub struct WisePayoutsWebhookResource {+ pub id: u64,+}++#[cfg(feature = "payouts")]+impl From<WisePayoutsWebhookData> for WisePayoutSyncResponse {+ fn from(data: WisePayoutsWebhookData) -> Self {+ Self {+ id: data.resource.id,+ status: data.current_state,+ }+ }+}++#[cfg(feature = "payouts")]+pub fn get_wise_webhooks_event(+ state: WiseSyncStatus,+) -> api_models::webhooks::IncomingWebhookEvent {+ match state {+ WiseSyncStatus::IncomingPaymentWaiting => {+ api_models::webhooks::IncomingWebhookEvent::PayoutProcessing+ }+ WiseSyncStatus::IncomingPaymentInitiated => {+ api_models::webhooks::IncomingWebhookEvent::PayoutProcessing+ }+ WiseSyncStatus::Processing => api_models::webhooks::IncomingWebhookEvent::PayoutProcessing,+ WiseSyncStatus::FundsConverted => {+ api_models::webhooks::IncomingWebhookEvent::PayoutProcessing+ }+ WiseSyncStatus::OutgoingPaymentSent => {+ api_models::webhooks::IncomingWebhookEvent::PayoutSuccess+ }+ WiseSyncStatus::Cancelled => api_models::webhooks::IncomingWebhookEvent::PayoutCancelled,+ WiseSyncStatus::FundsRefunded => api_models::webhooks::IncomingWebhookEvent::PayoutReversed,+ WiseSyncStatus::BouncedBack => api_models::webhooks::IncomingWebhookEvent::PayoutProcessing,+ WiseSyncStatus::ChargedBack => api_models::webhooks::IncomingWebhookEvent::PayoutReversed,+ WiseSyncStatus::Unknown => api_models::webhooks::IncomingWebhookEvent::EventNotSupported,+ }+}diff --git a/crates/hyperswitch_connectors/src/default_implementations.rs b/crates/hyperswitch_connectors/src/default_implementations.rsindex 484f20cf8d..489ac49cf2 100644--- a/crates/hyperswitch_connectors/src/default_implementations.rs+++ b/crates/hyperswitch_connectors/src/default_implementations.rs@@ -3562,7 +3562,6 @@ default_imp_for_payouts_retrieve!(connectors::Trustpayments,connectors::Tsys,connectors::UnifiedAuthenticationService,- connectors::Wise,connectors::Worldline,connectors::Worldpay,connectors::Worldpayvantiv,