Created
August 26, 2009 00:31
-
-
Save eligrey/175160 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // this example script uses a user-submitted script to modify image | |
| // data from a canvas in which the user drew art | |
| var sandbox = new JSandbox(), | |
| userArt = document.getElementById("userArt").getContext("2d"), | |
| imageData = userArt.getImageData(0, 0, userArt.width, userArt.height); | |
| sandbox.load("user-submitted-script.js", function () { // onload | |
| this.eval("doStuffWithImageData(input)", function (modifiedImageData) { | |
| userArt.putImageData(modifiedImageData, 0, 0); | |
| this.terminate(); | |
| sandbox = null; | |
| }, imageData); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
payment requests for bKash, Nagad, and Coinbase Commerce, enforces Bearer Token authentication, and handles real-time Webhook notifications. ### System Architecture Flow
[Your Client/Device] ──(Secure API Call)──> [Your API Server] ──(Real-time SDK/API)──> [bKash/Nagad/Coinbase] │ [Your Database/App] <──(Real-time Webhook)── [Your API Server] <──(Callback Notification)────┘--- ### 1. The Real-Time API Implementation (server.js) Make sure to install the required dependencies first:bash npm install express cors dotenv helmet body-parser axiosSave the following code asserver.js: ```javascript /** * Real-Time Payment & Payout Gateway API Wrapper * Supported Providers: bkash, nagad, rocket, coinbase * Authorization: Bearer Token * Language: Node.js (Express) */ require('dotenv').config(); const express = require('express'); const cors = require('cors'); const helmet = require('helmet'); const bodyParser = require('body-parser'); const app = express(); const PORT = process.env.PORT || 5000; // Security & Middleware configuration app.use(helmet()); // Secure HTTP headers app.use(cors()); // Enable Cross-Origin Resource Sharing app.use(bodyParser.json()); // Parse JSON payloads // Secure Master Token (Matches sandbox environment requirement) const MASTER_BEARER_TOKEN = process.env.MASTER_CODE || "SECURE-GATEWAY-TOKEN-2026"; // ========================================== // MIDDLEWARE: Authentication & Security // ========================================== const authenticateRequest = (req, res, next) => { const authHeader = req.headers['authorization']; if (!authHeader || !authHeader.startsWith('Bearer ')) { return res.status(401).json({ status: "ERROR", message: "Unauthorized: Missing or malformed Authorization header." }); } const token = authHeader.split(' ')[1]; if (token !== MASTER_BEARER_TOKEN) { return res.status(403).json({ status: "ERROR", message: "Forbidden: Invalid Bearer Token." }); } next(); }; // ========================================== // ENDPOINT 1: Initiate Real-Time Payment / Payout // POST /api/v1/pay // ========================================== app.post('/api/v1/pay', authenticateRequest, async (req, res) => { const { provider, amount, currency, receiver_wallet, reference } = req.body; // 1. Input Validation if (!provider || !amount || !currency || !receiver_wallet) { return res.status(400).json({ status: "FAILED", message: "Missing required parameters: provider, amount, currency, receiver_wallet" }); } const supportedProviders = ['bkash', 'nagad', 'rocket', 'coinbase']; if (!supportedProviders.includes(provider.toLowerCase())) { return res.status(400).json({ status: "FAILED", message:Unsupported provider. Supported: ${supportedProviders.join(', ')}}); } try { console.log(`[${new Date().toISOString()}] Initiating real-time transfer via ${provider.toUpperCase()}...`); // Generate dynamic transaction ID const transactionId = `TXN-${provider.toUpperCase()}-${Math.random().toString(36).substring(2, 8).toUpperCase()}`; // 2. Simulate MFS / Coinbase Gateway Handshake // In production, you would replace this block with the official API HTTP request of bKash/Nagad/Coinbase const gatewayResponse = { transaction_id: transactionId, provider: provider.toLowerCase(), amount: parseFloat(amount), currency: currency.toUpperCase(), receiver_wallet: receiver_wallet, reference: reference || `REF-${Math.floor(Math.random() * 9000) + 1000}`, status: "SUCCESSFUL", // Mock response status timestamp: new Date().toISOString() }; // 3. Return Instant Response to client return res.status(200).json({ status: "SUCCESS", message: `Payment/Transfer successfully processed via ${provider.toUpperCase()}`, data: gatewayResponse }); } catch (error) { console.error("Gateway Integration Error:", error.message); return res.status(500).json({ status: "ERROR", message: "Internal gateway timeout. Please retry.", error: error.message }); } }); // =======================