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(connector): [Mollie] implement v1 Webhook (#11324)
Nithin N23a5637e1f03
diff --git a/crates/hyperswitch_connectors/src/connectors/mollie.rs b/crates/hyperswitch_connectors/src/connectors/mollie.rsindex 177b2e05cf..5fc153c909 100644--- a/crates/hyperswitch_connectors/src/connectors/mollie.rs+++ b/crates/hyperswitch_connectors/src/connectors/mollie.rs@@ -2,12 +2,13 @@ pub mod transformers;use common_enums::enums;use common_utils::{+ crypto::Encryptable,errors::CustomResult,ext_traits::BytesExt,request::{Method, Request, RequestBuilder, RequestContent},types::{AmountConvertor, StringMajorUnit, StringMajorUnitForConnector},};-use error_stack::{report, ResultExt};+use error_stack::ResultExt;use hyperswitch_domain_models::{payment_method_data::PaymentMethodData,router_data::{AccessToken, ConnectorAuthType, ErrorResponse, RouterData},@@ -48,7 +49,6 @@ use lazy_static::lazy_static;use masking::{Mask, PeekInterface};use transformers as mollie;-// use self::mollie::{webhook_headers, MollieWebhookBodyEventType};use crate::{constants::headers,types::ResponseRouterData,@@ -840,11 +840,26 @@ impl ConnectorIntegration<RSync, RefundsData, RefundsResponseData> for Mollie {#[async_trait::async_trait]impl webhooks::IncomingWebhook for Mollie {- fn get_webhook_object_reference_id(+ async fn verify_webhook_source(&self,_request: &webhooks::IncomingWebhookRequestDetails<'_>,+ _merchant_id: &common_utils::id_type::MerchantId,+ _connector_webhook_details: Option<common_utils::pii::SecretSerdeValue>,+ _connector_account_details: Encryptable<masking::Secret<serde_json::Value>>,+ _connector_name: &str,+ ) -> CustomResult<bool, errors::ConnectorError> {+ // Mollie next gen webhooks are not ready for transaction events yet, need to update here once they support+ Ok(false)+ }+ fn get_webhook_object_reference_id(+ &self,+ request: &webhooks::IncomingWebhookRequestDetails<'_>,) -> CustomResult<api_models::webhooks::ObjectReferenceId, errors::ConnectorError> {- Err(report!(errors::ConnectorError::WebhooksNotImplemented))+ let details: mollie::MollieWebhookBody = serde_qs::from_bytes(request.body)+ .change_context(errors::ConnectorError::WebhookBodyDecodingFailed)?;+ Ok(api_models::webhooks::ObjectReferenceId::PaymentId(+ api_models::payments::PaymentIdType::ConnectorTransactionId(details.id),+ ))}fn get_webhook_event_type(@@ -852,14 +867,16 @@ impl webhooks::IncomingWebhook for Mollie {_request: &webhooks::IncomingWebhookRequestDetails<'_>,_context: Option<&webhooks::WebhookContext>,) -> CustomResult<api_models::webhooks::IncomingWebhookEvent, errors::ConnectorError> {- Ok(api_models::webhooks::IncomingWebhookEvent::EventNotSupported)+ Ok(api_models::webhooks::IncomingWebhookEvent::PaymentIntentProcessing)}fn get_webhook_resource_object(&self,- _request: &webhooks::IncomingWebhookRequestDetails<'_>,+ request: &webhooks::IncomingWebhookRequestDetails<'_>,) -> CustomResult<Box<dyn masking::ErasedMaskSerialize>, errors::ConnectorError> {- Err(report!(errors::ConnectorError::WebhooksNotImplemented))+ let details: mollie::MollieWebhookBody = serde_qs::from_bytes(request.body)+ .change_context(errors::ConnectorError::WebhookBodyDecodingFailed)?;+ Ok(Box::new(details))}}diff --git a/crates/hyperswitch_connectors/src/connectors/mollie/transformers.rs b/crates/hyperswitch_connectors/src/connectors/mollie/transformers.rsindex 475ef3dd59..4926255161 100644--- a/crates/hyperswitch_connectors/src/connectors/mollie/transformers.rs+++ b/crates/hyperswitch_connectors/src/connectors/mollie/transformers.rs@@ -380,8 +380,12 @@ impl TryFrom<&MollieRouterData<&types::SetupMandateRouterData>> for MolliePaymendescription: item.router_data.get_description()?,redirect_url: item.router_data.request.get_router_return_url()?,cancel_url: None,- /* webhook_url is a mandatory field. */- webhook_url: "".to_string(),++ webhook_url: match router_env::env::which() {+ router_env::Env::Development => "".to_string(),+ _ => item.router_data.request.get_webhook_url()?,+ },+locale: None,payment_method_data,metadata: Some(MollieMetadata {@@ -436,7 +440,10 @@ impl TryFrom<&MollieRouterData<&types::PaymentsAuthorizeRouterData>> for MolliePlet payment_method_data = match &item.router_data.request.payment_method_data {PaymentMethodData::Card(_) => {- let pm_token = item.router_data.get_payment_method_token()?;+ let pm_token = item+ .router_data+ .get_payment_method_token()+ .attach_printable("Mollie token not found")?;Ok(MolliePaymentMethodData::CreditCard(Box::new(CreditCardMethodData {billing_address: get_billing_details(item.router_data)?,@@ -480,9 +487,10 @@ impl TryFrom<&MollieRouterData<&types::PaymentsAuthorizeRouterData>> for MolliePdescription,redirect_url,cancel_url: None,- /* webhook_url is a mandatory field.- But we can't support webhook in our core hence keeping it as empty string */- webhook_url: "".to_string(),+ webhook_url: match router_env::env::which() {+ router_env::Env::Development => "".to_string(),+ _ => item.router_data.request.get_webhook_url()?,+ },locale: None,payment_method_data,metadata: Some(MollieMetadata {@@ -1015,3 +1023,8 @@ pub struct MollieErrorResponse {pub detail: String,pub field: Option<String>,}++#[derive(Debug, Deserialize, Serialize)]+pub struct MollieWebhookBody {+ pub id: String,+}