Skip to content

A self-hosted UPI & COD payment gateway with zero per-transaction platform fees, universal JavaScript checkout integration, dynamic QR payments, WhatsApp OTP authentication, and automated payment verification.

JavaScript

feat(vercel): configure multi-service deployment

jaygoga2188-collabae402569699a
diff --git a/.env.example b/.env.example
index f3edcc3..c96001a 100644
--- a/.env.example
+++ b/.env.example
@@ -8,6 +8,17 @@
# NODE_ENV is managed by the supervisor: 'production' by `npm start`, 'development' by `npm run dev`.
# NODE_ENV=development
+# --- VERCEL SERVICES ---
+# Vercel injects the following service-binding URLs at runtime. Do not set
+# these variables yourself in Vercel; they are declared in vercel.json.
+# PAYMENT_API_URL=
+# CHECKOUT_PORTAL_URL=
+# CONTROL_CENTER_URL=
+# GMAIL_OBSERVER_URL=
+# SMS_OBSERVER_URL=
+# Optional custom public origin used when payment-api returns checkout links.
+# CHECKOUT_PUBLIC_URL=https://your-domain.example
+
# --- SERVICE PORTS (Strictly Non-Docker Standard Host Topology) ---
CONTROL_CENTER_PORT=8090
PAYMENT_API_PORT=6100
@@ -80,3 +91,6 @@ WEBHOOK_INITIAL_BACKOFF_MS=5000
DEFAULT_APP_NAME="YOUPI PG"
DEFAULT_PRIMARY_COLOR="#2563eb"
DEFAULT_SUPPORT_EMAIL="[email protected]"
+# Vercel Services inject these URLs at runtime from the bindings in vercel.json.
+# Do not set PAYMENT_API_URL, CHECKOUT_PORTAL_URL, CONTROL_CENTER_URL,
+# GMAIL_OBSERVER_URL, or SMS_OBSERVER_URL manually in Vercel.
diff --git a/apps/checkout-portal/src/sdk/youpi-checkout.js b/apps/checkout-portal/src/sdk/youpi-checkout.js
index 121471f..f1eb57c 100644
--- a/apps/checkout-portal/src/sdk/youpi-checkout.js
+++ b/apps/checkout-portal/src/sdk/youpi-checkout.js
@@ -94,7 +94,7 @@
*/
constructor(options = {}) {
const defaultPortal = isBrowser
- ? (scriptConfig.portalUrl || (window.location.protocol + '//' + window.location.hostname + ':7000'))
+ ? (scriptConfig.portalUrl || window.location.origin)
: 'http://localhost:7000';
const defaultApi = isBrowser
diff --git a/apps/checkout-portal/src/sdk/youpi.js b/apps/checkout-portal/src/sdk/youpi.js
index 3e0fede..cde7e6a 100644
--- a/apps/checkout-portal/src/sdk/youpi.js
+++ b/apps/checkout-portal/src/sdk/youpi.js
@@ -94,7 +94,7 @@
*/
constructor(options = {}) {
const defaultPortal = isBrowser
- ? (scriptConfig.portalUrl || (window.location.protocol + '//' + window.location.hostname + ':7000'))
+ ? (scriptConfig.portalUrl || window.location.origin)
: 'http://localhost:7000';
const defaultApi = isBrowser
diff --git a/apps/checkout-portal/src/server.js b/apps/checkout-portal/src/server.js
index dbcaec8..cd9140c 100644
--- a/apps/checkout-portal/src/server.js
+++ b/apps/checkout-portal/src/server.js
@@ -1,4 +1,5 @@
import http from 'node:http';
+import https from 'node:https';
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
@@ -179,7 +180,7 @@ export class CheckoutServer {
}
} catch {}
- this.apiBaseUrl = options.apiBaseUrl || process.env.BASE_PAYMENT_API_URL || 'http://localhost:6100';
+ this.apiBaseUrl = options.apiBaseUrl || process.env.PAYMENT_API_URL || process.env.BASE_PAYMENT_API_URL || 'http://localhost:6100';
this.htmlTemplatePath = path.join(__dirname, 'views', 'checkout.html');
this.sdkScriptPath = path.join(__dirname, 'sdk', 'youpi-checkout.js');
this.template = fs.readFileSync(this.htmlTemplatePath, 'utf8');
@@ -187,8 +188,8 @@ export class CheckoutServer {
async fetchPaymentState(paymentId) {
try {
- const internalPort = process.env.PAYMENT_API_PORT || 6100;
- const res = await fetch(`http://127.0.0.1:${internalPort}/api/v1/checkout/${encodeURIComponent(paymentId)}/state`, {
+ const stateUrl = new URL(`/api/v1/checkout/${encodeURIComponent(paymentId)}/state`, this.apiBaseUrl);
+ const res = await fetch(stateUrl, {
headers: { 'X-Internal-Render': 'true', 'X-Internal-Token': getInternalServiceToken() }
});
if (!res.ok) return null;
@@ -309,14 +310,15 @@ export class CheckoutServer {
// Transparent API Proxy: /api/* -> Payment Core REST API
if (pathname.startsWith('/api/')) {
- const targetPort = Number(process.env.PAYMENT_API_PORT || 6100);
- const proxyReq = http.request({
- hostname: '127.0.0.1',
- port: targetPort,
- path: req.url,
+ const targetUrl = new URL(req.url, this.apiBaseUrl);
+ const requestClient = targetUrl.protocol === 'https:' ? https : http;
+ const proxyReq = requestClient.request({
+ hostname: targetUrl.hostname,
+ port: targetUrl.port || undefined,
+ path: `${targetUrl.pathname}${targetUrl.search}`,
method: req.method,
headers: {
- ...sanitizedForwardHeaders(req, `localhost:${targetPort}`),
+ ...sanitizedForwardHeaders(req, targetUrl.host),
'x-forwarded-host': req.headers.host || '',
'x-forwarded-proto': req.headers['x-forwarded-proto'] || 'https'
}
diff --git a/apps/checkout-portal/vercel-entrypoint.js b/apps/checkout-portal/vercel-entrypoint.js
new file mode 100644
index 0000000..b33ce9e
--- /dev/null
+++ b/apps/checkout-portal/vercel-entrypoint.js
@@ -0,0 +1,10 @@
+import { CheckoutServer } from './src/server.js';
+
+const checkout = new CheckoutServer({
+ apiBaseUrl: process.env.PAYMENT_API_URL || process.env.BASE_PAYMENT_API_URL
+});
+const server = checkout.createServer();
+
+export default function handler(req, res) {
+ return server.emit('request', req, res);
+}
diff --git a/apps/coin-wallet-store/src/server.js b/apps/coin-wallet-store/src/server.js
index 5ab5d11..ed05c93 100644
--- a/apps/coin-wallet-store/src/server.js
+++ b/apps/coin-wallet-store/src/server.js
@@ -1,4 +1,5 @@
import http from 'node:http';
+import https from 'node:https';
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
@@ -97,7 +98,7 @@ export class CoinWalletStoreServer {
*/
constructor(options = {}) {
const internalPort = process.env.PAYMENT_API_PORT || 6100;
- this.gatewayApiUrl = options.gatewayApiUrl || process.env.PAYMENT_API_INTERNAL_URL || `http://127.0.0.1:${internalPort}`;
+ this.gatewayApiUrl = options.gatewayApiUrl || process.env.PAYMENT_API_URL || process.env.PAYMENT_API_INTERNAL_URL || `http://127.0.0.1:${internalPort}`;
this.merchantId = options.merchantId || '00000000-0000-0000-0000-000000000001';
this.webhookSecret = options.webhookSecret || getCoinStoreWebhookSecret();
@@ -232,14 +233,16 @@ export class CoinWalletStoreServer {
// REVERSE PROXY: /checkout/*, /icons/*, /css/*, and /js/* -> Checkout Portal (Port 7000)
if (pathname.startsWith('/checkout') || pathname.startsWith('/icons/') || pathname.startsWith('/css/') || pathname.startsWith('/js/')) {
- const portalPort = Number(process.env.CHECKOUT_PORT || 7000);
- const proxyReq = http.request({
- hostname: '127.0.0.1',
- port: portalPort,
- path: req.url,
+ const portalUrl = process.env.CHECKOUT_PORTAL_URL || `http://127.0.0.1:${process.env.CHECKOUT_PORT || 7000}`;
+ const targetUrl = new URL(req.url, portalUrl);
+ const requestClient = targetUrl.protocol === 'https:' ? https : http;
+ const proxyReq = requestClient.request({
+ hostname: targetUrl.hostname,
+ port: targetUrl.port || undefined,
+ path: `${targetUrl.pathname}${targetUrl.search}`,
method: req.method,
headers: {
- ...sanitizedForwardHeaders(req, `localhost:${portalPort}`),
+ ...sanitizedForwardHeaders(req, targetUrl.host),
'x-forwarded-host': req.headers.host || '',
'x-forwarded-proto': req.headers['x-forwarded-proto'] || 'http'
}
@@ -263,13 +266,14 @@ export class CoinWalletStoreServer {
if (pathname.startsWith('/api/v1/')) {
try {
const parsedGateway = new URL(this.gatewayApiUrl);
- const proxyReq = http.request({
+ const requestClient = parsedGateway.protocol === 'https:' ? https : http;
+ const proxyReq = requestClient.request({
hostname: parsedGateway.hostname || '127.0.0.1',
- port: Number(parsedGateway.port || process.env.PAYMENT_API_PORT || 6100),
- path: req.url,
+ port: parsedGateway.port || undefined,
+ path: `${parsedGateway.pathname.replace(/\/$/, '')}${req.url}`,
method: req.method,
headers: {
- ...sanitizedForwardHeaders(req, `${parsedGateway.hostname}:${parsedGateway.port}`),
+ ...sanitizedForwardHeaders(req, parsedGateway.host),
'x-forwarded-host': req.headers.host || '',
'x-forwarded-proto': req.headers['x-forwarded-proto'] || 'http'
}
diff --git a/apps/coin-wallet-store/vercel-entrypoint.js b/apps/coin-wallet-store/vercel-entrypoint.js
new file mode 100644
index 0000000..bde52db
--- /dev/null
+++ b/apps/coin-wallet-store/vercel-entrypoint.js
@@ -0,0 +1,11 @@
+import { CoinWalletStoreServer } from './src/server.js';
+
+const store = new CoinWalletStoreServer({
+ gatewayApiUrl: process.env.PAYMENT_API_URL || process.env.PAYMENT_API_INTERNAL_URL,
+ portalBaseUrl: process.env.CHECKOUT_PORTAL_URL
+});
+const server = store.createServer();
+
+export default function handler(req, res) {
+ return server.emit('request', req, res);
+}
diff --git a/apps/control-center/vercel-entrypoint.js b/apps/control-center/vercel-entrypoint.js
new file mode 100644
index 0000000..736a0df
--- /dev/null
+++ b/apps/control-center/vercel-entrypoint.js
@@ -0,0 +1,11 @@
+import { ControlCenterServer } from './src/server.js';
+
+// Control Center is kept private in the Services route table. Its process
+// manager remains available for compatible hosts; Vercel does not expose it
+// publicly unless a rewrite is added explicitly.
+const controlCenter = new ControlCenterServer();
+const server = controlCenter.createServer();
+
+export default function handler(req, res) {
+ return server.emit('request', req, res);
+}
diff --git a/apps/gmail-observer/src/browser-automator.js b/apps/gmail-observer/src/browser-automator.js
index db5b696..83b5937 100644
--- a/apps/gmail-observer/src/browser-automator.js
+++ b/apps/gmail-observer/src/browser-automator.js
@@ -18,7 +18,7 @@ export class GmailBrowserAutomator {
*/
constructor(options) {
this.gmailPoller = options.gmailPoller;
- this.apiBaseUrl = options.apiBaseUrl || process.env.BASE_PAYMENT_API_URL || 'http://localhost:6100';
+ this.apiBaseUrl = options.apiBaseUrl || process.env.PAYMENT_API_URL || process.env.BASE_PAYMENT_API_URL || 'http://localhost:6100';
this.debuggingPort = options.debuggingPort || 9223;
this.profileDir = path.join(rootDir, 'data/browser-sessions/gmail');
this.stateFilePath = path.join(this.profileDir, 'login-state.json');
diff --git a/apps/gmail-observer/src/gmail-poller.js b/apps/gmail-observer/src/gmail-poller.js
index 1f72ff7..f5b1324 100644
--- a/apps/gmail-observer/src/gmail-poller.js
+++ b/apps/gmail-observer/src/gmail-poller.js
@@ -45,7 +45,7 @@ export class GmailPoller {
* }} options
*/
constructor(options = {}) {
- this.apiBaseUrl = options.apiBaseUrl || process.env.BASE_PAYMENT_API_URL || 'http://localhost:6100';
+ this.apiBaseUrl = options.apiBaseUrl || process.env.PAYMENT_API_URL || process.env.BASE_PAYMENT_API_URL || 'http://localhost:6100';
this.receivingAccountId = options.receivingAccountId || '00000000-0000-0000-0000-000000000002';
this.pollIntervalMs = options.pollIntervalMs || Number(process.env.GMAIL_POLL_INTERVAL_MS || 5000);
this.observerClient = new PaymentObserverClient({
diff --git a/apps/gmail-observer/vercel-entrypoint.js b/apps/gmail-observer/vercel-entrypoint.js
new file mode 100644
index 0000000..caebb6d
--- /dev/null
+++ b/apps/gmail-observer/vercel-entrypoint.js
@@ -0,0 +1,10 @@
+import { GmailObserverServer } from './src/server.js';
+
+const observer = new GmailObserverServer({
+ apiBaseUrl: process.env.PAYMENT_API_URL || process.env.BASE_PAYMENT_API_URL
+});
+const server = observer.createServer();
+
+export default function handler(req, res) {
+ return server.emit('request', req, res);
+}
diff --git a/apps/merchant-admin/src/server.js b/apps/merchant-admin/src/server.js
index 66e1b18..9e86b3a 100644
--- a/apps/merchant-admin/src/server.js
+++ b/apps/merchant-admin/src/server.js
@@ -1,4 +1,5 @@
import http from 'node:http';
+import https from 'node:https';
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
@@ -62,7 +63,7 @@ export class AdminServer {
*/
constructor(options = {}) {
this.db = options.db || getDatabase();
- this.apiBaseUrl = options.apiBaseUrl || process.env.BASE_PAYMENT_API_URL || 'http://localhost:6100';
+ this.apiBaseUrl = options.apiBaseUrl || process.env.PAYMENT_API_URL || process.env.BASE_PAYMENT_API_URL || 'http://localhost:6100';
this.merchantRepo = new MerchantRepository(this.db);
this.ticketRepo = new SupportTicketRepository(this.db);
this.htmlTemplatePath = path.join(__dirname, 'views', 'admin.html');
@@ -133,15 +134,17 @@ export class AdminServer {
res.end(JSON.stringify({ error: 'Unauthorized', code: 'AUTH_REQUIRED' }));
return;
}
- const ccPort = Number(process.env.CONTROL_CENTER_PORT || 8090);
- const forwardHeaders = sanitizedForwardHeaders(req, `localhost:${ccPort}`);
+ const controlCenterUrl = process.env.CONTROL_CENTER_URL || `http://127.0.0.1:${process.env.CONTROL_CENTER_PORT || 8090}`;
+ const targetUrl = new URL(req.url, controlCenterUrl);
+ const requestClient = targetUrl.protocol === 'https:' ? https : http;
+ const forwardHeaders = sanitizedForwardHeaders(req, targetUrl.host);
if (!forwardHeaders.authorization && !forwardHeaders.Authorization) {
forwardHeaders.Authorization = `Bearer ${getAdminToken()}`;
}
- const proxyReq = http.request({
- hostname: '127.0.0.1',
- port: ccPort,
- path: req.url,
+ const proxyReq = requestClient.request({
+ hostname: targetUrl.hostname,
+ port: targetUrl.port || undefined,
+ path: `${targetUrl.pathname}${targetUrl.search}`,
method: req.method,
headers: forwardHeaders
}, (proxyRes) => {
@@ -163,16 +166,17 @@ export class AdminServer {
// Transparent API Proxy: /api/* -> Payment Core REST API
if (pathname.startsWith('/api/')) {
- const targetPort = Number(process.env.PAYMENT_API_PORT || 6100);
+ const targetUrl = new URL(req.url, this.apiBaseUrl);
+ const requestClient = targetUrl.protocol === 'https:' ? https : http;
const defaultMerchant = this.merchantRepo.getDefault ? this.merchantRepo.getDefault() : (this.merchantRepo.findById('00000000-0000-0000-0000-000000000001') || this.merchantRepo.findAll()[0]);
const defaultMerchantId = defaultMerchant?.id || '00000000-0000-0000-0000-000000000001';
- const proxyReq = http.request({
- hostname: '127.0.0.1',
- port: targetPort,
- path: req.url,
+ const proxyReq = requestClient.request({
+ hostname: targetUrl.hostname,
+ port: targetUrl.port || undefined,
+ path: `${targetUrl.pathname}${targetUrl.search}`,
method: req.method,
headers: {
- ...sanitizedForwardHeaders(req, `localhost:${targetPort}`),
+ ...sanitizedForwardHeaders(req, targetUrl.host),
'x-merchant-id': req.headers['x-merchant-id'] || defaultMerchantId,
'x-forwarded-host': req.headers.host || '',
'x-forwarded-proto': req.headers['x-forwarded-proto'] || 'http'
diff --git a/apps/merchant-admin/vercel-entrypoint.js b/apps/merchant-admin/vercel-entrypoint.js
new file mode 100644
index 0000000..0bf3169
--- /dev/null
+++ b/apps/merchant-admin/vercel-entrypoint.js
@@ -0,0 +1,10 @@
+import { AdminServer } from './src/server.js';
+
+const admin = new AdminServer({
+ apiBaseUrl: process.env.PAYMENT_API_URL || process.env.BASE_PAYMENT_API_URL
+});
+const server = admin.createServer();
+
+export default function handler(req, res) {
+ return server.emit('request', req, res);
+}
diff --git a/apps/payment-api/src/index.js b/apps/payment-api/src/index.js
index 62a4551..cedae01 100644
--- a/apps/payment-api/src/index.js
+++ b/apps/payment-api/src/index.js
@@ -133,14 +133,14 @@ export function createPaymentApp(customDb = null, options = {}) {
const server = new HttpServer();
server.use(authGuard);
- let checkoutBaseUrl = process.env.BASE_CHECKOUT_URL || 'http://localhost:7000';
+ let checkoutBaseUrl = process.env.CHECKOUT_PORTAL_URL || process.env.BASE_CHECKOUT_URL || 'http://localhost:7000';
try {
const rootEnv = path.resolve(__dirname, '../../../.env');
if (fs.existsSync(rootEnv)) {
const raw = fs.readFileSync(rootEnv, 'utf8');
for (const line of raw.split(/\r?\n/)) {
const trimmed = line.trim();
- if (trimmed.startsWith('BASE_CHECKOUT_URL=')) {
+ if (trimmed.startsWith('BASE_CHECKOUT_URL=') && !process.env.CHECKOUT_PORTAL_URL) {
const val = trimmed.split('=')[1]?.trim();
if (val) checkoutBaseUrl = val.replace(/^["']|["']$/g, '');
}
@@ -327,7 +327,9 @@ export function createPaymentApp(customDb = null, options = {}) {
pollIntervalMs: Number(process.env.OBSERVER_POLL_INTERVAL_MS || 1500),
minSweepCooldownMs: Number(process.env.OBSERVER_SWEEP_COOLDOWN_MS || 2000),
smsPort: Number(process.env.SMS_OBSERVER_PORT || 6002),
- gmailPort: Number(process.env.GMAIL_OBSERVER_PORT || 6003)
+ gmailPort: Number(process.env.GMAIL_OBSERVER_PORT || 6003),
+ smsBaseUrl: process.env.SMS_OBSERVER_URL,
+ gmailBaseUrl: process.env.GMAIL_OBSERVER_URL
});
// Execute crash recovery on boot
diff --git a/apps/payment-api/src/routes/admin.routes.js b/apps/payment-api/src/routes/admin.routes.js
index eab105f..55f145f 100644
--- a/apps/payment-api/src/routes/admin.routes.js
+++ b/apps/payment-api/src/routes/admin.routes.js
@@ -180,8 +180,8 @@ export function registerAdminRoutes(server, ctx) {
// Query live Google Messages browser automator status
let smsStatus = { status: 'STANDBY', isPaired: false, messagesObserved: 0, isRunning: false };
try {
- const smsPort = Number(process.env.SMS_OBSERVER_PORT || 6002);
- const smsRes = await fetch(`http://localhost:${smsPort}/api/browser/status`, {
+ const smsBaseUrl = process.env.SMS_OBSERVER_URL || `http://localhost:${process.env.SMS_OBSERVER_PORT || 6002}`;
+ const smsRes = await fetch(new URL('/api/browser/status', smsBaseUrl), {
headers: { Authorization: `Bearer ${getObserverToken()}` },
signal: AbortSignal.timeout(1500)
});
@@ -193,8 +193,8 @@ export function registerAdminRoutes(server, ctx) {
// Query live Gmail browser automator status
let gmailStatus = { status: 'STANDBY', isLoggedIn: false, emailsObserved: 0, isRunning: false };
try {
- const gmailPort = Number(process.env.GMAIL_OBSERVER_PORT || 6003);
- const gmailRes = await fetch(`http://localhost:${gmailPort}/api/browser/status`, {
+ const gmailBaseUrl = process.env.GMAIL_OBSERVER_URL || `http://localhost:${process.env.GMAIL_OBSERVER_PORT || 6003}`;
+ const gmailRes = await fetch(new URL('/api/browser/status', gmailBaseUrl), {
headers: { Authorization: `Bearer ${getObserverToken()}` },
signal: AbortSignal.timeout(1500)
});
@@ -1545,7 +1545,8 @@ export function registerAdminRoutes(server, ctx) {
// Stop poller in observer service
try {
- await fetch(`http://127.0.0.1:${process.env.GMAIL_OBSERVER_PORT || 6003}/stop`, { method: 'POST' }).catch(() => {});
+ const gmailBaseUrl = process.env.GMAIL_OBSERVER_URL || `http://127.0.0.1:${process.env.GMAIL_OBSERVER_PORT || 6003}`;
+ await fetch(new URL('/stop', gmailBaseUrl), { method: 'POST' }).catch(() => {});
} catch {}
HttpServer.json(res, 200, {
diff --git a/apps/payment-api/src/routes/checkout.routes.js b/apps/payment-api/src/routes/checkout.routes.js
index b167bbc..d149ec2 100644
--- a/apps/payment-api/src/routes/checkout.routes.js
+++ b/apps/payment-api/src/routes/checkout.routes.js
@@ -235,8 +235,8 @@ async function checkUpiServerHealth(ctx, enabledMethods = [], sellingMode = 'OFF
if (!smsHealthy) {
try {
- const smsPort = Number(process.env.SMS_OBSERVER_PORT || 6002);
- const res = await fetch(`http://127.0.0.1:${smsPort}/api/browser/status`, {
+ const smsBaseUrl = process.env.SMS_OBSERVER_URL || `http://127.0.0.1:${process.env.SMS_OBSERVER_PORT || 6002}`;
+ const res = await fetch(new URL('/api/browser/status', smsBaseUrl), {
headers: { 'Authorization': `Bearer ${getObserverToken()}` },
signal: AbortSignal.timeout(800)
});
@@ -260,10 +260,10 @@ async function checkUpiServerHealth(ctx, enabledMethods = [], sellingMode = 'OFF
if (hasRefreshToken || hasApiKey) {
let pollerActive = false;
- const gmailPort = Number(process.env.GMAIL_OBSERVER_PORT || 6003);
+ const gmailBaseUrl = process.env.GMAIL_OBSERVER_URL || `http://127.0.0.1:${process.env.GMAIL_OBSERVER_PORT || 6003}`;
try {
- const res = await fetch(`http://127.0.0.1:${gmailPort}/health`, { signal: AbortSignal.timeout(800) });
+ const res = await fetch(new URL('/health', gmailBaseUrl), { signal: AbortSignal.timeout(800) });
if (res.ok) {
const data = await res.json();
if (data.status === 'UP') {
@@ -274,7 +274,7 @@ async function checkUpiServerHealth(ctx, enabledMethods = [], sellingMode = 'OFF
if (!pollerActive) {
try {
- const res = await fetch(`http://127.0.0.1:${gmailPort}/api/browser/status`, {
+ const res = await fetch(new URL('/api/browser/status', gmailBaseUrl), {
headers: { 'Authorization': `Bearer ${getObserverToken()}` },
signal: AbortSignal.timeout(800)
});
@@ -308,8 +308,8 @@ async function checkUpiServerHealth(ctx, enabledMethods = [], sellingMode = 'OFF
} else {
// Check if browser-based Gmail automator is actively logged in
try {
- const gmailPort = Number(process.env.GMAIL_OBSERVER_PORT || 6003);
- const res = await fetch(`http://127.0.0.1:${gmailPort}/api/browser/status`, {
+ const gmailBaseUrl = process.env.GMAIL_OBSERVER_URL || `http://127.0.0.1:${process.env.GMAIL_OBSERVER_PORT || 6003}`;
+ const res = await fetch(new URL('/api/browser/status', gmailBaseUrl), {
headers: { 'Authorization': `Bearer ${getObserverToken()}` },
signal: AbortSignal.timeout(800)
});
diff --git a/apps/payment-api/src/routes/payments.routes.js b/apps/payment-api/src/routes/payments.routes.js
index 9a2f0cc..f944b29 100644
--- a/apps/payment-api/src/routes/payments.routes.js
+++ b/apps/payment-api/src/routes/payments.routes.js
@@ -17,14 +17,25 @@ import { isAdminRequest, isPaymentOwner } from '../auth-guard.js';
* }} ctx
*/
export function registerPaymentRoutes(server, ctx) {
+ function resolvePublicDeploymentOrigin() {
+ const configured = process.env.CHECKOUT_PUBLIC_URL || process.env.PUBLIC_APP_URL;
+ if (configured) return configured.replace(/\/+$/, '');
+ if (process.env.VERCEL_URL) return `https://${process.env.VERCEL_URL}`;
+ return null;
+ }
+
function resolveCheckoutBaseUrl(merchant) {
+ // Service bindings are private and must never be returned to a browser.
+ // On Vercel, build checkout links from the public deployment origin instead.
+ const publicOrigin = resolvePublicDeploymentOrigin();
+ if (publicOrigin) return publicOrigin;
if (merchant?.branding) {
try {
const urls = resolveRuntimeUrls(merchant.branding);
if (urls && urls.checkoutUrl) return urls.checkoutUrl;
} catch {}
}
- return ctx.checkoutBaseUrl || 'http://localhost:7000';
+ return ctx.checkoutBaseUrl || process.env.CHECKOUT_PORTAL_URL || 'http://localhost:7000';
}
// POST /api/v1/payments
diff --git a/apps/payment-api/src/services/observer-poller.service.js b/apps/payment-api/src/services/observer-poller.service.js
index 0146dac..8d2d823 100644
--- a/apps/payment-api/src/services/observer-poller.service.js
+++ b/apps/payment-api/src/services/observer-poller.service.js
@@ -23,6 +23,8 @@ export class ObserverPollerService {
* minSweepCooldownMs?: number,
* smsPort?: number,
* gmailPort?: number,
+ * smsBaseUrl?: string,
+ * gmailBaseUrl?: string,
* observerToken?: string,
* autoStart?: boolean
* }} options
@@ -43,6 +45,8 @@ export class ObserverPollerService {
this.minSweepCooldownMs = Number(options.minSweepCooldownMs || process.env.OBSERVER_SWEEP_COOLDOWN_MS || 2000);
this.smsPort = Number(options.smsPort || process.env.SMS_OBSERVER_PORT || 6002);
this.gmailPort = Number(options.gmailPort || process.env.GMAIL_OBSERVER_PORT || 6003);
+ this.smsBaseUrl = options.smsBaseUrl || process.env.SMS_OBSERVER_URL || `http://localhost:${this.smsPort}`;
+ this.gmailBaseUrl = options.gmailBaseUrl || process.env.GMAIL_OBSERVER_URL || `http://localhost:${this.gmailPort}`;
this.observerToken = options.observerToken || null;
// Lifecycle and concurrency control state
@@ -272,7 +276,7 @@ export class ObserverPollerService {
const token = this.observerToken || getObserverToken();
const headers = token ? { 'Authorization': `Bearer ${token}` } : {};
- await fetch(`http://localhost:${this.smsPort}/api/sweep`, {
+ await fetch(new URL('/api/sweep', this.smsBaseUrl), {
method: 'POST',
headers,
signal: AbortSignal.timeout(1200)
@@ -303,7 +307,7 @@ export class ObserverPollerService {
const token = this.observerToken || getObserverToken();
const headers = token ? { 'Authorization': `Bearer ${token}` } : {};
- await fetch(`http://localhost:${this.gmailPort}/api/sweep`, {
+ await fetch(new URL('/api/sweep', this.gmailBaseUrl), {
method: 'POST',
headers,
signal: AbortSignal.timeout(1200)
diff --git a/apps/payment-api/vercel-entrypoint.js b/apps/payment-api/vercel-entrypoint.js
new file mode 100644
index 0000000..bcbe377
--- /dev/null
+++ b/apps/payment-api/vercel-entrypoint.js
@@ -0,0 +1,9 @@
+import { createPaymentApp } from './src/index.js';
+
+// Vercel invokes this module as a request handler. The native gateway router is
+// reused unchanged; no payment rules are duplicated in the adapter.
+const app = createPaymentApp();
+
+export default function handler(req, res) {
+ return app.rawServer.emit('request', req, res);
+}
diff --git a/apps/payment-help/src/server.js b/apps/payment-help/src/server.js
index 5322765..bcaf277 100644
--- a/apps/payment-help/src/server.js
+++ b/apps/payment-help/src/server.js
@@ -35,7 +35,7 @@ export class HelpServer {
*/
constructor(options = {}) {
this.db = options.db || getDatabase();
- this.apiBaseUrl = options.apiBaseUrl || process.env.BASE_PAYMENT_API_URL || 'http://localhost:6100';
+ this.apiBaseUrl = options.apiBaseUrl || process.env.PAYMENT_API_URL || process.env.BASE_PAYMENT_API_URL || 'http://localhost:6100';
this.ticketRepo = new SupportTicketRepository(this.db);
this.htmlTemplatePath = path.join(__dirname, 'views', 'help.html');
this.template = fs.readFileSync(this.htmlTemplatePath, 'utf8');
diff --git a/apps/payment-help/vercel-entrypoint.js b/apps/payment-help/vercel-entrypoint.js
new file mode 100644
index 0000000..4064e56
--- /dev/null
+++ b/apps/payment-help/vercel-entrypoint.js
@@ -0,0 +1,10 @@
+import { HelpServer } from './src/server.js';
+
+const help = new HelpServer({
+ apiBaseUrl: process.env.PAYMENT_API_URL || process.env.BASE_PAYMENT_API_URL
+});
+const server = help.createServer();
+
+export default function handler(req, res) {
+ return server.emit('request', req, res);
+}
diff --git a/apps/sms-observer/src/browser-automator.js b/apps/sms-observer/src/browser-automator.js
index f3a494b..96d61af 100644
--- a/apps/sms-observer/src/browser-automator.js
+++ b/apps/sms-observer/src/browser-automator.js
@@ -18,7 +18,7 @@ export class GoogleMessagesAutomator {
*/
constructor(options) {
this.smsService = options.smsService;
- this.apiBaseUrl = options.apiBaseUrl || process.env.BASE_PAYMENT_API_URL || 'http://localhost:6100';
+ this.apiBaseUrl = options.apiBaseUrl || process.env.PAYMENT_API_URL || process.env.BASE_PAYMENT_API_URL || 'http://localhost:6100';
this.debuggingPort = options.debuggingPort || 9222;
this.profileDir = path.join(rootDir, 'data/browser-sessions/google-messages');
this.stateFilePath = path.join(this.profileDir, 'pairing-state.json');
diff --git a/apps/sms-observer/src/sms-service.js b/apps/sms-observer/src/sms-service.js
index 46224f6..6cb2ae7 100644
--- a/apps/sms-observer/src/sms-service.js
+++ b/apps/sms-observer/src/sms-service.js
@@ -10,7 +10,7 @@ export class SmsObserverService {
* }} options
*/
constructor(options = {}) {
- this.apiBaseUrl = options.apiBaseUrl || process.env.BASE_PAYMENT_API_URL || 'http://localhost:6100';
+ this.apiBaseUrl = options.apiBaseUrl || process.env.PAYMENT_API_URL || process.env.BASE_PAYMENT_API_URL || 'http://localhost:6100';
this.receivingAccountId = options.receivingAccountId || '00000000-0000-0000-0000-000000000002';
this.pollIntervalMs = options.pollIntervalMs || Number(process.env.SMS_OBSERVER_POLL_INTERVAL_MS || 3000);
this.observerClient = new PaymentObserverClient({
diff --git a/apps/sms-observer/vercel-entrypoint.js b/apps/sms-observer/vercel-entrypoint.js
new file mode 100644
index 0000000..3dc1065
--- /dev/null
+++ b/apps/sms-observer/vercel-entrypoint.js
@@ -0,0 +1,10 @@
+import { SmsObserverServer } from './src/server.js';
+
+const observer = new SmsObserverServer({
+ apiBaseUrl: process.env.PAYMENT_API_URL || process.env.BASE_PAYMENT_API_URL
+});
+const server = observer.createServer();
+
+export default function handler(req, res) {
+ return server.emit('request', req, res);
+}
diff --git a/docs/CONFIGURATION.md b/docs/CONFIGURATION.md
index 4e051f8..2188c03 100644
--- a/docs/CONFIGURATION.md
+++ b/docs/CONFIGURATION.md
@@ -30,6 +30,20 @@
| `ANDROID_HEARTBEAT_TIMEOUT_MS` | `180000` | Inactivity window before Android device is marked DISCONNECTED |
| `CHECKOUT_FRAME_ANCESTORS` | unset (any origin in development, `'self'` in production) | Merchant origins (comma or space separated, e.g. `https://shop.example.com`) allowed to embed `/checkout/:id`. The `youpi.js` modal is an iframe, so a store on a different origin than the checkout portal must be listed here or the browser blocks the modal. When unset, any site may frame the checkout page in development, while a production deployment (either `NODE_ENV=production` or `YOUPI_MODE=production`) fences the page to its own origin. Only bare `http(s)` origins are accepted — a path, query, embedded credential or wildcard is ignored, so the value cannot widen the CSP or inject another directive |
| `YOUPI_ALLOW_PRIVATE_WEBHOOKS` | unset | Set to `true` to permit merchant webhook URLs on loopback/private networks. Required for self-hosted LAN targets; blocked by default as an SSRF guard |
+| `CHECKOUT_PUBLIC_URL` | unset | Optional public origin used by the Vercel Services payment API when it returns checkout links. If unset on Vercel, `VERCEL_URL` is used |
+
+### Vercel Services binding variables
+
+When deployed with the root `vercel.json`, Vercel injects these variables at
+runtime from service bindings. They must not be manually set to hostnames:
+
+| Variable | Injected into | Target service |
+| :--- | :--- | :--- |
+| `PAYMENT_API_URL` | checkout portal, merchant admin, payment help, coin store, Gmail observer, SMS observer | `payment-api` |
+| `CHECKOUT_PORTAL_URL` | payment API, coin store | `checkout-portal` |
+| `CONTROL_CENTER_URL` | merchant admin | `control-center` |
+| `GMAIL_OBSERVER_URL` | payment API | `gmail-observer` |
+| `SMS_OBSERVER_URL` | payment API | `sms-observer` |
---
diff --git a/docs/DEPLOYMENT.md b/docs/DEPLOYMENT.md
index e94a9f8..90166c8 100644
--- a/docs/DEPLOYMENT.md
+++ b/docs/DEPLOYMENT.md
@@ -2,8 +2,6 @@
This document describes how to deploy and run the clean distributable **YOUPI PG V2** package.
----
-
## 1. Prerequisites
- **Operating System**: Linux (Ubuntu 22.04+ / Debian 12+), macOS, or Windows 10/11 / Windows Server.
@@ -88,3 +86,19 @@ For production deployment:
2. Point your public domain (e.g. `pay.yourdomain.com`) to port `7000` (Checkout Portal) or `6100` (Payment API).
*The Checkout Portal automatically proxies all `/api/*` requests to the Payment API.*
3. Update `BASE_PAYMENT_API_URL` and `BASE_CHECKOUT_URL` in `.env` to match your public HTTPS domain.
+## Vercel Services
+
+The root `vercel.json` defines the approved multi-service deployment. Public
+traffic is routed to `/` (checkout), `/api/*` (payment API), `/admin/*`
+(merchant admin), `/help/*` (payment help), and `/store/*` (coin wallet store).
+The control center, Gmail observer, and SMS observer remain internal services.
+
+Service-to-service URLs are injected by Vercel bindings at runtime. The
+application reads `PAYMENT_API_URL`, `CHECKOUT_PORTAL_URL`,
+`CONTROL_CENTER_URL`, `GMAIL_OBSERVER_URL`, and `SMS_OBSERVER_URL`; these are
+binding variables and must not be manually configured with deployment URLs.
+
+Vercel Services is currently beta. The native deployment still remains the
+recommended production target for the SQLite-backed gateway and its long-lived
+observer processes; a Vercel deployment must use a persistent database and
+separate worker strategy before handling production payment traffic.
diff --git a/packages/merchant-sdk/src/client.js b/packages/merchant-sdk/src/client.js
index 73d6d97..12cb3c3 100644
--- a/packages/merchant-sdk/src/client.js
+++ b/packages/merchant-sdk/src/client.js
@@ -10,7 +10,7 @@ export class YoupiPaymentClient {
* }} options
*/
constructor(options = {}) {
- this.apiUrl = (options.apiUrl || process.env.BASE_PAYMENT_API_URL || 'http://localhost:6100').replace(/\/+$/, '');
+ this.apiUrl = (options.apiUrl || process.env.PAYMENT_API_URL || process.env.BASE_PAYMENT_API_URL || 'http://localhost:6100').replace(/\/+$/, '');
this.merchantId = options.merchantId || null;
this.webhookSecret = options.webhookSecret || null;
this.apiKey = options.apiKey || null;
diff --git a/packages/merchant-sdk/src/youpi-checkout.js b/packages/merchant-sdk/src/youpi-checkout.js
index 62bbedb..42fce3c 100644
--- a/packages/merchant-sdk/src/youpi-checkout.js
+++ b/packages/merchant-sdk/src/youpi-checkout.js
@@ -113,7 +113,7 @@
*/
constructor(options = {}) {
const defaultPortal = isBrowser
- ? (scriptConfig.portalUrl || (window.location.protocol + '//' + window.location.hostname + ':7000'))
+ ? (scriptConfig.portalUrl || window.location.origin)
: 'http://localhost:7000';
const defaultApi = isBrowser
diff --git a/packages/merchant-sdk/src/youpi.js b/packages/merchant-sdk/src/youpi.js
index 0bf5006..37738bf 100644
--- a/packages/merchant-sdk/src/youpi.js
+++ b/packages/merchant-sdk/src/youpi.js
@@ -113,7 +113,7 @@
*/
constructor(options = {}) {
const defaultPortal = isBrowser
- ? (scriptConfig.portalUrl || (window.location.protocol + '//' + window.location.hostname + ':7000'))
+ ? (scriptConfig.portalUrl || window.location.origin)
: 'http://localhost:7000';
const defaultApi = isBrowser
diff --git a/packages/observer-sdk/src/client.js b/packages/observer-sdk/src/client.js
index ce0b14e..2fc1858 100644
--- a/packages/observer-sdk/src/client.js
+++ b/packages/observer-sdk/src/client.js
@@ -8,7 +8,7 @@ export class PaymentObserverClient {
* }} options
*/
constructor(options) {
- this.apiBaseUrl = (options.apiBaseUrl || process.env.BASE_PAYMENT_API_URL || 'http://localhost:6100').replace(/\/+$/, '');
+ this.apiBaseUrl = (options.apiBaseUrl || process.env.PAYMENT_API_URL || process.env.BASE_PAYMENT_API_URL || 'http://localhost:6100').replace(/\/+$/, '');
this.sourceName = options.sourceName;
}
diff --git a/vercel.json b/vercel.json
new file mode 100644
index 0000000..a84601e
--- /dev/null
+++ b/vercel.json
@@ -0,0 +1,93 @@
+{
+ "$schema": "https://openapi.vercel.sh/vercel.json",
+ "services": {
+ "checkout-portal": {
+ "root": "apps/checkout-portal",
+ "runtime": "node",
+ "entrypoint": "vercel-entrypoint.js",
+ "bindings": [
+ { "type": "service", "service": "payment-api", "format": "url", "env": "PAYMENT_API_URL" }
+ ]
+ },
+ "coin-wallet-store": {
+ "root": "apps/coin-wallet-store",
+ "runtime": "node",
+ "entrypoint": "vercel-entrypoint.js",
+ "rewrites": [
+ { "source": "/store/:path(.*)", "destination": "/:path" },
+ { "source": "/store", "destination": "/" }
+ ],
+ "bindings": [
+ { "type": "service", "service": "payment-api", "format": "url", "env": "PAYMENT_API_URL" },
+ { "type": "service", "service": "checkout-portal", "format": "url", "env": "CHECKOUT_PORTAL_URL" }
+ ]
+ },
+ "control-center": {
+ "root": "apps/control-center",
+ "runtime": "node",
+ "entrypoint": "vercel-entrypoint.js"
+ },
+ "gmail-observer": {
+ "root": "apps/gmail-observer",
+ "runtime": "node",
+ "entrypoint": "vercel-entrypoint.js",
+ "bindings": [
+ { "type": "service", "service": "payment-api", "format": "url", "env": "PAYMENT_API_URL" }
+ ]
+ },
+ "merchant-admin": {
+ "root": "apps/merchant-admin",
+ "runtime": "node",
+ "entrypoint": "vercel-entrypoint.js",
+ "rewrites": [
+ { "source": "/admin/:path(.*)", "destination": "/:path" },
+ { "source": "/admin", "destination": "/" }
+ ],
+ "bindings": [
+ { "type": "service", "service": "payment-api", "format": "url", "env": "PAYMENT_API_URL" },
+ { "type": "service", "service": "control-center", "format": "url", "env": "CONTROL_CENTER_URL" }
+ ]
+ },
+ "payment-api": {
+ "root": "apps/payment-api",
+ "runtime": "node",
+ "entrypoint": "vercel-entrypoint.js",
+ "bindings": [
+ { "type": "service", "service": "checkout-portal", "format": "url", "env": "CHECKOUT_PORTAL_URL" },
+ { "type": "service", "service": "gmail-observer", "format": "url", "env": "GMAIL_OBSERVER_URL" },
+ { "type": "service", "service": "sms-observer", "format": "url", "env": "SMS_OBSERVER_URL" }
+ ]
+ },
+ "payment-help": {
+ "root": "apps/payment-help",
+ "runtime": "node",
+ "entrypoint": "vercel-entrypoint.js",
+ "rewrites": [
+ { "source": "/help/:path(.*)", "destination": "/:path" },
+ { "source": "/help", "destination": "/" }
+ ],
+ "bindings": [
+ { "type": "service", "service": "payment-api", "format": "url", "env": "PAYMENT_API_URL" }
+ ]
+ },
+ "sms-observer": {
+ "root": "apps/sms-observer",
+ "runtime": "node",
+ "entrypoint": "vercel-entrypoint.js",
+ "bindings": [
+ { "type": "service", "service": "payment-api", "format": "url", "env": "PAYMENT_API_URL" }
+ ]
+ }
+ },
+ "rewrites": [
+ { "source": "/api/(.*)", "destination": { "service": "payment-api" } },
+ { "source": "/admin/(.*)", "destination": { "service": "merchant-admin" } },
+ { "source": "/admin", "destination": { "service": "merchant-admin" } },
+ { "source": "/help/(.*)", "destination": { "service": "payment-help" } },
+ { "source": "/help", "destination": { "service": "payment-help" } },
+ { "source": "/store/(.*)", "destination": { "service": "coin-wallet-store" } },
+ { "source": "/store", "destination": { "service": "coin-wallet-store" } },
+ { "source": "/(.*)", "destination": { "service": "checkout-portal" } }
+ ]
+}
+