Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(connector): Add refund and dispute webhooks for Rapyd #1313

Merged
merged 12 commits into from
Jun 28, 2023
8 changes: 3 additions & 5 deletions crates/router/src/connector/rapyd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -810,10 +810,8 @@ impl api::IncomingWebhook for Rapyd {
.parse_struct("RapydIncomingWebhook")
.change_context(errors::ConnectorError::WebhookEventTypeNotFound)?;
Ok(match webhook.webhook_type {
rapyd::RapydWebhookObjectEventType::PaymentCompleted => {
api::IncomingWebhookEvent::PaymentIntentFailure
}
rapyd::RapydWebhookObjectEventType::PaymentCaptured => {
rapyd::RapydWebhookObjectEventType::PaymentCompleted
| rapyd::RapydWebhookObjectEventType::PaymentCaptured => {
api::IncomingWebhookEvent::PaymentIntentSuccess
}
rapyd::RapydWebhookObjectEventType::PaymentFailed => {
Expand Down Expand Up @@ -881,7 +879,7 @@ impl api::IncomingWebhook for Rapyd {
}?;
Ok(api::disputes::DisputePayload {
amount: webhook_dispute_data.amount.to_string(),
currency: webhook_dispute_data.currency,
currency: webhook_dispute_data.currency.to_string(),
ShankarSinghC marked this conversation as resolved.
Show resolved Hide resolved
dispute_stage: api_models::enums::DisputeStage::Dispute,
connector_dispute_id: webhook_dispute_data.token,
connector_reason: Some(webhook_dispute_data.dispute_reason_description),
Expand Down
19 changes: 11 additions & 8 deletions crates/router/src/connector/rapyd/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ pub struct ResponseData {
pub struct DisputeResponseData {
pub id: String,
pub amount: i64,
pub currency: String,
pub currency: api_models::enums::Currency,
pub token: String,
pub dispute_reason_description: String,
#[serde(with = "common_utils::custom_serde::timestamp")]
Expand Down Expand Up @@ -486,21 +486,24 @@ pub enum RapydWebhookObjectEventType {
}

#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, strum::Display)]
#[serde(rename_all = "UPPERCASE")]
pub enum RapydWebhookDisputeStatus {
Act,
Rvw,
Los,
#[serde(rename = "ACT")]
Active,
#[serde(rename = "RVW")]
Review,
#[serde(rename = "LOS")]
Lose,
#[serde(rename = "WIN")]
Win,
}

impl TryFrom<RapydWebhookDisputeStatus> for api_models::webhooks::IncomingWebhookEvent {
type Error = errors::ConnectorError;
fn try_from(value: RapydWebhookDisputeStatus) -> Result<Self, Self::Error> {
ShankarSinghC marked this conversation as resolved.
Show resolved Hide resolved
Ok(match value {
RapydWebhookDisputeStatus::Act => Self::DisputeOpened,
RapydWebhookDisputeStatus::Rvw => Self::DisputeChallenged,
RapydWebhookDisputeStatus::Los => Self::DisputeLost,
RapydWebhookDisputeStatus::Active => Self::DisputeOpened,
RapydWebhookDisputeStatus::Review => Self::DisputeChallenged,
RapydWebhookDisputeStatus::Lose => Self::DisputeLost,
RapydWebhookDisputeStatus::Win => Self::DisputeWon,
})
}
Expand Down