-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(connector): generate connector template code for gpayments authe…
…nticaition connector (#4584) Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
- Loading branch information
1 parent
2692995
commit 2a302eb
Showing
21 changed files
with
401 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,231 @@ | ||
pub mod transformers; | ||
|
||
use std::fmt::Debug; | ||
|
||
use error_stack::{report, ResultExt}; | ||
use masking::ExposeInterface; | ||
use transformers as gpayments; | ||
|
||
use crate::{ | ||
configs::settings, | ||
core::errors::{self, CustomResult}, | ||
events::connector_api_logs::ConnectorEvent, | ||
headers, | ||
services::{ | ||
request::{self, Mask}, | ||
ConnectorIntegration, ConnectorValidation, | ||
}, | ||
types::{ | ||
self, | ||
api::{self, ConnectorCommon, ConnectorCommonExt}, | ||
ErrorResponse, Response, | ||
}, | ||
utils::BytesExt, | ||
}; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct Gpayments; | ||
|
||
impl api::Payment for Gpayments {} | ||
impl api::PaymentSession for Gpayments {} | ||
impl api::ConnectorAccessToken for Gpayments {} | ||
impl api::MandateSetup for Gpayments {} | ||
impl api::PaymentAuthorize for Gpayments {} | ||
impl api::PaymentSync for Gpayments {} | ||
impl api::PaymentCapture for Gpayments {} | ||
impl api::PaymentVoid for Gpayments {} | ||
impl api::Refund for Gpayments {} | ||
impl api::RefundExecute for Gpayments {} | ||
impl api::RefundSync for Gpayments {} | ||
impl api::PaymentToken for Gpayments {} | ||
|
||
impl | ||
ConnectorIntegration< | ||
api::PaymentMethodToken, | ||
types::PaymentMethodTokenizationData, | ||
types::PaymentsResponseData, | ||
> for Gpayments | ||
{ | ||
// Not Implemented (R) | ||
} | ||
|
||
impl<Flow, Request, Response> ConnectorCommonExt<Flow, Request, Response> for Gpayments | ||
where | ||
Self: ConnectorIntegration<Flow, Request, Response>, | ||
{ | ||
fn build_headers( | ||
&self, | ||
req: &types::RouterData<Flow, Request, Response>, | ||
_connectors: &settings::Connectors, | ||
) -> CustomResult<Vec<(String, request::Maskable<String>)>, errors::ConnectorError> { | ||
let mut header = vec![( | ||
headers::CONTENT_TYPE.to_string(), | ||
self.get_content_type().to_string().into(), | ||
)]; | ||
let mut api_key = self.get_auth_header(&req.connector_auth_type)?; | ||
header.append(&mut api_key); | ||
Ok(header) | ||
} | ||
} | ||
|
||
impl ConnectorCommon for Gpayments { | ||
fn id(&self) -> &'static str { | ||
"gpayments" | ||
} | ||
|
||
fn get_currency_unit(&self) -> api::CurrencyUnit { | ||
api::CurrencyUnit::Minor | ||
// TODO! Check connector documentation, on which unit they are processing the currency. | ||
// If the connector accepts amount in lower unit ( i.e cents for USD) then return api::CurrencyUnit::Minor, | ||
// if connector accepts amount in base unit (i.e dollars for USD) then return api::CurrencyUnit::Base | ||
} | ||
|
||
fn common_get_content_type(&self) -> &'static str { | ||
"application/json" | ||
} | ||
|
||
fn base_url<'a>(&self, connectors: &'a settings::Connectors) -> &'a str { | ||
connectors.gpayments.base_url.as_ref() | ||
} | ||
|
||
fn get_auth_header( | ||
&self, | ||
auth_type: &types::ConnectorAuthType, | ||
) -> CustomResult<Vec<(String, request::Maskable<String>)>, errors::ConnectorError> { | ||
let auth = gpayments::GpaymentsAuthType::try_from(auth_type) | ||
.change_context(errors::ConnectorError::FailedToObtainAuthType)?; | ||
Ok(vec![( | ||
headers::AUTHORIZATION.to_string(), | ||
auth.api_key.expose().into_masked(), | ||
)]) | ||
} | ||
|
||
fn build_error_response( | ||
&self, | ||
res: Response, | ||
event_builder: Option<&mut ConnectorEvent>, | ||
) -> CustomResult<ErrorResponse, errors::ConnectorError> { | ||
let response: gpayments::GpaymentsErrorResponse = res | ||
.response | ||
.parse_struct("GpaymentsErrorResponse") | ||
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?; | ||
|
||
event_builder.map(|i| i.set_response_body(&response)); | ||
router_env::logger::info!(connector_response=?response); | ||
|
||
Ok(ErrorResponse { | ||
status_code: res.status_code, | ||
code: response.code, | ||
message: response.message, | ||
reason: response.reason, | ||
attempt_status: None, | ||
connector_transaction_id: None, | ||
}) | ||
} | ||
} | ||
|
||
impl ConnectorValidation for Gpayments { | ||
//TODO: implement functions when support enabled | ||
} | ||
|
||
impl ConnectorIntegration<api::Session, types::PaymentsSessionData, types::PaymentsResponseData> | ||
for Gpayments | ||
{ | ||
} | ||
|
||
impl ConnectorIntegration<api::AccessTokenAuth, types::AccessTokenRequestData, types::AccessToken> | ||
for Gpayments | ||
{ | ||
} | ||
|
||
impl | ||
ConnectorIntegration< | ||
api::SetupMandate, | ||
types::SetupMandateRequestData, | ||
types::PaymentsResponseData, | ||
> for Gpayments | ||
{ | ||
} | ||
|
||
impl ConnectorIntegration<api::Authorize, types::PaymentsAuthorizeData, types::PaymentsResponseData> | ||
for Gpayments | ||
{ | ||
} | ||
|
||
impl ConnectorIntegration<api::PSync, types::PaymentsSyncData, types::PaymentsResponseData> | ||
for Gpayments | ||
{ | ||
} | ||
|
||
impl ConnectorIntegration<api::Capture, types::PaymentsCaptureData, types::PaymentsResponseData> | ||
for Gpayments | ||
{ | ||
} | ||
|
||
impl ConnectorIntegration<api::Void, types::PaymentsCancelData, types::PaymentsResponseData> | ||
for Gpayments | ||
{ | ||
} | ||
|
||
impl ConnectorIntegration<api::Execute, types::RefundsData, types::RefundsResponseData> | ||
for Gpayments | ||
{ | ||
} | ||
|
||
impl ConnectorIntegration<api::RSync, types::RefundsData, types::RefundsResponseData> | ||
for Gpayments | ||
{ | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl api::IncomingWebhook for Gpayments { | ||
fn get_webhook_object_reference_id( | ||
&self, | ||
_request: &api::IncomingWebhookRequestDetails<'_>, | ||
) -> CustomResult<api::webhooks::ObjectReferenceId, errors::ConnectorError> { | ||
Err(report!(errors::ConnectorError::WebhooksNotImplemented)) | ||
} | ||
|
||
fn get_webhook_event_type( | ||
&self, | ||
_request: &api::IncomingWebhookRequestDetails<'_>, | ||
) -> CustomResult<api::IncomingWebhookEvent, errors::ConnectorError> { | ||
Err(report!(errors::ConnectorError::WebhooksNotImplemented)) | ||
} | ||
|
||
fn get_webhook_resource_object( | ||
&self, | ||
_request: &api::IncomingWebhookRequestDetails<'_>, | ||
) -> CustomResult<Box<dyn masking::ErasedMaskSerialize>, errors::ConnectorError> { | ||
Err(report!(errors::ConnectorError::WebhooksNotImplemented)) | ||
} | ||
} | ||
|
||
impl api::ExternalAuthentication for Gpayments {} | ||
impl api::ConnectorAuthentication for Gpayments {} | ||
impl api::ConnectorPreAuthentication for Gpayments {} | ||
impl api::ConnectorPostAuthentication for Gpayments {} | ||
impl | ||
ConnectorIntegration< | ||
api::Authentication, | ||
types::authentication::ConnectorAuthenticationRequestData, | ||
types::authentication::AuthenticationResponseData, | ||
> for Gpayments | ||
{ | ||
} | ||
impl | ||
ConnectorIntegration< | ||
api::PreAuthentication, | ||
types::authentication::PreAuthNRequestData, | ||
types::authentication::AuthenticationResponseData, | ||
> for Gpayments | ||
{ | ||
} | ||
impl | ||
ConnectorIntegration< | ||
api::PostAuthentication, | ||
types::authentication::ConnectorPostAuthenticationRequestData, | ||
types::authentication::AuthenticationResponseData, | ||
> for Gpayments | ||
{ | ||
} |
Oops, something went wrong.