Add ZarinPal e-payment and related checkout/search fixes.

Business settings can store ZarinPal merchant credentials, and the payment registry can initiate and verify ZarinPal alongside Mellat.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Alireza Hassani
2026-08-16 01:45:41 +03:30
co-authored by Cursor
parent c76c3967bb
commit b991a60cbc
19 changed files with 542 additions and 39 deletions
@@ -15,6 +15,7 @@ import {
DEFAULT_MELLAT_GATEWAY_SETTINGS,
DEFAULT_ORDER_PROCESS_STEPS,
DEFAULT_STUB_GATEWAY_SETTINGS,
DEFAULT_ZARINPAL_GATEWAY_SETTINGS,
EPaymentSettings,
HOME_CHART_IDS,
MellatGatewaySettings,
@@ -25,6 +26,7 @@ import {
type PaymentGatewayId,
OrderProcessStep,
StubGatewaySettings,
ZarinpalGatewaySettings,
} from './business-settings.types';
import {
defaultOrderStepColor,
@@ -131,6 +133,24 @@ function readStubGateway(value: unknown): StubGatewaySettings {
};
}
function readZarinpalGateway(value: unknown): ZarinpalGatewaySettings {
const source = isRecord(value) ? value : {};
return {
enabled: readBoolean(
source.enabled,
DEFAULT_ZARINPAL_GATEWAY_SETTINGS.enabled,
),
merchantId: readString(
source.merchantId,
DEFAULT_ZARINPAL_GATEWAY_SETTINGS.merchantId,
),
sandbox: readBoolean(
source.sandbox,
DEFAULT_ZARINPAL_GATEWAY_SETTINGS.sandbox,
),
};
}
export function normalizeEPaymentSettings(value: unknown): EPaymentSettings {
const source = isRecord(value) ? value : {};
const gateways = isRecord(source.gateways) ? source.gateways : {};
@@ -146,7 +166,7 @@ export function normalizeEPaymentSettings(value: unknown): EPaymentSettings {
sep: readStubGateway(gateways.sep),
snappay: readStubGateway(gateways.snappay),
digipay: readStubGateway(gateways.digipay),
zarinpal: readStubGateway(gateways.zarinpal),
zarinpal: readZarinpalGateway(gateways.zarinpal),
},
};
}
@@ -177,7 +197,11 @@ export function mergeEPaymentSettings(
sep: { enabled: patch.gateways.sep.enabled },
snappay: { enabled: patch.gateways.snappay.enabled },
digipay: { enabled: patch.gateways.digipay.enabled },
zarinpal: { enabled: patch.gateways.zarinpal.enabled },
zarinpal: {
enabled: patch.gateways.zarinpal.enabled,
merchantId: patch.gateways.zarinpal.merchantId.trim(),
sandbox: patch.gateways.zarinpal.sandbox,
},
},
};
}
@@ -228,10 +252,13 @@ export function isGatewayReady(
g.password.length > 0
);
}
case 'zarinpal': {
const g = settings.gateways.zarinpal;
return g.enabled && g.merchantId.length > 0;
}
case 'sep':
case 'snappay':
case 'digipay':
case 'zarinpal':
return false;
default:
return false;