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): [BRAINTREE] Add revoke mandate flow (#7525)

DEEPANSHU BANSAL2f55be45fba4
diff --git a/crates/hyperswitch_connectors/src/connectors/braintree.rs b/crates/hyperswitch_connectors/src/connectors/braintree.rs
index 705bf0688f..e965e96429 100644
--- a/crates/hyperswitch_connectors/src/connectors/braintree.rs
+++ b/crates/hyperswitch_connectors/src/connectors/braintree.rs
@@ -17,20 +17,22 @@ use hyperswitch_domain_models::{
router_data::{AccessToken, ConnectorAuthType, ErrorResponse, RouterData},
router_flow_types::{
access_token_auth::AccessTokenAuth,
+ mandate_revoke::MandateRevoke,
payments::{Authorize, Capture, PSync, PaymentMethodToken, Session, SetupMandate, Void},
refunds::{Execute, RSync},
CompleteAuthorize,
},
router_request_types::{
- AccessTokenRequestData, CompleteAuthorizeData, PaymentMethodTokenizationData,
- PaymentsAuthorizeData, PaymentsCancelData, PaymentsCaptureData, PaymentsSessionData,
- PaymentsSyncData, RefundsData, SetupMandateRequestData,
+ AccessTokenRequestData, CompleteAuthorizeData, MandateRevokeRequestData,
+ PaymentMethodTokenizationData, PaymentsAuthorizeData, PaymentsCancelData,
+ PaymentsCaptureData, PaymentsSessionData, PaymentsSyncData, RefundsData,
+ SetupMandateRequestData,
},
- router_response_types::{PaymentsResponseData, RefundsResponseData},
+ router_response_types::{MandateRevokeResponseData, PaymentsResponseData, RefundsResponseData},
types::{
- PaymentsAuthorizeRouterData, PaymentsCancelRouterData, PaymentsCaptureRouterData,
- PaymentsCompleteAuthorizeRouterData, PaymentsSyncRouterData, RefundSyncRouterData,
- RefundsRouterData, TokenizationRouterData,
+ MandateRevokeRouterData, PaymentsAuthorizeRouterData, PaymentsCancelRouterData,
+ PaymentsCaptureRouterData, PaymentsCompleteAuthorizeRouterData, PaymentsSyncRouterData,
+ RefundSyncRouterData, RefundsRouterData, TokenizationRouterData,
},
};
use hyperswitch_interfaces::{
@@ -44,9 +46,9 @@ use hyperswitch_interfaces::{
errors,
events::connector_api_logs::ConnectorEvent,
types::{
- PaymentsAuthorizeType, PaymentsCaptureType, PaymentsCompleteAuthorizeType,
- PaymentsSyncType, PaymentsVoidType, RefundExecuteType, RefundSyncType, Response,
- TokenizationType,
+ MandateRevokeType, PaymentsAuthorizeType, PaymentsCaptureType,
+ PaymentsCompleteAuthorizeType, PaymentsSyncType, PaymentsVoidType, RefundExecuteType,
+ RefundSyncType, Response, TokenizationType,
},
webhooks::{IncomingWebhook, IncomingWebhookFlowError, IncomingWebhookRequestDetails},
};
@@ -228,6 +230,7 @@ impl api::PaymentCapture for Braintree {}
impl api::PaymentsCompleteAuthorize for Braintree {}
impl api::PaymentSession for Braintree {}
impl api::ConnectorAccessToken for Braintree {}
+impl api::ConnectorMandateRevoke for Braintree {}
impl ConnectorIntegration<AccessTokenAuth, AccessTokenRequestData, AccessToken> for Braintree {
// Not Implemented (R)
@@ -590,6 +593,76 @@ impl ConnectorIntegration<Authorize, PaymentsAuthorizeData, PaymentsResponseData
}
}
+impl ConnectorIntegration<MandateRevoke, MandateRevokeRequestData, MandateRevokeResponseData>
+ for Braintree
+{
+ fn get_headers(
+ &self,
+ req: &MandateRevokeRouterData,
+ connectors: &Connectors,
+ ) -> CustomResult<Vec<(String, masking::Maskable<String>)>, errors::ConnectorError> {
+ self.build_headers(req, connectors)
+ }
+ fn get_url(
+ &self,
+ _req: &MandateRevokeRouterData,
+ connectors: &Connectors,
+ ) -> CustomResult<String, errors::ConnectorError> {
+ Ok(self.base_url(connectors).to_string())
+ }
+ fn build_request(
+ &self,
+ req: &MandateRevokeRouterData,
+ connectors: &Connectors,
+ ) -> CustomResult<Option<Request>, errors::ConnectorError> {
+ Ok(Some(
+ RequestBuilder::new()
+ .method(Method::Post)
+ .url(&MandateRevokeType::get_url(self, req, connectors)?)
+ .attach_default_headers()
+ .headers(MandateRevokeType::get_headers(self, req, connectors)?)
+ .set_body(MandateRevokeType::get_request_body(self, req, connectors)?)
+ .build(),
+ ))
+ }
+ fn get_request_body(
+ &self,
+ req: &MandateRevokeRouterData,
+ _connectors: &Connectors,
+ ) -> CustomResult<RequestContent, errors::ConnectorError> {
+ let connector_req = transformers::BraintreeRevokeMandateRequest::try_from(req)?;
+ Ok(RequestContent::Json(Box::new(connector_req)))
+ }
+
+ fn handle_response(
+ &self,
+ data: &MandateRevokeRouterData,
+ event_builder: Option<&mut ConnectorEvent>,
+ res: Response,
+ ) -> CustomResult<MandateRevokeRouterData, errors::ConnectorError> {
+ let response: transformers::BraintreeRevokeMandateResponse = res
+ .response
+ .parse_struct("BraintreeRevokeMandateResponse")
+ .change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
+
+ event_builder.map(|i| i.set_response_body(&response));
+ router_env::logger::info!(connector_response=?response);
+
+ RouterData::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)
+ }
+}
+
impl ConnectorIntegration<Void, PaymentsCancelData, PaymentsResponseData> for Braintree {
fn get_headers(
&self,
diff --git a/crates/hyperswitch_connectors/src/connectors/braintree/transformers.rs b/crates/hyperswitch_connectors/src/connectors/braintree/transformers.rs
index 9951707e2d..2a5fabb778 100644
--- a/crates/hyperswitch_connectors/src/connectors/braintree/transformers.rs
+++ b/crates/hyperswitch_connectors/src/connectors/braintree/transformers.rs
@@ -6,9 +6,12 @@ use hyperswitch_domain_models::{
payment_method_data::PaymentMethodData,
router_data::{ConnectorAuthType, PaymentMethodToken, RouterData},
router_flow_types::refunds::{Execute, RSync},
- router_request_types::{CompleteAuthorizeData, PaymentsAuthorizeData, ResponseId},
+ router_request_types::{
+ CompleteAuthorizeData, MandateRevokeRequestData, PaymentsAuthorizeData, ResponseId,
+ },
router_response_types::{
- MandateReference, PaymentsResponseData, RedirectForm, RefundsResponseData,
+ MandateReference, MandateRevokeResponseData, PaymentsResponseData, RedirectForm,
+ RefundsResponseData,
},
types::{self, RefundsRouterData},
};
@@ -38,6 +41,7 @@ pub const VOID_TRANSACTION_MUTATION: &str = "mutation voidTransaction($input: R
pub const REFUND_TRANSACTION_MUTATION: &str = "mutation refundTransaction($input: RefundTransactionInput!) { refundTransaction(input: $input) {clientMutationId refund { id legacyId amount { value currencyCode } status } } }";
pub const AUTHORIZE_AND_VAULT_CREDIT_CARD_MUTATION: &str="mutation authorizeCreditCard($input: AuthorizeCreditCardInput!) { authorizeCreditCard(input: $input) { transaction { id status createdAt paymentMethod { id } } } }";
pub const CHARGE_AND_VAULT_TRANSACTION_MUTATION: &str ="mutation ChargeCreditCard($input: ChargeCreditCardInput!) { chargeCreditCard(input: $input) { transaction { id status createdAt paymentMethod { id } } } }";
+pub const DELETE_PAYMENT_METHOD_FROM_VAULT_MUTATION: &str = "mutation deletePaymentMethodFromVault($input: DeletePaymentMethodFromVaultInput!) { deletePaymentMethodFromVault(input: $input) { clientMutationId } }";
pub const TRANSACTION_QUERY: &str = "query($input: TransactionSearchInput!) { search { transactions(input: $input) { edges { node { id status } } } } }";
pub const REFUND_QUERY: &str = "query($input: RefundSearchInput!) { search { refunds(input: $input, first: 1) { edges { node { id status createdAt amount { value currencyCode } orderId } } } } }";
@@ -1355,6 +1359,94 @@ impl TryFrom<PaymentsCaptureResponseRouterData<BraintreeCaptureResponse>>
}
}
+#[derive(Debug, Serialize)]
+#[serde(rename_all = "camelCase")]
+pub struct DeletePaymentMethodFromVaultInputData {
+ payment_method_id: Secret<String>,
+}
+
+#[derive(Debug, Serialize)]
+pub struct VariableDeletePaymentMethodFromVaultInput {
+ input: DeletePaymentMethodFromVaultInputData,
+}
+
+#[derive(Debug, Serialize)]
+pub struct BraintreeRevokeMandateRequest {
+ query: String,
+ variables: VariableDeletePaymentMethodFromVaultInput,
+}
+
+impl TryFrom<&types::MandateRevokeRouterData> for BraintreeRevokeMandateRequest {
+ type Error = error_stack::Report<errors::ConnectorError>;
+ fn try_from(item: &types::MandateRevokeRouterData) -> Result<Self, Self::Error> {
+ let query = DELETE_PAYMENT_METHOD_FROM_VAULT_MUTATION.to_string();
+ let variables = VariableDeletePaymentMethodFromVaultInput {
+ input: DeletePaymentMethodFromVaultInputData {
+ payment_method_id: Secret::new(
+ item.request
+ .connector_mandate_id
+ .clone()
+ .ok_or(errors::ConnectorError::MissingConnectorMandateID)?,
+ ),
+ },
+ };
+ Ok(Self { query, variables })
+ }
+}
+
+impl<F>
+ TryFrom<
+ ResponseRouterData<
+ F,
+ BraintreeRevokeMandateResponse,
+ MandateRevokeRequestData,
+ MandateRevokeResponseData,
+ >,
+ > for RouterData<F, MandateRevokeRequestData, MandateRevokeResponseData>
+{
+ type Error = error_stack::Report<errors::ConnectorError>;
+ fn try_from(
+ item: ResponseRouterData<
+ F,
+ BraintreeRevokeMandateResponse,
+ MandateRevokeRequestData,
+ MandateRevokeResponseData,
+ >,
+ ) -> Result<Self, Self::Error> {
+ Ok(Self {
+ response: match item.response {
+ BraintreeRevokeMandateResponse::ErrorResponse(error_response) => {
+ build_error_response(error_response.errors.as_ref(), item.http_code)
+ }
+ BraintreeRevokeMandateResponse::RevokeMandateResponse(..) => {
+ Ok(MandateRevokeResponseData {
+ mandate_status: common_enums::MandateStatus::Revoked,
+ })
+ }
+ },
+ ..item.data
+ })
+ }
+}
+
+#[derive(Debug, Clone, Deserialize, Serialize)]
+#[serde(untagged)]
+pub enum BraintreeRevokeMandateResponse {
+ RevokeMandateResponse(Box<RevokeMandateResponse>),
+ ErrorResponse(Box<ErrorResponse>),
+}
+
+#[derive(Debug, Clone, Deserialize, Serialize)]
+pub struct RevokeMandateResponse {
+ data: DeletePaymentMethodFromVault,
+}
+
+#[derive(Debug, Clone, Deserialize, Serialize)]
+#[serde(rename_all = "camelCase")]
+pub struct DeletePaymentMethodFromVault {
+ client_mutation_id: Option<String>,
+}
+
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CancelInputData {
diff --git a/crates/hyperswitch_connectors/src/default_implementations.rs b/crates/hyperswitch_connectors/src/default_implementations.rs
index 4b47db0f94..23b9602b0a 100644
--- a/crates/hyperswitch_connectors/src/default_implementations.rs
+++ b/crates/hyperswitch_connectors/src/default_implementations.rs
@@ -3187,7 +3187,6 @@ default_imp_for_revoking_mandates!(
connectors::Billwerk,
connectors::Bitpay,
connectors::Bluesnap,
- connectors::Braintree,
connectors::Boku,
connectors::Cashtocode,
connectors::Chargebee,