-
Notifications
You must be signed in to change notification settings - Fork 4.4k
feat(connector): [Peachpayments] Add Webhook Flow and Support For merchant_order_reference_id #9781
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
1c27e1d
72a65e1
e6451b2
3d47e15
e0fdc4d
35b3dc1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,11 +5,12 @@ use std::sync::LazyLock; | |
use common_enums::{self, enums}; | ||
use common_utils::{ | ||
errors::CustomResult, | ||
ext_traits::BytesExt, | ||
ext_traits::{ByteSliceExt, BytesExt}, | ||
id_type, | ||
request::{Method, Request, RequestBuilder, RequestContent}, | ||
types::{AmountConvertor, MinorUnit, MinorUnitForConnector}, | ||
}; | ||
use error_stack::{report, ResultExt}; | ||
use error_stack::ResultExt; | ||
use hyperswitch_domain_models::{ | ||
router_data::{AccessToken, ConnectorAuthType, ErrorResponse, RouterData}, | ||
router_flow_types::{ | ||
|
@@ -42,7 +43,7 @@ use hyperswitch_interfaces::{ | |
types::{self, Response}, | ||
webhooks, | ||
}; | ||
use masking::{ExposeInterface, Mask}; | ||
use masking::{ExposeInterface, Mask, Secret}; | ||
use transformers as peachpayments; | ||
|
||
use crate::{constants::headers, types::ResponseRouterData, utils}; | ||
|
@@ -542,23 +543,90 @@ impl ConnectorIntegration<RSync, RefundsData, RefundsResponseData> for Peachpaym | |
impl webhooks::IncomingWebhook for Peachpayments { | ||
fn get_webhook_object_reference_id( | ||
&self, | ||
_request: &webhooks::IncomingWebhookRequestDetails<'_>, | ||
request: &webhooks::IncomingWebhookRequestDetails<'_>, | ||
) -> CustomResult<api_models::webhooks::ObjectReferenceId, errors::ConnectorError> { | ||
Err(report!(errors::ConnectorError::WebhooksNotImplemented)) | ||
let webhook_body: peachpayments::PeachpaymentsIncomingWebhook = request | ||
.body | ||
.parse_struct("PeachpaymentsIncomingWebhook") | ||
.change_context(errors::ConnectorError::WebhookBodyDecodingFailed)?; | ||
|
||
let reference_id = 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), | ||
)) | ||
} | ||
|
||
fn get_webhook_event_type( | ||
&self, | ||
_request: &webhooks::IncomingWebhookRequestDetails<'_>, | ||
request: &webhooks::IncomingWebhookRequestDetails<'_>, | ||
) -> CustomResult<api_models::webhooks::IncomingWebhookEvent, errors::ConnectorError> { | ||
Err(report!(errors::ConnectorError::WebhooksNotImplemented)) | ||
let webhook_body: peachpayments::PeachpaymentsIncomingWebhook = request | ||
.body | ||
.parse_struct("PeachpaymentsIncomingWebhook") | ||
.change_context(errors::ConnectorError::WebhookBodyDecodingFailed)?; | ||
|
||
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 => { | ||
Ok(api_models::webhooks::IncomingWebhookEvent::PaymentIntentSuccess) | ||
} | ||
peachpayments::PeachpaymentsPaymentStatus::Authorized | ||
| peachpayments::PeachpaymentsPaymentStatus::Approved => { | ||
Ok(api_models::webhooks::IncomingWebhookEvent::PaymentIntentAuthorizationSuccess) | ||
} | ||
peachpayments::PeachpaymentsPaymentStatus::Pending => { | ||
Ok(api_models::webhooks::IncomingWebhookEvent::PaymentIntentProcessing) | ||
} | ||
peachpayments::PeachpaymentsPaymentStatus::Declined | ||
| peachpayments::PeachpaymentsPaymentStatus::Failed => { | ||
Ok(api_models::webhooks::IncomingWebhookEvent::PaymentIntentFailure) | ||
} | ||
peachpayments::PeachpaymentsPaymentStatus::Voided | ||
| peachpayments::PeachpaymentsPaymentStatus::Reversed => { | ||
Ok(api_models::webhooks::IncomingWebhookEvent::PaymentIntentCancelled) | ||
} | ||
peachpayments::PeachpaymentsPaymentStatus::ThreedsRequired => { | ||
Ok(api_models::webhooks::IncomingWebhookEvent::PaymentActionRequired) | ||
} | ||
} | ||
} else { | ||
Err(errors::ConnectorError::WebhookEventTypeNotFound) | ||
} | ||
} | ||
_ => Err(errors::ConnectorError::WebhookEventTypeNotFound), | ||
} | ||
.change_context(errors::ConnectorError::WebhookEventTypeNotFound) | ||
} | ||
|
||
fn get_webhook_resource_object( | ||
&self, | ||
_request: &webhooks::IncomingWebhookRequestDetails<'_>, | ||
request: &webhooks::IncomingWebhookRequestDetails<'_>, | ||
) -> CustomResult<Box<dyn masking::ErasedMaskSerialize>, errors::ConnectorError> { | ||
Err(report!(errors::ConnectorError::WebhooksNotImplemented)) | ||
let webhook_body: peachpayments::PeachpaymentsIncomingWebhook = request | ||
.body | ||
.parse_struct("PeachpaymentsIncomingWebhook") | ||
.change_context(errors::ConnectorError::WebhookBodyDecodingFailed)?; | ||
|
||
Ok(Box::new(webhook_body)) | ||
} | ||
|
||
async fn verify_webhook_source( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have information on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Peach doesn't support any algorithm as of now. |
||
&self, | ||
_request: &webhooks::IncomingWebhookRequestDetails<'_>, | ||
_merchant_id: &id_type::MerchantId, | ||
_connector_webhook_details: Option<common_utils::pii::SecretSerdeValue>, | ||
_connector_account_details: common_utils::crypto::Encryptable<Secret<serde_json::Value>>, | ||
_connector_name: &str, | ||
) -> CustomResult<bool, errors::ConnectorError> { | ||
Ok(false) | ||
} | ||
} | ||
|
||
|
@@ -625,7 +693,8 @@ static PEACHPAYMENTS_CONNECTOR_INFO: ConnectorInfo = ConnectorInfo { | |
integration_status: enums::ConnectorIntegrationStatus::Beta, | ||
}; | ||
|
||
static PEACHPAYMENTS_SUPPORTED_WEBHOOK_FLOWS: [enums::EventClass; 0] = []; | ||
static PEACHPAYMENTS_SUPPORTED_WEBHOOK_FLOWS: [enums::EventClass; 1] = | ||
[enums::EventClass::Payments]; | ||
|
||
impl ConnectorSpecifications for Peachpayments { | ||
fn get_connector_about(&self) -> Option<&'static ConnectorInfo> { | ||
|
Uh oh!
There was an error while loading. Please reload this page.