Skip to content

Commit

Permalink
feat(core): Add click to pay support in hyperswitch (#6769)
Browse files Browse the repository at this point in the history
Co-authored-by: sai-harsha-vardhan <[email protected]>
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
Co-authored-by: Sai Harsha Vardhan <[email protected]>
  • Loading branch information
4 people authored Dec 16, 2024
1 parent 73f9ba5 commit d0d4dec
Show file tree
Hide file tree
Showing 50 changed files with 1,287 additions and 855 deletions.
1 change: 1 addition & 0 deletions .typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ nin = "nin" # National identification number, a field used by PayU connector
requestor = "requestor" #Used in external 3ds flows
substituters = "substituters" # Present in `flake.nix`
unsuccess = "unsuccess" # Used in cryptopay request
authetication = "authetication" #UAS pre-authentication URL

[files]
extend-exclude = [
Expand Down
5 changes: 4 additions & 1 deletion api-reference-v2/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -3488,7 +3488,9 @@
"enum": [
"threedsecureio",
"netcetera",
"gpayments"
"gpayments",
"ctp_mastercard",
"unified_authentication_service"
]
},
"AuthenticationStatus": {
Expand Down Expand Up @@ -6430,6 +6432,7 @@
"checkout",
"coinbase",
"cryptopay",
"ctp_mastercard",
"cybersource",
"datatrans",
"deutschebank",
Expand Down
5 changes: 4 additions & 1 deletion api-reference/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -5925,7 +5925,9 @@
"enum": [
"threedsecureio",
"netcetera",
"gpayments"
"gpayments",
"ctp_mastercard",
"unified_authentication_service"
]
},
"AuthenticationStatus": {
Expand Down Expand Up @@ -8792,6 +8794,7 @@
"checkout",
"coinbase",
"cryptopay",
"ctp_mastercard",
"cybersource",
"datatrans",
"deutschebank",
Expand Down
2 changes: 2 additions & 0 deletions crates/api_models/src/connector_enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ pub enum Connector {
Checkout,
Coinbase,
Cryptopay,
CtpMastercard,
Cybersource,
Datatrans,
Deutschebank,
Expand Down Expand Up @@ -278,6 +279,7 @@ impl Connector {
| Self::Threedsecureio
| Self::Datatrans
| Self::Netcetera
| Self::CtpMastercard
| Self::Noon
| Self::Stripe => false,
Self::Checkout | Self::Nmi | Self::Cybersource => true,
Expand Down
7 changes: 6 additions & 1 deletion crates/common_enums/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2591,12 +2591,17 @@ pub enum AuthenticationConnectors {
Threedsecureio,
Netcetera,
Gpayments,
CtpMastercard,
UnifiedAuthenticationService,
}

impl AuthenticationConnectors {
pub fn is_separate_version_call_required(self) -> bool {
match self {
Self::Threedsecureio | Self::Netcetera => false,
Self::Threedsecureio
| Self::Netcetera
| Self::CtpMastercard
| Self::UnifiedAuthenticationService => false,
Self::Gpayments => true,
}
}
Expand Down
7 changes: 7 additions & 0 deletions crates/connector_configs/src/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ pub struct ConnectorConfig {
pub zen: Option<ConnectorTomlConfig>,
pub zsl: Option<ConnectorTomlConfig>,
pub taxjar: Option<ConnectorTomlConfig>,
pub ctp_mastercard: Option<ConnectorTomlConfig>,
pub unified_authentication_service: Option<ConnectorTomlConfig>,
}

impl ConnectorConfig {
Expand Down Expand Up @@ -296,6 +298,10 @@ impl ConnectorConfig {
AuthenticationConnectors::Threedsecureio => Ok(connector_data.threedsecureio),
AuthenticationConnectors::Netcetera => Ok(connector_data.netcetera),
AuthenticationConnectors::Gpayments => Ok(connector_data.gpayments),
AuthenticationConnectors::CtpMastercard => Ok(connector_data.ctp_mastercard),
AuthenticationConnectors::UnifiedAuthenticationService => {
Ok(connector_data.unified_authentication_service)
}
}
}

Expand Down Expand Up @@ -412,6 +418,7 @@ impl ConnectorConfig {
#[cfg(feature = "dummy_connector")]
Connector::DummyConnector7 => Ok(connector_data.paypal_test),
Connector::Netcetera => Ok(connector_data.netcetera),
Connector::CtpMastercard => Ok(connector_data.ctp_mastercard),
}
}
}
9 changes: 5 additions & 4 deletions crates/hyperswitch_connectors/src/connectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub mod boku;
pub mod cashtocode;
pub mod coinbase;
pub mod cryptopay;
pub mod ctp_mastercard;
pub mod datatrans;
pub mod deutschebank;
pub mod digitalvirgo;
Expand Down Expand Up @@ -55,10 +56,10 @@ pub mod zsl;
pub use self::{
airwallex::Airwallex, amazonpay::Amazonpay, bambora::Bambora, bamboraapac::Bamboraapac,
billwerk::Billwerk, bitpay::Bitpay, bluesnap::Bluesnap, boku::Boku, cashtocode::Cashtocode,
coinbase::Coinbase, cryptopay::Cryptopay, datatrans::Datatrans, deutschebank::Deutschebank,
digitalvirgo::Digitalvirgo, dlocal::Dlocal, elavon::Elavon, fiserv::Fiserv,
fiservemea::Fiservemea, fiuu::Fiuu, forte::Forte, globepay::Globepay, gocardless::Gocardless,
helcim::Helcim, inespay::Inespay, jpmorgan::Jpmorgan, mollie::Mollie,
coinbase::Coinbase, cryptopay::Cryptopay, ctp_mastercard::CtpMastercard, datatrans::Datatrans,
deutschebank::Deutschebank, digitalvirgo::Digitalvirgo, dlocal::Dlocal, elavon::Elavon,
fiserv::Fiserv, fiservemea::Fiservemea, fiuu::Fiuu, forte::Forte, globepay::Globepay,
gocardless::Gocardless, helcim::Helcim, inespay::Inespay, jpmorgan::Jpmorgan, mollie::Mollie,
multisafepay::Multisafepay, nexinets::Nexinets, nexixpay::Nexixpay, nomupay::Nomupay,
novalnet::Novalnet, paybox::Paybox, payeezy::Payeezy, payu::Payu, placetopay::Placetopay,
powertranz::Powertranz, prophetpay::Prophetpay, rapyd::Rapyd, razorpay::Razorpay,
Expand Down
124 changes: 124 additions & 0 deletions crates/hyperswitch_connectors/src/connectors/ctp_mastercard.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
use common_utils::errors::CustomResult;
use error_stack::report;
use hyperswitch_domain_models::{
router_data::{AccessToken, RouterData},
router_flow_types::{
access_token_auth::AccessTokenAuth,
payments::{Authorize, Capture, PSync, PaymentMethodToken, Session, SetupMandate, Void},
refunds::{Execute, RSync},
},
router_request_types::{
AccessTokenRequestData, PaymentMethodTokenizationData, PaymentsAuthorizeData,
PaymentsCancelData, PaymentsCaptureData, PaymentsSessionData, PaymentsSyncData,
RefundsData, SetupMandateRequestData,
},
router_response_types::{PaymentsResponseData, RefundsResponseData},
};
use hyperswitch_interfaces::{
api::{self, ConnectorCommon, ConnectorCommonExt, ConnectorIntegration, ConnectorValidation},
configs::Connectors,
errors, webhooks,
};

use crate::constants::headers;

#[derive(Clone)]
pub struct CtpMastercard;

impl api::Payment for CtpMastercard {}
impl api::PaymentSession for CtpMastercard {}
impl api::ConnectorAccessToken for CtpMastercard {}
impl api::MandateSetup for CtpMastercard {}
impl api::PaymentAuthorize for CtpMastercard {}
impl api::PaymentSync for CtpMastercard {}
impl api::PaymentCapture for CtpMastercard {}
impl api::PaymentVoid for CtpMastercard {}
impl api::Refund for CtpMastercard {}
impl api::RefundExecute for CtpMastercard {}
impl api::RefundSync for CtpMastercard {}
impl api::PaymentToken for CtpMastercard {}

impl ConnectorIntegration<PaymentMethodToken, PaymentMethodTokenizationData, PaymentsResponseData>
for CtpMastercard
{
// Not Implemented (R)
}

impl<Flow, Request, Response> ConnectorCommonExt<Flow, Request, Response> for CtpMastercard
where
Self: ConnectorIntegration<Flow, Request, Response>,
{
fn build_headers(
&self,
req: &RouterData<Flow, Request, Response>,
_connectors: &Connectors,
) -> CustomResult<Vec<(String, masking::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 CtpMastercard {
fn id(&self) -> &'static str {
"ctp_mastercard"
}

fn base_url<'a>(&self, _connectors: &'a Connectors) -> &'a str {
""
}
}

impl ConnectorValidation for CtpMastercard {}

impl ConnectorIntegration<Session, PaymentsSessionData, PaymentsResponseData> for CtpMastercard {}

impl ConnectorIntegration<AccessTokenAuth, AccessTokenRequestData, AccessToken> for CtpMastercard {}

impl ConnectorIntegration<SetupMandate, SetupMandateRequestData, PaymentsResponseData>
for CtpMastercard
{
}

impl ConnectorIntegration<Authorize, PaymentsAuthorizeData, PaymentsResponseData>
for CtpMastercard
{
}

impl ConnectorIntegration<PSync, PaymentsSyncData, PaymentsResponseData> for CtpMastercard {}

impl ConnectorIntegration<Capture, PaymentsCaptureData, PaymentsResponseData> for CtpMastercard {}

impl ConnectorIntegration<RSync, RefundsData, RefundsResponseData> for CtpMastercard {}

impl ConnectorIntegration<Void, PaymentsCancelData, PaymentsResponseData> for CtpMastercard {}

impl ConnectorIntegration<Execute, RefundsData, RefundsResponseData> for CtpMastercard {}

#[async_trait::async_trait]
impl webhooks::IncomingWebhook for CtpMastercard {
fn get_webhook_object_reference_id(
&self,
_request: &webhooks::IncomingWebhookRequestDetails<'_>,
) -> CustomResult<api_models::webhooks::ObjectReferenceId, errors::ConnectorError> {
Err(report!(errors::ConnectorError::WebhooksNotImplemented))
}

fn get_webhook_event_type(
&self,
_request: &webhooks::IncomingWebhookRequestDetails<'_>,
) -> CustomResult<api_models::webhooks::IncomingWebhookEvent, errors::ConnectorError> {
Err(report!(errors::ConnectorError::WebhooksNotImplemented))
}

fn get_webhook_resource_object(
&self,
_request: &webhooks::IncomingWebhookRequestDetails<'_>,
) -> CustomResult<Box<dyn masking::ErasedMaskSerialize>, errors::ConnectorError> {
Err(report!(errors::ConnectorError::WebhooksNotImplemented))
}
}
Loading

0 comments on commit d0d4dec

Please sign in to comment.