Skip to content

Commit d850f17

Browse files
feat(router): add support for relay refund incoming webhooks (#6974)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
1 parent 15fd4de commit d850f17

File tree

16 files changed

+485
-94
lines changed

16 files changed

+485
-94
lines changed

crates/api_models/src/webhooks.rs

+6
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ pub enum WebhookResponseTracker {
120120
status: common_enums::MandateStatus,
121121
},
122122
NoEffect,
123+
Relay {
124+
relay_id: common_utils::id_type::RelayId,
125+
status: common_enums::RelayStatus,
126+
},
123127
}
124128

125129
impl WebhookResponseTracker {
@@ -132,6 +136,7 @@ impl WebhookResponseTracker {
132136
Self::NoEffect | Self::Mandate { .. } => None,
133137
#[cfg(feature = "payouts")]
134138
Self::Payout { .. } => None,
139+
Self::Relay { .. } => None,
135140
}
136141
}
137142

@@ -144,6 +149,7 @@ impl WebhookResponseTracker {
144149
Self::NoEffect | Self::Mandate { .. } => None,
145150
#[cfg(feature = "payouts")]
146151
Self::Payout { .. } => None,
152+
Self::Relay { .. } => None,
147153
}
148154
}
149155
}

crates/common_utils/src/id_type/relay.rs

+11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::str::FromStr;
2+
13
crate::id_type!(
24
RelayId,
35
"A type for relay_id that can be used for relay ids"
@@ -11,3 +13,12 @@ crate::impl_queryable_id_type!(RelayId);
1113
crate::impl_to_sql_from_sql_id_type!(RelayId);
1214

1315
crate::impl_debug_id_type!(RelayId);
16+
17+
impl FromStr for RelayId {
18+
type Err = error_stack::Report<crate::errors::ValidationError>;
19+
20+
fn from_str(s: &str) -> Result<Self, Self::Err> {
21+
let cow_string = std::borrow::Cow::Owned(s.to_string());
22+
Self::try_from(cow_string)
23+
}
24+
}

crates/diesel_models/src/query/relay.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use diesel::{associations::HasTable, ExpressionMethods};
1+
use diesel::{associations::HasTable, BoolExpressionMethods, ExpressionMethods};
22

33
use super::generics;
44
use crate::{
@@ -46,4 +46,18 @@ impl Relay {
4646
)
4747
.await
4848
}
49+
50+
pub async fn find_by_profile_id_connector_reference_id(
51+
conn: &PgPooledConn,
52+
profile_id: &common_utils::id_type::ProfileId,
53+
connector_reference_id: &str,
54+
) -> StorageResult<Self> {
55+
generics::generic_find_one::<<Self as HasTable>::Table, _, _>(
56+
conn,
57+
dsl::profile_id
58+
.eq(profile_id.to_owned())
59+
.and(dsl::connector_reference_id.eq(connector_reference_id.to_owned())),
60+
)
61+
.await
62+
}
4963
}

crates/hyperswitch_domain_models/src/relay.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl RelayUpdate {
8181
match response {
8282
Err(error) => Self::ErrorUpdate {
8383
error_code: error.code,
84-
error_message: error.message,
84+
error_message: error.reason.unwrap_or(error.message),
8585
status: common_enums::RelayStatus::Failure,
8686
},
8787
Ok(response) => Self::StatusUpdate {

0 commit comments

Comments
 (0)