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

chore: introduce order create integration for nordea and payme (#10752)

Hrithikesh5aed4336d2e7
diff --git a/crates/hyperswitch_connectors/src/connectors/nordea.rs b/crates/hyperswitch_connectors/src/connectors/nordea.rs
index f33397ba99..44d007ec89 100644
--- a/crates/hyperswitch_connectors/src/connectors/nordea.rs
+++ b/crates/hyperswitch_connectors/src/connectors/nordea.rs
@@ -18,10 +18,10 @@ use hyperswitch_domain_models::{
access_token_auth::AccessTokenAuth,
payments::{Authorize, Capture, PSync, PaymentMethodToken, Session, SetupMandate, Void},
refunds::{Execute, RSync},
- AccessTokenAuthentication, PreProcessing,
+ AccessTokenAuthentication, CreateOrder, PreProcessing,
},
router_request_types::{
- AccessTokenAuthenticationRequestData, AccessTokenRequestData,
+ AccessTokenAuthenticationRequestData, AccessTokenRequestData, CreateOrderRequestData,
PaymentMethodTokenizationData, PaymentsAuthorizeData, PaymentsCancelData,
PaymentsCaptureData, PaymentsPreProcessingData, PaymentsSessionData, PaymentsSyncData,
RefundsData, SetupMandateRequestData,
@@ -31,7 +31,7 @@ use hyperswitch_domain_models::{
SupportedPaymentMethods, SupportedPaymentMethodsExt,
},
types::{
- AccessTokenAuthenticationRouterData, PaymentsAuthorizeRouterData,
+ AccessTokenAuthenticationRouterData, CreateOrderRouterData, PaymentsAuthorizeRouterData,
PaymentsPreProcessingRouterData, PaymentsSyncRouterData, RefreshTokenRouterData,
RefundsRouterData,
},
@@ -238,6 +238,7 @@ impl Nordea {
}
impl api::Payment for Nordea {}
+impl api::PaymentsCreateOrder for Nordea {}
impl api::PaymentSession for Nordea {}
impl api::ConnectorAuthenticationToken for Nordea {}
impl api::ConnectorAccessToken for Nordea {}
@@ -740,6 +741,117 @@ impl ConnectorIntegration<SetupMandate, SetupMandateRequestData, PaymentsRespons
}
}
+impl ConnectorIntegration<CreateOrder, CreateOrderRequestData, PaymentsResponseData> for Nordea {
+ fn get_headers(
+ &self,
+ req: &CreateOrderRouterData,
+ 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: &CreateOrderRouterData,
+ connectors: &Connectors,
+ ) -> CustomResult<String, errors::ConnectorError> {
+ // Determine the payment endpoint based on country and currency
+ let country = req.get_billing_country()?;
+
+ let currency = req.request.currency;
+
+ let endpoint = match (country, currency) {
+ (api_models::enums::CountryAlpha2::FI, api_models::enums::Currency::EUR) => {
+ "/personal/v5/payments/sepa-credit-transfers"
+ }
+ (api_models::enums::CountryAlpha2::DK, api_models::enums::Currency::DKK) => {
+ "/personal/v5/payments/domestic-credit-transfers"
+ }
+ (
+ api_models::enums::CountryAlpha2::FI
+ | api_models::enums::CountryAlpha2::DK
+ | api_models::enums::CountryAlpha2::SE
+ | api_models::enums::CountryAlpha2::NO,
+ _,
+ ) => "/personal/v5/payments/cross-border-credit-transfers",
+ _ => {
+ return Err(errors::ConnectorError::NotSupported {
+ message: format!("Country {country:?} is not supported by Nordea"),
+ connector: "Nordea",
+ }
+ .into())
+ }
+ };
+
+ Ok(format!("{}{}", self.base_url(connectors), endpoint))
+ }
+
+ fn get_request_body(
+ &self,
+ req: &CreateOrderRouterData,
+ _connectors: &Connectors,
+ ) -> CustomResult<RequestContent, errors::ConnectorError> {
+ let minor_amount = req.request.minor_amount;
+ let currency = req.request.currency;
+
+ let amount = utils::convert_amount(self.amount_converter, minor_amount, currency)?;
+ let connector_router_data = NordeaRouterData::from((amount, req));
+ let connector_req = NordeaPaymentsRequest::try_from(&connector_router_data)?;
+ Ok(RequestContent::Json(Box::new(connector_req)))
+ }
+
+ fn build_request(
+ &self,
+ req: &CreateOrderRouterData,
+ connectors: &Connectors,
+ ) -> CustomResult<Option<Request>, errors::ConnectorError> {
+ Ok(Some(
+ RequestBuilder::new()
+ .method(Method::Post)
+ .url(&types::CreateOrderType::get_url(self, req, connectors)?)
+ .attach_default_headers()
+ .headers(types::CreateOrderType::get_headers(self, req, connectors)?)
+ .set_body(types::CreateOrderType::get_request_body(
+ self, req, connectors,
+ )?)
+ .build(),
+ ))
+ }
+
+ fn handle_response(
+ &self,
+ data: &CreateOrderRouterData,
+ event_builder: Option<&mut ConnectorEvent>,
+ res: Response,
+ ) -> CustomResult<CreateOrderRouterData, errors::ConnectorError> {
+ let response: NordeaPaymentsInitiateResponse = res
+ .response
+ .parse_struct("NordeaPaymentsInitiateResponse")
+ .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<PreProcessing, PaymentsPreProcessingData, PaymentsResponseData>
for Nordea
{
diff --git a/crates/hyperswitch_connectors/src/connectors/nordea/transformers.rs b/crates/hyperswitch_connectors/src/connectors/nordea/transformers.rs
index 4546ec4035..aa912d0071 100644
--- a/crates/hyperswitch_connectors/src/connectors/nordea/transformers.rs
+++ b/crates/hyperswitch_connectors/src/connectors/nordea/transformers.rs
@@ -9,8 +9,8 @@ use hyperswitch_domain_models::{
router_request_types::{PaymentsAuthorizeData, PaymentsPreProcessingData, ResponseId},
router_response_types::{PaymentsResponseData, RedirectForm},
types::{
- self, AccessTokenAuthenticationRouterData, PaymentsAuthorizeRouterData,
- PaymentsPreProcessingRouterData, PaymentsSyncRouterData,
+ self, AccessTokenAuthenticationRouterData, CreateOrderRouterData,
+ PaymentsAuthorizeRouterData, PaymentsPreProcessingRouterData, PaymentsSyncRouterData,
},
};
use hyperswitch_interfaces::errors;
@@ -31,7 +31,8 @@ use crate::{
},
},
types::{
- PaymentsPreprocessingResponseRouterData, PaymentsSyncResponseRouterData, ResponseRouterData,
+ CreateOrderResponseRouterData, PaymentsPreprocessingResponseRouterData,
+ PaymentsSyncResponseRouterData, ResponseRouterData,
},
utils::{self, get_unimplemented_payment_method_error_message, RouterData as _},
};
@@ -253,6 +254,117 @@ fn get_creditor_account_from_metadata(
Ok(creditor_account)
}
+fn get_creditor_account_from_metadata_for_create_order(
+ router_data: &CreateOrderRouterData,
+) -> Result<CreditorAccount, Error> {
+ let metadata: NordeaConnectorMetadataObject =
+ utils::to_connector_meta_from_secret(router_data.connector_meta_data.clone())
+ .change_context(errors::ConnectorError::InvalidConnectorConfig {
+ config: "merchant_connector_account.metadata",
+ })?;
+ let creditor_account = CreditorAccount {
+ account: AccountNumber {
+ account_type: AccountType::try_from(metadata.account_type.as_str())
+ .unwrap_or(AccountType::Iban),
+ currency: Some(router_data.request.currency),
+ value: metadata.destination_account_number,
+ },
+ country: router_data.get_optional_billing_country(),
+ // Merchant is the beneficiary in this case
+ name: Some(metadata.merchant_name),
+ message: router_data
+ .description
+ .as_ref()
+ .map(|desc| desc.chars().take(20).collect::<String>()),
+ bank: Some(CreditorBank {
+ address: None,
+ bank_code: None,
+ bank_name: None,
+ business_identifier_code: None,
+ country: router_data.get_billing_country()?,
+ }),
+ creditor_address: None,
+ // Either Reference or Message must be supplied in the request
+ reference: None,
+ };
+ Ok(creditor_account)
+}
+
+impl TryFrom<&NordeaRouterData<&CreateOrderRouterData>> for NordeaPaymentsRequest {
+ type Error = Error;
+ fn try_from(item: &NordeaRouterData<&CreateOrderRouterData>) -> Result<Self, Self::Error> {
+ match item.router_data.request.payment_method_data.clone() {
+ Some(PaymentMethodData::BankDebit(bank_debit_data)) => match bank_debit_data {
+ BankDebitData::SepaBankDebit { iban, .. } => {
+ let creditor_account =
+ get_creditor_account_from_metadata_for_create_order(item.router_data)?;
+ let debitor_account = DebitorAccount {
+ account: AccountNumber {
+ account_type: AccountType::Iban,
+ currency: Some(item.router_data.request.currency),
+ value: iban,
+ },
+ message: item
+ .router_data
+ .description
+ .as_ref()
+ .map(|desc| desc.chars().take(20).collect::<String>()),
+ };
+
+ let instructed_amount = super::requests::InstructedAmount {
+ amount: item.amount.clone(),
+ currency: item.router_data.request.currency,
+ };
+
+ Ok(Self {
+ creditor_account,
+ debitor_account,
+ end_to_end_identification: None,
+ external_id: Some(item.router_data.connector_request_reference_id.clone()),
+ instructed_amount,
+ recurring: None,
+ request_availability_of_funds: None,
+ requested_execution_date: None,
+ tpp_messages: None,
+ urgency: None,
+ })
+ }
+ BankDebitData::AchBankDebit { .. }
+ | BankDebitData::BacsBankDebit { .. }
+ | BankDebitData::BecsBankDebit { .. }
+ | BankDebitData::SepaGuarenteedBankDebit { .. } => {
+ Err(errors::ConnectorError::NotImplemented(
+ get_unimplemented_payment_method_error_message("Nordea"),
+ )
+ .into())
+ }
+ },
+ Some(PaymentMethodData::CardRedirect(_))
+ | Some(PaymentMethodData::CardDetailsForNetworkTransactionId(_))
+ | Some(PaymentMethodData::NetworkTokenDetailsForNetworkTransactionId(_))
+ | Some(PaymentMethodData::Wallet(_))
+ | Some(PaymentMethodData::PayLater(_))
+ | Some(PaymentMethodData::BankRedirect(_))
+ | Some(PaymentMethodData::BankTransfer(_))
+ | Some(PaymentMethodData::Crypto(_))
+ | Some(PaymentMethodData::MandatePayment)
+ | Some(PaymentMethodData::Reward)
+ | Some(PaymentMethodData::RealTimePayment(_))
+ | Some(PaymentMethodData::MobilePayment(_))
+ | Some(PaymentMethodData::Upi(_))
+ | Some(PaymentMethodData::Voucher(_))
+ | Some(PaymentMethodData::GiftCard(_))
+ | Some(PaymentMethodData::OpenBanking(_))
+ | Some(PaymentMethodData::CardToken(_))
+ | Some(PaymentMethodData::NetworkToken(_))
+ | Some(PaymentMethodData::Card(_))
+ | None => {
+ Err(errors::ConnectorError::NotImplemented("Payment method".to_string()).into())
+ }
+ }
+ }
+}
+
impl TryFrom<&NordeaRouterData<&PaymentsPreProcessingRouterData>> for NordeaPaymentsRequest {
type Error = Error;
fn try_from(
@@ -425,6 +537,22 @@ impl TryFrom<PaymentsPreprocessingResponseRouterData<NordeaPaymentsInitiateRespo
}
}
+impl TryFrom<CreateOrderResponseRouterData<NordeaPaymentsInitiateResponse>>
+ for CreateOrderRouterData
+{
+ type Error = Error;
+ fn try_from(
+ item: CreateOrderResponseRouterData<NordeaPaymentsInitiateResponse>,
+ ) -> Result<Self, Self::Error> {
+ let (response, status) = convert_nordea_payment_response(&item.response)?;
+ Ok(Self {
+ status,
+ response: Ok(response),
+ ..item.data
+ })
+ }
+}
+
impl
TryFrom<
ResponseRouterData<
diff --git a/crates/hyperswitch_connectors/src/connectors/payme.rs b/crates/hyperswitch_connectors/src/connectors/payme.rs
index a7e7a50c47..84d713c610 100644
--- a/crates/hyperswitch_connectors/src/connectors/payme.rs
+++ b/crates/hyperswitch_connectors/src/connectors/payme.rs
@@ -21,21 +21,22 @@ use hyperswitch_domain_models::{
access_token_auth::AccessTokenAuth,
payments::{Authorize, Capture, PSync, PaymentMethodToken, Session, SetupMandate, Void},
refunds::{Execute, RSync},
- CompleteAuthorize, InitPayment, PreProcessing,
+ CompleteAuthorize, CreateOrder, InitPayment, PreProcessing,
},
router_request_types::{
- AccessTokenRequestData, CompleteAuthorizeData, PaymentMethodTokenizationData,
- PaymentsAuthorizeData, PaymentsCancelData, PaymentsCaptureData, PaymentsPreProcessingData,
- PaymentsSessionData, PaymentsSyncData, RefundsData, SetupMandateRequestData,
+ AccessTokenRequestData, CompleteAuthorizeData, CreateOrderRequestData,
+ PaymentMethodTokenizationData, PaymentsAuthorizeData, PaymentsCancelData,
+ PaymentsCaptureData, PaymentsPreProcessingData, PaymentsSessionData, PaymentsSyncData,
+ RefundsData, SetupMandateRequestData,
},
router_response_types::{
ConnectorInfo, PaymentMethodDetails, PaymentsResponseData, RefundsResponseData,
SupportedPaymentMethods, SupportedPaymentMethodsExt,
},
types::{
- PaymentsAuthorizeRouterData, PaymentsCancelRouterData, PaymentsCaptureRouterData,
- PaymentsCompleteAuthorizeRouterData, PaymentsPreProcessingRouterData, RefundsRouterData,
- TokenizationRouterData,
+ CreateOrderRouterData, PaymentsAuthorizeRouterData, PaymentsCancelRouterData,
+ PaymentsCaptureRouterData, PaymentsCompleteAuthorizeRouterData,
+ PaymentsPreProcessingRouterData, RefundsRouterData, TokenizationRouterData,
},
};
use hyperswitch_interfaces::{
@@ -48,7 +49,7 @@ use hyperswitch_interfaces::{
errors,
events::connector_api_logs::ConnectorEvent,
types::{
- PaymentsAuthorizeType, PaymentsCaptureType, PaymentsCompleteAuthorizeType,
+ CreateOrderType, PaymentsAuthorizeType, PaymentsCaptureType, PaymentsCompleteAuthorizeType,
PaymentsPreProcessingType, PaymentsSyncType, PaymentsVoidType, RefundExecuteType,
RefundSyncType, Response, TokenizationType,
},
@@ -80,6 +81,7 @@ impl Payme {
}
}
impl api::Payment for Payme {}
+impl api::PaymentsCreateOrder for Payme {}
impl api::PaymentSession for Payme {}
impl api::PaymentsCompleteAuthorize for Payme {}
impl api::ConnectorAccessToken for Payme {}
@@ -302,6 +304,108 @@ impl ConnectorIntegration<Session, PaymentsSessionData, PaymentsResponseData> fo
impl PaymentsPreProcessing for Payme {}
+impl ConnectorIntegration<CreateOrder, CreateOrderRequestData, PaymentsResponseData> for Payme {
+ fn get_headers(
+ &self,
+ req: &CreateOrderRouterData,
+ 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: &CreateOrderRouterData,
+ connectors: &Connectors,
+ ) -> CustomResult<String, errors::ConnectorError> {
+ Ok(format!("{}api/generate-sale", self.base_url(connectors)))
+ }
+
+ fn get_request_body(
+ &self,
+ req: &CreateOrderRouterData,
+ _connectors: &Connectors,
+ ) -> CustomResult<RequestContent, errors::ConnectorError> {
+ let req_amount = req.request.minor_amount;
+ let req_currency = req.request.currency;
+ let amount = utils::convert_amount(self.amount_converter, req_amount, req_currency)?;
+ let connector_router_data = payme::PaymeRouterData::try_from((amount, req))?;
+ let connector_req = payme::GenerateSaleRequest::try_from(&connector_router_data)?;
+ Ok(RequestContent::Json(Box::new(connector_req)))
+ }
+
+ fn build_request(
+ &self,
+ req: &CreateOrderRouterData,
+ connectors: &Connectors,
+ ) -> CustomResult<Option<Request>, errors::ConnectorError> {
+ let req = Some(
+ RequestBuilder::new()
+ .method(Method::Post)
+ .attach_default_headers()
+ .headers(CreateOrderType::get_headers(self, req, connectors)?)
+ .url(&CreateOrderType::get_url(self, req, connectors)?)
+ .set_body(CreateOrderType::get_request_body(self, req, connectors)?)
+ .build(),
+ );
+ Ok(req)
+ }
+
+ fn handle_response(
+ &self,
+ data: &CreateOrderRouterData,
+ event_builder: Option<&mut ConnectorEvent>,
+ res: Response,
+ ) -> CustomResult<CreateOrderRouterData, errors::ConnectorError> {
+ let response: payme::GenerateSaleResponse = res
+ .response
+ .parse_struct("Payme GenerateSaleResponse")
+ .change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
+
+ let req_amount = data.request.minor_amount;
+ let req_currency = data.request.currency;
+
+ let apple_pay_amount = utils::convert_amount(
+ self.apple_pay_google_pay_amount_converter,
+ req_amount,
+ req_currency,
+ )?;
+
+ event_builder.map(|i| i.set_response_body(&response));
+ router_env::logger::info!(connector_response=?response);
+
+ RouterData::foreign_try_from((
+ ResponseRouterData {
+ response,
+ data: data.clone(),
+ http_code: res.status_code,
+ },
+ apple_pay_amount,
+ ))
+ }
+
+ fn get_error_response(
+ &self,
+ res: Response,
+ event_builder: Option<&mut ConnectorEvent>,
+ ) -> CustomResult<ErrorResponse, errors::ConnectorError> {
+ self.build_error_response(res, event_builder)
+ }
+
+ fn get_5xx_error_response(
+ &self,
+ res: Response,
+ event_builder: Option<&mut ConnectorEvent>,
+ ) -> CustomResult<ErrorResponse, errors::ConnectorError> {
+ // we are always getting 500 in error scenarios
+ self.build_error_response(res, event_builder)
+ }
+}
+
impl ConnectorIntegration<PreProcessing, PaymentsPreProcessingData, PaymentsResponseData>
for Payme
{
diff --git a/crates/hyperswitch_connectors/src/connectors/payme/transformers.rs b/crates/hyperswitch_connectors/src/connectors/payme/transformers.rs
index 0fef9f53da..ab5bb93c2e 100644
--- a/crates/hyperswitch_connectors/src/connectors/payme/transformers.rs
+++ b/crates/hyperswitch_connectors/src/connectors/payme/transformers.rs
@@ -3,6 +3,7 @@ use std::collections::HashMap;
use api_models::enums::{AuthenticationType, PaymentMethod};
use common_enums::enums;
use common_utils::{
+ ext_traits::OptionExt,
pii,
types::{MinorUnit, StringMajorUnit},
};
@@ -11,15 +12,18 @@ use hyperswitch_domain_models::{
payment_method_data::{PaymentMethodData, WalletData},
router_data::{ConnectorAuthType, ErrorResponse, PaymentMethodToken, RouterData},
router_flow_types::{Execute, Void},
- router_request_types::{PaymentsCancelData, PaymentsPreProcessingData, ResponseId},
+ router_request_types::{
+ CreateOrderRequestData, PaymentsCancelData, PaymentsPreProcessingData, ResponseId,
+ },
router_response_types::{
MandateReference, PaymentsResponseData, PreprocessingResponseId, RedirectForm,
RefundsResponseData,
},
types::{
- PaymentsAuthorizeRouterData, PaymentsCancelRouterData, PaymentsCaptureRouterData,
- PaymentsCompleteAuthorizeRouterData, PaymentsPreProcessingRouterData,
- PaymentsSyncRouterData, RefundSyncRouterData, RefundsRouterData, TokenizationRouterData,
+ CreateOrderRouterData, PaymentsAuthorizeRouterData, PaymentsCancelRouterData,
+ PaymentsCaptureRouterData, PaymentsCompleteAuthorizeRouterData,
+ PaymentsPreProcessingRouterData, PaymentsSyncRouterData, RefundSyncRouterData,
+ RefundsRouterData, TokenizationRouterData,
},
};
use hyperswitch_interfaces::{consts, errors};
@@ -356,6 +360,67 @@ pub enum SalePaymentMethod {
ApplePay,
}
+impl TryFrom<&PaymeRouterData<&CreateOrderRouterData>> for GenerateSaleRequest {
+ type Error = error_stack::Report<errors::ConnectorError>;
+ fn try_from(item: &PaymeRouterData<&CreateOrderRouterData>) -> Result<Self, Self::Error> {
+ let sale_type = SaleType::try_from(item.router_data)?;
+ let seller_payme_id =
+ PaymeAuthType::try_from(&item.router_data.connector_auth_type)?.seller_payme_id;
+ let order_details = item
+ .router_data
+ .request
+ .order_details
+ .clone()
+ .get_required_value("order_details")
+ .change_context(errors::ConnectorError::MissingRequiredField {
+ field_name: "order_details",
+ })?;
+ let services = get_services(item.router_data.auth_type);
+ let product_name = order_details
+ .first()
+ .ok_or_else(utils::missing_field_err("order_details"))?
+ .product_name
+ .clone();
+ let pmd = item
+ .router_data
+ .request
+ .payment_method_data
+ .to_owned()
+ .ok_or_else(utils::missing_field_err("payment_method_data"))?;
+ let sale_return_url = item
+ .router_data
+ .request
+ .router_return_url
+ .clone()
+ .get_required_value("router_return_url")
+ .change_context(errors::ConnectorError::MissingRequiredField {
+ field_name: "router_return_url",
+ })?;
+ let sale_callback_url = item
+ .router_data
+ .request
+ .webhook_url
+ .clone()
+ .get_required_value("webhook_url")
+ .change_context(errors::ConnectorError::MissingRequiredField {
+ field_name: "webhook_url",
+ })?;
+ Ok(Self {
+ seller_payme_id,
+ sale_price: item.amount.to_owned(),
+ currency: item.router_data.request.currency,
+ product_name,
+ sale_payment_method: SalePaymentMethod::try_from(&pmd)?,
+ sale_type,
+ transaction_id: item.router_data.payment_id.clone(),
+ sale_return_url,
+ sale_callback_url,
+ language: LANGUAGE.to_string(),
+ services,
+ })
+ }
+}
+
impl TryFrom<&PaymeRouterData<&PaymentsPreProcessingRouterData>> for GenerateSaleRequest {
type Error = error_stack::Report<errors::ConnectorError>;
fn try_from(
@@ -365,7 +430,7 @@ impl TryFrom<&PaymeRouterData<&PaymentsPreProcessingRouterData>> for GenerateSal
let seller_payme_id =
PaymeAuthType::try_from(&item.router_data.connector_auth_type)?.seller_payme_id;
let order_details = item.router_data.request.get_order_details()?;
- let services = get_services(item.router_data);
+ let services = get_services(item.router_data.auth_type);
let product_name = order_details
.first()
.ok_or_else(utils::missing_field_err("order_details"))?
@@ -633,6 +698,132 @@ impl<F>
}
}
+impl<F>
+ utils::ForeignTryFrom<(
+ ResponseRouterData<F, GenerateSaleResponse, CreateOrderRequestData, PaymentsResponseData>,
+ StringMajorUnit,
+ )> for RouterData<F, CreateOrderRequestData, PaymentsResponseData>
+{
+ type Error = error_stack::Report<errors::ConnectorError>;
+ fn foreign_try_from(
+ (item, apple_pay_amount): (
+ ResponseRouterData<
+ F,
+ GenerateSaleResponse,
+ CreateOrderRequestData,
+ PaymentsResponseData,
+ >,
+ StringMajorUnit,
+ ),
+ ) -> Result<Self, Self::Error> {
+ match item.data.payment_method {
+ PaymentMethod::Card => {
+ match item.data.auth_type {
+ AuthenticationType::NoThreeDs => {
+ Ok(Self {
+ // We don't get any status from payme, so defaulting it to pending
+ // then move to authorize flow
+ status: enums::AttemptStatus::Pending,
+ preprocessing_id: Some(item.response.payme_sale_id.to_owned()),
+ response: Ok(PaymentsResponseData::PreProcessingResponse {
+ pre_processing_id: PreprocessingResponseId::ConnectorTransactionId(
+ item.response.payme_sale_id,
+ ),
+ connector_metadata: None,
+ session_token: None,
+ connector_response_reference_id: None,
+ }),
+ ..item.data
+ })
+ }
+ AuthenticationType::ThreeDs => Ok(Self {
+ // We don't go to authorize flow in 3ds,
+ // Response is send directly after preprocessing flow
+ // redirection data is send to run script along
+ // status is made authentication_pending to show redirection
+ status: enums::AttemptStatus::AuthenticationPending,
+ preprocessing_id: Some(item.response.payme_sale_id.to_owned()),
+ response: Ok(PaymentsResponseData::TransactionResponse {
+ resource_id: ResponseId::ConnectorTransactionId(
+ item.response.payme_sale_id.to_owned(),
+ ),
+ redirection_data: Box::new(Some(RedirectForm::Payme)),
+ 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
+ }),
+ }
+ }
+ _ => {
+ let currency_code = item.data.request.currency;
+ let pmd = item.data.request.payment_method_data.to_owned();
+ let payme_auth_type = PaymeAuthType::try_from(&item.data.connector_auth_type)?;
+
+ let session_token = match pmd {
+ Some(PaymentMethodData::Wallet(WalletData::ApplePayThirdPartySdk(
+ _,
+ ))) => Some(api_models::payments::SessionToken::ApplePay(Box::new(
+ api_models::payments::ApplepaySessionTokenResponse {
+ session_token_data: Some(
+ api_models::payments::ApplePaySessionResponse::NoSessionResponse(api_models::payments::NullObject),
+ ),
+ payment_request_data: Some(
+ api_models::payments::ApplePayPaymentRequest {
+ country_code: item.data.get_billing_country()?,
+ currency_code,
+ total: api_models::payments::AmountInfo {
+ label: "Apple Pay".to_string(),
+ total_type: None,
+ amount: apple_pay_amount,
+ },
+ merchant_capabilities: None,
+ supported_networks: None,
+ merchant_identifier: None,
+ required_billing_contact_fields: None,
+ required_shipping_contact_fields: None,
+ recurring_payment_request: None,
+ },
+ ),
+ connector: "payme".to_string(),
+ delayed_session_token: true,
+ sdk_next_action: api_models::payments::SdkNextAction {
+ next_action: api_models::payments::NextActionCall::Sync,
+ },
+ connector_reference_id: Some(item.response.payme_sale_id.to_owned()),
+ connector_sdk_public_key: Some(
+ payme_auth_type.payme_public_key.expose(),
+ ),
+ connector_merchant_id: payme_auth_type
+ .payme_merchant_id
+ .map(|mid| mid.expose()),
+ },
+ ))),
+ _ => None,
+ };
+ Ok(Self {
+ // We don't get any status from payme, so defaulting it to pending
+ status: enums::AttemptStatus::Pending,
+ preprocessing_id: Some(item.response.payme_sale_id.to_owned()),
+ response: Ok(PaymentsResponseData::PreProcessingResponse {
+ pre_processing_id: PreprocessingResponseId::ConnectorTransactionId(
+ item.response.payme_sale_id,
+ ),
+ connector_metadata: None,
+ session_token,
+ connector_response_reference_id: None,
+ }),
+ ..item.data
+ })
+ }
+ }
+ }
+}
+
impl TryFrom<&PaymeRouterData<&PaymentsAuthorizeRouterData>> for MandateRequest {
type Error = error_stack::Report<errors::ConnectorError>;
fn try_from(item: &PaymeRouterData<&PaymentsAuthorizeRouterData>) -> Result<Self, Self::Error> {
@@ -857,6 +1048,23 @@ impl TryFrom<&ConnectorAuthType> for PaymeAuthType {
}
}
+impl TryFrom<&CreateOrderRouterData> for SaleType {
+ type Error = error_stack::Report<errors::ConnectorError>;
+ fn try_from(value: &CreateOrderRouterData) -> Result<Self, Self::Error> {
+ let sale_type = if value.request.setup_mandate_details.is_some() {
+ // First mandate
+ Self::Token
+ } else {
+ // Normal payments
+ match value.request.is_auto_capture() {
+ true => Self::Sale,
+ false => Self::Authorize,
+ }
+ };
+ Ok(sale_type)
+ }
+}
+
impl TryFrom<&PaymentsPreProcessingRouterData> for SaleType {
type Error = error_stack::Report<errors::ConnectorError>;
fn try_from(value: &PaymentsPreProcessingRouterData) -> Result<Self, Self::Error> {
@@ -1201,8 +1409,8 @@ impl<F, T> TryFrom<ResponseRouterData<F, PaymeQueryTransactionResponse, T, Refun
}
}
-fn get_services(item: &PaymentsPreProcessingRouterData) -> Option<ThreeDs> {
- match item.auth_type {
+fn get_services(auth_type: AuthenticationType) -> Option<ThreeDs> {
+ match auth_type {
AuthenticationType::ThreeDs => {
let settings = ThreeDsSettings { active: true };
Some(ThreeDs {
diff --git a/crates/hyperswitch_connectors/src/default_implementations.rs b/crates/hyperswitch_connectors/src/default_implementations.rs
index 1aefda7970..7c7959a433 100644
--- a/crates/hyperswitch_connectors/src/default_implementations.rs
+++ b/crates/hyperswitch_connectors/src/default_implementations.rs
@@ -861,7 +861,6 @@ default_imp_for_create_order!(
connectors::Nmi,
connectors::Nomupay,
connectors::Noon,
- connectors::Nordea,
connectors::Novalnet,
connectors::Nexinets,
connectors::Nexixpay,
@@ -873,7 +872,6 @@ default_imp_for_create_order!(
connectors::Payjustnow,
connectors::Payjustnowinstore,
connectors::Payload,
- connectors::Payme,
connectors::Payone,
connectors::Paypal,
connectors::Paysafe,
diff --git a/crates/hyperswitch_domain_models/src/router_request_types.rs b/crates/hyperswitch_domain_models/src/router_request_types.rs
index 6091b29d27..8d9c42618f 100644
--- a/crates/hyperswitch_domain_models/src/router_request_types.rs
+++ b/crates/hyperswitch_domain_models/src/router_request_types.rs
@@ -541,6 +541,23 @@ pub struct CreateOrderRequestData {
pub currency: storage_enums::Currency,
pub payment_method_data: Option<PaymentMethodData>,
pub order_details: Option<Vec<OrderDetailsWithAmount>>,
+ pub webhook_url: Option<String>,
+ pub router_return_url: Option<String>,
+ pub setup_mandate_details: Option<mandates::MandateData>,
+ pub capture_method: Option<storage_enums::CaptureMethod>,
+}
+
+impl CreateOrderRequestData {
+ pub fn is_auto_capture(&self) -> bool {
+ match self.capture_method {
+ Some(storage_enums::CaptureMethod::Automatic)
+ | Some(storage_enums::CaptureMethod::SequentialAutomatic)
+ | None => true,
+ Some(storage_enums::CaptureMethod::Manual)
+ | Some(storage_enums::CaptureMethod::ManualMultiple)
+ | Some(storage_enums::CaptureMethod::Scheduled) => false,
+ }
+ }
}
impl TryFrom<PaymentsAuthorizeData> for CreateOrderRequestData {
@@ -552,6 +569,10 @@ impl TryFrom<PaymentsAuthorizeData> for CreateOrderRequestData {
currency: data.currency,
payment_method_data: Some(data.payment_method_data),
order_details: data.order_details,
+ webhook_url: data.webhook_url,
+ router_return_url: data.router_return_url,
+ setup_mandate_details: data.setup_mandate_details,
+ capture_method: data.capture_method,
})
}
}
@@ -565,6 +586,10 @@ impl TryFrom<ExternalVaultProxyPaymentsData> for CreateOrderRequestData {
currency: data.currency,
payment_method_data: None,
order_details: data.order_details,
+ webhook_url: data.webhook_url,
+ router_return_url: data.router_return_url,
+ setup_mandate_details: data.setup_mandate_details,
+ capture_method: data.capture_method,
})
}
}