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): [Stripebilling] add record back support for stripebilling (#7561)

CHALLA NISHANTH BABU1c3f0572e353
diff --git a/crates/hyperswitch_connectors/src/connectors/stripebilling.rs b/crates/hyperswitch_connectors/src/connectors/stripebilling.rs
index f17f1bd302..568f8b4919 100644
--- a/crates/hyperswitch_connectors/src/connectors/stripebilling.rs
+++ b/crates/hyperswitch_connectors/src/connectors/stripebilling.rs
@@ -27,6 +27,13 @@ use hyperswitch_domain_models::{
RefundSyncRouterData, RefundsRouterData,
},
};
+#[cfg(all(feature = "v2", feature = "revenue_recovery"))]
+use hyperswitch_domain_models::{
+ router_flow_types::RecoveryRecordBack,
+ router_request_types::revenue_recovery::RevenueRecoveryRecordBackRequest,
+ router_response_types::revenue_recovery::RevenueRecoveryRecordBackResponse,
+ types::RevenueRecoveryRecordBackRouterData,
+};
use hyperswitch_interfaces::{
api::{
self, ConnectorCommon, ConnectorCommonExt, ConnectorIntegration, ConnectorSpecifications,
@@ -68,6 +75,8 @@ impl api::Refund for Stripebilling {}
impl api::RefundExecute for Stripebilling {}
impl api::RefundSync for Stripebilling {}
impl api::PaymentToken for Stripebilling {}
+#[cfg(all(feature = "revenue_recovery", feature = "v2"))]
+impl api::revenue_recovery::RevenueRecoveryRecordBack for Stripebilling {}
impl ConnectorIntegration<PaymentMethodToken, PaymentMethodTokenizationData, PaymentsResponseData>
for Stripebilling
@@ -550,6 +559,98 @@ impl ConnectorIntegration<RSync, RefundsData, RefundsResponseData> for Stripebil
}
}
+#[cfg(all(feature = "v2", feature = "revenue_recovery"))]
+impl
+ ConnectorIntegration<
+ RecoveryRecordBack,
+ RevenueRecoveryRecordBackRequest,
+ RevenueRecoveryRecordBackResponse,
+ > for Stripebilling
+{
+ fn get_headers(
+ &self,
+ req: &RevenueRecoveryRecordBackRouterData,
+ connectors: &Connectors,
+ ) -> CustomResult<Vec<(String, masking::Maskable<String>)>, errors::ConnectorError> {
+ self.build_headers(req, connectors)
+ }
+
+ fn get_content_type(&self) -> &'static str {
+ self.common_get_content_type()
+ }
+
+ fn get_url(
+ &self,
+ req: &RevenueRecoveryRecordBackRouterData,
+ connectors: &Connectors,
+ ) -> CustomResult<String, errors::ConnectorError> {
+ let invoice_id = req
+ .request
+ .merchant_reference_id
+ .get_string_repr()
+ .to_string();
+ match req.request.attempt_status {
+ common_enums::AttemptStatus::Charged => Ok(format!(
+ "{}/v1/invoices/{invoice_id}/pay?paid_out_of_band=true",
+ self.base_url(connectors),
+ )),
+ common_enums::AttemptStatus::Failure => Ok(format!(
+ "{}/v1/invoices/{invoice_id}/void",
+ self.base_url(connectors),
+ )),
+ _ => Err(errors::ConnectorError::FailedToObtainIntegrationUrl.into()),
+ }
+ }
+
+ fn build_request(
+ &self,
+ req: &RevenueRecoveryRecordBackRouterData,
+ connectors: &Connectors,
+ ) -> CustomResult<Option<Request>, errors::ConnectorError> {
+ Ok(Some(
+ RequestBuilder::new()
+ .method(Method::Post)
+ .url(&types::RevenueRecoveryRecordBackType::get_url(
+ self, req, connectors,
+ )?)
+ .attach_default_headers()
+ .headers(types::RevenueRecoveryRecordBackType::get_headers(
+ self, req, connectors,
+ )?)
+ .build(),
+ ))
+ }
+
+ fn handle_response(
+ &self,
+ data: &RevenueRecoveryRecordBackRouterData,
+ event_builder: Option<&mut ConnectorEvent>,
+ res: Response,
+ ) -> CustomResult<RevenueRecoveryRecordBackRouterData, errors::ConnectorError> {
+ let response = res
+ .response
+ .parse_struct::<stripebilling::StripebillingRecordBackResponse>(
+ "StripebillingRecordBackResponse",
+ )
+ .change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
+ event_builder.map(|i| i.set_response_body(&response));
+ router_env::logger::info!(connector_response=?response);
+ RevenueRecoveryRecordBackRouterData::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, errors::ConnectorError> {
+ self.build_error_response(res, event_builder)
+ }
+}
+
#[async_trait::async_trait]
impl webhooks::IncomingWebhook for Stripebilling {
fn get_webhook_source_verification_algorithm(
diff --git a/crates/hyperswitch_connectors/src/connectors/stripebilling/transformers.rs b/crates/hyperswitch_connectors/src/connectors/stripebilling/transformers.rs
index b184f989a4..ccd40f851e 100644
--- a/crates/hyperswitch_connectors/src/connectors/stripebilling/transformers.rs
+++ b/crates/hyperswitch_connectors/src/connectors/stripebilling/transformers.rs
@@ -2,6 +2,8 @@
use std::str::FromStr;
use common_enums::enums;
+#[cfg(all(feature = "revenue_recovery", feature = "v2"))]
+use common_utils::id_type;
use common_utils::{errors::CustomResult, ext_traits::ByteSliceExt, types::StringMinorUnit};
use error_stack::ResultExt;
#[cfg(all(feature = "revenue_recovery", feature = "v2"))]
@@ -14,6 +16,13 @@ use hyperswitch_domain_models::{
router_response_types::{PaymentsResponseData, RefundsResponseData},
types::{PaymentsAuthorizeRouterData, RefundsRouterData},
};
+#[cfg(all(feature = "v2", feature = "revenue_recovery"))]
+use hyperswitch_domain_models::{
+ router_flow_types::RecoveryRecordBack,
+ router_request_types::revenue_recovery::RevenueRecoveryRecordBackRequest,
+ router_response_types::revenue_recovery::RevenueRecoveryRecordBackResponse,
+ types::RevenueRecoveryRecordBackRouterData,
+};
use hyperswitch_interfaces::errors;
use masking::Secret;
use serde::{Deserialize, Serialize};
@@ -360,7 +369,7 @@ impl TryFrom<StripebillingInvoiceBody> for revenue_recovery::RevenueRecoveryInvo
type Error = error_stack::Report<errors::ConnectorError>;
fn try_from(item: StripebillingInvoiceBody) -> Result<Self, Self::Error> {
let merchant_reference_id =
- common_utils::id_type::PaymentReferenceId::from_str(&item.data.object.invoice_id)
+ id_type::PaymentReferenceId::from_str(&item.data.object.invoice_id)
.change_context(errors::ConnectorError::WebhookBodyDecodingFailed)?;
Ok(Self {
amount: item.data.object.amount,
@@ -369,3 +378,42 @@ impl TryFrom<StripebillingInvoiceBody> for revenue_recovery::RevenueRecoveryInvo
})
}
}
+
+#[derive(Debug, Deserialize, Serialize, Clone)]
+pub struct StripebillingRecordBackResponse {
+ pub id: String,
+}
+
+#[cfg(all(feature = "v2", feature = "revenue_recovery"))]
+impl
+ TryFrom<
+ ResponseRouterData<
+ RecoveryRecordBack,
+ StripebillingRecordBackResponse,
+ RevenueRecoveryRecordBackRequest,
+ RevenueRecoveryRecordBackResponse,
+ >,
+ > for RevenueRecoveryRecordBackRouterData
+{
+ type Error = error_stack::Report<errors::ConnectorError>;
+ fn try_from(
+ item: ResponseRouterData<
+ RecoveryRecordBack,
+ StripebillingRecordBackResponse,
+ RevenueRecoveryRecordBackRequest,
+ RevenueRecoveryRecordBackResponse,
+ >,
+ ) -> Result<Self, Self::Error> {
+ Ok(Self {
+ response: Ok(RevenueRecoveryRecordBackResponse {
+ merchant_reference_id: id_type::PaymentReferenceId::from_str(
+ item.response.id.as_str(),
+ )
+ .change_context(errors::ConnectorError::MissingRequiredField {
+ field_name: "invoice_id in the response",
+ })?,
+ }),
+ ..item.data
+ })
+ }
+}
diff --git a/crates/hyperswitch_connectors/src/default_implementations.rs b/crates/hyperswitch_connectors/src/default_implementations.rs
index 246a3f1e2d..3aa9568316 100644
--- a/crates/hyperswitch_connectors/src/default_implementations.rs
+++ b/crates/hyperswitch_connectors/src/default_implementations.rs
@@ -3743,7 +3743,6 @@ default_imp_for_revenue_recovery_record_back!(
connectors::Shift4,
connectors::Stax,
connectors::Square,
- connectors::Stripebilling,
connectors::Taxjar,
connectors::Thunes,
connectors::Trustpay,