Skip to content

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

feat(connector): [AFFIRM] add Connector Template Code (#8650)

sweta-sharma9bc02516d6ca
diff --git a/config/config.example.toml b/config/config.example.toml
index a2951f2c2e..1b08a6b906 100644
--- a/config/config.example.toml
+++ b/config/config.example.toml
@@ -185,6 +185,7 @@ adyen.base_url = "https://checkout-test.adyen.com/"
adyen.payout_base_url = "https://pal-test.adyen.com/"
adyen.dispute_base_url = "https://ca-test.adyen.com/"
adyenplatform.base_url = "https://balanceplatform-api-test.adyen.com/"
+affirm.base_url = "https://sandbox.affirm.com/api"
airwallex.base_url = "https://api-demo.airwallex.com/"
amazonpay.base_url = "https://pay-api.amazon.com/v2"
applepay.base_url = "https://apple-pay-gateway.apple.com/"
diff --git a/config/deployments/integration_test.toml b/config/deployments/integration_test.toml
index 5cce8fa105..94e7d986fb 100644
--- a/config/deployments/integration_test.toml
+++ b/config/deployments/integration_test.toml
@@ -24,6 +24,7 @@ adyen.base_url = "https://checkout-test.adyen.com/"
adyen.payout_base_url = "https://pal-test.adyen.com/"
adyen.dispute_base_url = "https://ca-test.adyen.com/"
adyenplatform.base_url = "https://balanceplatform-api-test.adyen.com/"
+affirm.base_url = "https://sandbox.affirm.com/api"
airwallex.base_url = "https://api-demo.airwallex.com/"
amazonpay.base_url = "https://pay-api.amazon.com/v2"
applepay.base_url = "https://apple-pay-gateway.apple.com/"
diff --git a/config/deployments/production.toml b/config/deployments/production.toml
index 64c41e374f..10704f8f13 100644
--- a/config/deployments/production.toml
+++ b/config/deployments/production.toml
@@ -28,6 +28,7 @@ adyen.base_url = "https://{{merchant_endpoint_prefix}}-checkout-live.adyenpaymen
adyen.payout_base_url = "https://{{merchant_endpoint_prefix}}-pal-live.adyenpayments.com/"
adyen.dispute_base_url = "https://{{merchant_endpoint_prefix}}-ca-live.adyen.com/"
adyenplatform.base_url = "https://balanceplatform-api-live.adyen.com/"
+affirm.base_url = "https://api.affirm.com/api"
airwallex.base_url = "https://api.airwallex.com/"
amazonpay.base_url = "https://pay-api.amazon.com/v2"
applepay.base_url = "https://apple-pay-gateway.apple.com/"
diff --git a/config/deployments/sandbox.toml b/config/deployments/sandbox.toml
index ebc95c2a26..9fce2a0d85 100644
--- a/config/deployments/sandbox.toml
+++ b/config/deployments/sandbox.toml
@@ -28,6 +28,7 @@ adyen.base_url = "https://checkout-test.adyen.com/"
adyen.payout_base_url = "https://pal-test.adyen.com/"
adyen.dispute_base_url = "https://ca-test.adyen.com/"
adyenplatform.base_url = "https://balanceplatform-api-test.adyen.com/"
+affirm.base_url = "https://sandbox.affirm.com/api"
airwallex.base_url = "https://api-demo.airwallex.com/"
amazonpay.base_url = "https://pay-api.amazon.com/v2"
applepay.base_url = "https://apple-pay-gateway.apple.com/"
diff --git a/config/development.toml b/config/development.toml
index 04d664f706..613de3a05e 100644
--- a/config/development.toml
+++ b/config/development.toml
@@ -222,6 +222,7 @@ checksum_auth_key = "54455354"
aci.base_url = "https://eu-test.oppwa.com/"
adyen.base_url = "https://checkout-test.adyen.com/"
adyenplatform.base_url = "https://balanceplatform-api-test.adyen.com/"
+affirm.base_url = "https://sandbox.affirm.com/api"
adyen.payout_base_url = "https://pal-test.adyen.com/"
adyen.dispute_base_url = "https://ca-test.adyen.com/"
airwallex.base_url = "https://api-demo.airwallex.com/"
diff --git a/config/docker_compose.toml b/config/docker_compose.toml
index 121af48623..124b06208f 100644
--- a/config/docker_compose.toml
+++ b/config/docker_compose.toml
@@ -109,6 +109,7 @@ hash_key = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
aci.base_url = "https://eu-test.oppwa.com/"
adyen.base_url = "https://checkout-test.adyen.com/"
adyenplatform.base_url = "https://balanceplatform-api-test.adyen.com/"
+affirm.base_url = "https://sandbox.affirm.com/api"
adyen.payout_base_url = "https://pal-test.adyen.com/"
adyen.dispute_base_url = "https://ca-test.adyen.com/"
airwallex.base_url = "https://api-demo.airwallex.com/"
diff --git a/crates/connector_configs/toml/development.toml b/crates/connector_configs/toml/development.toml
index 77fb8141c0..8ed9c6ba94 100644
--- a/crates/connector_configs/toml/development.toml
+++ b/crates/connector_configs/toml/development.toml
@@ -6333,3 +6333,7 @@ api_key="API Key"
[silverflow.connector_auth.BodyKey]
api_key="API Key"
key1="Secret Key"
+
+[affirm]
+[affirm.connector_auth.HeaderKey]
+api_key = "API Key"
diff --git a/crates/connector_configs/toml/production.toml b/crates/connector_configs/toml/production.toml
index cf9c19fcab..b9b702f4ec 100644
--- a/crates/connector_configs/toml/production.toml
+++ b/crates/connector_configs/toml/production.toml
@@ -4940,3 +4940,7 @@ api_key="API Key"
[silverflow.connector_auth.BodyKey]
api_key="API Key"
key1="Secret Key"
+
+[affirm]
+[affirm.connector_auth.HeaderKey]
+api_key = "API Key"
diff --git a/crates/connector_configs/toml/sandbox.toml b/crates/connector_configs/toml/sandbox.toml
index 28aca80b17..168a445767 100644
--- a/crates/connector_configs/toml/sandbox.toml
+++ b/crates/connector_configs/toml/sandbox.toml
@@ -6307,3 +6307,7 @@ api_key="API Key"
[silverflow.connector_auth.BodyKey]
api_key="API Key"
key1="Secret Key"
+
+[affirm]
+[affirm.connector_auth.HeaderKey]
+api_key = "API Key"
diff --git a/crates/hyperswitch_connectors/src/connectors.rs b/crates/hyperswitch_connectors/src/connectors.rs
index 84b53c9714..38e0f2886b 100644
--- a/crates/hyperswitch_connectors/src/connectors.rs
+++ b/crates/hyperswitch_connectors/src/connectors.rs
@@ -1,6 +1,7 @@
pub mod aci;
pub mod adyen;
pub mod adyenplatform;
+pub mod affirm;
pub mod airwallex;
pub mod amazonpay;
pub mod archipel;
@@ -115,7 +116,7 @@ pub mod zsl;
#[cfg(feature = "dummy_connector")]
pub use self::dummyconnector::DummyConnector;
pub use self::{
- aci::Aci, adyen::Adyen, adyenplatform::Adyenplatform, airwallex::Airwallex,
+ aci::Aci, adyen::Adyen, adyenplatform::Adyenplatform, affirm::Affirm, airwallex::Airwallex,
amazonpay::Amazonpay, archipel::Archipel, authipay::Authipay, authorizedotnet::Authorizedotnet,
bambora::Bambora, bamboraapac::Bamboraapac, bankofamerica::Bankofamerica,
barclaycard::Barclaycard, billwerk::Billwerk, bitpay::Bitpay, bluesnap::Bluesnap, boku::Boku,
diff --git a/crates/hyperswitch_connectors/src/connectors/affirm.rs b/crates/hyperswitch_connectors/src/connectors/affirm.rs
new file mode 100644
index 0000000000..9a0a6fb4df
--- /dev/null
+++ b/crates/hyperswitch_connectors/src/connectors/affirm.rs
@@ -0,0 +1,622 @@
+pub mod transformers;
+
+use std::sync::LazyLock;
+
+use common_enums::enums;
+use common_utils::{
+ errors::CustomResult,
+ ext_traits::BytesExt,
+ request::{Method, Request, RequestBuilder, RequestContent},
+ types::{AmountConvertor, StringMinorUnit, StringMinorUnitForConnector},
+};
+use error_stack::{report, ResultExt};
+use hyperswitch_domain_models::{
+ payment_method_data::PaymentMethodData,
+ router_data::{AccessToken, ConnectorAuthType, ErrorResponse, 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::{
+ ConnectorInfo, PaymentsResponseData, RefundsResponseData, SupportedPaymentMethods,
+ },
+ types::{
+ PaymentsAuthorizeRouterData, PaymentsCaptureRouterData, PaymentsSyncRouterData,
+ RefundSyncRouterData, RefundsRouterData,
+ },
+};
+use hyperswitch_interfaces::{
+ api::{
+ self, ConnectorCommon, ConnectorCommonExt, ConnectorIntegration, ConnectorSpecifications,
+ ConnectorValidation,
+ },
+ configs::Connectors,
+ errors,
+ events::connector_api_logs::ConnectorEvent,
+ types::{self, Response},
+ webhooks,
+};
+use masking::{ExposeInterface, Mask};
+use transformers as affirm;
+
+use crate::{constants::headers, types::ResponseRouterData, utils};
+
+#[derive(Clone)]
+pub struct Affirm {
+ amount_converter: &'static (dyn AmountConvertor<Output = StringMinorUnit> + Sync),
+}
+
+impl Affirm {
+ pub fn new() -> &'static Self {
+ &Self {
+ amount_converter: &StringMinorUnitForConnector,
+ }
+ }
+}
+
+impl api::Payment for Affirm {}
+impl api::PaymentSession for Affirm {}
+impl api::ConnectorAccessToken for Affirm {}
+impl api::MandateSetup for Affirm {}
+impl api::PaymentAuthorize for Affirm {}
+impl api::PaymentSync for Affirm {}
+impl api::PaymentCapture for Affirm {}
+impl api::PaymentVoid for Affirm {}
+impl api::Refund for Affirm {}
+impl api::RefundExecute for Affirm {}
+impl api::RefundSync for Affirm {}
+impl api::PaymentToken for Affirm {}
+
+impl ConnectorIntegration<PaymentMethodToken, PaymentMethodTokenizationData, PaymentsResponseData>
+ for Affirm
+{
+ // Not Implemented (R)
+}
+
+impl<Flow, Request, Response> ConnectorCommonExt<Flow, Request, Response> for Affirm
+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 Affirm {
+ fn id(&self) -> &'static str {
+ "affirm"
+ }
+
+ 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 Connectors) -> &'a str {
+ connectors.affirm.base_url.as_ref()
+ }
+
+ fn get_auth_header(
+ &self,
+ auth_type: &ConnectorAuthType,
+ ) -> CustomResult<Vec<(String, masking::Maskable<String>)>, errors::ConnectorError> {
+ let auth = affirm::AffirmAuthType::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: affirm::AffirmErrorResponse = res
+ .response
+ .parse_struct("AffirmErrorResponse")
+ .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,
+ network_advice_code: None,
+ network_decline_code: None,
+ network_error_message: None,
+ })
+ }
+}
+
+impl ConnectorValidation for Affirm {
+ fn validate_mandate_payment(
+ &self,
+ _pm_type: Option<enums::PaymentMethodType>,
+ pm_data: PaymentMethodData,
+ ) -> CustomResult<(), errors::ConnectorError> {
+ match pm_data {
+ PaymentMethodData::Card(_) => Err(errors::ConnectorError::NotImplemented(
+ "validate_mandate_payment does not support cards".to_string(),
+ )
+ .into()),
+ _ => Ok(()),
+ }
+ }
+
+ fn validate_psync_reference_id(
+ &self,
+ _data: &PaymentsSyncData,
+ _is_three_ds: bool,
+ _status: enums::AttemptStatus,
+ _connector_meta_data: Option<common_utils::pii::SecretSerdeValue>,
+ ) -> CustomResult<(), errors::ConnectorError> {
+ Ok(())
+ }
+}
+
+impl ConnectorIntegration<Session, PaymentsSessionData, PaymentsResponseData> for Affirm {
+ //TODO: implement sessions flow
+}
+
+impl ConnectorIntegration<AccessTokenAuth, AccessTokenRequestData, AccessToken> for Affirm {}
+
+impl ConnectorIntegration<SetupMandate, SetupMandateRequestData, PaymentsResponseData> for Affirm {}
+
+impl ConnectorIntegration<Authorize, PaymentsAuthorizeData, PaymentsResponseData> for Affirm {
+ fn get_headers(
+ &self,
+ req: &PaymentsAuthorizeRouterData,
+ connectors: &Connectors,
+ ) -> CustomResult<Vec<(String, masking::Maskable<String>)>, errors::ConnectorError> {
+ self.build_headers(req, connectors)
+ }
+
+ fn get_content_type(&self) -> &'static str {
+ self.common_get_content_type()
+ }
+
+ fn get_url(
+ &self,
+ _req: &PaymentsAuthorizeRouterData,
+ _connectors: &Connectors,
+ ) -> CustomResult<String, errors::ConnectorError> {
+ Err(errors::ConnectorError::NotImplemented("get_url method".to_string()).into())
+ }
+
+ fn get_request_body(
+ &self,
+ req: &PaymentsAuthorizeRouterData,
+ _connectors: &Connectors,
+ ) -> CustomResult<RequestContent, errors::ConnectorError> {
+ let amount = utils::convert_amount(
+ self.amount_converter,
+ req.request.minor_amount,
+ req.request.currency,
+ )?;
+
+ let connector_router_data = affirm::AffirmRouterData::from((amount, req));
+ let connector_req = affirm::AffirmPaymentsRequest::try_from(&connector_router_data)?;
+ Ok(RequestContent::Json(Box::new(connector_req)))
+ }
+
+ fn build_request(
+ &self,
+ req: &PaymentsAuthorizeRouterData,
+ connectors: &Connectors,
+ ) -> CustomResult<Option<Request>, errors::ConnectorError> {
+ Ok(Some(
+ RequestBuilder::new()
+ .method(Method::Post)
+ .url(&types::PaymentsAuthorizeType::get_url(
+ self, req, connectors,
+ )?)
+ .attach_default_headers()
+ .headers(types::PaymentsAuthorizeType::get_headers(
+ self, req, connectors,
+ )?)
+ .set_body(types::PaymentsAuthorizeType::get_request_body(
+ self, req, connectors,
+ )?)
+ .build(),
+ ))
+ }
+
+ fn handle_response(
+ &self,
+ data: &PaymentsAuthorizeRouterData,
+ event_builder: Option<&mut ConnectorEvent>,
+ res: Response,
+ ) -> CustomResult<PaymentsAuthorizeRouterData, errors::ConnectorError> {
+ let response: affirm::AffirmPaymentsResponse = res
+ .response
+ .parse_struct("Affirm PaymentsAuthorizeResponse")
+ .change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
+ event_builder.map(|i| i.set_response_body(&response));
+ router_env::logger::info!(connector_response=?response);
+ RouterData::try_from(ResponseRouterData {
+ response,
+ data: data.clone(),
+ http_code: res.status_code,
+ })
+ }
+
+ fn get_error_response(
+ &self,
+ res: Response,
+ event_builder: Option<&mut ConnectorEvent>,
+ ) -> CustomResult<ErrorResponse, errors::ConnectorError> {
+ self.build_error_response(res, event_builder)
+ }
+}
+
+impl ConnectorIntegration<PSync, PaymentsSyncData, PaymentsResponseData> for Affirm {
+ fn get_headers(
+ &self,
+ req: &PaymentsSyncRouterData,
+ connectors: &Connectors,
+ ) -> CustomResult<Vec<(String, masking::Maskable<String>)>, errors::ConnectorError> {
+ self.build_headers(req, connectors)
+ }
+
+ fn get_content_type(&self) -> &'static str {
+ self.common_get_content_type()
+ }
+
+ fn get_url(
+ &self,
+ _req: &PaymentsSyncRouterData,
+ _connectors: &Connectors,
+ ) -> CustomResult<String, errors::ConnectorError> {
+ Err(errors::ConnectorError::NotImplemented("get_url method".to_string()).into())
+ }
+
+ fn build_request(
+ &self,
+ req: &PaymentsSyncRouterData,
+ connectors: &Connectors,
+ ) -> CustomResult<Option<Request>, errors::ConnectorError> {
+ Ok(Some(
+ RequestBuilder::new()
+ .method(Method::Get)
+ .url(&types::PaymentsSyncType::get_url(self, req, connectors)?)
+ .attach_default_headers()
+ .headers(types::PaymentsSyncType::get_headers(self, req, connectors)?)
+ .build(),
+ ))
+ }
+
+ fn handle_response(
+ &self,
+ data: &PaymentsSyncRouterData,
+ event_builder: Option<&mut ConnectorEvent>,
+ res: Response,
+ ) -> CustomResult<PaymentsSyncRouterData, errors::ConnectorError> {
+ let response: affirm::AffirmPaymentsResponse = res
+ .response
+ .parse_struct("affirm PaymentsSyncResponse")
+ .change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
+ event_builder.map(|i| i.set_response_body(&response));
+ router_env::logger::info!(connector_response=?response);
+ RouterData::try_from(ResponseRouterData {
+ response,
+ data: data.clone(),
+ http_code: res.status_code,
+ })
+ }
+
+ fn get_error_response(
+ &self,
+ res: Response,
+ event_builder: Option<&mut ConnectorEvent>,
+ ) -> CustomResult<ErrorResponse, errors::ConnectorError> {
+ self.build_error_response(res, event_builder)
+ }
+}
+
+impl ConnectorIntegration<Capture, PaymentsCaptureData, PaymentsResponseData> for Affirm {
+ fn get_headers(
+ &self,
+ req: &PaymentsCaptureRouterData,
+ connectors: &Connectors,
+ ) -> CustomResult<Vec<(String, masking::Maskable<String>)>, errors::ConnectorError> {
+ self.build_headers(req, connectors)
+ }
+
+ fn get_content_type(&self) -> &'static str {
+ self.common_get_content_type()
+ }
+
+ fn get_url(
+ &self,
+ _req: &PaymentsCaptureRouterData,
+ _connectors: &Connectors,
+ ) -> CustomResult<String, errors::ConnectorError> {
+ Err(errors::ConnectorError::NotImplemented("get_url method".to_string()).into())
+ }
+
+ fn get_request_body(
+ &self,
+ _req: &PaymentsCaptureRouterData,
+ _connectors: &Connectors,
+ ) -> CustomResult<RequestContent, errors::ConnectorError> {
+ Err(errors::ConnectorError::NotImplemented("get_request_body method".to_string()).into())
+ }
+
+ fn build_request(
+ &self,
+ req: &PaymentsCaptureRouterData,
+ connectors: &Connectors,
+ ) -> CustomResult<Option<Request>, errors::ConnectorError> {
+ Ok(Some(
+ RequestBuilder::new()
+ .method(Method::Post)
+ .url(&types::PaymentsCaptureType::get_url(self, req, connectors)?)
+ .attach_default_headers()
+ .headers(types::PaymentsCaptureType::get_headers(
+ self, req, connectors,
+ )?)
+ .set_body(types::PaymentsCaptureType::get_request_body(
+ self, req, connectors,
+ )?)
+ .build(),
+ ))
+ }
+
+ fn handle_response(
+ &self,
+ data: &PaymentsCaptureRouterData,
+ event_builder: Option<&mut ConnectorEvent>,
+ res: Response,
+ ) -> CustomResult<PaymentsCaptureRouterData, errors::ConnectorError> {
+ let response: affirm::AffirmPaymentsResponse = res
+ .response
+ .parse_struct("Affirm PaymentsCaptureResponse")
+ .change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
+ event_builder.map(|i| i.set_response_body(&response));
+ router_env::logger::info!(connector_response=?response);
+ RouterData::try_from(ResponseRouterData {
+ response,
+ data: data.clone(),
+ http_code: res.status_code,
+ })
+ }
+
+ fn get_error_response(
+ &self,
+ res: Response,
+ event_builder: Option<&mut ConnectorEvent>,
+ ) -> CustomResult<ErrorResponse, errors::ConnectorError> {
+ self.build_error_response(res, event_builder)
+ }
+}
+
+impl ConnectorIntegration<Void, PaymentsCancelData, PaymentsResponseData> for Affirm {}
+
+impl ConnectorIntegration<Execute, RefundsData, RefundsResponseData> for Affirm {
+ fn get_headers(
+ &self,
+ req: &RefundsRouterData<Execute>,
+ connectors: &Connectors,
+ ) -> CustomResult<Vec<(String, masking::Maskable<String>)>, errors::ConnectorError> {
+ self.build_headers(req, connectors)
+ }
+
+ fn get_content_type(&self) -> &'static str {
+ self.common_get_content_type()
+ }
+
+ fn get_url(
+ &self,
+ _req: &RefundsRouterData<Execute>,
+ _connectors: &Connectors,
+ ) -> CustomResult<String, errors::ConnectorError> {
+ Err(errors::ConnectorError::NotImplemented("get_url method".to_string()).into())
+ }
+
+ fn get_request_body(
+ &self,
+ req: &RefundsRouterData<Execute>,
+ _connectors: &Connectors,
+ ) -> CustomResult<RequestContent, errors::ConnectorError> {
+ let refund_amount = utils::convert_amount(
+ self.amount_converter,
+ req.request.minor_refund_amount,
+ req.request.currency,
+ )?;
+
+ let connector_router_data = affirm::AffirmRouterData::from((refund_amount, req));
+ let connector_req = affirm::AffirmRefundRequest::try_from(&connector_router_data)?;
+ Ok(RequestContent::Json(Box::new(connector_req)))
+ }
+
+ fn build_request(
+ &self,
+ req: &RefundsRouterData<Execute>,
+ connectors: &Connectors,
+ ) -> CustomResult<Option<Request>, errors::ConnectorError> {
+ let request = RequestBuilder::new()
+ .method(Method::Post)
+ .url(&types::RefundExecuteType::get_url(self, req, connectors)?)
+ .attach_default_headers()
+ .headers(types::RefundExecuteType::get_headers(
+ self, req, connectors,
+ )?)
+ .set_body(types::RefundExecuteType::get_request_body(
+ self, req, connectors,
+ )?)
+ .build();
+ Ok(Some(request))
+ }
+
+ fn handle_response(
+ &self,
+ data: &RefundsRouterData<Execute>,
+ event_builder: Option<&mut ConnectorEvent>,
+ res: Response,
+ ) -> CustomResult<RefundsRouterData<Execute>, errors::ConnectorError> {
+ let response: affirm::RefundResponse =
+ res.response
+ .parse_struct("affirm RefundResponse")
+ .change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
+ event_builder.map(|i| i.set_response_body(&response));
+ router_env::logger::info!(connector_response=?response);
+ RouterData::try_from(ResponseRouterData {
+ response,
+ data: data.clone(),
+ http_code: res.status_code,
+ })
+ }
+
+ fn get_error_response(
+ &self,
+ res: Response,
+ event_builder: Option<&mut ConnectorEvent>,
+ ) -> CustomResult<ErrorResponse, errors::ConnectorError> {
+ self.build_error_response(res, event_builder)
+ }
+}
+
+impl ConnectorIntegration<RSync, RefundsData, RefundsResponseData> for Affirm {
+ fn get_headers(
+ &self,
+ req: &RefundSyncRouterData,
+ connectors: &Connectors,
+ ) -> CustomResult<Vec<(String, masking::Maskable<String>)>, errors::ConnectorError> {
+ self.build_headers(req, connectors)
+ }
+
+ fn get_content_type(&self) -> &'static str {
+ self.common_get_content_type()
+ }
+
+ fn get_url(
+ &self,
+ _req: &RefundSyncRouterData,
+ _connectors: &Connectors,
+ ) -> CustomResult<String, errors::ConnectorError> {
+ Err(errors::ConnectorError::NotImplemented("get_url method".to_string()).into())
+ }
+
+ fn build_request(
+ &self,
+ req: &RefundSyncRouterData,
+ connectors: &Connectors,
+ ) -> CustomResult<Option<Request>, errors::ConnectorError> {
+ Ok(Some(
+ RequestBuilder::new()
+ .method(Method::Get)
+ .url(&types::RefundSyncType::get_url(self, req, connectors)?)
+ .attach_default_headers()
+ .headers(types::RefundSyncType::get_headers(self, req, connectors)?)
+ .set_body(types::RefundSyncType::get_request_body(
+ self, req, connectors,
+ )?)
+ .build(),
+ ))
+ }
+
+ fn handle_response(
+ &self,
+ data: &RefundSyncRouterData,
+ event_builder: Option<&mut ConnectorEvent>,
+ res: Response,
+ ) -> CustomResult<RefundSyncRouterData, errors::ConnectorError> {
+ let response: affirm::RefundResponse = res
+ .response
+ .parse_struct("affirm RefundSyncResponse")
+ .change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
+ event_builder.map(|i| i.set_response_body(&response));
+ router_env::logger::info!(connector_response=?response);
+ RouterData::try_from(ResponseRouterData {
+ response,
+ data: data.clone(),
+ http_code: res.status_code,
+ })
+ }
+
+ fn get_error_response(
+ &self,
+ res: Response,
+ event_builder: Option<&mut ConnectorEvent>,
+ ) -> CustomResult<ErrorResponse, errors::ConnectorError> {
+ self.build_error_response(res, event_builder)
+ }
+}
+
+#[async_trait::async_trait]
+impl webhooks::IncomingWebhook for Affirm {
+ 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))
+ }
+}
+
+static AFFIRM_SUPPORTED_PAYMENT_METHODS: LazyLock<SupportedPaymentMethods> =
+ LazyLock::new(SupportedPaymentMethods::new);
+
+static AFFIRM_CONNECTOR_INFO: ConnectorInfo = ConnectorInfo {
+ display_name: "Affirm",
+ description: "Affirm connector",
+ connector_type: enums::PaymentConnectorCategory::PaymentGateway,
+};
+
+static AFFIRM_SUPPORTED_WEBHOOK_FLOWS: [enums::EventClass; 0] = [];
+
+impl ConnectorSpecifications for Affirm {
+ fn get_connector_about(&self) -> Option<&'static ConnectorInfo> {
+ Some(&AFFIRM_CONNECTOR_INFO)
+ }
+
+ fn get_supported_payment_methods(&self) -> Option<&'static SupportedPaymentMethods> {
+ Some(&*AFFIRM_SUPPORTED_PAYMENT_METHODS)
+ }
+
+ fn get_supported_webhook_flows(&self) -> Option<&'static [enums::EventClass]> {
+ Some(&AFFIRM_SUPPORTED_WEBHOOK_FLOWS)
+ }
+}
diff --git a/crates/hyperswitch_connectors/src/connectors/affirm/transformers.rs b/crates/hyperswitch_connectors/src/connectors/affirm/transformers.rs
new file mode 100644
index 0000000000..4b606e04bb
--- /dev/null
+++ b/crates/hyperswitch_connectors/src/connectors/affirm/transformers.rs
@@ -0,0 +1,219 @@
+use common_enums::enums;
+use common_utils::types::StringMinorUnit;
+use hyperswitch_domain_models::{
+ payment_method_data::PaymentMethodData,
+ router_data::{ConnectorAuthType, RouterData},
+ router_flow_types::refunds::{Execute, RSync},
+ router_request_types::ResponseId,
+ router_response_types::{PaymentsResponseData, RefundsResponseData},
+ types::{PaymentsAuthorizeRouterData, RefundsRouterData},
+};
+use hyperswitch_interfaces::errors;
+use masking::Secret;
+use serde::{Deserialize, Serialize};
+
+use crate::types::{RefundsResponseRouterData, ResponseRouterData};
+
+//TODO: Fill the struct with respective fields
+pub struct AffirmRouterData<T> {
+ pub amount: StringMinorUnit, // The type of amount that a connector accepts, for example, String, i64, f64, etc.
+ pub router_data: T,
+}
+
+impl<T> From<(StringMinorUnit, T)> for AffirmRouterData<T> {
+ fn from((amount, item): (StringMinorUnit, T)) -> Self {
+ //Todo : use utils to convert the amount to the type of amount that a connector accepts
+ Self {
+ amount,
+ router_data: item,
+ }
+ }
+}
+
+//TODO: Fill the struct with respective fields
+#[derive(Default, Debug, Serialize, PartialEq)]
+pub struct AffirmPaymentsRequest {
+ amount: StringMinorUnit,
+ card: AffirmCard,
+}
+
+#[derive(Default, Debug, Serialize, Eq, PartialEq)]
+pub struct AffirmCard {
+ number: cards::CardNumber,
+ expiry_month: Secret<String>,
+ expiry_year: Secret<String>,
+ cvc: Secret<String>,
+ complete: bool,
+}
+
+impl TryFrom<&AffirmRouterData<&PaymentsAuthorizeRouterData>> for AffirmPaymentsRequest {
+ type Error = error_stack::Report<errors::ConnectorError>;
+ fn try_from(
+ item: &AffirmRouterData<&PaymentsAuthorizeRouterData>,
+ ) -> Result<Self, Self::Error> {
+ match item.router_data.request.payment_method_data.clone() {
+ PaymentMethodData::Card(_) => Err(errors::ConnectorError::NotImplemented(
+ "Card payment method not implemented".to_string(),
+ )
+ .into()),
+ _ => Err(errors::ConnectorError::NotImplemented("Payment method".to_string()).into()),
+ }
+ }
+}
+
+//TODO: Fill the struct with respective fields
+// Auth Struct
+pub struct AffirmAuthType {
+ pub(super) api_key: Secret<String>,
+}
+
+impl TryFrom<&ConnectorAuthType> for AffirmAuthType {
+ type Error = error_stack::Report<errors::ConnectorError>;
+ fn try_from(auth_type: &ConnectorAuthType) -> Result<Self, Self::Error> {
+ match auth_type {
+ ConnectorAuthType::HeaderKey { api_key } => Ok(Self {
+ api_key: api_key.to_owned(),
+ }),
+ _ => Err(errors::ConnectorError::FailedToObtainAuthType.into()),
+ }
+ }
+}
+// PaymentsResponse
+//TODO: Append the remaining status flags
+#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize, PartialEq)]
+#[serde(rename_all = "lowercase")]
+pub enum AffirmPaymentStatus {
+ Succeeded,
+ Failed,
+ #[default]
+ Processing,
+}
+
+impl From<AffirmPaymentStatus> for common_enums::AttemptStatus {
+ fn from(item: AffirmPaymentStatus) -> Self {
+ match item {
+ AffirmPaymentStatus::Succeeded => Self::Charged,
+ AffirmPaymentStatus::Failed => Self::Failure,
+ AffirmPaymentStatus::Processing => Self::Authorizing,
+ }
+ }
+}
+
+//TODO: Fill the struct with respective fields
+#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq)]
+pub struct AffirmPaymentsResponse {
+ status: AffirmPaymentStatus,
+ id: String,
+}
+
+impl<F, T> TryFrom<ResponseRouterData<F, AffirmPaymentsResponse, T, PaymentsResponseData>>
+ for RouterData<F, T, PaymentsResponseData>
+{
+ type Error = error_stack::Report<errors::ConnectorError>;
+ fn try_from(
+ item: ResponseRouterData<F, AffirmPaymentsResponse, T, PaymentsResponseData>,
+ ) -> Result<Self, Self::Error> {
+ Ok(Self {
+ status: common_enums::AttemptStatus::from(item.response.status),
+ response: Ok(PaymentsResponseData::TransactionResponse {
+ resource_id: ResponseId::ConnectorTransactionId(item.response.id),
+ redirection_data: Box::new(None),
+ mandate_reference: Box::new(None),
+ connector_metadata: None,
+ network_txn_id: None,
+ connector_response_reference_id: None,
+ incremental_authorization_allowed: None,
+ charges: None,
+ }),
+ ..item.data
+ })
+ }
+}
+
+//TODO: Fill the struct with respective fields
+// REFUND :
+// Type definition for RefundRequest
+#[derive(Default, Debug, Serialize)]
+pub struct AffirmRefundRequest {
+ pub amount: StringMinorUnit,
+}
+
+impl<F> TryFrom<&AffirmRouterData<&RefundsRouterData<F>>> for AffirmRefundRequest {
+ type Error = error_stack::Report<errors::ConnectorError>;
+ fn try_from(item: &AffirmRouterData<&RefundsRouterData<F>>) -> Result<Self, Self::Error> {
+ Ok(Self {
+ amount: item.amount.to_owned(),
+ })
+ }
+}
+
+// Type definition for Refund Response
+
+#[allow(dead_code)]
+#[derive(Debug, Copy, Serialize, Default, Deserialize, Clone)]
+pub enum RefundStatus {
+ Succeeded,
+ Failed,
+ #[default]
+ Processing,
+}
+
+impl From<RefundStatus> for enums::RefundStatus {
+ fn from(item: RefundStatus) -> Self {
+ match item {
+ RefundStatus::Succeeded => Self::Success,
+ RefundStatus::Failed => Self::Failure,
+ RefundStatus::Processing => Self::Pending,
+ //TODO: Review mapping
+ }
+ }
+}
+
+//TODO: Fill the struct with respective fields
+#[derive(Default, Debug, Clone, Serialize, Deserialize)]
+pub struct RefundResponse {
+ id: String,
+ status: RefundStatus,
+}
+
+impl TryFrom<RefundsResponseRouterData<Execute, RefundResponse>> for RefundsRouterData<Execute> {
+ type Error = error_stack::Report<errors::ConnectorError>;
+ fn try_from(
+ item: RefundsResponseRouterData<Execute, RefundResponse>,
+ ) -> Result<Self, Self::Error> {
+ Ok(Self {
+ response: Ok(RefundsResponseData {
+ connector_refund_id: item.response.id.to_string(),
+ refund_status: enums::RefundStatus::from(item.response.status),
+ }),
+ ..item.data
+ })
+ }
+}
+
+impl TryFrom<RefundsResponseRouterData<RSync, RefundResponse>> for RefundsRouterData<RSync> {
+ type Error = error_stack::Report<errors::ConnectorError>;
+ fn try_from(
+ item: RefundsResponseRouterData<RSync, RefundResponse>,
+ ) -> Result<Self, Self::Error> {
+ Ok(Self {
+ response: Ok(RefundsResponseData {
+ connector_refund_id: item.response.id.to_string(),
+ refund_status: enums::RefundStatus::from(item.response.status),
+ }),
+ ..item.data
+ })
+ }
+}
+
+//TODO: Fill the struct with respective fields
+#[derive(Default, Debug, Serialize, Deserialize, PartialEq)]
+pub struct AffirmErrorResponse {
+ pub status_code: u16,
+ pub code: String,
+ pub message: String,
+ pub reason: Option<String>,
+ pub network_advice_code: Option<String>,
+ pub network_decline_code: Option<String>,
+ pub network_error_message: Option<String>,
+}
diff --git a/crates/hyperswitch_connectors/src/default_implementations.rs b/crates/hyperswitch_connectors/src/default_implementations.rs
index bdf3ee5604..96f8cd13bf 100644
--- a/crates/hyperswitch_connectors/src/default_implementations.rs
+++ b/crates/hyperswitch_connectors/src/default_implementations.rs
@@ -145,6 +145,7 @@ default_imp_for_authorize_session_token!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Archipel,
@@ -272,6 +273,7 @@ default_imp_for_calculate_tax!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Archipel,
@@ -400,6 +402,7 @@ default_imp_for_session_update!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Archipel,
@@ -528,6 +531,7 @@ default_imp_for_post_session_tokens!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Archipel,
@@ -655,6 +659,7 @@ default_imp_for_create_order!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Archipel,
@@ -783,6 +788,7 @@ default_imp_for_update_metadata!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Archipel,
@@ -915,6 +921,7 @@ default_imp_for_complete_authorize!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Amazonpay,
connectors::Archipel,
connectors::Authipay,
@@ -1023,6 +1030,7 @@ default_imp_for_incremental_authorization!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Authipay,
@@ -1149,6 +1157,7 @@ default_imp_for_create_customer!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Archipel,
@@ -1276,6 +1285,7 @@ default_imp_for_connector_redirect_response!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Amazonpay,
connectors::Archipel,
connectors::Authipay,
@@ -1384,6 +1394,7 @@ default_imp_for_pre_processing_steps!(
connectors::Vgs,
connectors::Aci,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Amazonpay,
connectors::Archipel,
connectors::Authipay,
@@ -1501,6 +1512,7 @@ default_imp_for_post_processing_steps!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Archipel,
@@ -1630,6 +1642,7 @@ default_imp_for_approve!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Archipel,
@@ -1760,6 +1773,7 @@ default_imp_for_reject!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Archipel,
@@ -1890,6 +1904,7 @@ default_imp_for_webhook_source_verification!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Archipel,
@@ -2019,6 +2034,7 @@ default_imp_for_accept_dispute!(
connectors::Vgs,
connectors::Aci,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Archipel,
@@ -2147,6 +2163,7 @@ default_imp_for_submit_evidence!(
connectors::Vgs,
connectors::Aci,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Archipel,
@@ -2274,6 +2291,7 @@ default_imp_for_defend_dispute!(
connectors::Vgs,
connectors::Aci,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Archipel,
@@ -2411,6 +2429,7 @@ default_imp_for_file_upload!(
connectors::Vgs,
connectors::Aci,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Archipel,
@@ -2528,6 +2547,7 @@ macro_rules! default_imp_for_payouts {
}
default_imp_for_payouts!(
+ connectors::Affirm,
connectors::Vgs,
connectors::Aci,
connectors::Airwallex,
@@ -2653,6 +2673,7 @@ default_imp_for_payouts_create!(
connectors::Vgs,
connectors::Aci,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Archipel,
@@ -2780,6 +2801,7 @@ default_imp_for_payouts_retrieve!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Archipel,
@@ -2909,6 +2931,7 @@ default_imp_for_payouts_eligibility!(
connectors::Vgs,
connectors::Aci,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Archipel,
@@ -3034,6 +3057,7 @@ macro_rules! default_imp_for_payouts_fulfill {
#[cfg(feature = "payouts")]
default_imp_for_payouts_fulfill!(
+ connectors::Affirm,
connectors::Vgs,
connectors::Aci,
connectors::Airwallex,
@@ -3160,6 +3184,7 @@ default_imp_for_payouts_cancel!(
connectors::Vgs,
connectors::Aci,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Archipel,
@@ -3288,6 +3313,7 @@ default_imp_for_payouts_quote!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Archipel,
@@ -3417,6 +3443,7 @@ default_imp_for_payouts_recipient!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Archipel,
@@ -3545,6 +3572,7 @@ default_imp_for_payouts_recipient_account!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Archipel,
@@ -3675,6 +3703,7 @@ default_imp_for_frm_sale!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Archipel,
@@ -3805,6 +3834,7 @@ default_imp_for_frm_checkout!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Archipel,
@@ -3935,6 +3965,7 @@ default_imp_for_frm_transaction!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Archipel,
@@ -4065,6 +4096,7 @@ default_imp_for_frm_fulfillment!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Archipel,
@@ -4195,6 +4227,7 @@ default_imp_for_frm_record_return!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Archipel,
@@ -4322,6 +4355,7 @@ default_imp_for_revoking_mandates!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Archipel,
@@ -4447,6 +4481,7 @@ default_imp_for_uas_pre_authentication!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Archipel,
@@ -4574,6 +4609,7 @@ default_imp_for_uas_post_authentication!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Archipel,
@@ -4702,6 +4738,7 @@ default_imp_for_uas_authentication_confirmation!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Archipel,
@@ -4822,6 +4859,7 @@ default_imp_for_connector_request_id!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Archipel,
connectors::Authipay,
@@ -4944,6 +4982,7 @@ default_imp_for_fraud_check!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Archipel,
@@ -5096,6 +5135,7 @@ default_imp_for_connector_authentication!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Archipel,
@@ -5221,6 +5261,7 @@ default_imp_for_uas_authentication!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Archipel,
@@ -5341,6 +5382,7 @@ default_imp_for_revenue_recovery!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Archipel,
@@ -5472,6 +5514,7 @@ default_imp_for_billing_connector_payment_sync!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Archipel,
@@ -5602,6 +5645,7 @@ default_imp_for_revenue_recovery_record_back!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Archipel,
@@ -5730,6 +5774,7 @@ default_imp_for_billing_connector_invoice_sync!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Archipel,
@@ -5853,6 +5898,7 @@ default_imp_for_external_vault!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Archipel,
@@ -5982,6 +6028,7 @@ default_imp_for_external_vault_insert!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Archipel,
@@ -6111,6 +6158,7 @@ default_imp_for_external_vault_retrieve!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Archipel,
@@ -6240,6 +6288,7 @@ default_imp_for_external_vault_delete!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Archipel,
@@ -6369,6 +6418,7 @@ default_imp_for_external_vault_create!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Archipel,
diff --git a/crates/hyperswitch_connectors/src/default_implementations_v2.rs b/crates/hyperswitch_connectors/src/default_implementations_v2.rs
index 89a7b3de2a..2e24253a8a 100644
--- a/crates/hyperswitch_connectors/src/default_implementations_v2.rs
+++ b/crates/hyperswitch_connectors/src/default_implementations_v2.rs
@@ -253,6 +253,7 @@ default_imp_for_new_connector_integration_payment!(
connectors::Airwallex,
connectors::Amazonpay,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Authipay,
connectors::Authorizedotnet,
connectors::Bambora,
@@ -381,6 +382,7 @@ default_imp_for_new_connector_integration_refund!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Authipay,
@@ -506,6 +508,7 @@ default_imp_for_new_connector_integration_connector_access_token!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Authipay,
@@ -637,6 +640,7 @@ default_imp_for_new_connector_integration_accept_dispute!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Authipay,
@@ -766,6 +770,7 @@ default_imp_for_new_connector_integration_submit_evidence!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Authipay,
@@ -895,6 +900,7 @@ default_imp_for_new_connector_integration_defend_dispute!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Authipay,
@@ -1035,6 +1041,7 @@ default_imp_for_new_connector_integration_file_upload!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Authipay,
@@ -1167,6 +1174,7 @@ default_imp_for_new_connector_integration_payouts_create!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Authipay,
@@ -1299,6 +1307,7 @@ default_imp_for_new_connector_integration_payouts_eligibility!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Authipay,
@@ -1431,6 +1440,7 @@ default_imp_for_new_connector_integration_payouts_fulfill!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Authipay,
@@ -1563,6 +1573,7 @@ default_imp_for_new_connector_integration_payouts_cancel!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Authipay,
@@ -1695,6 +1706,7 @@ default_imp_for_new_connector_integration_payouts_quote!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Authipay,
@@ -1827,6 +1839,7 @@ default_imp_for_new_connector_integration_payouts_recipient!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Authipay,
@@ -1959,6 +1972,7 @@ default_imp_for_new_connector_integration_payouts_sync!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Authipay,
@@ -2091,6 +2105,7 @@ default_imp_for_new_connector_integration_payouts_recipient_account!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Authipay,
@@ -2221,6 +2236,7 @@ default_imp_for_new_connector_integration_webhook_source_verification!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Authipay,
@@ -2353,6 +2369,7 @@ default_imp_for_new_connector_integration_frm_sale!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Authipay,
@@ -2485,6 +2502,7 @@ default_imp_for_new_connector_integration_frm_checkout!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Authipay,
@@ -2617,6 +2635,7 @@ default_imp_for_new_connector_integration_frm_transaction!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Authipay,
@@ -2749,6 +2768,7 @@ default_imp_for_new_connector_integration_frm_fulfillment!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Authipay,
@@ -2881,6 +2901,7 @@ default_imp_for_new_connector_integration_frm_record_return!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Authipay,
@@ -3010,6 +3031,7 @@ default_imp_for_new_connector_integration_revoking_mandates!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Authipay,
@@ -3129,6 +3151,7 @@ macro_rules! default_imp_for_new_connector_integration_frm {
#[cfg(feature = "frm")]
default_imp_for_new_connector_integration_frm!(
+ connectors::Affirm,
connectors::Vgs,
connectors::Airwallex,
connectors::Amazonpay,
@@ -3258,6 +3281,7 @@ macro_rules! default_imp_for_new_connector_integration_connector_authentication
}
default_imp_for_new_connector_integration_connector_authentication!(
+ connectors::Affirm,
connectors::Vgs,
connectors::Airwallex,
connectors::Amazonpay,
@@ -3376,6 +3400,7 @@ macro_rules! default_imp_for_new_connector_integration_revenue_recovery {
}
default_imp_for_new_connector_integration_revenue_recovery!(
+ connectors::Affirm,
connectors::Vgs,
connectors::Airwallex,
connectors::Amazonpay,
@@ -3507,6 +3532,7 @@ default_imp_for_new_connector_integration_external_vault!(
connectors::Aci,
connectors::Adyen,
connectors::Adyenplatform,
+ connectors::Affirm,
connectors::Airwallex,
connectors::Amazonpay,
connectors::Archipel,
diff --git a/crates/hyperswitch_domain_models/src/connector_endpoints.rs b/crates/hyperswitch_domain_models/src/connector_endpoints.rs
index 9e4b94f946..a1da7a4d3b 100644
--- a/crates/hyperswitch_domain_models/src/connector_endpoints.rs
+++ b/crates/hyperswitch_domain_models/src/connector_endpoints.rs
@@ -15,6 +15,7 @@ pub struct Connectors {
pub authipay: ConnectorParams,
pub adyen: AdyenParamsWithThreeBaseUrls,
pub adyenplatform: ConnectorParams,
+ pub affirm: ConnectorParams,
pub airwallex: ConnectorParams,
pub amazonpay: ConnectorParams,
pub applepay: ConnectorParams,
diff --git a/crates/router/src/connector.rs b/crates/router/src/connector.rs
index d50086f548..9e7d5a9fea 100644
--- a/crates/router/src/connector.rs
+++ b/crates/router/src/connector.rs
@@ -3,17 +3,18 @@ pub mod utils;
#[cfg(feature = "dummy_connector")]
pub use hyperswitch_connectors::connectors::DummyConnector;
pub use hyperswitch_connectors::connectors::{
- aci, aci::Aci, adyen, adyen::Adyen, adyenplatform, adyenplatform::Adyenplatform, airwallex,
- airwallex::Airwallex, amazonpay, amazonpay::Amazonpay, archipel, archipel::Archipel, authipay,
- authipay::Authipay, authorizedotnet, authorizedotnet::Authorizedotnet, bambora,
- bambora::Bambora, bamboraapac, bamboraapac::Bamboraapac, bankofamerica,
- bankofamerica::Bankofamerica, barclaycard, barclaycard::Barclaycard, billwerk,
- billwerk::Billwerk, bitpay, bitpay::Bitpay, bluesnap, bluesnap::Bluesnap, boku, boku::Boku,
- braintree, braintree::Braintree, cashtocode, cashtocode::Cashtocode, celero, celero::Celero,
- chargebee, chargebee::Chargebee, checkbook, checkbook::Checkbook, checkout, checkout::Checkout,
- coinbase, coinbase::Coinbase, coingate, coingate::Coingate, cryptopay, cryptopay::Cryptopay,
- ctp_mastercard, ctp_mastercard::CtpMastercard, cybersource, cybersource::Cybersource,
- datatrans, datatrans::Datatrans, deutschebank, deutschebank::Deutschebank, digitalvirgo,
+ aci, aci::Aci, adyen, adyen::Adyen, adyenplatform, adyenplatform::Adyenplatform, affirm,
+ affirm::Affirm, airwallex, airwallex::Airwallex, amazonpay, amazonpay::Amazonpay, archipel,
+ archipel::Archipel, authipay, authipay::Authipay, authorizedotnet,
+ authorizedotnet::Authorizedotnet, bambora, bambora::Bambora, bamboraapac,
+ bamboraapac::Bamboraapac, bankofamerica, bankofamerica::Bankofamerica, barclaycard,
+ barclaycard::Barclaycard, billwerk, billwerk::Billwerk, bitpay, bitpay::Bitpay, bluesnap,
+ bluesnap::Bluesnap, boku, boku::Boku, braintree, braintree::Braintree, cashtocode,
+ cashtocode::Cashtocode, celero, celero::Celero, chargebee, chargebee::Chargebee, checkbook,
+ checkbook::Checkbook, checkout, checkout::Checkout, coinbase, coinbase::Coinbase, coingate,
+ coingate::Coingate, cryptopay, cryptopay::Cryptopay, ctp_mastercard,
+ ctp_mastercard::CtpMastercard, cybersource, cybersource::Cybersource, datatrans,
+ datatrans::Datatrans, deutschebank, deutschebank::Deutschebank, digitalvirgo,
digitalvirgo::Digitalvirgo, dlocal, dlocal::Dlocal, dwolla, dwolla::Dwolla, ebanx,
ebanx::Ebanx, elavon, elavon::Elavon, facilitapay, facilitapay::Facilitapay, fiserv,
fiserv::Fiserv, fiservemea, fiservemea::Fiservemea, fiuu, fiuu::Fiuu, forte, forte::Forte,
diff --git a/crates/router/tests/connectors/affirm.rs b/crates/router/tests/connectors/affirm.rs
new file mode 100644
index 0000000000..dfabb854ff
--- /dev/null
+++ b/crates/router/tests/connectors/affirm.rs
@@ -0,0 +1,421 @@
+use hyperswitch_domain_models::payment_method_data::{Card, PaymentMethodData};
+use masking::Secret;
+use router::types::{self, api, storage::enums};
+use test_utils::connector_auth;
+
+use crate::utils::{self, ConnectorActions};
+
+#[derive(Clone, Copy)]
+struct AffirmTest;
+impl ConnectorActions for AffirmTest {}
+impl utils::Connector for AffirmTest {
+ fn get_data(&self) -> api::ConnectorData {
+ use router::connector::Affirm;
+ utils::construct_connector_data_old(
+ Box::new(Affirm::new()),
+ types::Connector::Plaid,
+ api::GetToken::Connector,
+ None,
+ )
+ }
+
+ fn get_auth_token(&self) -> types::ConnectorAuthType {
+ utils::to_connector_auth_type(
+ connector_auth::ConnectorAuthentication::new()
+ .affirm
+ .expect("Missing connector authentication configuration")
+ .into(),
+ )
+ }
+
+ fn get_name(&self) -> String {
+ "affirm".to_string()
+ }
+}
+
+static CONNECTOR: AffirmTest = AffirmTest {};
+
+fn get_default_payment_info() -> Option<utils::PaymentInfo> {
+ None
+}
+
+fn payment_method_details() -> Option<types::PaymentsAuthorizeData> {
+ None
+}
+
+// Cards Positive Tests
+// Creates a payment using the manual capture flow (Non 3DS).
+#[actix_web::test]
+async fn should_only_authorize_payment() {
+ let response = CONNECTOR
+ .authorize_payment(payment_method_details(), get_default_payment_info())
+ .await
+ .expect("Authorize payment response");
+ assert_eq!(response.status, enums::AttemptStatus::Authorized);
+}
+
+// Captures a payment using the manual capture flow (Non 3DS).
+#[actix_web::test]
+async fn should_capture_authorized_payment() {
+ let response = CONNECTOR
+ .authorize_and_capture_payment(payment_method_details(), None, get_default_payment_info())
+ .await
+ .expect("Capture payment response");
+ assert_eq!(response.status, enums::AttemptStatus::Charged);
+}
+
+// Partially captures a payment using the manual capture flow (Non 3DS).
+#[actix_web::test]
+async fn should_partially_capture_authorized_payment() {
+ let response = CONNECTOR
+ .authorize_and_capture_payment(
+ payment_method_details(),
+ Some(types::PaymentsCaptureData {
+ amount_to_capture: 50,
+ ..utils::PaymentCaptureType::default().0
+ }),
+ get_default_payment_info(),
+ )
+ .await
+ .expect("Capture payment response");
+ assert_eq!(response.status, enums::AttemptStatus::Charged);
+}
+
+// Synchronizes a payment using the manual capture flow (Non 3DS).
+#[actix_web::test]
+async fn should_sync_authorized_payment() {
+ let authorize_response = CONNECTOR
+ .authorize_payment(payment_method_details(), get_default_payment_info())
+ .await
+ .expect("Authorize payment response");
+ let txn_id = utils::get_connector_transaction_id(authorize_response.response);
+ let response = CONNECTOR
+ .psync_retry_till_status_matches(
+ enums::AttemptStatus::Authorized,
+ Some(types::PaymentsSyncData {
+ connector_transaction_id: types::ResponseId::ConnectorTransactionId(
+ txn_id.unwrap(),
+ ),
+ ..Default::default()
+ }),
+ get_default_payment_info(),
+ )
+ .await
+ .expect("PSync response");
+ assert_eq!(response.status, enums::AttemptStatus::Authorized,);
+}
+
+// Voids a payment using the manual capture flow (Non 3DS).
+#[actix_web::test]
+async fn should_void_authorized_payment() {
+ let response = CONNECTOR
+ .authorize_and_void_payment(
+ payment_method_details(),
+ Some(types::PaymentsCancelData {
+ connector_transaction_id: String::from(""),
+ cancellation_reason: Some("requested_by_customer".to_string()),
+ ..Default::default()
+ }),
+ get_default_payment_info(),
+ )
+ .await
+ .expect("Void payment response");
+ assert_eq!(response.status, enums::AttemptStatus::Voided);
+}
+
+// Refunds a payment using the manual capture flow (Non 3DS).
+#[actix_web::test]
+async fn should_refund_manually_captured_payment() {
+ let response = CONNECTOR
+ .capture_payment_and_refund(
+ payment_method_details(),
+ None,
+ None,
+ get_default_payment_info(),
+ )
+ .await
+ .unwrap();
+ assert_eq!(
+ response.response.unwrap().refund_status,
+ enums::RefundStatus::Success,
+ );
+}
+
+// Partially refunds a payment using the manual capture flow (Non 3DS).
+#[actix_web::test]
+async fn should_partially_refund_manually_captured_payment() {
+ let response = CONNECTOR
+ .capture_payment_and_refund(
+ payment_method_details(),
+ None,
+ Some(types::RefundsData {
+ refund_amount: 50,
+ ..utils::PaymentRefundType::default().0
+ }),
+ get_default_payment_info(),
+ )
+ .await
+ .unwrap();
+ assert_eq!(
+ response.response.unwrap().refund_status,
+ enums::RefundStatus::Success,
+ );
+}
+
+// Synchronizes a refund using the manual capture flow (Non 3DS).
+#[actix_web::test]
+async fn should_sync_manually_captured_refund() {
+ let refund_response = CONNECTOR
+ .capture_payment_and_refund(
+ payment_method_details(),
+ None,
+ None,
+ get_default_payment_info(),
+ )
+ .await
+ .unwrap();
+ let response = CONNECTOR
+ .rsync_retry_till_status_matches(
+ enums::RefundStatus::Success,
+ refund_response.response.unwrap().connector_refund_id,
+ None,
+ get_default_payment_info(),
+ )
+ .await
+ .unwrap();
+ assert_eq!(
+ response.response.unwrap().refund_status,
+ enums::RefundStatus::Success,
+ );
+}
+
+// Creates a payment using the automatic capture flow (Non 3DS).
+#[actix_web::test]
+async fn should_make_payment() {
+ let authorize_response = CONNECTOR
+ .make_payment(payment_method_details(), get_default_payment_info())
+ .await
+ .unwrap();
+ assert_eq!(authorize_response.status, enums::AttemptStatus::Charged);
+}
+
+// Synchronizes a payment using the automatic capture flow (Non 3DS).
+#[actix_web::test]
+async fn should_sync_auto_captured_payment() {
+ let authorize_response = CONNECTOR
+ .make_payment(payment_method_details(), get_default_payment_info())
+ .await
+ .unwrap();
+ assert_eq!(authorize_response.status, enums::AttemptStatus::Charged);
+ let txn_id = utils::get_connector_transaction_id(authorize_response.response);
+ assert_ne!(txn_id, None, "Empty connector transaction id");
+ let response = CONNECTOR
+ .psync_retry_till_status_matches(
+ enums::AttemptStatus::Charged,
+ Some(types::PaymentsSyncData {
+ connector_transaction_id: types::ResponseId::ConnectorTransactionId(
+ txn_id.unwrap(),
+ ),
+ capture_method: Some(enums::CaptureMethod::Automatic),
+ ..Default::default()
+ }),
+ get_default_payment_info(),
+ )
+ .await
+ .unwrap();
+ assert_eq!(response.status, enums::AttemptStatus::Charged,);
+}
+
+// Refunds a payment using the automatic capture flow (Non 3DS).
+#[actix_web::test]
+async fn should_refund_auto_captured_payment() {
+ let response = CONNECTOR
+ .make_payment_and_refund(payment_method_details(), None, get_default_payment_info())
+ .await
+ .unwrap();
+ assert_eq!(
+ response.response.unwrap().refund_status,
+ enums::RefundStatus::Success,
+ );
+}
+
+// Partially refunds a payment using the automatic capture flow (Non 3DS).
+#[actix_web::test]
+async fn should_partially_refund_succeeded_payment() {
+ let refund_response = CONNECTOR
+ .make_payment_and_refund(
+ payment_method_details(),
+ Some(types::RefundsData {
+ refund_amount: 50,
+ ..utils::PaymentRefundType::default().0
+ }),
+ get_default_payment_info(),
+ )
+ .await
+ .unwrap();
+ assert_eq!(
+ refund_response.response.unwrap().refund_status,
+ enums::RefundStatus::Success,
+ );
+}
+
+// Creates multiple refunds against a payment using the automatic capture flow (Non 3DS).
+#[actix_web::test]
+async fn should_refund_succeeded_payment_multiple_times() {
+ CONNECTOR
+ .make_payment_and_multiple_refund(
+ payment_method_details(),
+ Some(types::RefundsData {
+ refund_amount: 50,
+ ..utils::PaymentRefundType::default().0
+ }),
+ get_default_payment_info(),
+ )
+ .await;
+}
+
+// Synchronizes a refund using the automatic capture flow (Non 3DS).
+#[actix_web::test]
+async fn should_sync_refund() {
+ let refund_response = CONNECTOR
+ .make_payment_and_refund(payment_method_details(), None, get_default_payment_info())
+ .await
+ .unwrap();
+ let response = CONNECTOR
+ .rsync_retry_till_status_matches(
+ enums::RefundStatus::Success,
+ refund_response.response.unwrap().connector_refund_id,
+ None,
+ get_default_payment_info(),
+ )
+ .await
+ .unwrap();
+ assert_eq!(
+ response.response.unwrap().refund_status,
+ enums::RefundStatus::Success,
+ );
+}
+
+// Cards Negative scenarios
+// Creates a payment with incorrect CVC.
+#[actix_web::test]
+async fn should_fail_payment_for_incorrect_cvc() {
+ let response = CONNECTOR
+ .make_payment(
+ Some(types::PaymentsAuthorizeData {
+ payment_method_data: PaymentMethodData::Card(Card {
+ card_cvc: Secret::new("12345".to_string()),
+ ..utils::CCardType::default().0
+ }),
+ ..utils::PaymentAuthorizeType::default().0
+ }),
+ get_default_payment_info(),
+ )
+ .await
+ .unwrap();
+ assert_eq!(
+ response.response.unwrap_err().message,
+ "Your card's security code is invalid.".to_string(),
+ );
+}
+
+// Creates a payment with incorrect expiry month.
+#[actix_web::test]
+async fn should_fail_payment_for_invalid_exp_month() {
+ let response = CONNECTOR
+ .make_payment(
+ Some(types::PaymentsAuthorizeData {
+ payment_method_data: PaymentMethodData::Card(Card {
+ card_exp_month: Secret::new("20".to_string()),
+ ..utils::CCardType::default().0
+ }),
+ ..utils::PaymentAuthorizeType::default().0
+ }),
+ get_default_payment_info(),
+ )
+ .await
+ .unwrap();
+ assert_eq!(
+ response.response.unwrap_err().message,
+ "Your card's expiration month is invalid.".to_string(),
+ );
+}
+
+// Creates a payment with incorrect expiry year.
+#[actix_web::test]
+async fn should_fail_payment_for_incorrect_expiry_year() {
+ let response = CONNECTOR
+ .make_payment(
+ Some(types::PaymentsAuthorizeData {
+ payment_method_data: PaymentMethodData::Card(Card {
+ card_exp_year: Secret::new("2000".to_string()),
+ ..utils::CCardType::default().0
+ }),
+ ..utils::PaymentAuthorizeType::default().0
+ }),
+ get_default_payment_info(),
+ )
+ .await
+ .unwrap();
+ assert_eq!(
+ response.response.unwrap_err().message,
+ "Your card's expiration year is invalid.".to_string(),
+ );
+}
+
+// Voids a payment using automatic capture flow (Non 3DS).
+#[actix_web::test]
+async fn should_fail_void_payment_for_auto_capture() {
+ let authorize_response = CONNECTOR
+ .make_payment(payment_method_details(), get_default_payment_info())
+ .await
+ .unwrap();
+ assert_eq!(authorize_response.status, enums::AttemptStatus::Charged);
+ let txn_id = utils::get_connector_transaction_id(authorize_response.response);
+ assert_ne!(txn_id, None, "Empty connector transaction id");
+ let void_response = CONNECTOR
+ .void_payment(txn_id.unwrap(), None, get_default_payment_info())
+ .await
+ .unwrap();
+ assert_eq!(
+ void_response.response.unwrap_err().message,
+ "You cannot cancel this PaymentIntent because it has a status of succeeded."
+ );
+}
+
+// Captures a payment using invalid connector payment id.
+#[actix_web::test]
+async fn should_fail_capture_for_invalid_payment() {
+ let capture_response = CONNECTOR
+ .capture_payment("123456789".to_string(), None, get_default_payment_info())
+ .await
+ .unwrap();
+ assert_eq!(
+ capture_response.response.unwrap_err().message,
+ String::from("No such payment_intent: '123456789'")
+ );
+}
+
+// Refunds a payment with refund amount higher than payment amount.
+#[actix_web::test]
+async fn should_fail_for_refund_amount_higher_than_payment_amount() {
+ let response = CONNECTOR
+ .make_payment_and_refund(
+ payment_method_details(),
+ Some(types::RefundsData {
+ refund_amount: 150,
+ ..utils::PaymentRefundType::default().0
+ }),
+ get_default_payment_info(),
+ )
+ .await
+ .unwrap();
+ assert_eq!(
+ response.response.unwrap_err().message,
+ "Refund amount (₹1.50) is greater than charge amount (₹1.00)",
+ );
+}
+
+// Connector dependent test cases goes here
+
+// [#478]: add unit tests for non 3DS, wallets & webhooks in connector tests
diff --git a/crates/router/tests/connectors/main.rs b/crates/router/tests/connectors/main.rs
index 6206691809..a8a22b7ba1 100644
--- a/crates/router/tests/connectors/main.rs
+++ b/crates/router/tests/connectors/main.rs
@@ -9,6 +9,7 @@ use test_utils::connector_auth;
mod aci;
mod adyen;
mod adyenplatform;
+mod affirm;
mod airwallex;
mod amazonpay;
mod authorizedotnet;
diff --git a/crates/test_utils/src/connector_auth.rs b/crates/test_utils/src/connector_auth.rs
index 14e08be162..9025fc48c0 100644
--- a/crates/test_utils/src/connector_auth.rs
+++ b/crates/test_utils/src/connector_auth.rs
@@ -10,6 +10,7 @@ pub struct ConnectorAuthentication {
pub adyen: Option<BodyKey>,
#[cfg(feature = "payouts")]
pub adyenplatform: Option<HeaderKey>,
+ pub affirm: Option<HeaderKey>,
#[cfg(feature = "payouts")]
pub adyen: Option<SignatureKey>,
#[cfg(not(feature = "payouts"))]
diff --git a/loadtest/config/development.toml b/loadtest/config/development.toml
index 7f1d34749c..58196d18cf 100644
--- a/loadtest/config/development.toml
+++ b/loadtest/config/development.toml
@@ -76,6 +76,7 @@ hash_key = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
aci.base_url = "https://eu-test.oppwa.com/"
adyen.base_url = "https://checkout-test.adyen.com/"
adyenplatform.base_url = "https://balanceplatform-api-test.adyen.com/"
+affirm.base_url = "https://sandbox.affirm.com/api"
adyen.payout_base_url = "https://pal-test.adyen.com/"
adyen.dispute_base_url = "https://ca-test.adyen.com/"
airwallex.base_url = "https://api-demo.airwallex.com/"
diff --git a/scripts/add_connector.sh b/scripts/add_connector.sh
index 863906c7bd..6be58f422f 100755
--- a/scripts/add_connector.sh
+++ b/scripts/add_connector.sh
@@ -6,7 +6,7 @@ function find_prev_connector() {
git checkout $self
cp $self $self.tmp
# Add new connector to existing list and sort it
- connectors=(aci adyen adyenplatform airwallex amazonpay applepay archipel authipay authorizedotnet bambora bamboraapac bankofamerica barclaycard billwerk bitpay bluesnap boku braintree cashtocode celero chargebee checkbook checkout coinbase cryptopay ctp_visa cybersource datatrans deutschebank digitalvirgo dlocal dummyconnector dwolla ebanx elavon facilitapay fiserv fiservemea fiuu forte getnet globalpay globepay gocardless gpayments helcim hipay hyperswitch_vault iatapay inespay itaubank jpmorgan juspaythreedsserver klarna mifinity mollie moneris multisafepay netcetera nexinets nexixpay nomupay noon nordea novalnet nuvei opayo opennode paybox payeezy payload payme payone paypal paystack payu placetopay plaid powertranz prophetpay rapyd razorpay recurly redsys santander shift4 silverflow square stax stripe stripebilling taxjar threedsecureio thunes tokenio trustpay tsys unified_authentication_service vgs volt wellsfargo wellsfargopayout wise worldline worldpay worldpayvantiv worldpayxml xendit zsl "$1")
+ connectors=(aci adyen adyenplatform affirm airwallex amazonpay applepay archipel authipay authorizedotnet bambora bamboraapac bankofamerica barclaycard billwerk bitpay bluesnap boku braintree cashtocode celero chargebee checkbook checkout coinbase cryptopay ctp_visa cybersource datatrans deutschebank digitalvirgo dlocal dummyconnector dwolla ebanx elavon facilitapay fiserv fiservemea fiuu forte getnet globalpay globepay gocardless gpayments helcim hipay hyperswitch_vault iatapay inespay itaubank jpmorgan juspaythreedsserver klarna mifinity mollie moneris multisafepay netcetera nexinets nexixpay nomupay noon nordea novalnet nuvei opayo opennode paybox payeezy payload payme payone paypal paystack payu placetopay plaid powertranz prophetpay rapyd razorpay recurly redsys santander shift4 silverflow square stax stripe stripebilling taxjar threedsecureio thunes tokenio trustpay tsys unified_authentication_service vgs volt wellsfargo wellsfargopayout wise worldline worldpay worldpayvantiv worldpayxml xendit zsl "$1")
IFS=$'\n' sorted=($(sort <<<"${connectors[*]}")); unset IFS
res="$(echo ${sorted[@]})"