'use strict'; /** * Configuration for the Apple Pay on the Web sample. * * Everything secret lives HERE, on the server. Nothing in this file is ever sent to the * browser — the checkout page gets only an amount and a currency. Your API key in page * source would let anyone charge your account. * * Copy .env.example to .env and fill it in, or set these in the environment. */ const fs = require('fs'); const path = require('path'); (function loadEnv() { const envPath = path.join(__dirname, '.env'); if (!fs.existsSync(envPath)) return; for (const line of fs.readFileSync(envPath, 'utf8').split('\n')) { const m = line.match(/^\s*([A-Z0-9_]+)\s*=\s*(.*)\s*$/i); if (!m) continue; if (process.env[m[1]] === undefined) process.env[m[1]] = m[2].replace(/^["']|["']$/g, ''); } })(); const config = { // TruePay's API. Sandbox while you build; switch to the production host to go live. baseUrl: process.env.TRUEPAY_BASE_URL || 'https://api.sandbox.truepay.ompay.om', // Your merchant API key and secret, from the merchant portal. Server-side only. apiKey: process.env.TRUEPAY_API_KEY || '', apiSecret: process.env.TRUEPAY_API_SECRET || '', // The fully-qualified host serving your checkout page — no scheme, no path, no port. // This is what TruePay sends to Apple as initiativeContext, and Apple will only issue // a session for a domain already registered and verified against YOUR Apple merchant // identifier. It must match the address bar exactly: if customers reach you at // www.example.om, "example.om" here is rejected. domain: process.env.APPLE_PAY_DOMAIN || 'shop.example.om', // What the Apple Pay sheet shows as the payee. Cosmetic. displayName: process.env.APPLE_PAY_DISPLAY_NAME || 'Example Shop', // Apple Pay JS needs a country and the currency of the charge. TruePay settles in OMR. countryCode: process.env.APPLE_PAY_COUNTRY || 'OM', currency: process.env.CURRENCY || 'OMR', port: parseInt(process.env.PORT, 10) || 4300, }; function missing() { const out = []; if (!config.apiKey) out.push('TRUEPAY_API_KEY'); if (!config.apiSecret) out.push('TRUEPAY_API_SECRET'); if (!config.domain || config.domain === 'shop.example.om') out.push('APPLE_PAY_DOMAIN'); return out; } module.exports = { config, missing };