Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
feat(connector): [Checkout] support account-specific payment hosts (#15216)
nithin-juspay1cc3e4e29b69
diff --git a/config/config.example.toml b/config/config.example.tomlindex 3484c7c230..48c41f0a14 100644--- a/config/config.example.toml+++ b/config/config.example.toml@@ -368,7 +368,7 @@ cashtocode.base_url = "https://cluster05.api-test.cashtocode.com"celero.base_url = "https://sandbox.gotnpgateway.com"chargebee.base_url = "https://$.chargebee.com/api/"checkbook.base_url = "https://api.sandbox.checkbook.io"-checkout.base_url = "https://api.sandbox.checkout.com/"+checkout.base_url = "https://{{optional_client_id}}api.sandbox.checkout.com/"citigate.base_url = "https://gw-test.cgate.tech"coinbase.base_url = "https://api.commerce.coinbase.com"coingate.base_url = "https://api-sandbox.coingate.com"diff --git a/config/deployments/integration_test.toml b/config/deployments/integration_test.tomlindex 4310c253d5..f88fe6bd73 100644--- a/config/deployments/integration_test.toml+++ b/config/deployments/integration_test.toml@@ -61,7 +61,7 @@ cashtocode.base_url = "https://cluster05.api-test.cashtocode.com"celero.base_url = "https://sandbox.gotnpgateway.com"chargebee.base_url = "https://$.chargebee.com/api/"checkbook.base_url = "https://api.sandbox.checkbook.io"-checkout.base_url = "https://api.sandbox.checkout.com/"+checkout.base_url = "https://{{optional_client_id}}api.sandbox.checkout.com/"citigate.base_url = "https://gw-test.cgate.tech"coinbase.base_url = "https://api.commerce.coinbase.com"coingate.base_url = "https://api-sandbox.coingate.com"diff --git a/config/deployments/production.toml b/config/deployments/production.tomlindex 3cf4fc92f1..385ace246d 100644--- a/config/deployments/production.toml+++ b/config/deployments/production.toml@@ -64,7 +64,7 @@ cashtocode.base_url = "https://cluster14.api.cashtocode.com"celero.base_url = "https://app.gotnpgateway.com"chargebee.base_url = "https://{{merchant_endpoint_prefix}}.chargebee.com/api/"checkbook.base_url = "https://api.checkbook.io"-checkout.base_url = "https://api.checkout.com/"+checkout.base_url = "https://{{optional_client_id}}api.checkout.com/"citigate.base_url = "https://gw.cgate.tech"coinbase.base_url = "https://api.commerce.coinbase.com"coingate.base_url = "https://api.coingate.com"diff --git a/config/deployments/sandbox.toml b/config/deployments/sandbox.tomlindex 9497d43ce0..942140d97a 100644--- a/config/deployments/sandbox.toml+++ b/config/deployments/sandbox.toml@@ -63,7 +63,7 @@ breadpay.base_url = "https://api-sandbox.getbread.com"cashtocode.base_url = "https://cluster05.api-test.cashtocode.com"celero.base_url = "https://sandbox.gotnpgateway.com"checkbook.base_url = "https://api.sandbox.checkbook.io"-checkout.base_url = "https://api.sandbox.checkout.com/"+checkout.base_url = "https://{{optional_client_id}}api.sandbox.checkout.com/"citigate.base_url = "https://gw-test.cgate.tech"chargebee.base_url = "https://$.chargebee.com/api/"coinbase.base_url = "https://api.commerce.coinbase.com"diff --git a/config/development.toml b/config/development.tomlindex 15b9476700..7e2fbe206a 100644--- a/config/development.toml+++ b/config/development.toml@@ -379,7 +379,7 @@ cashtocode.base_url = "https://cluster05.api-test.cashtocode.com"celero.base_url = "https://sandbox.gotnpgateway.com"chargebee.base_url = "https://$.chargebee.com/api/"checkbook.base_url = "https://api.sandbox.checkbook.io"-checkout.base_url = "https://api.sandbox.checkout.com/"+checkout.base_url = "https://{{optional_client_id}}api.sandbox.checkout.com/"citigate.base_url = "https://gw-test.cgate.tech"coinbase.base_url = "https://api.commerce.coinbase.com"coingate.base_url = "https://api-sandbox.coingate.com"diff --git a/config/docker_compose.toml b/config/docker_compose.tomlindex dd0b92afa7..ac3e823c6a 100644--- a/config/docker_compose.toml+++ b/config/docker_compose.toml@@ -271,7 +271,7 @@ cashtocode.base_url = "https://cluster05.api-test.cashtocode.com"celero.base_url = "https://sandbox.gotnpgateway.com"chargebee.base_url = "https://$.chargebee.com/api/"checkbook.base_url = "https://api.sandbox.checkbook.io"-checkout.base_url = "https://api.sandbox.checkout.com/"+checkout.base_url = "https://{{optional_client_id}}api.sandbox.checkout.com/"citigate.base_url = "https://gw-test.cgate.tech"coinbase.base_url = "https://api.commerce.coinbase.com"coingate.base_url = "https://api-sandbox.coingate.com"diff --git a/crates/connector_configs/toml/development.toml b/crates/connector_configs/toml/development.tomlindex b59a65c991..d76cb71ee6 100644--- a/crates/connector_configs/toml/development.toml+++ b/crates/connector_configs/toml/development.toml@@ -2036,6 +2036,12 @@ label="Acquirer Country Code"placeholder="Enter Acquirer Country Code"required=falsetype="Text"+[checkout.metadata.connector_client_id]+name="connector_client_id"+label="Checkout Client ID (API Domain Prefix)"+placeholder="Enter Checkout Client ID (cli_...)"+required=false+type="Text"[checkout_payout][[checkout_payout.wallet]]diff --git a/crates/connector_configs/toml/production.toml b/crates/connector_configs/toml/production.tomlindex faf54fe0ad..b7dbf45432 100644--- a/crates/connector_configs/toml/production.toml+++ b/crates/connector_configs/toml/production.toml@@ -1780,6 +1780,12 @@ placeholder = "Enter Allowed Auth Methods"required = truetype = "MultiSelect"options = ["PAN_ONLY", "CRYPTOGRAM_3DS"]+[checkout.metadata.connector_client_id]+name = "connector_client_id"+label = "Checkout Client ID (API Domain Prefix)"+placeholder = "Enter Checkout Client ID (cli_...)"+required = false+type = "Text"[checkout_payout]diff --git a/crates/connector_configs/toml/sandbox.toml b/crates/connector_configs/toml/sandbox.tomlindex 76df37f5b1..9228d7dac5 100644--- a/crates/connector_configs/toml/sandbox.toml+++ b/crates/connector_configs/toml/sandbox.toml@@ -2033,6 +2033,12 @@ label = "Acquirer Country Code"placeholder = "Enter Acquirer Country Code"required = falsetype = "Text"+[checkout.metadata.connector_client_id]+name = "connector_client_id"+label = "Checkout Client ID (API Domain Prefix)"+placeholder = "Enter Checkout Client ID (cli_...)"+required = false+type = "Text"[checkout_payout][[checkout_payout.wallet]]diff --git a/crates/hyperswitch_connectors/src/connectors/checkout.rs b/crates/hyperswitch_connectors/src/connectors/checkout.rsindex 3d0fcfaa9f..06aaa7d387 100644--- a/crates/hyperswitch_connectors/src/connectors/checkout.rs+++ b/crates/hyperswitch_connectors/src/connectors/checkout.rs@@ -77,6 +77,46 @@ use crate::{utils::{self, ConnectorErrorType, RefundsRequestData},};+const OPTIONAL_CLIENT_ID: &str = "{{optional_client_id}}";++/// Resolves the shared Checkout API host or the account-specific host derived from client ID.+/// A plain custom base URL without the optional placeholder keeps its configured host. An absent+/// client ID preserves the shared-host setup; a malformed client ID fails rather than using the wrong host.+/// Placeholder-free URLs use the same resolution flow without an early return. Trim the trailing+/// `/` from the resolved host; request builders add path separators when appending their paths.+fn get_checkout_payments_payouts_base_url(+ base_url: &str,+ connector_metadata: &Option<common_utils::pii::SecretSerdeValue>,+) -> CustomResult<String, errors::ConnectorError> {+ let resolved_base_url = if base_url.contains(OPTIONAL_CLIENT_ID) {+ let metadata = checkout::CheckoutConnectorMetadataObject::try_from(connector_metadata)?;+ let optional_client_id = metadata+ .connector_client_id+ .as_ref()+ .map(|client_id| {+ client_id+ .peek()+ .strip_prefix("cli_")+ .and_then(|value| value.get(..8))+ .filter(|value| value.bytes().all(|byte| byte.is_ascii_alphanumeric()))+ .map(|prefix| format!("{prefix}."))+ .ok_or_else(|| {+ error_stack::report!(errors::ConnectorError::InvalidConnectorConfig {+ config: "metadata.connector_client_id",+ })+ })+ })+ .transpose()?+ .unwrap_or_default();++ base_url.replace(OPTIONAL_CLIENT_ID, &optional_client_id)+ } else {+ base_url.to_string()+ };++ Ok(resolved_base_url.trim_end_matches('/').to_string())+}+#[derive(Clone)]pub struct Checkout {amount_converter: &'static (dyn AmountConvertor<Output = MinorUnit> + Sync),@@ -331,10 +371,16 @@ impl ConnectorIntegration<PaymentMethodToken, PaymentMethodTokenizationData, Payfn get_url(&self,- _req: &TokenizationRouterData,+ req: &TokenizationRouterData,connectors: &Connectors,) -> CustomResult<String, errors::ConnectorError> {- Ok(format!("{}tokens", self.base_url(connectors)))+ Ok(format!(+ "{}/tokens",+ get_checkout_payments_payouts_base_url(+ self.base_url(connectors),+ &req.connector_meta_data+ )?+ ))}fn get_request_body(@@ -417,10 +463,16 @@ impl ConnectorIntegration<SetupMandate, SetupMandateRequestData, PaymentsResponsfn get_url(&self,- _req: &SetupMandateRouterData,+ req: &SetupMandateRouterData,connectors: &Connectors,) -> CustomResult<String, errors::ConnectorError> {- Ok(format!("{}{}", self.base_url(connectors), "payments"))+ Ok(format!(+ "{}/payments",+ get_checkout_payments_payouts_base_url(+ self.base_url(connectors),+ &req.connector_meta_data+ )?+ ))}fn get_request_body(@@ -508,8 +560,11 @@ impl ConnectorIntegration<Capture, PaymentsCaptureData, PaymentsResponseData> fo) -> CustomResult<String, errors::ConnectorError> {let id = req.request.connector_transaction_id.as_str();Ok(format!(- "{}payments/{id}/captures",- self.base_url(connectors)+ "{}/payments/{id}/captures",+ get_checkout_payments_payouts_base_url(+ self.base_url(connectors),+ &req.connector_meta_data+ )?))}fn get_request_body(@@ -594,9 +649,11 @@ impl ConnectorIntegration<PSync, PaymentsSyncData, PaymentsResponseData> for CheSyncRequestType::SinglePaymentSync => "",};Ok(format!(- "{}{}{}{}",- self.base_url(connectors),- "payments/",+ "{}/payments/{}{}",+ get_checkout_payments_payouts_base_url(+ self.base_url(connectors),+ &req.connector_meta_data+ )?,req.request.connector_transaction_id.get_connector_transaction_id()@@ -689,10 +746,16 @@ impl ConnectorIntegration<Authorize, PaymentsAuthorizeData, PaymentsResponseDatafn get_url(&self,- _req: &PaymentsAuthorizeRouterData,+ req: &PaymentsAuthorizeRouterData,connectors: &Connectors,) -> CustomResult<String, errors::ConnectorError> {- Ok(format!("{}{}", self.base_url(connectors), "payments"))+ Ok(format!(+ "{}/payments",+ get_checkout_payments_payouts_base_url(+ self.base_url(connectors),+ &req.connector_meta_data+ )?+ ))}fn get_request_body(@@ -772,8 +835,11 @@ impl ConnectorIntegration<Void, PaymentsCancelData, PaymentsResponseData> for Chconnectors: &Connectors,) -> CustomResult<String, errors::ConnectorError> {Ok(format!(- "{}payments/{}/voids",- self.base_url(connectors),+ "{}/payments/{}/voids",+ get_checkout_payments_payouts_base_url(+ self.base_url(connectors),+ &req.connector_meta_data+ )?,req.request.connector_transaction_id))}@@ -858,8 +924,11 @@ impl ConnectorIntegration<Execute, RefundsData, RefundsResponseData> for Checkou) -> CustomResult<String, errors::ConnectorError> {let id = req.request.connector_transaction_id.clone();Ok(format!(- "{}payments/{}/refunds",- self.base_url(connectors),+ "{}/payments/{}/refunds",+ get_checkout_payments_payouts_base_url(+ self.base_url(connectors),+ &req.connector_meta_data+ )?,id))}@@ -945,7 +1014,10 @@ impl ConnectorIntegration<RSync, RefundsData, RefundsResponseData> for Checkoutlet id = req.request.connector_transaction_id.clone();Ok(format!("{}/payments/{}/actions",- self.base_url(connectors),+ get_checkout_payments_payouts_base_url(+ self.base_url(connectors),+ &req.connector_meta_data+ )?,id))}@@ -1023,11 +1095,12 @@ impl ConnectorIntegration<Accept, AcceptDisputeRequestData, AcceptDisputeResponsconnectors: &Connectors,) -> CustomResult<String, errors::ConnectorError> {Ok(format!(- "{}{}{}{}",- self.base_url(connectors),- "disputes/",- req.request.connector_dispute_id,- "/accept"+ "{}/disputes/{}/accept",+ get_checkout_payments_payouts_base_url(+ self.base_url(connectors),+ &req.connector_meta_data+ )?,+ req.request.connector_dispute_id))}@@ -1118,10 +1191,16 @@ impl ConnectorIntegration<Upload, UploadFileRequestData, UploadFileResponse> forfn get_url(&self,- _req: &UploadFileRouterData,+ req: &UploadFileRouterData,connectors: &Connectors,) -> CustomResult<String, errors::ConnectorError> {- Ok(format!("{}{}", self.base_url(connectors), "files"))+ Ok(format!(+ "{}/files",+ get_checkout_payments_payouts_base_url(+ self.base_url(connectors),+ &req.connector_meta_data+ )?+ ))}fn get_request_body(@@ -1207,8 +1286,11 @@ impl ConnectorIntegration<Evidence, SubmitEvidenceRequestData, SubmitEvidenceResconnectors: &Connectors,) -> CustomResult<String, errors::ConnectorError> {Ok(format!(- "{}disputes/{}/evidence",- self.base_url(connectors),+ "{}/disputes/{}/evidence",+ get_checkout_payments_payouts_base_url(+ self.base_url(connectors),+ &req.connector_meta_data+ )?,req.request.connector_dispute_id,))}@@ -1282,8 +1364,11 @@ impl ConnectorIntegration<Defend, DefendDisputeRequestData, DefendDisputeResponsconnectors: &Connectors,) -> CustomResult<String, errors::ConnectorError> {Ok(format!(- "{}disputes/{}/evidence",- self.base_url(connectors),+ "{}/disputes/{}/evidence",+ get_checkout_payments_payouts_base_url(+ self.base_url(connectors),+ &req.connector_meta_data+ )?,req.request.connector_dispute_id,))}diff --git a/crates/hyperswitch_connectors/src/connectors/checkout/transformers.rs b/crates/hyperswitch_connectors/src/connectors/checkout/transformers.rsindex d465c3d959..4a01fa9a76 100644--- a/crates/hyperswitch_connectors/src/connectors/checkout/transformers.rs+++ b/crates/hyperswitch_connectors/src/connectors/checkout/transformers.rs@@ -350,6 +350,27 @@ impl From<Option<MitCategory>> for CheckoutPaymentType {}}+#[derive(Debug, Default, Deserialize)]+pub struct CheckoutConnectorMetadataObject {+ pub connector_client_id: Option<Secret<String>>,+}++impl TryFrom<&Option<common_utils::pii::SecretSerdeValue>> for CheckoutConnectorMetadataObject {+ type Error = error_stack::Report<errors::ConnectorError>;++ fn try_from(+ meta_data: &Option<common_utils::pii::SecretSerdeValue>,+ ) -> Result<Self, Self::Error> {+ match meta_data {+ Some(metadata) => utils::to_connector_meta_from_secret::<Self>(Some(metadata.clone()))+ .change_context(errors::ConnectorError::InvalidConnectorConfig {+ config: "metadata",+ }),+ None => Ok(Self::default()),+ }+ }+}+pub struct CheckoutAuthType {pub(super) api_key: Secret<String>,pub(super) processing_channel_id: Secret<String>,diff --git a/crates/router/src/core/unified_connector_service/connector_config.rs b/crates/router/src/core/unified_connector_service/connector_config.rsindex 0eef80e014..b2cb193aca 100644--- a/crates/router/src/core/unified_connector_service/connector_config.rs+++ b/crates/router/src/core/unified_connector_service/connector_config.rs@@ -63,9 +63,10 @@ pub struct AdyenMetadata {endpoint_prefix: Option<Secret<String>>,}-/// Checkout payout configuration stored on the merchant connector account.+/// Checkout payment and payout configuration stored on the merchant connector account.#[derive(Debug, serde::Deserialize)]pub struct CheckoutMetadata {+ /// Optional Checkout client ID used to derive the account-specific API subdomain.connector_client_id: Option<Secret<String>>,/// Checkout currency account (`ca_...`) used as the payout `source.id`.connector_currency_account_id: Option<Secret<String>>,