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

test(cypress): add offer engine payment coverage (#13897)

venkatakarthikm-makerddb7f3d72ea3
diff --git a/cypress-tests/cypress.config.js b/cypress-tests/cypress.config.js
index fa92283162..7a99851bc8 100644
--- a/cypress-tests/cypress.config.js
+++ b/cypress-tests/cypress.config.js
@@ -24,6 +24,7 @@ const forwardedEnv = [
"SUPERPOSITION_AUTH_TOKEN",
"SUPERPOSITION_ORG_ID",
"SUPERPOSITION_WORKSPACE_ID",
+ "OFFER_ENGINE_API_KEY",
].reduce((acc, name) => {
// Only forward what is actually set, so an absent variable never shadows a
// CYPRESS_ prefixed one
diff --git a/cypress-tests/cypress/e2e/configs/Payment/Commons.js b/cypress-tests/cypress/e2e/configs/Payment/Commons.js
index 4ea971c52f..996d445656 100644
--- a/cypress-tests/cypress/e2e/configs/Payment/Commons.js
+++ b/cypress-tests/cypress/e2e/configs/Payment/Commons.js
@@ -1,6 +1,8 @@
// This file is the default. To override, add to connector.js
import { getCurrency, getCustomExchange } from "./Modifiers";
+export const OFFER_QUOTE_ID_PLACEHOLDER = "OFFER_QUOTE_ID_FROM_STATE";
+
export const blockedPaymentErrorBodyForIssuingCountry = {
status: 200,
expectBlockedPayment: true,
@@ -4705,6 +4707,138 @@ export const connectorDetails = {
},
}),
},
+ offer_engine: {
+ PaymentIntentForOffer: getCustomExchange({
+ Request: {
+ currency: "USD",
+ amount: 100000,
+ },
+ Response: {
+ status: 200,
+ body: {
+ status: "requires_payment_method",
+ },
+ },
+ }),
+ OfferEligibilityCheck: getCustomExchange({
+ Request: {
+ payment_method_type: "card",
+ payment_method_data: {
+ card: successfulNo3DSCardDetails,
+ billing: standardBillingAddress,
+ },
+ },
+ Response: {
+ status: 200,
+ body: {
+ amount_details: {
+ total_amount: 100000,
+ net_amount: 98000,
+ currency: "USD",
+ },
+ offer_details: {
+ uplifted_offer_quote_ids: [""],
+ eligible_offers: [
+ {
+ offer_amount: 2000,
+ currency: "USD",
+ code: "TESTHS",
+ },
+ ],
+ },
+ },
+ },
+ }),
+ ConfirmWithOfferApplied: getCustomExchange({
+ Request: {
+ payment_method: "card",
+ payment_method_data: {
+ card: successfulNo3DSCardDetails,
+ billing: standardBillingAddress,
+ },
+ offer_details: {
+ offer_quote_ids: [OFFER_QUOTE_ID_PLACEHOLDER],
+ },
+ },
+ Response: {
+ status: 200,
+ body: {
+ status: "succeeded",
+ amount: 100000,
+ net_amount: 98000,
+ amount_received: 98000,
+ currency: "USD",
+ },
+ },
+ }),
+ AppliedOfferOnRetrieve: getCustomExchange({
+ Request: {},
+ Response: {
+ status: 200,
+ body: {
+ status: "succeeded",
+ net_amount: 98000,
+ amount_received: 98000,
+ applied_offer: {
+ offer_amount: 2000,
+ currency: "USD",
+ },
+ },
+ },
+ }),
+ ConfirmWithoutOffer: getCustomExchange({
+ Request: {
+ payment_method: "card",
+ payment_method_data: {
+ card: successfulNo3DSCardDetails,
+ billing: standardBillingAddress,
+ },
+ },
+ Response: {
+ status: 200,
+ body: {
+ status: "succeeded",
+ amount: 100000,
+ net_amount: 100000,
+ amount_received: 100000,
+ currency: "USD",
+ applied_offer: null,
+ },
+ },
+ }),
+ // PR #13850: a saved-card confirm carries only payment_token + card_token
+ // (CVC), not the PAN. Verifies /apply still resolves card_bin/network
+ // correctly at confirm time for a repeat customer, instead of sending
+ // them null (the bug this PR fixed). Card is saved via the existing
+ // card_pm.SaveCardUseNo3DSAutoCapture fixture; the eligibility/confirm/
+ // retrieve expectations for this flow are identical to the plain-card
+ // case above (OfferEligibilityCheck/ConfirmWithOfferApplied/
+ // AppliedOfferOnRetrieve), reused directly rather than duplicated here —
+ // saveCardConfirmCallTest already strips payment_method_data out of
+ // whatever confirm fixture it's given.
+ // PR #13766: once a card has availed an offer, Offer Engine blocks that
+ // same card (via card_alias, a PAN-free fingerprint) from availing it
+ // again, independent of the customer.
+ VelocityEligibilityCheckSecondUse: getCustomExchange({
+ Request: {
+ payment_method_type: "card",
+ payment_method_data: {
+ card: successfulNo3DSCardDetails,
+ billing: standardBillingAddress,
+ },
+ },
+ Response: {
+ status: 200,
+ body: {
+ amount_details: {
+ total_amount: 100000,
+ net_amount: 100000,
+ currency: "USD",
+ },
+ },
+ },
+ }),
+ },
auth_service_eligibility: {
OrgEnabledMerchantEnabled: getCustomExchange({
Request: {
diff --git a/cypress-tests/cypress/e2e/spec/Payment/54-OfferEngine.cy.js b/cypress-tests/cypress/e2e/spec/Payment/54-OfferEngine.cy.js
new file mode 100644
index 0000000000..150f5d97f8
--- /dev/null
+++ b/cypress-tests/cypress/e2e/spec/Payment/54-OfferEngine.cy.js
@@ -0,0 +1,265 @@
+import * as fixtures from "../../../fixtures/imports";
+import State from "../../../utils/State";
+import { connectorDetails } from "../../../e2e/configs/Payment/Commons";
+import getConnectorDetails from "../../configs/Payment/Utils";
+
+let globalState;
+
+describe("Offer Engine", () => {
+ before("seed global state and verify Offer Engine connectivity", function () {
+ let skip = false;
+
+ cy.task("getGlobalState")
+ .then((state) => {
+ globalState = new State(state);
+
+ return cy.setMerchantOfferEngineConfig(globalState);
+ })
+ .then(() => {
+ // Scoped per merchant (processor_merchant_id), since the untargeted
+ // default is "none"/false for all three keys. Only this spec's
+ // merchant needs offers enabled, so this lives here rather than in
+ // 01-AccountCreate.cy.js's common setup.
+ cy.createSuperpositionOverrides(
+ globalState,
+ {
+ "offer_engine.enabled": true,
+ "offer_engine.credential_source": "merchant",
+ "payments.should_perform_eligibility": true,
+ },
+ { processor_merchant_id: globalState.get("merchantId") }
+ );
+ })
+ .then(() => {
+ return cy.offerEngineConnectivityCheck(globalState);
+ })
+ .then((reachable) => {
+ // /offer_engine/connectivity always reports unreachable when
+ // offer_engine.credential_source is "merchant", since that check has
+ // no merchant context to resolve credentials against. Fall back to a
+ // merchant-scoped signal: does this run's merchant have its own
+ // offer_engine_config set (via setMerchantOfferEngineConfig above).
+ if (reachable) {
+ return cy.wrap(true);
+ }
+
+ return cy.offerEngineMerchantConfiguredCheck(globalState);
+ })
+ .then((reachable) => {
+ if (!reachable) {
+ cy.task(
+ "cli_log",
+ "Offer Engine is not reachable/enabled in this environment, skipping Offer Engine spec"
+ );
+ skip = true;
+ }
+ })
+ .then(() => {
+ if (skip) {
+ this.skip();
+ }
+ });
+ });
+
+ after("flush global state", () => {
+ // Clear so a stale quote id can never leak into a later spec/run via
+ // persisted globalState if some future eligibility call here ever
+ // returns zero eligible offers (the "set only if present" pattern in
+ // paymentsOfferEligibilityCheck would otherwise just leave the old
+ // value in place rather than failing loudly).
+ globalState.set("offerQuoteId", undefined);
+ cy.task("setGlobalState", globalState.data);
+ });
+
+ context("Eligible offer is surfaced and applied at confirm", () => {
+ it("payment intent create call", () => {
+ cy.createPaymentIntentTest(
+ fixtures.createPaymentBody,
+ connectorDetails.offer_engine.PaymentIntentForOffer,
+ "no_three_ds",
+ "automatic",
+ globalState
+ );
+ });
+
+ it("payment eligibility check surfaces an eligible offer", () => {
+ // Clear before each cycle so a stale quote id from a previous
+ // context can never silently be reused if this call were to return
+ // zero eligible offers.
+ globalState.set("offerQuoteId", undefined);
+ cy.paymentsOfferEligibilityCheck(
+ fixtures.eligibilityCheckBody,
+ connectorDetails.offer_engine.OfferEligibilityCheck,
+ globalState
+ );
+ });
+
+ it("confirm call applies the selected offer", () => {
+ cy.confirmCallTest(
+ fixtures.confirmBody,
+ connectorDetails.offer_engine.ConfirmWithOfferApplied,
+ true,
+ globalState
+ );
+ });
+
+ it("applied_offer is reflected on payment retrieve", () => {
+ cy.retrievePaymentCallTest({
+ globalState,
+ data: connectorDetails.offer_engine.AppliedOfferOnRetrieve,
+ expectedIntentStatus: "succeeded",
+ });
+ });
+ });
+
+ context("Payment without an offer stays unaffected", () => {
+ it("payment intent create call", () => {
+ cy.createPaymentIntentTest(
+ fixtures.createPaymentBody,
+ connectorDetails.offer_engine.PaymentIntentForOffer,
+ "no_three_ds",
+ "automatic",
+ globalState
+ );
+ });
+
+ it("confirm call without offer_details leaves applied_offer null", () => {
+ cy.confirmCallTest(
+ fixtures.confirmBody,
+ connectorDetails.offer_engine.ConfirmWithoutOffer,
+ true,
+ globalState
+ );
+ });
+ });
+
+ // PR #13766 secondary change: when offers are enabled, the payment-method-
+ // list response should signal the SDK to run eligibility before confirm
+ // (sdk_next_action.next_action: eligibility_check,
+ // should_block_confirm: true) rather than going straight to confirm. This
+ // is the actual gating mechanism the SDK relies on — 54-OfferEngine.cy.js's
+ // other contexts call /eligibility directly and never exercise this signal.
+ context(
+ "Payment method list signals eligibility check when offers are enabled",
+ () => {
+ it("payment intent create call", () => {
+ cy.createPaymentIntentTest(
+ fixtures.createPaymentBody,
+ connectorDetails.offer_engine.PaymentIntentForOffer,
+ "no_three_ds",
+ "automatic",
+ globalState
+ );
+ });
+
+ it("payment method list signals an eligibility check is required", () => {
+ cy.paymentMethodListSdkNextActionCheck(globalState, {
+ next_action: "eligibility_check",
+ should_block_confirm: true,
+ });
+ });
+ }
+ );
+
+ // PR #13850: confirm-time /apply reads the card straight off
+ // payment_data.payment_method_data. For a saved-card confirm that's still
+ // the CardToken variant at that point (the real card is only dereferenced
+ // later, in the connector-call phase), so /apply used to see null
+ // card_bin/card_network/card_alias. This exercises exactly that path: a
+ // second payment confirmed via payment_token (not raw PAN) with an offer
+ // applied.
+ context("Offer applies correctly on a saved-card confirm", () => {
+ it("create customer", () => {
+ cy.createCustomerCallTest(fixtures.customerCreateBody, globalState);
+ });
+
+ it("save a card via a plain create+confirm payment", () => {
+ cy.createConfirmPaymentTest(
+ fixtures.createConfirmPaymentBody,
+ getConnectorDetails(globalState.get("connectorId"))["card_pm"][
+ "SaveCardUseNo3DSAutoCapture"
+ ],
+ "no_three_ds",
+ "automatic",
+ globalState
+ );
+ });
+
+ it("list customer payment methods", () => {
+ cy.listCustomerPMCallTest(globalState);
+ });
+
+ it("payment intent create call", () => {
+ cy.createPaymentIntentTest(
+ fixtures.createPaymentBody,
+ connectorDetails.offer_engine.PaymentIntentForOffer,
+ "no_three_ds",
+ "automatic",
+ globalState
+ );
+ });
+
+ it("payment eligibility check surfaces an eligible offer", () => {
+ // Clear before each cycle so a stale quote id from a previous
+ // context can never silently be reused if this call were to return
+ // zero eligible offers.
+ globalState.set("offerQuoteId", undefined);
+ cy.paymentsOfferEligibilityCheck(
+ fixtures.eligibilityCheckBody,
+ connectorDetails.offer_engine.OfferEligibilityCheck,
+ globalState
+ );
+ });
+
+ it("saved-card confirm call applies the selected offer", () => {
+ const saveCardBody = Cypress._.cloneDeep(fixtures.saveCardConfirmBody);
+ cy.saveCardConfirmCallTest(
+ saveCardBody,
+ connectorDetails.offer_engine.ConfirmWithOfferApplied,
+ globalState
+ );
+ });
+
+ it("applied_offer is reflected on payment retrieve", () => {
+ cy.retrievePaymentCallTest({
+ globalState,
+ data: connectorDetails.offer_engine.AppliedOfferOnRetrieve,
+ expectedIntentStatus: "succeeded",
+ });
+ });
+ });
+
+ // PR #13766: once a card has availed an offer, Offer Engine blocks that
+ // exact card (via a PAN-free card_alias fingerprint) from availing it
+ // again, independent of which customer/payment uses it.
+ //
+ // Commented out for now: this needs a dedicated once-per-card offer
+ // (the PR's own testing used offer code HSVELO1, counter
+ // CARD_IDENTIFIER = MAX 1) rather than TESTHS, since TESTHS has no
+ // redemption cap and reusing it here would collide with the "saved-card"
+ // context above (which also uses this same card and needs the offer to
+ // still be applicable). HSVELO1 already exists on qaoffers but is
+ // currently Paused, and neither of us has access to Offer Engine's
+ // "Custom Rule Configuration" to build an equivalent counter from
+ // scratch. Re-enable once HSVELO1 is activated.
+ //
+ // context("Once-per-card offer velocity blocks reuse of the same card", () => {
+ // it("payment intent create call", () => {
+ // cy.createPaymentIntentTest(
+ // fixtures.createPaymentBody,
+ // connectorDetails.offer_engine.PaymentIntentForOffer,
+ // "no_three_ds",
+ // "automatic",
+ // globalState
+ // );
+ // });
+ //
+ // it("eligibility check no longer surfaces an offer for the already-used card", () => {
+ // cy.paymentsOfferEligibilityCheck(
+ // fixtures.eligibilityCheckBody,
+ // connectorDetails.offer_engine.VelocityEligibilityCheckSecondUse,
+ // globalState
+ // );
+ // });
+ // });
+});
diff --git a/cypress-tests/cypress/e2e/spec/Payment/54-OfferEngineBrowse.cy.js b/cypress-tests/cypress/e2e/spec/Payment/54-OfferEngineBrowse.cy.js
new file mode 100644
index 0000000000..24d0662ad0
--- /dev/null
+++ b/cypress-tests/cypress/e2e/spec/Payment/54-OfferEngineBrowse.cy.js
@@ -0,0 +1,73 @@
+import State from "../../../utils/State";
+
+let globalState;
+
+// PR #13999: POST /offer_engine/offers/list — a merchant-dashboard browse
+// endpoint, separate from the payment-flow eligibility endpoint covered by
+// 54-OfferEngine.cy.js. No payment intent is involved; it just surfaces
+// whatever offers this merchant currently has configured and eligible.
+describe("Offer Engine - Browse Offers", () => {
+ before("seed global state and verify Offer Engine connectivity", function () {
+ let skip = false;
+
+ cy.task("getGlobalState")
+ .then((state) => {
+ globalState = new State(state);
+
+ return cy.offerEngineConnectivityCheck(globalState);
+ })
+ .then((reachable) => {
+ if (reachable) {
+ return cy.wrap(true);
+ }
+
+ return cy.offerEngineMerchantConfiguredCheck(globalState);
+ })
+ .then((reachable) => {
+ if (!reachable) {
+ cy.task(
+ "cli_log",
+ "Offer Engine is not reachable/enabled in this environment, skipping Offer Engine Browse spec"
+ );
+ skip = true;
+ }
+ })
+ .then(() => {
+ if (skip) {
+ this.skip();
+ }
+ });
+ });
+
+ after("flush global state", () => {
+ cy.task("setGlobalState", globalState.data);
+ });
+
+ it("browse offers without an order context", () => {
+ cy.browseOffersCall(
+ {},
+ {
+ Response: {
+ status: 200,
+ },
+ },
+ globalState
+ );
+ });
+
+ it("browse offers with an order context", () => {
+ cy.browseOffersCall(
+ {
+ offer_payment_info: {
+ currency: "USD",
+ },
+ },
+ {
+ Response: {
+ status: 200,
+ },
+ },
+ globalState
+ );
+ });
+});
diff --git a/cypress-tests/cypress/support/commands.js b/cypress-tests/cypress/support/commands.js
index 9bff9f9740..a79aa34b6e 100644
--- a/cypress-tests/cypress/support/commands.js
+++ b/cypress-tests/cypress/support/commands.js
@@ -36,6 +36,7 @@ import getConnectorDetails, {
shouldIncludeConnector,
stringifyWithBigInt,
} from "../e2e/configs/Payment/Utils";
+import { OFFER_QUOTE_ID_PLACEHOLDER } from "../e2e/configs/Payment/Commons";
import { injectGotymePayoutBankTransfer } from "../e2e/configs/Payout/Utils";
import { execConfig, validateConfig } from "../utils/featureFlags";
import * as RequestBodyUtils from "../utils/RequestBodyUtils";
@@ -3399,6 +3400,19 @@ Cypress.Commands.add(
if (!reqData?.setup_future_usage && confirmBody.setup_future_usage) {
delete confirmBody.setup_future_usage;
}
+ if (!reqData?.offer_details && confirmBody.offer_details) {
+ delete confirmBody.offer_details;
+ }
+ if (
+ confirmBody.offer_details?.offer_quote_ids?.includes(
+ OFFER_QUOTE_ID_PLACEHOLDER
+ )
+ ) {
+ const offerQuoteId = globalState.get("offerQuoteId");
+ expect(offerQuoteId, "offerQuoteId").to.not.be.undefined;
+
+ confirmBody.offer_details.offer_quote_ids = [offerQuoteId];
+ }
if (reqData?.split_payments && supportsSplitPayments(globalState)) {
confirmBody.split_payments = reqData.split_payments;
@@ -4608,6 +4622,17 @@ Cypress.Commands.add(
Object.assign(saveCardConfirmBody, requestDataWithoutPMD);
}
+ if (
+ saveCardConfirmBody.offer_details?.offer_quote_ids?.includes(
+ OFFER_QUOTE_ID_PLACEHOLDER
+ )
+ ) {
+ const offerQuoteId = globalState.get("offerQuoteId");
+ expect(offerQuoteId, "offerQuoteId").to.not.be.undefined;
+
+ saveCardConfirmBody.offer_details.offer_quote_ids = [offerQuoteId];
+ }
+
cy.request({
method: "POST",
url: `${globalState.get("baseUrl")}/payments/${paymentIntentID}/confirm`,
@@ -5063,6 +5088,50 @@ Cypress.Commands.add(
).to.equal(expectedIntentStatus);
}
+ if (resData?.body && "applied_offer" in resData.body) {
+ // Scoped to offer-engine fixtures only (identified by the
+ // presence of applied_offer, unique to that flow): retrieve
+ // responses across the rest of the suite were never checked
+ // against net_amount/amount_received before, and some existing
+ // fixtures elsewhere (e.g. fiuu's OnlineBankingFpx) reuse a
+ // confirm-step expectation for retrieve that doesn't actually
+ // hold once the mock resolves further — not something this
+ // command should start enforcing suite-wide.
+ for (const key of ["net_amount", "amount_received"]) {
+ if (resData?.body?.[key] !== undefined) {
+ expect(response.body[key], key).to.equal(resData.body[key]);
+ }
+ }
+
+ const expectedAppliedOffer = resData.body.applied_offer;
+
+ if (expectedAppliedOffer === null) {
+ expect(response.body.applied_offer, "applied_offer").to.be.null;
+ } else {
+ const appliedOffer = response.body.applied_offer;
+ expect(appliedOffer, "applied_offer").to.not.be.null;
+ expect(appliedOffer.offer_id, "applied_offer.offer_id").to.be.a(
+ "string"
+ ).and.not.be.empty;
+ expect(
+ appliedOffer.offer_engine_merchant_id,
+ "applied_offer.offer_engine_merchant_id"
+ ).to.be.a("string").and.not.be.empty;
+ expect(
+ appliedOffer.offer_engine_txn_id,
+ "applied_offer.offer_engine_txn_id"
+ ).to.be.a("string").and.not.be.empty;
+
+ for (const key of ["offer_amount", "currency"]) {
+ if (expectedAppliedOffer[key] !== undefined) {
+ expect(appliedOffer[key], `applied_offer.${key}`).to.equal(
+ expectedAppliedOffer[key]
+ );
+ }
+ }
+ }
+ }
+
if (
!unconfirmedPayment &&
["succeeded", "processing", "requires_customer_action"].includes(
@@ -8965,6 +9034,304 @@ Cypress.Commands.add(
}
);
+Cypress.Commands.add(
+ "paymentsOfferEligibilityCheck",
+ (requestBody, data, globalState) => {
+ const { Request: reqData, Response: resData } = data || {};
+
+ const publishableKey = globalState.get("publishableKey");
+ const baseUrl = globalState.get("baseUrl");
+ const paymentId = globalState.get("paymentID");
+ const clientSecret = globalState.get("clientSecret");
+ const url = `${baseUrl}/payments/${paymentId}/eligibility`;
+
+ const body = {
+ ...requestBody,
+ client_secret: clientSecret,
+ ...reqData,
+ };
+
+ cy.request({
+ method: "POST",
+ url: url,
+ headers: {
+ "Content-Type": "application/json",
+ "api-key": publishableKey,
+ },
+ body: body,
+ failOnStatusCode: false,
+ }).then((response) => {
+ logRequestId(response.headers["x-request-id"]);
+
+ cy.wrap(response).then(() => {
+ expect(response.headers["content-type"]).to.include("application/json");
+
+ if (response.status === 200) {
+ expect(response.body)
+ .to.have.property("payment_id")
+ .to.equal(paymentId);
+
+ if (resData?.body?.amount_details) {
+ expect(response.body).to.have.property("amount_details");
+ for (const key in resData.body.amount_details) {
+ expect(response.body.amount_details[key], [
+ `amount_details.${key}`,
+ ]).to.equal(resData.body.amount_details[key]);
+ }
+ }
+
+ if (resData?.body?.offer_details) {
+ expect(response.body).to.have.property("offer_details");
+ const expectedOfferDetails = resData.body.offer_details;
+ const offerDetails = response.body.offer_details;
+
+ if (expectedOfferDetails.uplifted_offer_quote_ids) {
+ expect(
+ offerDetails.uplifted_offer_quote_ids,
+ "offer_details.uplifted_offer_quote_ids"
+ )
+ .to.be.an("array")
+ .with.length(
+ expectedOfferDetails.uplifted_offer_quote_ids.length
+ );
+ offerDetails.uplifted_offer_quote_ids.forEach((id) => {
+ expect(
+ id,
+ "offer_details.uplifted_offer_quote_ids[].id"
+ ).to.be.a("string").and.not.be.empty;
+ });
+ }
+
+ if (expectedOfferDetails.eligible_offers) {
+ expect(
+ offerDetails.eligible_offers,
+ "offer_details.eligible_offers"
+ )
+ .to.be.an("array")
+ .with.length(expectedOfferDetails.eligible_offers.length);
+
+ offerDetails.eligible_offers.forEach((offer, index) => {
+ const expectedOffer =
+ expectedOfferDetails.eligible_offers[index];
+
+ expect(
+ offer.offer_quote_id,
+ "eligible_offers[].offer_quote_id"
+ ).to.be.a("string").and.not.be.empty;
+ expect(offer.title, "eligible_offers[].title").to.be.a("string")
+ .and.not.be.empty;
+ expect(
+ offer.description,
+ "eligible_offers[].description"
+ ).to.be.a("string").and.not.be.empty;
+
+ for (const key of ["offer_amount", "currency", "code"]) {
+ if (expectedOffer[key] !== undefined) {
+ expect(offer[key], `eligible_offers[].${key}`).to.equal(
+ expectedOffer[key]
+ );
+ }
+ }
+ });
+ }
+ }
+
+ const eligibleOffers =
+ response.body.offer_details?.eligible_offers || [];
+ if (eligibleOffers.length > 0) {
+ globalState.set("offerQuoteId", eligibleOffers[0].offer_quote_id);
+ }
+ } else {
+ throw new Error(
+ `Offer eligibility check failed with status: ${response.status} and message: ${response.body?.error?.message}`
+ );
+ }
+ });
+ });
+ }
+);
+
+// With offer_engine.credential_source set to "merchant" (a Superposition
+// override), the router only reads Offer Engine credentials from this
+// merchant account's own offer_engine_config field, not from any static
+// application config.
+Cypress.Commands.add("setMerchantOfferEngineConfig", (globalState) => {
+ const baseUrl = globalState.get("baseUrl");
+ const adminApiKey = globalState.get("adminApiKey");
+ const merchantId = globalState.get("merchantId");
+ const offerEngineApiKey = Cypress.env("OFFER_ENGINE_API_KEY");
+
+ if (!offerEngineApiKey) {
+ cy.task(
+ "cli_log",
+ "OFFER_ENGINE_API_KEY is not set; skipping merchant-level Offer Engine config"
+ );
+ return cy.wrap(null);
+ }
+
+ return cy
+ .request({
+ method: "POST",
+ url: `${baseUrl}/accounts/${merchantId}`,
+ headers: {
+ "Content-Type": "application/json",
+ "api-key": adminApiKey,
+ },
+ body: {
+ merchant_id: merchantId,
+ offer_engine_config: {
+ api_key: offerEngineApiKey,
+ // Offer Engine's own merchant id (distinct from the Hyperswitch
+ // merchant id above) — a pre-provisioned Offer Engine account, not
+ // something a fresh Cypress-created merchant has a counterpart for.
+ merchant_id: "qaoffers",
+ },
+ },
+ failOnStatusCode: false,
+ })
+ .then((response) => {
+ logRequestId(response.headers["x-request-id"]);
+ expect(response.status).to.equal(200);
+ // offer_engine_config is a write-only Secret field: GET /account/{id}
+ // never echoes it back, so there is no way to re-derive "is this
+ // merchant configured" from a later read. Record success here instead.
+ globalState.set("offerEngineMerchantConfigured", true);
+ });
+});
+
+Cypress.Commands.add("offerEngineConnectivityCheck", (globalState) => {
+ const baseUrl = globalState.get("baseUrl");
+ const adminApiKey = globalState.get("adminApiKey");
+
+ return cy
+ .request({
+ method: "POST",
+ url: `${baseUrl}/offer_engine/connectivity`,
+ headers: {
+ "Content-Type": "application/json",
+ "api-key": adminApiKey,
+ },
+ failOnStatusCode: false,
+ })
+ .then((response) => {
+ logRequestId(response.headers["x-request-id"]);
+
+ return cy.wrap(
+ response.status === 200 && Boolean(response.body?.reachable)
+ );
+ });
+});
+
+// /offer_engine/connectivity has no merchant context, so when
+// offer_engine.credential_source is "merchant" it always resolves to
+// enabled: false/reachable: null regardless of whether any merchant has
+// valid Offer Engine credentials configured. offer_engine_config is also a
+// write-only Secret field (GET /account/{id} never echoes it back), so
+// there's no way to re-derive "is this merchant configured" from a read.
+// Fall back to whatever setMerchantOfferEngineConfig recorded in
+// globalState when it ran during account setup.
+Cypress.Commands.add("offerEngineMerchantConfiguredCheck", (globalState) => {
+ return cy.wrap(Boolean(globalState.get("offerEngineMerchantConfigured")));
+});
+
+// PR #13999: POST /offer_engine/offers/list — the merchant-dashboard browse
+// endpoint. Uses the secret api-key (ApiKeyAuth), not the publishable key
+// used by the payment-flow eligibility endpoint.
+Cypress.Commands.add("browseOffersCall", (requestBody, data, globalState) => {
+ const { Request: reqData, Response: resData } = data || {};
+
+ const baseUrl = globalState.get("baseUrl");
+ // This route uses ApiKeyAuth (the merchant's own secret key from
+ // apiKeyCreateTest), not adminApiKey (platform-level, admin-only routes).
+ const apiKey = globalState.get("apiKey");
+
+ const body = {
+ ...requestBody,
+ ...reqData,
+ };
+
+ return cy
+ .request({
+ method: "POST",
+ url: `${baseUrl}/offer_engine/offers/list`,
+ headers: {
+ "Content-Type": "application/json",
+ "api-key": apiKey,
+ },
+ body,
+ failOnStatusCode: false,
+ })
+ .then((response) => {
+ logRequestId(response.headers["x-request-id"]);
+
+ cy.wrap(response).then(() => {
+ expect(response.headers["content-type"]).to.include("application/json");
+ expect(response.status).to.equal(resData?.status ?? 200);
+
+ if (response.status === 200) {
+ expect(response.body).to.have.property("offers");
+ expect(response.body.offers).to.be.an("array");
+
+ if (resData?.body?.offers) {
+ for (const key in resData.body.offers) {
+ const expectedOffer = resData.body.offers[key];
+ const actualOffer = response.body.offers[key];
+ expect(actualOffer, `offers[${key}]`).to.exist;
+ for (const field in expectedOffer) {
+ expect(actualOffer[field], `offers[${key}].${field}`).to.equal(
+ expectedOffer[field]
+ );
+ }
+ }
+ }
+ }
+ });
+ });
+});
+
+// PR #13766 secondary change: when offers are enabled for the merchant/
+// profile (and payments.should_perform_eligibility is on), the PML response
+// should signal the SDK to run eligibility and block confirm until it
+// resolves, via sdk_next_action.
+Cypress.Commands.add(
+ "paymentMethodListSdkNextActionCheck",
+ (globalState, expectedNextAction) => {
+ const baseUrl = globalState.get("baseUrl");
+ const publishableKey = globalState.get("publishableKey");
+ const clientSecret = globalState.get("clientSecret");
+
+ return cy
+ .request({
+ method: "GET",
+ url: `${baseUrl}/account/payment_methods?client_secret=${clientSecret}`,
+ headers: {
+ "Content-Type": "application/json",
+ "api-key": publishableKey,
+ },
+ failOnStatusCode: false,
+ })
+ .then((response) => {
+ logRequestId(response.headers["x-request-id"]);
+
+ cy.wrap(response).then(() => {
+ expect(response.headers["content-type"]).to.include(
+ "application/json"
+ );
+ expect(response.status).to.equal(200);
+ expect(response.body).to.have.property("sdk_next_action");
+ expect(
+ response.body.sdk_next_action.next_action,
+ "sdk_next_action.next_action"
+ ).to.equal(expectedNextAction.next_action);
+ expect(
+ response.body.sdk_next_action.should_block_confirm,
+ "sdk_next_action.should_block_confirm"
+ ).to.equal(expectedNextAction.should_block_confirm);
+ });
+ });
+ }
+);
+
// DDC Race Condition Test Commands
Cypress.Commands.add(
"ddcServerSideRaceConditionTest",
diff --git a/cypress-tests/cypress/utils/specSelection/config.js b/cypress-tests/cypress/utils/specSelection/config.js
index dcad27c098..2e3d139a8f 100644
--- a/cypress-tests/cypress/utils/specSelection/config.js
+++ b/cypress-tests/cypress/utils/specSelection/config.js
@@ -176,6 +176,7 @@ const PAYMENT_SPEC_METHODS = Object.freeze({
"54-RefundType.cy.js": ["card"],
"55-DynamicFields.cy.js": ["card"],
"56-VaultTokenizationDisable.cy.js": ["card"],
+ "54-OfferEngine.cy.js": ["card"],
"54-ConnectorAgnosticMandates.cy.js": ["card"],
});