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): [Peachpayments] Perform PSync and RSync using reference_id (#11448)

Anurag8bc500845c13
diff --git a/crates/hyperswitch_connectors/src/connectors/peachpayments.rs b/crates/hyperswitch_connectors/src/connectors/peachpayments.rs
index 8071774fc1..deb5b2d6cb 100644
--- a/crates/hyperswitch_connectors/src/connectors/peachpayments.rs
+++ b/crates/hyperswitch_connectors/src/connectors/peachpayments.rs
@@ -46,11 +46,7 @@ use hyperswitch_interfaces::{
use masking::{ExposeInterface, Mask, Secret};
use transformers as peachpayments;
-use crate::{
- constants::headers,
- types::ResponseRouterData,
- utils::{self, RefundsRequestData},
-};
+use crate::{constants::headers, types::ResponseRouterData, utils};
const REFUND: &str = "Refund";
#[derive(Clone)]
@@ -167,7 +163,17 @@ impl ConnectorCommon for Peachpayments {
}
}
-impl ConnectorValidation for Peachpayments {}
+impl ConnectorValidation for Peachpayments {
+ 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 Peachpayments {
//TODO: implement sessions flow
@@ -312,15 +318,11 @@ impl ConnectorIntegration<PSync, PaymentsSyncData, PaymentsResponseData> for Pea
req: &PaymentsSyncRouterData,
connectors: &Connectors,
) -> CustomResult<String, errors::ConnectorError> {
- let connector_transaction_id = req
- .request
- .connector_transaction_id
- .get_connector_transaction_id()
- .change_context(errors::ConnectorError::MissingConnectorTransactionID)?;
+ let reference_id = req.connector_request_reference_id.clone();
Ok(format!(
- "{}/transactions/{}",
+ "{}/transactions/by-reference/{}",
self.base_url(connectors),
- connector_transaction_id
+ reference_id
))
}
@@ -651,11 +653,11 @@ impl ConnectorIntegration<RSync, RefundsData, RefundsResponseData> for Peachpaym
req: &RefundSyncRouterData,
connectors: &Connectors,
) -> CustomResult<String, errors::ConnectorError> {
- let connector_refund_id = req.request.get_connector_refund_id()?;
+ let refund_id = req.request.refund_id.clone();
Ok(format!(
- "{}/transactions/{}",
+ "{}/transactions/by-reference/{}",
self.base_url(connectors),
- connector_refund_id
+ refund_id
))
}
@@ -718,23 +720,19 @@ impl webhooks::IncomingWebhook for Peachpayments {
.as_ref()
.map(|txn| txn.transaction_type.description.clone());
+ let reference_id = webhook_body
+ .transaction
+ .as_ref()
+ .map(|txn| txn.reference_id.clone())
+ .ok_or(errors::ConnectorError::WebhookReferenceIdNotFound)?;
+
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),
+ api_models::webhooks::RefundIdType::RefundId(reference_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),
+ api_models::payments::PaymentIdType::PaymentAttemptId(reference_id),
))
}
}
@@ -846,7 +844,7 @@ static PEACHPAYMENTS_SUPPORTED_PAYMENT_METHODS: LazyLock<SupportedPaymentMethods
specific_features: Some(
api_models::feature_matrix::PaymentMethodSpecificFeatures::Card({
api_models::feature_matrix::CardSpecificFeatures {
- three_ds: common_enums::FeatureStatus::Supported,
+ three_ds: common_enums::FeatureStatus::NotSupported,
no_three_ds: common_enums::FeatureStatus::Supported,
supported_card_networks: supported_card_network.clone(),
}
@@ -865,7 +863,7 @@ static PEACHPAYMENTS_SUPPORTED_PAYMENT_METHODS: LazyLock<SupportedPaymentMethods
specific_features: Some(
api_models::feature_matrix::PaymentMethodSpecificFeatures::Card({
api_models::feature_matrix::CardSpecificFeatures {
- three_ds: common_enums::FeatureStatus::Supported,
+ three_ds: common_enums::FeatureStatus::NotSupported,
no_three_ds: common_enums::FeatureStatus::Supported,
supported_card_networks: supported_card_network.clone(),
}
@@ -895,8 +893,8 @@ static PEACHPAYMENTS_CONNECTOR_INFO: ConnectorInfo = ConnectorInfo {
integration_status: enums::ConnectorIntegrationStatus::Live,
};
-static PEACHPAYMENTS_SUPPORTED_WEBHOOK_FLOWS: [enums::EventClass; 1] =
- [enums::EventClass::Payments];
+static PEACHPAYMENTS_SUPPORTED_WEBHOOK_FLOWS: [enums::EventClass; 2] =
+ [enums::EventClass::Payments, enums::EventClass::Refunds];
impl ConnectorSpecifications for Peachpayments {
fn get_connector_about(&self) -> Option<&'static ConnectorInfo> {
diff --git a/crates/hyperswitch_connectors/src/connectors/peachpayments/transformers.rs b/crates/hyperswitch_connectors/src/connectors/peachpayments/transformers.rs
index e04ddf52c8..c97f6bb9ff 100644
--- a/crates/hyperswitch_connectors/src/connectors/peachpayments/transformers.rs
+++ b/crates/hyperswitch_connectors/src/connectors/peachpayments/transformers.rs
@@ -758,6 +758,7 @@ impl From<PeachpaymentsRefundStatus> for common_enums::RefundStatus {
#[serde(rename_all = "camelCase")]
pub struct PeachpaymentsPaymentsData {
pub transaction_id: String,
+ pub reference_id: String,
pub response_code: Option<ResponseCode>,
pub transaction_result: PeachpaymentsPaymentStatus,
pub ecommerce_card_payment_only_transaction_data: Option<EcommerceCardPaymentOnlyResponseData>,
@@ -767,6 +768,7 @@ pub struct PeachpaymentsPaymentsData {
#[serde(rename_all = "camelCase")]
pub struct PeachpaymentsRsyncResponse {
pub transaction_id: String,
+ pub reference_id: String,
pub transaction_result: PeachpaymentsRefundStatus,
pub response_code: Option<ResponseCode>,
}
@@ -823,7 +825,7 @@ impl<F>
status_code: item.http_code,
attempt_status: None,
connector_transaction_id: Some(item.response.transaction_id),
- connector_response_reference_id: None,
+ connector_response_reference_id: Some(item.response.reference_id),
network_advice_code: None,
network_decline_code: None,
network_error_message: None,
@@ -863,8 +865,8 @@ impl
reason: None,
status_code: item.http_code,
attempt_status: None,
- connector_transaction_id: Some(item.response.transaction_id),
- connector_response_reference_id: None,
+ connector_transaction_id: None,
+ connector_response_reference_id: Some(item.response.reference_id),
network_advice_code: None,
network_decline_code: None,
network_error_message: None,
@@ -889,6 +891,7 @@ impl
#[serde(rename_all = "camelCase")]
pub struct PeachpaymentsCaptureResponse {
pub transaction_id: String,
+ pub reference_id: String,
pub response_code: Option<ResponseCode>,
pub transaction_result: PeachpaymentsPaymentStatus,
pub authorization_code: Option<String>,
@@ -986,8 +989,8 @@ pub fn get_peachpayments_response(
.and_then(|data| data.description),
status_code,
attempt_status: Some(status),
- connector_transaction_id: Some(response.transaction_id.clone()),
- connector_response_reference_id: None,
+ connector_transaction_id: Some(response.transaction_id),
+ connector_response_reference_id: Some(response.reference_id),
network_advice_code: None,
network_decline_code: None,
network_error_message: None,
@@ -1000,7 +1003,7 @@ pub fn get_peachpayments_response(
mandate_reference: Box::new(None),
connector_metadata: None,
network_txn_id: None,
- connector_response_reference_id: Some(response.transaction_id),
+ connector_response_reference_id: Some(response.reference_id),
incremental_authorization_allowed: None,
authentication_data: None,
charges: None,
@@ -1033,7 +1036,7 @@ pub fn get_webhook_response(
status_code,
attempt_status: Some(status),
connector_transaction_id: Some(transaction.transaction_id.clone()),
- connector_response_reference_id: None,
+ connector_response_reference_id: Some(transaction.reference_id),
network_advice_code: None,
network_decline_code: None,
network_error_message: None,
@@ -1041,16 +1044,12 @@ pub fn get_webhook_response(
})
} else {
Ok(PaymentsResponseData::TransactionResponse {
- resource_id: ResponseId::ConnectorTransactionId(
- transaction
- .original_transaction_id
- .unwrap_or(transaction.transaction_id.clone()),
- ),
+ resource_id: ResponseId::ConnectorTransactionId(transaction.transaction_id),
redirection_data: Box::new(None),
mandate_reference: Box::new(None),
connector_metadata: None,
network_txn_id: None,
- connector_response_reference_id: Some(transaction.transaction_id.clone()),
+ connector_response_reference_id: Some(transaction.reference_id.clone()),
incremental_authorization_allowed: None,
authentication_data: None,
charges: None,
@@ -1102,7 +1101,7 @@ impl<F, T> TryFrom<ResponseRouterData<F, PeachpaymentsCaptureResponse, T, Paymen
status_code: item.http_code,
attempt_status: Some(status),
connector_transaction_id: Some(item.response.transaction_id.clone()),
- connector_response_reference_id: None,
+ connector_response_reference_id: Some(item.response.reference_id),
network_advice_code: None,
network_decline_code: None,
network_error_message: None,
@@ -1121,7 +1120,7 @@ impl<F, T> TryFrom<ResponseRouterData<F, PeachpaymentsCaptureResponse, T, Paymen
})
}),
network_txn_id: None,
- connector_response_reference_id: Some(item.response.transaction_id),
+ connector_response_reference_id: Some(item.response.reference_id),
incremental_authorization_allowed: None,
authentication_data: None,
charges: None,