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(core): Add Peachpayments Data Inside connector_metadata in Payments Request (#11059)

Anurag6e6cae51fd60
diff --git a/api-reference/v1/openapi_spec_v1.json b/api-reference/v1/openapi_spec_v1.json
index 3dcfe16d35..34cb2f5cb3 100644
--- a/api-reference/v1/openapi_spec_v1.json
+++ b/api-reference/v1/openapi_spec_v1.json
@@ -15186,6 +15186,14 @@
}
],
"nullable": true
+ },
+ "peachpayments": {
+ "allOf": [
+ {
+ "$ref": "#/components/schemas/PeachpaymentsData"
+ }
+ ],
+ "nullable": true
}
}
},
@@ -33343,6 +33351,16 @@
}
}
},
+ "PeachpaymentsData": {
+ "type": "object",
+ "properties": {
+ "rrn": {
+ "type": "string",
+ "description": "A numeric reference number supplied by the system retaining the original source information and used to assist in locating that information or a copy thereof.",
+ "nullable": true
+ }
+ }
+ },
"PeriodUnit": {
"type": "string",
"enum": [
diff --git a/api-reference/v2/openapi_spec_v2.json b/api-reference/v2/openapi_spec_v2.json
index 1656829274..76ba117518 100644
--- a/api-reference/v2/openapi_spec_v2.json
+++ b/api-reference/v2/openapi_spec_v2.json
@@ -10761,6 +10761,14 @@
}
],
"nullable": true
+ },
+ "peachpayments": {
+ "allOf": [
+ {
+ "$ref": "#/components/schemas/PeachpaymentsData"
+ }
+ ],
+ "nullable": true
}
}
},
@@ -24982,6 +24990,16 @@
}
}
},
+ "PeachpaymentsData": {
+ "type": "object",
+ "properties": {
+ "rrn": {
+ "type": "string",
+ "description": "A numeric reference number supplied by the system retaining the original source information and used to assist in locating that information or a copy thereof.",
+ "nullable": true
+ }
+ }
+ },
"PhoneDetails": {
"type": "object",
"properties": {
diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs
index a6807d2e54..6efd7c67cd 100644
--- a/crates/api_models/src/payments.rs
+++ b/crates/api_models/src/payments.rs
@@ -9844,6 +9844,8 @@ pub struct ConnectorMetadata {
pub braintree: Option<BraintreeData>,
#[smithy(value_type = "Option<AdyenConnectorMetadata>")]
pub adyen: Option<AdyenConnectorMetadata>,
+ #[smithy(value_type = "Option<PeachpaymentsData>")]
+ pub peachpayments: Option<PeachpaymentsData>,
}
impl ConnectorMetadata {
@@ -9980,6 +9982,13 @@ pub enum ApplePayCombinedMetadata {
},
}
+#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, ToSchema, SmithyModel)]
+#[smithy(namespace = "com.hyperswitch.smithy.types")]
+pub struct PeachpaymentsData {
+ /// A numeric reference number supplied by the system retaining the original source information and used to assist in locating that information or a copy thereof.
+ pub rrn: Option<String>,
+}
+
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct PaymentRequestMetadata {
pub supported_networks: Vec<String>,
diff --git a/crates/hyperswitch_connectors/src/connectors/peachpayments.rs b/crates/hyperswitch_connectors/src/connectors/peachpayments.rs
index ee7bdf01c7..8071774fc1 100644
--- a/crates/hyperswitch_connectors/src/connectors/peachpayments.rs
+++ b/crates/hyperswitch_connectors/src/connectors/peachpayments.rs
@@ -52,6 +52,7 @@ use crate::{
utils::{self, RefundsRequestData},
};
+const REFUND: &str = "Refund";
#[derive(Clone)]
pub struct Peachpayments {
amount_converter: &'static (dyn AmountConvertor<Output = MinorUnit> + Sync),
@@ -712,15 +713,30 @@ impl webhooks::IncomingWebhook for Peachpayments {
.parse_struct("PeachpaymentsIncomingWebhook")
.change_context(errors::ConnectorError::WebhookBodyDecodingFailed)?;
- let reference_id = webhook_body
+ let description = webhook_body
.transaction
.as_ref()
- .map(|txn| txn.reference_id.clone())
- .ok_or(errors::ConnectorError::WebhookReferenceIdNotFound)?;
-
- Ok(api_models::webhooks::ObjectReferenceId::PaymentId(
- api_models::payments::PaymentIdType::PaymentAttemptId(reference_id),
- ))
+ .map(|txn| txn.transaction_type.description.clone());
+
+ if description == Some(REFUND.to_string()) {
+ let refund_id = webhook_body
+ .transaction
+ .as_ref()
+ .map(|txn| txn.transaction_id.clone())
+ .ok_or(errors::ConnectorError::WebhookReferenceIdNotFound)?;
+ Ok(api_models::webhooks::ObjectReferenceId::RefundId(
+ api_models::webhooks::RefundIdType::ConnectorRefundId(refund_id),
+ ))
+ } else {
+ let transaction_id = webhook_body
+ .transaction
+ .as_ref()
+ .map(|txn| txn.transaction_id.clone())
+ .ok_or(errors::ConnectorError::WebhookReferenceIdNotFound)?;
+ Ok(api_models::webhooks::ObjectReferenceId::PaymentId(
+ api_models::payments::PaymentIdType::ConnectorTransactionId(transaction_id),
+ ))
+ }
}
fn get_webhook_event_type(
@@ -733,14 +749,25 @@ impl webhooks::IncomingWebhook for Peachpayments {
.parse_struct("PeachpaymentsIncomingWebhook")
.change_context(errors::ConnectorError::WebhookBodyDecodingFailed)?;
+ let description = webhook_body
+ .transaction
+ .as_ref()
+ .map(|txn| txn.transaction_type.description.clone());
+
match webhook_body.webhook_type.as_str() {
"transaction" => {
if let Some(transaction) = webhook_body.transaction {
match transaction.transaction_result {
- peachpayments::PeachpaymentsPaymentStatus::Successful
- | peachpayments::PeachpaymentsPaymentStatus::ApprovedConfirmed => {
+ peachpayments::PeachpaymentsPaymentStatus::Successful => {
Ok(api_models::webhooks::IncomingWebhookEvent::PaymentIntentSuccess)
}
+ peachpayments::PeachpaymentsPaymentStatus::ApprovedConfirmed => {
+ if description == Some(REFUND.to_string()) {
+ Ok(api_models::webhooks::IncomingWebhookEvent::RefundSuccess)
+ } else {
+ Ok(api_models::webhooks::IncomingWebhookEvent::PaymentIntentSuccess)
+ }
+ }
peachpayments::PeachpaymentsPaymentStatus::Authorized
| peachpayments::PeachpaymentsPaymentStatus::Approved => {
Ok(api_models::webhooks::IncomingWebhookEvent::PaymentIntentAuthorizationSuccess)
@@ -750,7 +777,11 @@ impl webhooks::IncomingWebhook for Peachpayments {
}
peachpayments::PeachpaymentsPaymentStatus::Declined
| peachpayments::PeachpaymentsPaymentStatus::Failed => {
- Ok(api_models::webhooks::IncomingWebhookEvent::PaymentIntentFailure)
+ if description == Some(REFUND.to_string()) {
+ Ok(api_models::webhooks::IncomingWebhookEvent::RefundFailure)
+ } else {
+ Ok(api_models::webhooks::IncomingWebhookEvent::PaymentIntentFailure)
+ }
}
peachpayments::PeachpaymentsPaymentStatus::Voided
| peachpayments::PeachpaymentsPaymentStatus::Reversed => {
diff --git a/crates/hyperswitch_connectors/src/connectors/peachpayments/transformers.rs b/crates/hyperswitch_connectors/src/connectors/peachpayments/transformers.rs
index ad609798da..e04ddf52c8 100644
--- a/crates/hyperswitch_connectors/src/connectors/peachpayments/transformers.rs
+++ b/crates/hyperswitch_connectors/src/connectors/peachpayments/transformers.rs
@@ -102,6 +102,7 @@ pub struct EcommerceCardPaymentOnlyTransactionData {
pub routing_reference: RoutingReference,
pub card: CardDetails,
pub amount: AmountDetails,
+ #[serde(skip_serializing_if = "Option::is_none")]
pub rrn: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub pre_auth_inc_ext_capture_flow: Option<PreAuthIncExtCaptureFlow>,
@@ -139,6 +140,7 @@ pub struct EcommerceNetworkTokenPaymentOnlyTransactionData {
pub network_token_data: NetworkTokenDetails,
pub amount: AmountDetails,
pub cof_data: CardOnFileData,
+ #[serde(skip_serializing_if = "Option::is_none")]
pub rrn: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub pre_auth_inc_ext_capture_flow: Option<PreAuthIncExtCaptureFlow>,
@@ -788,7 +790,7 @@ pub enum PeachpaymentsRefundStatus {
Failed,
}
-#[derive(Debug, Clone, Deserialize, Serialize)]
+#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct RefundBalanceData {
pub amount: AmountDetails,
@@ -796,7 +798,7 @@ pub struct RefundBalanceData {
pub refund_history: Vec<RefundHistory>,
}
-#[derive(Debug, Clone, Deserialize, Serialize)]
+#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct RefundHistory {
pub transaction_id: String,
@@ -933,7 +935,7 @@ impl ResponseCode {
pub struct EcommerceCardPaymentOnlyResponseData {
pub amount: Option<AmountDetails>,
pub stan: Option<Secret<String>>,
- pub rrn: Option<Secret<String>>,
+ pub rrn: Option<String>,
pub approval_code: Option<String>,
pub merchant_advice_code: Option<String>,
pub description: Option<String>,
@@ -1151,11 +1153,19 @@ pub struct WebhookTransaction {
pub reference_id: String,
pub transaction_result: PeachpaymentsPaymentStatus,
pub error_message: Option<String>,
+ pub transaction_type: TransactionType,
pub response_code: Option<ResponseCode>,
pub ecommerce_card_payment_only_transaction_data: Option<EcommerceCardPaymentOnlyResponseData>,
+ pub refund_balance_data: Option<RefundBalanceData>,
pub payment_method: Secret<String>,
}
+#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
+pub struct TransactionType {
+ pub value: i32,
+ pub description: String,
+}
+
// Error Response
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
diff --git a/crates/hyperswitch_connectors/src/utils.rs b/crates/hyperswitch_connectors/src/utils.rs
index ff24a8d4ea..0cdff5af1d 100644
--- a/crates/hyperswitch_connectors/src/utils.rs
+++ b/crates/hyperswitch_connectors/src/utils.rs
@@ -7450,6 +7450,7 @@ pub(crate) fn convert_setup_mandate_router_data_to_authorize_router_data(
.request
.partner_merchant_identifier_details
.clone(),
+ rrn: None,
feature_metadata: None,
}
}
diff --git a/crates/hyperswitch_domain_models/src/router_request_types.rs b/crates/hyperswitch_domain_models/src/router_request_types.rs
index 2c160f88ef..1b8e918c11 100644
--- a/crates/hyperswitch_domain_models/src/router_request_types.rs
+++ b/crates/hyperswitch_domain_models/src/router_request_types.rs
@@ -102,6 +102,7 @@ pub struct PaymentsAuthorizeData {
pub tokenization: Option<common_enums::Tokenization>,
pub partner_merchant_identifier_details:
Option<common_types::payments::PartnerMerchantIdentifierDetails>,
+ pub rrn: Option<String>,
pub feature_metadata: Option<api_models::payments::FeatureMetadata>,
}
diff --git a/crates/openapi/src/openapi.rs b/crates/openapi/src/openapi.rs
index e98eb2c88b..27fcc27705 100644
--- a/crates/openapi/src/openapi.rs
+++ b/crates/openapi/src/openapi.rs
@@ -539,6 +539,7 @@ Never share your secret api keys. Keep them guarded and secure.
api_models::payments::AirwallexData,
api_models::payments::BraintreeData,
api_models::payments::NoonData,
+ api_models::payments::PeachpaymentsData,
api_models::payments::OrderDetailsWithAmount,
api_models::payments::NextActionType,
api_models::payments::WalletData,
diff --git a/crates/openapi/src/openapi_v2.rs b/crates/openapi/src/openapi_v2.rs
index 1932561876..9abee942d0 100644
--- a/crates/openapi/src/openapi_v2.rs
+++ b/crates/openapi/src/openapi_v2.rs
@@ -488,6 +488,7 @@ Never share your secret api keys. Keep them guarded and secure.
api_models::payments::AirwallexData,
api_models::payments::BraintreeData,
api_models::payments::NoonData,
+ api_models::payments::PeachpaymentsData,
api_models::payments::OrderDetailsWithAmount,
api_models::payments::NextActionType,
api_models::payments::WalletData,
diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs
index 7c026e9647..8f2e46bf0b 100644
--- a/crates/router/src/core/payments/transformers.rs
+++ b/crates/router/src/core/payments/transformers.rs
@@ -416,6 +416,11 @@ pub async fn construct_payment_router_data_for_authorize<'a>(
.and_then(|noon| noon.order_category.clone())
});
+ let rrn = connector_metadata
+ .as_ref()
+ .and_then(|metadata| metadata.peachpayments.as_ref())
+ .and_then(|peachpaymentsdata| peachpaymentsdata.rrn.clone());
+
// TODO: few fields are repeated in both routerdata and request
let request = types::PaymentsAuthorizeData {
payment_method_data: payment_data
@@ -485,6 +490,7 @@ pub async fn construct_payment_router_data_for_authorize<'a>(
is_stored_credential: None,
billing_descriptor: None,
partner_merchant_identifier_details: None,
+ rrn,
feature_metadata: None,
};
let connector_mandate_request_reference_id = payment_data
@@ -4731,6 +4737,13 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsAuthoriz
let shipping_cost = payment_data.payment_intent.amount_details.shipping_cost;
+ let rrn = payment_data
+ .payment_intent
+ .connector_metadata
+ .as_ref()
+ .and_then(|metadata| metadata.peachpayments.as_ref())
+ .and_then(|peachpaymentsdata| peachpaymentsdata.rrn.clone());
+
Ok(Self {
payment_method_data: payment_method_data
.unwrap_or(domain::PaymentMethodData::Card(domain::Card::default())),
@@ -4788,6 +4801,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsAuthoriz
is_stored_credential: None,
billing_descriptor: None,
partner_merchant_identifier_details: None,
+ rrn,
feature_metadata: None,
})
}
@@ -4858,6 +4872,11 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsAuthoriz
let merchant_config_currency =
braintree_metadata.and_then(|braintree| braintree.merchant_config_currency);
+ let rrn = connector_metadata
+ .as_ref()
+ .and_then(|metadata| metadata.peachpayments.as_ref())
+ .and_then(|peachpaymentsdata| peachpaymentsdata.rrn.clone());
+
let order_details = additional_data
.payment_data
.payment_intent
@@ -5044,6 +5063,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsAuthoriz
partner_merchant_identifier_details: payment_data
.payment_intent
.partner_merchant_identifier_details,
+ rrn,
feature_metadata,
})
}
diff --git a/crates/router/src/types.rs b/crates/router/src/types.rs
index 9c46f4d080..2242267805 100644
--- a/crates/router/src/types.rs
+++ b/crates/router/src/types.rs
@@ -1350,6 +1350,7 @@ impl ForeignFrom<&SetupMandateRouterData> for PaymentsAuthorizeData {
.request
.partner_merchant_identifier_details
.clone(),
+ rrn: None,
feature_metadata: None,
}
}
diff --git a/crates/router/src/types/api/verify_connector.rs b/crates/router/src/types/api/verify_connector.rs
index d8daf666d4..cfa8c58110 100644
--- a/crates/router/src/types/api/verify_connector.rs
+++ b/crates/router/src/types/api/verify_connector.rs
@@ -74,6 +74,7 @@ impl VerifyConnectorData {
billing_descriptor: None,
tokenization: None,
partner_merchant_identifier_details: None,
+ rrn: None,
feature_metadata: None,
}
}
diff --git a/crates/router/tests/connectors/utils.rs b/crates/router/tests/connectors/utils.rs
index 4c02545025..1440c6beef 100644
--- a/crates/router/tests/connectors/utils.rs
+++ b/crates/router/tests/connectors/utils.rs
@@ -1021,6 +1021,7 @@ impl Default for PaymentAuthorizeType {
billing_descriptor: None,
tokenization: None,
partner_merchant_identifier_details: None,
+ rrn: None,
feature_metadata: None,
};
Self(data)