mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-02 12:06:56 +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 => {
|
authorizedotnet::AuthorizedotnetWebhookEvent::RefundCreated => {
|
||||||
Ok(api_models::webhooks::ObjectReferenceId::RefundId(
|
Ok(api_models::webhooks::ObjectReferenceId::RefundId(
|
||||||
api_models::webhooks::RefundIdType::ConnectorRefundId(
|
api_models::webhooks::RefundIdType::ConnectorRefundId(
|
||||||
authorizedotnet::get_trans_id(details)?,
|
authorizedotnet::get_trans_id(&details)?,
|
||||||
),
|
),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
_ => Ok(api_models::webhooks::ObjectReferenceId::PaymentId(
|
_ => Ok(api_models::webhooks::ObjectReferenceId::PaymentId(
|
||||||
api_models::payments::PaymentIdType::ConnectorTransactionId(
|
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,
|
&self,
|
||||||
request: &api::IncomingWebhookRequestDetails<'_>,
|
request: &api::IncomingWebhookRequestDetails<'_>,
|
||||||
) -> CustomResult<serde_json::Value, errors::ConnectorError> {
|
) -> CustomResult<serde_json::Value, errors::ConnectorError> {
|
||||||
let payload = serde_json::to_value(request.body)
|
let payload: authorizedotnet::AuthorizedotnetWebhookObjectId = request
|
||||||
.into_report()
|
.body
|
||||||
|
.parse_struct("AuthorizedotnetWebhookObjectId")
|
||||||
.change_context(errors::ConnectorError::WebhookResourceObjectNotFound)?;
|
.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 {
|
pub struct ResponseMessage {
|
||||||
code: String,
|
code: String,
|
||||||
pub text: String,
|
pub text: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize, PartialEq)]
|
#[derive(Debug, Default, Clone, Deserialize, PartialEq, Serialize)]
|
||||||
enum ResultCode {
|
enum ResultCode {
|
||||||
|
#[default]
|
||||||
Ok,
|
Ok,
|
||||||
Error,
|
Error,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize, PartialEq)]
|
#[derive(Debug, Default, Clone, Deserialize, PartialEq, Serialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct ResponseMessages {
|
pub struct ResponseMessages {
|
||||||
result_code: ResultCode,
|
result_code: ResultCode,
|
||||||
@ -723,7 +724,7 @@ impl TryFrom<&types::PaymentsSyncRouterData> for AuthorizedotnetCreateSyncReques
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub enum SyncStatus {
|
pub enum SyncStatus {
|
||||||
RefundSettledSuccessfully,
|
RefundSettledSuccessfully,
|
||||||
@ -738,7 +739,7 @@ pub enum SyncStatus {
|
|||||||
#[serde(rename = "FDSPendingReview")]
|
#[serde(rename = "FDSPendingReview")]
|
||||||
FDSPendingReview,
|
FDSPendingReview,
|
||||||
}
|
}
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct SyncTransactionResponse {
|
pub struct SyncTransactionResponse {
|
||||||
#[serde(rename = "transId")]
|
#[serde(rename = "transId")]
|
||||||
@ -746,7 +747,7 @@ pub struct SyncTransactionResponse {
|
|||||||
transaction_status: SyncStatus,
|
transaction_status: SyncStatus,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
pub struct AuthorizedotnetSyncResponse {
|
pub struct AuthorizedotnetSyncResponse {
|
||||||
transaction: Option<SyncTransactionResponse>,
|
transaction: Option<SyncTransactionResponse>,
|
||||||
messages: ResponseMessages,
|
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(
|
pub fn get_trans_id(
|
||||||
details: AuthorizedotnetWebhookObjectId,
|
details: &AuthorizedotnetWebhookObjectId,
|
||||||
) -> Result<String, errors::ConnectorError> {
|
) -> Result<String, errors::ConnectorError> {
|
||||||
details
|
details
|
||||||
.payload
|
.payload
|
||||||
.id
|
.id
|
||||||
|
.clone()
|
||||||
.ok_or(errors::ConnectorError::WebhookReferenceIdNotFound)
|
.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