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): create merchants with a known payment response hash key (#15374)

venkatakarthikm-makera0cfd39ea04b
diff --git a/cypress-tests/README.md b/cypress-tests/README.md
index 984624f7be..c616f38e62 100644
--- a/cypress-tests/README.md
+++ b/cypress-tests/README.md
@@ -123,9 +123,10 @@ CYPRESS_CONNECTOR="connector_id" npm run cypress:ci
# `Payment/54-ConnectorAgnosticMandates`.
export PM_SERVICE_URL="pm_service_url"
- # Payment/52-PaymentResponseHash requires the full key configured on the
- # merchant account. API responses expose only the first four characters.
- export CYPRESS_PAYMENT_RESPONSE_HASH_KEY="merchant_payment_response_hash_key"
+ # Optional. The tests create merchants with a built-in payment response hash
+ # key (at least 32 characters) because API responses expose only its first
+ # four characters. Set this to use a different key.
+ export CYPRESS_PAYMENT_RESPONSE_HASH_KEY="merchant_payment_response_hash_key_of_32_chars_or_more"
```
> [!IMPORTANT]
diff --git a/cypress-tests/cypress/support/commands.js b/cypress-tests/cypress/support/commands.js
index e64af121a4..c0a9777629 100644
--- a/cypress-tests/cypress/support/commands.js
+++ b/cypress-tests/cypress/support/commands.js
@@ -846,6 +846,8 @@ Cypress.Commands.add(
const merchantId = RequestBodyUtils.generateRandomString();
RequestBodyUtils.setMerchantId(merchantCreateBody, merchantId);
+ merchantCreateBody.payment_response_hash_key =
+ RequestBodyUtils.getPaymentResponseHashKey();
cy.request({
method: "POST",
@@ -12499,8 +12501,9 @@ Cypress.Commands.add("retrieveNonExistentPaymentLinkTest", (globalState) => {
/**
* Fetches merchant account config and stores payment response hash settings in globalState.
- * The full signing key must be supplied as CYPRESS_PAYMENT_RESPONSE_HASH_KEY;
- * account responses expose only its first four characters.
+ * Merchants are created with the key from getPaymentResponseHashKey (the test
+ * default, or CYPRESS_PAYMENT_RESPONSE_HASH_KEY); account responses expose only
+ * its first four characters.
* Also skips the suite if enable_payment_response_hash is false/absent.
*
* The backend falls back to merchant-account-level settings when business profile
@@ -12548,15 +12551,7 @@ Cypress.Commands.add("fetchPaymentResponseHashConfig", (globalState) => {
}
// Signature verification requires the full configured key, not the API prefix.
- const paymentResponseHashKey = Cypress.env("PAYMENT_RESPONSE_HASH_KEY");
- if (
- typeof paymentResponseHashKey !== "string" ||
- paymentResponseHashKey.length === 0
- ) {
- throw new Error(
- "Set CYPRESS_PAYMENT_RESPONSE_HASH_KEY to the merchant's full signing key for signature verification"
- );
- }
+ const paymentResponseHashKey = RequestBodyUtils.getPaymentResponseHashKey();
expect(
paymentResponseHashKeyPrefix,
diff --git a/cypress-tests/cypress/utils/RequestBodyUtils.js b/cypress-tests/cypress/utils/RequestBodyUtils.js
index 55a50eaf3f..a39a9c4a27 100644
--- a/cypress-tests/cypress/utils/RequestBodyUtils.js
+++ b/cypress-tests/cypress/utils/RequestBodyUtils.js
@@ -41,6 +41,15 @@ export const setMerchantId = (merchantCreateBody, merchantId) => {
merchantCreateBody["merchant_id"] = merchantId;
};
+// The API returns only the first four characters of a merchant's
+// payment_response_hash_key, so the tests create merchants with a key they know.
+// The key must be at least 32 characters. CYPRESS_PAYMENT_RESPONSE_HASH_KEY overrides it.
+const DEFAULT_PAYMENT_RESPONSE_HASH_KEY =
+ "cypress_payment_response_hash_key_0123456789";
+
+export const getPaymentResponseHashKey = () =>
+ Cypress.env("PAYMENT_RESPONSE_HASH_KEY") || DEFAULT_PAYMENT_RESPONSE_HASH_KEY;
+
export function isoTimeTomorrow() {
const now = new Date();