mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-29 09:07:09 +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
|
||||
.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<types::ErrorResponse, errors::ConnectorError> {
|
||||
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<api::Execute, types::RefundsData, types::Ref
|
||||
Ok(format!(
|
||||
"{}merchants/{}/transactions/{}",
|
||||
self.base_url(connectors),
|
||||
auth_type.merchant_account,
|
||||
auth_type.merchant_id,
|
||||
connector_payment_id
|
||||
))
|
||||
}
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
use base64::Engine;
|
||||
use error_stack::ResultExt;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
consts,
|
||||
core::errors,
|
||||
pii::PeekInterface,
|
||||
types::{self, api, storage::enums},
|
||||
@ -135,17 +137,24 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> 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<errors::ConnectorError>;
|
||||
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 {
|
||||
api_key: api_key.to_string(),
|
||||
merchant_account: key1.to_string(),
|
||||
auth_header,
|
||||
merchant_id: merchant_id.to_owned(),
|
||||
})
|
||||
} else {
|
||||
Err(errors::ConnectorError::FailedToObtainAuthType)?
|
||||
|
||||
Reference in New Issue
Block a user