Skip to content

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

feat(connector): [Gocardless] Add mandate webhoooks (#2468)

DEEPANSHU BANSAL8d53c663a5e2
diff --git a/crates/router/src/connector/gocardless.rs b/crates/router/src/connector/gocardless.rs
index dda88a5ea5..3e2621a0c9 100644
--- a/crates/router/src/connector/gocardless.rs
+++ b/crates/router/src/connector/gocardless.rs
@@ -746,6 +746,12 @@ impl api::IncomingWebhook for Gocardless {
api_models::webhooks::RefundIdType::ConnectorRefundId(link.refund.to_owned());
api::webhooks::ObjectReferenceId::RefundId(refund_id)
}
+ transformers::WebhooksLink::MandateWebhookLink(link) => {
+ let mandate_id = api_models::webhooks::MandateIdType::ConnectorMandateId(
+ link.mandate.to_owned(),
+ );
+ api::webhooks::ObjectReferenceId::MandateId(mandate_id)
+ }
};
Ok(reference_id)
}
@@ -792,6 +798,27 @@ impl api::IncomingWebhook for Gocardless {
api::IncomingWebhookEvent::EventNotSupported
}
},
+ transformers::WebhookAction::MandatesAction(action) => match action {
+ transformers::MandatesAction::Active | transformers::MandatesAction::Reinstated => {
+ api::IncomingWebhookEvent::MandateActive
+ }
+ transformers::MandatesAction::Expired
+ | transformers::MandatesAction::Cancelled
+ | transformers::MandatesAction::Failed
+ | transformers::MandatesAction::Consumed => {
+ api::IncomingWebhookEvent::MandateRevoked
+ }
+ transformers::MandatesAction::Created
+ | transformers::MandatesAction::CustomerApprovalGranted
+ | transformers::MandatesAction::CustomerApprovalSkipped
+ | transformers::MandatesAction::Transferred
+ | transformers::MandatesAction::Submitted
+ | transformers::MandatesAction::ResubmissionRequested
+ | transformers::MandatesAction::Replaced
+ | transformers::MandatesAction::Blocked => {
+ api::IncomingWebhookEvent::EventNotSupported
+ }
+ },
};
Ok(event_type)
}
@@ -817,6 +844,9 @@ impl api::IncomingWebhook for Gocardless {
transformers::WebhookResourceType::Refunds => serde_json::to_value(first_event)
.into_report()
.change_context(errors::ConnectorError::WebhookBodyDecodingFailed),
+ transformers::WebhookResourceType::Mandates => serde_json::to_value(first_event)
+ .into_report()
+ .change_context(errors::ConnectorError::WebhookBodyDecodingFailed),
}
}
}
diff --git a/crates/router/src/connector/gocardless/transformers.rs b/crates/router/src/connector/gocardless/transformers.rs
index 6acaee59ed..8187c5ccc4 100644
--- a/crates/router/src/connector/gocardless/transformers.rs
+++ b/crates/router/src/connector/gocardless/transformers.rs
@@ -873,6 +873,7 @@ pub struct WebhookEvent {
pub enum WebhookResourceType {
Payments,
Refunds,
+ Mandates,
}
#[derive(Debug, Serialize, Deserialize)]
@@ -880,6 +881,7 @@ pub enum WebhookResourceType {
pub enum WebhookAction {
PaymentsAction(PaymentsAction),
RefundsAction(RefundsAction),
+ MandatesAction(MandatesAction),
}
#[derive(Debug, Serialize, Deserialize)]
@@ -909,11 +911,31 @@ pub enum RefundsAction {
FundsReturned,
}
+#[derive(Debug, Serialize, Deserialize)]
+#[serde(rename_all = "snake_case")]
+pub enum MandatesAction {
+ Created,
+ CustomerApprovalGranted,
+ CustomerApprovalSkipped,
+ Active,
+ Cancelled,
+ Failed,
+ Transferred,
+ Expired,
+ Submitted,
+ ResubmissionRequested,
+ Reinstated,
+ Replaced,
+ Consumed,
+ Blocked,
+}
+
#[derive(Debug, Serialize, Deserialize)]
#[serde(untagged)]
pub enum WebhooksLink {
PaymentWebhooksLink(PaymentWebhooksLink),
RefundWebhookLink(RefundWebhookLink),
+ MandateWebhookLink(MandateWebhookLink),
}
#[derive(Debug, Serialize, Deserialize)]
@@ -926,12 +948,17 @@ pub struct PaymentWebhooksLink {
pub payment: String,
}
+#[derive(Debug, Serialize, Deserialize)]
+pub struct MandateWebhookLink {
+ pub mandate: String,
+}
+
impl TryFrom<&WebhookEvent> for GocardlessPaymentsResponse {
type Error = error_stack::Report<errors::ConnectorError>;
fn try_from(item: &WebhookEvent) -> Result<Self, Self::Error> {
let id = match &item.links {
WebhooksLink::PaymentWebhooksLink(link) => link.payment.to_owned(),
- WebhooksLink::RefundWebhookLink(_) => {
+ WebhooksLink::RefundWebhookLink(_) | WebhooksLink::MandateWebhookLink(_) => {
Err(errors::ConnectorError::WebhookEventTypeNotFound)?
}
};
@@ -962,7 +989,7 @@ impl TryFrom<&WebhookAction> for GocardlessPaymentStatus {
| PaymentsAction::ResubmissionRequired
| PaymentsAction::Created => Err(errors::ConnectorError::WebhookEventTypeNotFound)?,
},
- WebhookAction::RefundsAction(_) => {
+ WebhookAction::RefundsAction(_) | WebhookAction::MandatesAction(_) => {
Err(errors::ConnectorError::WebhookEventTypeNotFound)?
}
}