Add MoonPay card on-ramp (same underpinning as RM Circle)
Signed /api/moonpay-url endpoint: public key from MOONPAY_PUBLIC_KEY env or site config, SECRET from MOONPAY_SECRET_KEY env ONLY (never site config, since /api/config exposes siteConfig). Wallet-prefilled signed MoonPay URL when keys are set, else a generic buy page. "Buy POL with a card" button under the Buy packages tiles. Zero custody: MoonPay is merchant of record; crypto goes straight to the buyer's wallet. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -316,6 +316,27 @@ const server = http.createServer(async (req, res) => {
|
||||
chainName: c.chainName, explorer: c.explorer, rpc: c.rpcs[0],
|
||||
emailAuth: mailer.hasKey() || !IS_PROD }, siteConfig()));
|
||||
}
|
||||
if (p === '/api/moonpay-url' && req.method === 'GET') {
|
||||
// Card on-ramp deep link. With MoonPay keys set — PUBLIC key via
|
||||
// MOONPAY_PUBLIC_KEY env or site config, SECRET key via MOONPAY_SECRET_KEY
|
||||
// env ONLY (never site config, since /api/config exposes siteConfig) —
|
||||
// returns a SIGNED checkout URL prefilled with the buyer's own wallet and
|
||||
// a POL amount; otherwise a generic MoonPay buy page. Zero custody either
|
||||
// way: MoonPay is merchant of record and the crypto goes straight to the
|
||||
// buyer's wallet — this site never touches or holds anyone's money.
|
||||
const addr = (u.searchParams.get('address') || '').trim();
|
||||
let pol = Math.round(Number(u.searchParams.get('pol')) || 0);
|
||||
if (!pol || pol < 30) pol = 30;
|
||||
if (pol > 100000) pol = 100000;
|
||||
const pk = (process.env.MOONPAY_PUBLIC_KEY || siteConfig().moonpayPublicKey || '').trim();
|
||||
const sk = (process.env.MOONPAY_SECRET_KEY || '').trim();
|
||||
if (pk && sk && /^0x[0-9a-fA-F]{40}$/.test(addr)) {
|
||||
const qs = '?apiKey=' + encodeURIComponent(pk) + '¤cyCode=pol_polygon&walletAddress=' + encodeURIComponent(addr) + '"eCurrencyAmount=' + pol;
|
||||
const sig = crypto.createHmac('sha256', sk).update(qs).digest('base64');
|
||||
return json(res, 200, { url: 'https://buy.moonpay.com/' + qs + '&signature=' + encodeURIComponent(sig), signed: true, pol });
|
||||
}
|
||||
return json(res, 200, { url: 'https://www.moonpay.com/buy/pol', signed: false, pol });
|
||||
}
|
||||
if (p === '/api/catalog' && req.method === 'GET') {
|
||||
return json(res, 200, { products: await chain.catalog() });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user