From 205ead022eedc9c251db37c68d0e4a10e1ebfe28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Djk=C3=A1=C5=A5o?= Date: Thu, 14 Mar 2024 15:05:57 +0100 Subject: [PATCH] was missing cancelation request --- simple-payment-gateway/src/routes/register.rs | 2 +- simple-payment-gateway/src/routes/webhooks.rs | 30 +++++++++++++++---- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/simple-payment-gateway/src/routes/register.rs b/simple-payment-gateway/src/routes/register.rs index e7648c4..9ac83cf 100644 --- a/simple-payment-gateway/src/routes/register.rs +++ b/simple-payment-gateway/src/routes/register.rs @@ -5,7 +5,7 @@ use axum::{ http::{HeaderMap, StatusCode}, }; use saleor_app_sdk::{AuthData, AuthToken}; -use tracing::{debug, error, info}; +use tracing::{debug, info}; use crate::app::{AppError, AppState}; diff --git a/simple-payment-gateway/src/routes/webhooks.rs b/simple-payment-gateway/src/routes/webhooks.rs index abc8a38..897e3f6 100644 --- a/simple-payment-gateway/src/routes/webhooks.rs +++ b/simple-payment-gateway/src/routes/webhooks.rs @@ -6,10 +6,11 @@ use saleor_app_sdk::{ headers::SALEOR_API_URL_HEADER, webhooks::{ sync_response::{ - ChargeRequestedResult, PaymentGatewayInitializeSessionResponse, RefundRequestedResult, - TransactionChargeRequestedResponse, TransactionInitializeSessionResponse, - TransactionProcessSessionResponse, TransactionRefundRequestedResponse, - TransactionSessionResult, + CancelationRequestedResult, ChargeRequestedResult, + PaymentGatewayInitializeSessionResponse, RefundRequestedResult, + TransactionCancelationRequestedResponse, TransactionChargeRequestedResponse, + TransactionInitializeSessionResponse, TransactionProcessSessionResponse, + TransactionRefundRequestedResponse, TransactionSessionResult, }, utils::{get_webhook_event_type, EitherWebhookType}, SyncWebhookEventType, @@ -24,8 +25,9 @@ use crate::{ app::{ActiveGateway, AppError, AppState, GatewayType}, queries::{ event_transactions::{ - TransactionChargeRequested2, TransactionFlowStrategyEnum, - TransactionInitializeSession2, TransactionProcessSession2, TransactionRefundRequested2, + TransactionCancelationRequested, TransactionChargeRequested2, + TransactionFlowStrategyEnum, TransactionInitializeSession2, TransactionProcessSession2, + TransactionRefundRequested2, }, mutation_transaction_update::{ TransactionUpdate, TransactionUpdateInput, TransactionUpdateVariables, @@ -50,6 +52,22 @@ pub async fn webhooks( let event_type = get_webhook_event_type(&headers)?; let res: Json = match event_type { EitherWebhookType::Sync(a) => match a { + SyncWebhookEventType::TransactionCancelationRequested => { + let data = serde_json::from_str::(&body)?; + Json::from(serde_json::to_value( + TransactionCancelationRequestedResponse { + time: None, + psp_reference: "".to_owned(), + external_url: None, + message: None, + amount: data + .action + .amount + .and_then(|a| Decimal::from_str(&a.0).ok()), + result: Some(CancelationRequestedResult::CancelSuccess), + }, + )?) + } SyncWebhookEventType::PaymentGatewayInitializeSession => Json::from( serde_json::to_value(PaymentGatewayInitializeSessionResponse:: { data: None })?, ),