-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(connector): generate connector template code for gpayments authenticaition connector #4584
Merged
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
50645f7
feat(connector): generate connector template code for gpayments authe…
hrithikesh026 94dd5b6
docs(openapi): re-generate OpenAPI specification
hyperswitch-bot[bot] 6da442d
fix: rename gpayments enum variant in AuthenticationConnectors
hrithikesh026 f0414ee
docs(openapi): re-generate OpenAPI specification
hyperswitch-bot[bot] 52245ca
Merge branch 'main' into generate-template-code-for-gpayments
hrithikesh026 225d609
chore: comment out newly added connector enum type from Connector enum
hrithikesh026 c0ad8a3
regerate openapi spec
hrithikesh026 648159d
Merge branch 'main' into generate-template-code-for-gpayments
hrithikesh026 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please comment this out as this is template code.
Follow any past template code PR and comment out at all the necessary places