mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-10-31 10:06:32 +08:00 
			
		
		
		
	enhance(braintree): create basic auth for braintree (#602)
This commit is contained in:
		| @ -39,7 +39,7 @@ impl ConnectorCommon for Braintree { | |||||||
|         let auth: braintree::BraintreeAuthType = auth_type |         let auth: braintree::BraintreeAuthType = auth_type | ||||||
|             .try_into() |             .try_into() | ||||||
|             .change_context(errors::ConnectorError::FailedToObtainAuthType)?; |             .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!( |         Ok(format!( | ||||||
|             "{}/merchants/{}/client_token", |             "{}/merchants/{}/client_token", | ||||||
|             self.base_url(connectors), |             self.base_url(connectors), | ||||||
|             auth_type.merchant_account, |             auth_type.merchant_id, | ||||||
|         )) |         )) | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @ -131,6 +131,7 @@ impl | |||||||
|         &self, |         &self, | ||||||
|         res: types::Response, |         res: types::Response, | ||||||
|     ) -> CustomResult<types::ErrorResponse, errors::ConnectorError> { |     ) -> CustomResult<types::ErrorResponse, errors::ConnectorError> { | ||||||
|  |         logger::debug!(braintree_payments_error_response=?res); | ||||||
|         let response: braintree::ErrorResponse = res |         let response: braintree::ErrorResponse = res | ||||||
|             .response |             .response | ||||||
|             .parse_struct("Error Response") |             .parse_struct("Error Response") | ||||||
| @ -241,7 +242,7 @@ impl | |||||||
|         Ok(format!( |         Ok(format!( | ||||||
|             "{}/merchants/{}/transactions/{}", |             "{}/merchants/{}/transactions/{}", | ||||||
|             self.base_url(connectors), |             self.base_url(connectors), | ||||||
|             auth_type.merchant_account, |             auth_type.merchant_id, | ||||||
|             connector_payment_id |             connector_payment_id | ||||||
|         )) |         )) | ||||||
|     } |     } | ||||||
| @ -341,7 +342,7 @@ impl | |||||||
|         Ok(format!( |         Ok(format!( | ||||||
|             "{}merchants/{}/transactions", |             "{}merchants/{}/transactions", | ||||||
|             self.base_url(connectors), |             self.base_url(connectors), | ||||||
|             auth_type.merchant_account |             auth_type.merchant_id | ||||||
|         )) |         )) | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @ -452,7 +453,7 @@ impl | |||||||
|         Ok(format!( |         Ok(format!( | ||||||
|             "{}merchants/{}/transactions/{}/void", |             "{}merchants/{}/transactions/{}/void", | ||||||
|             self.base_url(connectors), |             self.base_url(connectors), | ||||||
|             auth_type.merchant_account, |             auth_type.merchant_id, | ||||||
|             req.request.connector_transaction_id |             req.request.connector_transaction_id | ||||||
|         )) |         )) | ||||||
|     } |     } | ||||||
| @ -556,7 +557,7 @@ impl services::ConnectorIntegration<api::Execute, types::RefundsData, types::Ref | |||||||
|         Ok(format!( |         Ok(format!( | ||||||
|             "{}merchants/{}/transactions/{}", |             "{}merchants/{}/transactions/{}", | ||||||
|             self.base_url(connectors), |             self.base_url(connectors), | ||||||
|             auth_type.merchant_account, |             auth_type.merchant_id, | ||||||
|             connector_payment_id |             connector_payment_id | ||||||
|         )) |         )) | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -1,7 +1,9 @@ | |||||||
|  | use base64::Engine; | ||||||
| use error_stack::ResultExt; | use error_stack::ResultExt; | ||||||
| use serde::{Deserialize, Serialize}; | use serde::{Deserialize, Serialize}; | ||||||
|  |  | ||||||
| use crate::{ | use crate::{ | ||||||
|  |     consts, | ||||||
|     core::errors, |     core::errors, | ||||||
|     pii::PeekInterface, |     pii::PeekInterface, | ||||||
|     types::{self, api, storage::enums}, |     types::{self, api, storage::enums}, | ||||||
| @ -135,17 +137,24 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for BraintreePaymentsRequest { | |||||||
| } | } | ||||||
|  |  | ||||||
| pub struct BraintreeAuthType { | pub struct BraintreeAuthType { | ||||||
|     pub(super) api_key: String, |     pub(super) auth_header: String, | ||||||
|     pub(super) merchant_account: String, |     pub(super) merchant_id: String, | ||||||
| } | } | ||||||
|  |  | ||||||
| impl TryFrom<&types::ConnectorAuthType> for BraintreeAuthType { | impl TryFrom<&types::ConnectorAuthType> for BraintreeAuthType { | ||||||
|     type Error = error_stack::Report<errors::ConnectorError>; |     type Error = error_stack::Report<errors::ConnectorError>; | ||||||
|     fn try_from(item: &types::ConnectorAuthType) -> Result<Self, Self::Error> { |     fn try_from(item: &types::ConnectorAuthType) -> Result<Self, Self::Error> { | ||||||
|         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 { |             Ok(Self { | ||||||
|                 api_key: api_key.to_string(), |                 auth_header, | ||||||
|                 merchant_account: key1.to_string(), |                 merchant_id: merchant_id.to_owned(), | ||||||
|             }) |             }) | ||||||
|         } else { |         } else { | ||||||
|             Err(errors::ConnectorError::FailedToObtainAuthType)? |             Err(errors::ConnectorError::FailedToObtainAuthType)? | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 Narayan Bhat
					Narayan Bhat