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

ci(cypress): added refund webhooks for supported connectors (#11754)

Vasanth2ef119e5c284
diff --git a/cypress-tests/cypress.config.js b/cypress-tests/cypress.config.js
index 887fa768f8..1c80ca3f51 100644
--- a/cypress-tests/cypress.config.js
+++ b/cypress-tests/cypress.config.js
@@ -1,4 +1,3 @@
-import crypto from "node:crypto";
import { defineConfig } from "cypress";
import mochawesome from "cypress-mochawesome-reporter/plugin.js";
import fs from "fs";
@@ -33,10 +32,6 @@ export default defineConfig({
console.log(message);
return null;
},
- hmac_sha256: ({ secret, message }) => {
- const key = Buffer.from(secret, "hex");
- return crypto.createHmac("sha256", key).update(message).digest("hex");
- },
});
on("after:spec", (spec, results) => {
// Clean up resources after each spec
diff --git a/cypress-tests/cypress/e2e/configs/Payment/Airwallex.js b/cypress-tests/cypress/e2e/configs/Payment/Airwallex.js
index 42b676f6e0..77a853e876 100644
--- a/cypress-tests/cypress/e2e/configs/Payment/Airwallex.js
+++ b/cypress-tests/cypress/e2e/configs/Payment/Airwallex.js
@@ -915,5 +915,10 @@ export const connectorDetails = {
path: "sourceId",
type: "string",
},
+ RefundIdConfig: {
+ // Airwallex refund webhooks use sourceId to carry the connector refund ID
+ path: "sourceId",
+ type: "string",
+ },
},
};
diff --git a/cypress-tests/cypress/e2e/configs/Payment/Finix.js b/cypress-tests/cypress/e2e/configs/Payment/Finix.js
index 30d76118b9..fd3bee5fd5 100644
--- a/cypress-tests/cypress/e2e/configs/Payment/Finix.js
+++ b/cypress-tests/cypress/e2e/configs/Payment/Finix.js
@@ -714,5 +714,10 @@ export const connectorDetails = {
// Type of payment reference ID
type: "string",
},
+ RefundIdConfig: {
+ // Finix refund (REVERSAL) webhooks carry the connector refund ID in the transfers array
+ path: "_embedded.transfers.0.id",
+ type: "string",
+ },
},
};
diff --git a/cypress-tests/cypress/e2e/configs/Payment/Fiuu.js b/cypress-tests/cypress/e2e/configs/Payment/Fiuu.js
index 96416a866b..d5b70abb01 100644
--- a/cypress-tests/cypress/e2e/configs/Payment/Fiuu.js
+++ b/cypress-tests/cypress/e2e/configs/Payment/Fiuu.js
@@ -996,6 +996,11 @@ export const connectorDetails = {
// Fiuu webhook handler uses PaymentAttemptId for lookup, not ConnectorTransactionId
source: "paymentAttemptID",
},
+ RefundIdConfig: {
+ // Fiuu refund webhooks carry the connector refund ID in the RefundID field
+ path: "RefundID",
+ type: "string",
+ },
},
payment_method_blocking_pm: {
BlockIssuingCountry: {
diff --git a/cypress-tests/cypress/e2e/configs/Payment/Nmi.js b/cypress-tests/cypress/e2e/configs/Payment/Nmi.js
index 0e4878f071..9f5a122e26 100644
--- a/cypress-tests/cypress/e2e/configs/Payment/Nmi.js
+++ b/cypress-tests/cypress/e2e/configs/Payment/Nmi.js
@@ -678,5 +678,11 @@ export const connectorDetails = {
// NMI webhook handler uses PaymentAttemptId for lookup, not ConnectorTransactionId
source: "paymentAttemptID",
},
+ RefundIdConfig: {
+ path: "event_body.order_id",
+ type: "string",
+ // NMI webhook handler uses RefundId for lookup, not ConnectorRefundId
+ source: "refundId",
+ },
},
};
diff --git a/cypress-tests/cypress/e2e/configs/Payment/Novalnet.js b/cypress-tests/cypress/e2e/configs/Payment/Novalnet.js
index 9033b22a38..a820f380bf 100644
--- a/cypress-tests/cypress/e2e/configs/Payment/Novalnet.js
+++ b/cypress-tests/cypress/e2e/configs/Payment/Novalnet.js
@@ -765,5 +765,11 @@ export const connectorDetails = {
// Type of payment reference ID
type: "number",
},
+ RefundIdConfig: {
+ // Novalnet refund webhooks use the transaction ID (tid) as the connector refund reference
+ // Must be "number" type because Rust struct expects i64
+ path: "event.tid",
+ type: "number",
+ },
},
};
diff --git a/cypress-tests/cypress/e2e/configs/Payment/Paypal.js b/cypress-tests/cypress/e2e/configs/Payment/Paypal.js
index b70b55983f..3c5b9f26a1 100644
--- a/cypress-tests/cypress/e2e/configs/Payment/Paypal.js
+++ b/cypress-tests/cypress/e2e/configs/Payment/Paypal.js
@@ -908,5 +908,10 @@ export const connectorDetails = {
path: "resource.supplementary_data.related_ids.order_id",
type: "string",
},
+ RefundIdConfig: {
+ // PayPal refund webhooks use resource.id as the connector refund reference
+ path: "resource.id",
+ type: "string",
+ },
},
};
diff --git a/cypress-tests/cypress/e2e/configs/Payment/Stripe.js b/cypress-tests/cypress/e2e/configs/Payment/Stripe.js
index 473cbb71e4..ef08dcfaf3 100644
--- a/cypress-tests/cypress/e2e/configs/Payment/Stripe.js
+++ b/cypress-tests/cypress/e2e/configs/Payment/Stripe.js
@@ -1073,5 +1073,10 @@ export const connectorDetails = {
// Type of payment reference ID
type: "string",
},
+ RefundIdConfig: {
+ // Stripe refund webhooks use data.object.id as the connector refund reference
+ path: "data.object.id",
+ type: "string",
+ },
},
};
diff --git a/cypress-tests/cypress/e2e/configs/Payment/Utils.js b/cypress-tests/cypress/e2e/configs/Payment/Utils.js
index ac32326dca..2d5b1c6d32 100644
--- a/cypress-tests/cypress/e2e/configs/Payment/Utils.js
+++ b/cypress-tests/cypress/e2e/configs/Payment/Utils.js
@@ -498,6 +498,15 @@ export const CONNECTOR_LISTS = {
"trustpay",
"worldpay",
],
+ REFUNDS_WEBHOOK: [
+ "airwallex",
+ "finix",
+ "fiuu",
+ "nmi",
+ "novalnet",
+ "paypal",
+ "stripe",
+ ],
CARD_INSTALLMENTS: ["adyen"],
AUTO_RETRY: [
"cybersource",
diff --git a/cypress-tests/cypress/e2e/configs/Payment/WorldPay.js b/cypress-tests/cypress/e2e/configs/Payment/WorldPay.js
index 1438a6947e..6eb0fb7a20 100644
--- a/cypress-tests/cypress/e2e/configs/Payment/WorldPay.js
+++ b/cypress-tests/cypress/e2e/configs/Payment/WorldPay.js
@@ -1085,21 +1085,4 @@ export const connectorDetails = {
},
},
},
- webhook: {
- TransactionIdConfig: {
- // Defines how to locate and parse the payment reference ID from connector-specific webhook payloads
- path: "eventDetails.transactionReference",
- // Type of payment reference ID
- type: "string",
- // WorldPay webhook handler uses PaymentAttemptId for lookup, not ConnectorTransactionId
- source: "paymentAttemptID",
- },
- // WorldPay requires mandatory HMAC-SHA256 webhook signature verification.
- // This hex secret is used both during connector creation (connector_webhook_details)
- // and to compute the Event-Signature header when sending test webhooks.
- webhookSecret:
- "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
- signatureHeader: "Event-Signature",
- signaturePrefix: "mac/sha256/",
- },
};
diff --git a/cypress-tests/cypress/e2e/spec/Payment/44-PaymentWebhook.cy.js b/cypress-tests/cypress/e2e/spec/Payment/44-PaymentWebhook.cy.js
index d415eda2e5..15fe8a237d 100644
--- a/cypress-tests/cypress/e2e/spec/Payment/44-PaymentWebhook.cy.js
+++ b/cypress-tests/cypress/e2e/spec/Payment/44-PaymentWebhook.cy.js
@@ -47,17 +47,6 @@ describe("Payment Webhook Tests", () => {
it("Create merchant connector account", () => {
const connectorBody = structuredClone(fixtures.createConnectorBody);
- // If connector requires webhook signature verification (e.g. WorldPay),
- // set connector_webhook_details with the test secret during connector creation
- const webhookConfig = getConnectorDetails(globalState.get("connectorId"))[
- "webhook"
- ];
- if (webhookConfig?.webhookSecret) {
- connectorBody.connector_webhook_details = {
- merchant_secret: webhookConfig.webhookSecret,
- };
- }
-
cy.createConnectorCallTest(
"payment_processor",
connectorBody,
diff --git a/cypress-tests/cypress/e2e/spec/Payment/45-RefundWebhook.cy.js b/cypress-tests/cypress/e2e/spec/Payment/45-RefundWebhook.cy.js
new file mode 100644
index 0000000000..6b5610cf5a
--- /dev/null
+++ b/cypress-tests/cypress/e2e/spec/Payment/45-RefundWebhook.cy.js
@@ -0,0 +1,156 @@
+import * as fixtures from "../../../fixtures/imports";
+import State from "../../../utils/State";
+import getConnectorDetails, * as utils from "../../configs/Payment/Utils";
+import { payment_methods_enabled } from "../../configs/Payment/Commons";
+
+let globalState;
+let connector;
+
+describe("Refund Webhook Tests", () => {
+ before("seed global state", function () {
+ let skip = false;
+
+ cy.task("getGlobalState")
+ .then((state) => {
+ globalState = new State(state);
+ connector = globalState.get("connectorId");
+
+ if (
+ utils.shouldIncludeConnector(
+ connector,
+ utils.CONNECTOR_LISTS.INCLUDE.REFUNDS_WEBHOOK
+ )
+ ) {
+ skip = true;
+ }
+ })
+ .then(() => {
+ if (skip) {
+ this.skip();
+ }
+ });
+ });
+
+ after("flush global state", () => {
+ cy.task("setGlobalState", globalState.data);
+ });
+
+ it("merchant-create-call-test", () => {
+ cy.merchantCreateCallTest(fixtures.merchantCreateBody, globalState);
+ });
+
+ it("api-key-create-call-test", () => {
+ cy.apiKeyCreateTest(fixtures.apiKeyCreateBody, globalState);
+ });
+
+ it("Create merchant connector account", () => {
+ const connectorBody = structuredClone(fixtures.createConnectorBody);
+
+ const webhookConfig = getConnectorDetails(globalState.get("connectorId"))[
+ "webhook"
+ ];
+ if (webhookConfig?.webhookSecret) {
+ connectorBody.connector_webhook_details = {
+ merchant_secret: webhookConfig.webhookSecret,
+ };
+ }
+
+ cy.createConnectorCallTest(
+ "payment_processor",
+ connectorBody,
+ payment_methods_enabled,
+ globalState
+ );
+ });
+
+ context("NoThreeDS Auto Capture + Refund flow", () => {
+ it("create-payment-call-test", () => {
+ const data = getConnectorDetails(globalState.get("connectorId"))[
+ "card_pm"
+ ]["PaymentIntent"];
+
+ cy.createPaymentIntentTest(
+ fixtures.createPaymentBody,
+ data,
+ "no_three_ds",
+ "automatic",
+ globalState
+ );
+ });
+
+ it("payment_methods-call-test", () => {
+ cy.paymentMethodsCallTest(globalState);
+ });
+
+ it("Confirm No 3DS Auto Capture", () => {
+ const data = getConnectorDetails(globalState.get("connectorId"))[
+ "card_pm"
+ ]["No3DSAutoCapture"];
+
+ cy.confirmCallTest(fixtures.confirmBody, data, true, globalState);
+ });
+
+ it("refund-call-test", () => {
+ const data = getConnectorDetails(globalState.get("connectorId"))[
+ "card_pm"
+ ]["Refund"];
+
+ cy.refundCallTest(fixtures.refundBody, data, globalState);
+ });
+
+ it("sync-refund-call-test", () => {
+ // Sync to ensure connectorRefundId is populated in globalState
+ // before sending the refund webhook
+ const data = getConnectorDetails(globalState.get("connectorId"))[
+ "card_pm"
+ ]["SyncRefund"];
+
+ cy.syncRefundCallTest(data, globalState);
+ });
+ });
+
+ context("Refund Webhook Processing - Status Update & Retrieval", function () {
+ let merchantId;
+
+ before(function () {
+ connector = globalState.get("connectorId");
+ merchantId = globalState.get("merchantId");
+
+ // Skip this context if connectorRefundId is not available
+ // (sandbox connectors may not return it)
+ if (!globalState.get("connectorRefundId")) {
+ this.skip();
+ }
+ });
+
+ it("Update-refund_status", () => {
+ const refundManualUpdateRequestBody = {
+ merchant_id: merchantId,
+ status: "pending",
+ };
+
+ cy.manualRefundStatusUpdateTest(
+ globalState,
+ refundManualUpdateRequestBody
+ );
+ });
+
+ it("send-refund-webhook", () => {
+ const webhookBody = structuredClone(
+ fixtures.IncomingWebhookBody.webhookBodies[connector]["refund"]
+ );
+
+ const webhookConfig = getConnectorDetails(connector)["webhook"];
+
+ cy.IncomingWebhookTest(globalState, webhookBody, webhookConfig, "refund");
+ });
+
+ it("Sync Refund Call Test", () => {
+ const data = getConnectorDetails(globalState.get("connectorId"))[
+ "card_pm"
+ ]["SyncRefund"];
+
+ cy.syncRefundCallTest(data, globalState);
+ });
+ });
+});
diff --git a/cypress-tests/cypress/fixtures/webhooks/airwallex_refund_webhook.json b/cypress-tests/cypress/fixtures/webhooks/airwallex_refund_webhook.json
new file mode 100644
index 0000000000..d38a032dd0
--- /dev/null
+++ b/cypress-tests/cypress/fixtures/webhooks/airwallex_refund_webhook.json
@@ -0,0 +1,7 @@
+{
+ "name": "refund.succeeded",
+ "sourceId": "{{connector_refund_id}}",
+ "data": {
+ "object": {}
+ }
+}
diff --git a/cypress-tests/cypress/fixtures/webhooks/finix_refund_webhook.json b/cypress-tests/cypress/fixtures/webhooks/finix_refund_webhook.json
new file mode 100644
index 0000000000..72775a1e62
--- /dev/null
+++ b/cypress-tests/cypress/fixtures/webhooks/finix_refund_webhook.json
@@ -0,0 +1,21 @@
+{
+ "id": "event_cgGzzdKrV3fbsd74ugymaX",
+ "type": "created",
+ "entity": "transfer",
+ "occurred_at": "2025-12-22T05:19:03.022174",
+ "_embedded": {
+ "transfers": [
+ {
+ "id": "{{connector_refund_id}}",
+ "amount": 6000,
+ "state": "SUCCEEDED",
+ "currency": "USD",
+ "type": "REVERSAL",
+ "trace_id": "FNXtrace123456",
+ "created_at": "2025-12-22T05:19:03.437Z",
+ "updated_at": "2025-12-22T05:19:03.437Z",
+ "tags": {}
+ }
+ ]
+ }
+}
diff --git a/cypress-tests/cypress/fixtures/webhooks/fiuu_refund_webhook.json b/cypress-tests/cypress/fixtures/webhooks/fiuu_refund_webhook.json
new file mode 100644
index 0000000000..cc8d9fbf28
--- /dev/null
+++ b/cypress-tests/cypress/fixtures/webhooks/fiuu_refund_webhook.json
@@ -0,0 +1,10 @@
+{
+ "RefundType": "P",
+ "MerchantID": "test_merchant_id",
+ "RefID": "test_ref_id",
+ "RefundID": "{{connector_refund_id}}",
+ "TxnID": "test_txn_id",
+ "Amount": "60.00",
+ "Status": "00",
+ "Signature": "dGVzdF9zaWduYXR1cmU="
+}
diff --git a/cypress-tests/cypress/fixtures/webhooks/import.js b/cypress-tests/cypress/fixtures/webhooks/import.js
index 4fa6ec7b3c..0342c32ba7 100644
--- a/cypress-tests/cypress/fixtures/webhooks/import.js
+++ b/cypress-tests/cypress/fixtures/webhooks/import.js
@@ -10,11 +10,18 @@ import novalnetPayment from "./novalnet_payment_webhook.json";
import payloadPayment from "./payload_payment_webhook.json";
import paypalPayment from "./paypal_payment_webhook.json";
import trustpayPayment from "./trustpay_payment_webhook.json";
-import worldpayPayment from "./worldpay_payment_webhook.json";
+import airwallexRefund from "./airwallex_refund_webhook.json";
+import finixRefund from "./finix_refund_webhook.json";
+import fiuuRefund from "./fiuu_refund_webhook.json";
+import nmiRefund from "./nmi_refund_webhook.json";
+import novalnetRefund from "./novalnet_refund_webhook.json";
+import paypalRefund from "./paypal_refund_webhook.json";
+import stripeRefund from "./stripe_refund_webhook.json";
export const webhookBodies = {
stripe: {
payment: stripePayment,
+ refund: stripeRefund,
},
noon: {
payment: noonPayment,
@@ -24,32 +31,35 @@ export const webhookBodies = {
},
airwallex: {
payment: airwallexPayment,
+ refund: airwallexRefund,
},
finix: {
payment: finixPayment,
+ refund: finixRefund,
},
fiuu: {
payment: fiuuPayment,
+ refund: fiuuRefund,
},
mollie: {
payment: molliePayment,
},
nmi: {
payment: nmiPayment,
+ refund: nmiRefund,
},
novalnet: {
payment: novalnetPayment,
+ refund: novalnetRefund,
},
payload: {
payment: payloadPayment,
},
paypal: {
payment: paypalPayment,
+ refund: paypalRefund,
},
trustpay: {
payment: trustpayPayment,
},
- worldpay: {
- payment: worldpayPayment,
- },
};
diff --git a/cypress-tests/cypress/fixtures/webhooks/nmi_refund_webhook.json b/cypress-tests/cypress/fixtures/webhooks/nmi_refund_webhook.json
new file mode 100644
index 0000000000..b8ef10bcfc
--- /dev/null
+++ b/cypress-tests/cypress/fixtures/webhooks/nmi_refund_webhook.json
@@ -0,0 +1,11 @@
+{
+ "event_type": "transaction.refund.success",
+ "event_body": {
+ "transaction_id": "123456789",
+ "order_id": "{{refund_id}}",
+ "condition": "success",
+ "action": {
+ "action_type": "refund"
+ }
+ }
+}
diff --git a/cypress-tests/cypress/fixtures/webhooks/novalnet_refund_webhook.json b/cypress-tests/cypress/fixtures/webhooks/novalnet_refund_webhook.json
new file mode 100644
index 0000000000..e672798b74
--- /dev/null
+++ b/cypress-tests/cypress/fixtures/webhooks/novalnet_refund_webhook.json
@@ -0,0 +1,30 @@
+{
+ "event": {
+ "checksum": "dGVzdF9jaGVja3N1bQ==",
+ "tid": "{{connector_refund_id}}",
+ "parent_tid": null,
+ "type": "TRANSACTION_REFUND"
+ },
+ "result": {
+ "status": "SUCCESS",
+ "status_code": 100,
+ "status_text": "Successful"
+ },
+ "transaction": {
+ "amount": 6000,
+ "currency": "EUR",
+ "order_no": null,
+ "payment_type": "CREDITCARD",
+ "refund": {
+ "amount": 6000,
+ "currency": "EUR",
+ "payment_type": null,
+ "tid": null
+ },
+ "refunded_amount": 6000,
+ "status": "CONFIRMED",
+ "status_code": 100,
+ "test_mode": 1,
+ "tid": 12345678
+ }
+}
diff --git a/cypress-tests/cypress/fixtures/webhooks/paypal_refund_webhook.json b/cypress-tests/cypress/fixtures/webhooks/paypal_refund_webhook.json
new file mode 100644
index 0000000000..ce005538e4
--- /dev/null
+++ b/cypress-tests/cypress/fixtures/webhooks/paypal_refund_webhook.json
@@ -0,0 +1,16 @@
+{
+ "event_type": "PAYMENT.CAPTURE.REFUNDED",
+ "resource": {
+ "id": "{{connector_refund_id}}",
+ "amount": {
+ "currency_code": "USD",
+ "value": "60.00"
+ },
+ "seller_payable_breakdown": {
+ "total_refunded_amount": {
+ "currency_code": "USD",
+ "value": "60.00"
+ }
+ }
+ }
+}
diff --git a/cypress-tests/cypress/fixtures/webhooks/stripe_refund_webhook.json b/cypress-tests/cypress/fixtures/webhooks/stripe_refund_webhook.json
new file mode 100644
index 0000000000..aba4f429f5
--- /dev/null
+++ b/cypress-tests/cypress/fixtures/webhooks/stripe_refund_webhook.json
@@ -0,0 +1,25 @@
+{
+ "id": "evt_1NG8Du2eZvKYlo2CUI79vXWy",
+ "object": "event",
+ "api_version": "2019-02-19",
+ "created": 1686089970,
+ "data": {
+ "object": {
+ "id": "{{connector_refund_id}}",
+ "object": "refund",
+ "amount": 6000,
+ "currency": "usd",
+ "created": 1686089970,
+ "metadata": {},
+ "payment_intent": "pi_1NG8Du2eZvKYlo2C",
+ "status": "succeeded"
+ }
+ },
+ "livemode": false,
+ "pending_webhooks": 0,
+ "request": {
+ "id": null,
+ "idempotency_key": null
+ },
+ "type": "charge.refund.updated"
+}
diff --git a/cypress-tests/cypress/fixtures/webhooks/worldpay_payment_webhook.json b/cypress-tests/cypress/fixtures/webhooks/worldpay_payment_webhook.json
deleted file mode 100644
index 177a5b73b2..0000000000
--- a/cypress-tests/cypress/fixtures/webhooks/worldpay_payment_webhook.json
+++ /dev/null
@@ -1,8 +0,0 @@
-{
- "eventId": "evt_worldpay_001",
- "eventTimestamp": "2024-06-15T12:00:00.000Z",
- "eventDetails": {
- "type": "sentForSettlement",
- "transactionReference": "{{connector_transaction_id}}"
- }
-}
diff --git a/cypress-tests/cypress/support/commands.js b/cypress-tests/cypress/support/commands.js
index 001c689433..14d7aa4063 100644
--- a/cypress-tests/cypress/support/commands.js
+++ b/cypress-tests/cypress/support/commands.js
@@ -3415,6 +3415,7 @@ Cypress.Commands.add("refundCallTest", (requestBody, data, globalState) => {
expect(response.headers["content-type"]).to.include("application/json");
if (response.status === 200) {
globalState.set("refundId", response.body.refund_id);
+ globalState.set("connectorRefundId", response.body.connector_refund_id);
for (const key in resData.body) {
expect(resData.body[key]).to.equal(response.body[key]);
}
@@ -3444,6 +3445,9 @@ Cypress.Commands.add("syncRefundCallTest", (data, globalState) => {
cy.wrap(response).then(() => {
expect(response.headers["content-type"]).to.include("application/json");
+ if (response.status === 200) {
+ globalState.set("connectorRefundId", response.body.connector_refund_id);
+ }
for (const key in resData.body) {
expect(resData.body[key]).to.equal(response.body[key]);
}
@@ -5614,21 +5618,84 @@ Cypress.Commands.add(
}
);
+Cypress.Commands.add(
+ "manualRefundStatusUpdateTest",
+ (globalState, refundManualUpdateRequestBody) => {
+ const merchantId = globalState.get("merchantId");
+ const refundId = globalState.get("refundId");
+ const completeUrl = `${Cypress.env("BASEURL")}/refunds/${refundId}/manual-update`;
+ const adminApiKey = globalState.get("adminApiKey");
+
+ cy.request({
+ method: "PUT",
+ url: completeUrl,
+ headers: {
+ "Content-Type": "application/json",
+ "api-key": adminApiKey,
+ "X-Merchant-Id": merchantId,
+ },
+ body: refundManualUpdateRequestBody,
+ failOnStatusCode: false,
+ }).then((response) => {
+ logRequestId(response.headers["x-request-id"]);
+
+ cy.wrap(response).then(() => {
+ if (response.status === 200) {
+ expect(response.status).to.eq(200);
+ } else {
+ throw new Error(
+ `Refund Manual Update Call Failed with error code "${response.body?.error?.code}" error message "${response.body?.error?.message}"`
+ );
+ }
+ });
+ });
+ }
+);
+
Cypress.Commands.add(
"IncomingWebhookTest",
- (globalState, webhookBody, webhookConfig) => {
+ (globalState, webhookBody, webhookConfig, webhookType = "payment") => {
const connector = globalState.get("connectorId");
const merchantId = globalState.get("merchantId");
const completeUrl = `${Cypress.env("BASEURL")}/webhooks/${merchantId}/${connector}`;
- // Normalize transaction ID
- const txnConfig = webhookConfig.TransactionIdConfig;
- const txnId =
- txnConfig.source === "paymentAttemptID"
- ? `${globalState.get("paymentID")}_1`
- : globalState.get("connectorTransactionID");
+ // Resolve the reference ID based on webhook type
+ const webhookTypeMap = {
+ payment: {
+ configKey: "TransactionIdConfig",
+ resolveId: (config) =>
+ config.source === "paymentAttemptID"
+ ? `${globalState.get("paymentID")}_1`
+ : globalState.get("connectorTransactionID"),
+ },
+ refund: {
+ configKey: "RefundIdConfig",
+ resolveId: (config) =>
+ config.source === "refundId"
+ ? globalState.get("refundId")
+ : globalState.get("connectorRefundId"),
+ },
+ };
+
+ const { configKey, resolveId } = webhookTypeMap[webhookType];
+ const config = webhookConfig[configKey];
+ const id = resolveId(config);
+
+ cy.task(
+ "cli_log",
+ `${webhookType} webhook ID: ${id}, config: ${configKey}`
+ );
+
+ if (!id) {
+ cy.task(
+ "cli_log",
+ `Skipping ${webhookType} webhook: ID is not available`
+ );
+
+ return;
+ }
- setNormalizedValue(webhookBody, txnConfig, txnId);
+ setNormalizedValue(webhookBody, config, id);
const contentType = webhookConfig.contentType || "application/json";