From c47619b5ea09ad08ec8ff5ef336aef5b502ff3ec Mon Sep 17 00:00:00 2001 From: Narayan Bhat <48803246+Narayanbhat166@users.noreply.github.com> Date: Sun, 19 Feb 2023 19:16:40 +0530 Subject: [PATCH] enhance(braintree): create basic auth for braintree (#602) --- crates/router/src/connector/braintree.rs | 13 +++++++------ .../src/connector/braintree/transformers.rs | 19 ++++++++++++++----- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/crates/router/src/connector/braintree.rs b/crates/router/src/connector/braintree.rs index 42c7ecf146..a757fea17b 100644 --- a/crates/router/src/connector/braintree.rs +++ b/crates/router/src/connector/braintree.rs @@ -39,7 +39,7 @@ impl ConnectorCommon for Braintree { let auth: braintree::BraintreeAuthType = auth_type .try_into() .change_context(errors::ConnectorError::FailedToObtainAuthType)?; - Ok(vec![(headers::AUTHORIZATION.to_string(), auth.api_key)]) + Ok(vec![(headers::AUTHORIZATION.to_string(), auth.auth_header)]) } } @@ -103,7 +103,7 @@ impl Ok(format!( "{}/merchants/{}/client_token", self.base_url(connectors), - auth_type.merchant_account, + auth_type.merchant_id, )) } @@ -131,6 +131,7 @@ impl &self, res: types::Response, ) -> CustomResult { + logger::debug!(braintree_payments_error_response=?res); let response: braintree::ErrorResponse = res .response .parse_struct("Error Response") @@ -241,7 +242,7 @@ impl Ok(format!( "{}/merchants/{}/transactions/{}", self.base_url(connectors), - auth_type.merchant_account, + auth_type.merchant_id, connector_payment_id )) } @@ -341,7 +342,7 @@ impl Ok(format!( "{}merchants/{}/transactions", self.base_url(connectors), - auth_type.merchant_account + auth_type.merchant_id )) } @@ -452,7 +453,7 @@ impl Ok(format!( "{}merchants/{}/transactions/{}/void", self.base_url(connectors), - auth_type.merchant_account, + auth_type.merchant_id, req.request.connector_transaction_id )) } @@ -556,7 +557,7 @@ impl services::ConnectorIntegration for BraintreePaymentsRequest { } pub struct BraintreeAuthType { - pub(super) api_key: String, - pub(super) merchant_account: String, + pub(super) auth_header: String, + pub(super) merchant_id: String, } impl TryFrom<&types::ConnectorAuthType> for BraintreeAuthType { type Error = error_stack::Report; fn try_from(item: &types::ConnectorAuthType) -> Result { - if let types::ConnectorAuthType::BodyKey { api_key, key1 } = item { + if let types::ConnectorAuthType::SignatureKey { + api_key: public_key, + key1: merchant_id, + api_secret: private_key, + } = item + { + let auth_key = format!("{public_key}:{private_key}"); + let auth_header = format!("Basic {}", consts::BASE64_ENGINE.encode(auth_key)); Ok(Self { - api_key: api_key.to_string(), - merchant_account: key1.to_string(), + auth_header, + merchant_id: merchant_id.to_owned(), }) } else { Err(errors::ConnectorError::FailedToObtainAuthType)?