mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-01 19:42:27 +08:00
fix(connector): [Authorizedotnet]Fix webhooks (#1261)
Signed-off-by: chikke srujan <121822803+srujanchikke@users.noreply.github.com>
This commit is contained in:
@ -667,13 +667,13 @@ impl api::IncomingWebhook for Authorizedotnet {
|
||||
authorizedotnet::AuthorizedotnetWebhookEvent::RefundCreated => {
|
||||
Ok(api_models::webhooks::ObjectReferenceId::RefundId(
|
||||
api_models::webhooks::RefundIdType::ConnectorRefundId(
|
||||
authorizedotnet::get_trans_id(details)?,
|
||||
authorizedotnet::get_trans_id(&details)?,
|
||||
),
|
||||
))
|
||||
}
|
||||
_ => Ok(api_models::webhooks::ObjectReferenceId::PaymentId(
|
||||
api_models::payments::PaymentIdType::ConnectorTransactionId(
|
||||
authorizedotnet::get_trans_id(details)?,
|
||||
authorizedotnet::get_trans_id(&details)?,
|
||||
),
|
||||
)),
|
||||
}
|
||||
@ -712,10 +712,16 @@ impl api::IncomingWebhook for Authorizedotnet {
|
||||
&self,
|
||||
request: &api::IncomingWebhookRequestDetails<'_>,
|
||||
) -> CustomResult<serde_json::Value, errors::ConnectorError> {
|
||||
let payload = serde_json::to_value(request.body)
|
||||
.into_report()
|
||||
let payload: authorizedotnet::AuthorizedotnetWebhookObjectId = request
|
||||
.body
|
||||
.parse_struct("AuthorizedotnetWebhookObjectId")
|
||||
.change_context(errors::ConnectorError::WebhookResourceObjectNotFound)?;
|
||||
Ok(payload)
|
||||
let sync_payload = serde_json::to_value(
|
||||
authorizedotnet::AuthorizedotnetSyncResponse::try_from(payload)?,
|
||||
)
|
||||
.into_report()
|
||||
.change_context(errors::ConnectorError::ResponseHandlingFailed)?;
|
||||
Ok(sync_payload)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -343,19 +343,20 @@ impl From<AuthorizedotnetPaymentStatus> for enums::AttemptStatus {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, PartialEq)]
|
||||
#[derive(Debug, Default, Clone, Deserialize, PartialEq, Serialize)]
|
||||
pub struct ResponseMessage {
|
||||
code: String,
|
||||
pub text: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, PartialEq)]
|
||||
#[derive(Debug, Default, Clone, Deserialize, PartialEq, Serialize)]
|
||||
enum ResultCode {
|
||||
#[default]
|
||||
Ok,
|
||||
Error,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, PartialEq)]
|
||||
#[derive(Debug, Default, Clone, Deserialize, PartialEq, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ResponseMessages {
|
||||
result_code: ResultCode,
|
||||
@ -723,7 +724,7 @@ impl TryFrom<&types::PaymentsSyncRouterData> for AuthorizedotnetCreateSyncReques
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub enum SyncStatus {
|
||||
RefundSettledSuccessfully,
|
||||
@ -738,7 +739,7 @@ pub enum SyncStatus {
|
||||
#[serde(rename = "FDSPendingReview")]
|
||||
FDSPendingReview,
|
||||
}
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct SyncTransactionResponse {
|
||||
#[serde(rename = "transId")]
|
||||
@ -746,7 +747,7 @@ pub struct SyncTransactionResponse {
|
||||
transaction_status: SyncStatus,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct AuthorizedotnetSyncResponse {
|
||||
transaction: Option<SyncTransactionResponse>,
|
||||
messages: ResponseMessages,
|
||||
@ -932,11 +933,41 @@ impl From<AuthorizedotnetWebhookEvent> for api::IncomingWebhookEvent {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<AuthorizedotnetWebhookEvent> for SyncStatus {
|
||||
// status mapping reference https://developer.authorize.net/api/reference/features/webhooks.html#Event_Types_and_Payloads
|
||||
fn from(event_type: AuthorizedotnetWebhookEvent) -> Self {
|
||||
match event_type {
|
||||
AuthorizedotnetWebhookEvent::AuthorizationCreated => Self::AuthorizedPendingCapture,
|
||||
AuthorizedotnetWebhookEvent::CaptureCreated
|
||||
| AuthorizedotnetWebhookEvent::AuthCapCreated => Self::CapturedPendingSettlement,
|
||||
AuthorizedotnetWebhookEvent::PriorAuthCapture => Self::SettledSuccessfully,
|
||||
AuthorizedotnetWebhookEvent::VoidCreated => Self::Voided,
|
||||
AuthorizedotnetWebhookEvent::RefundCreated => Self::RefundSettledSuccessfully,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_trans_id(
|
||||
details: AuthorizedotnetWebhookObjectId,
|
||||
details: &AuthorizedotnetWebhookObjectId,
|
||||
) -> Result<String, errors::ConnectorError> {
|
||||
details
|
||||
.payload
|
||||
.id
|
||||
.clone()
|
||||
.ok_or(errors::ConnectorError::WebhookReferenceIdNotFound)
|
||||
}
|
||||
|
||||
impl TryFrom<AuthorizedotnetWebhookObjectId> for AuthorizedotnetSyncResponse {
|
||||
type Error = error_stack::Report<errors::ConnectorError>;
|
||||
fn try_from(item: AuthorizedotnetWebhookObjectId) -> Result<Self, Self::Error> {
|
||||
Ok(Self {
|
||||
transaction: Some(SyncTransactionResponse {
|
||||
transaction_id: get_trans_id(&item)?,
|
||||
transaction_status: SyncStatus::from(item.event_type),
|
||||
}),
|
||||
messages: ResponseMessages {
|
||||
..Default::default()
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user