### Install eupago-integration Source: https://github.com/rafaelferreiratvd/eupago-integration/blob/master/README.md Install the eupago-integration package using npm. ```bash npm install --save eupago-integration ``` -------------------------------- ### Create EuPago Payment Reference in Express.js Source: https://context7.com/rafaelferreiratvd/eupago-integration/llms.txt Use this snippet to create a payment reference for EuPago. Ensure the 'eupago-integration' library is installed and the EUPAGO_API_KEY environment variable is set. It handles amount validation and processes payment requests via POST to '/api/checkout'. ```javascript const express = require('express'); const eupago = require('eupago-integration')(); const app = express(); app.use(express.json()); app.post('/api/checkout', async (req, res) => { const { amount, orderId, paymentMethod, phoneNumber } = req.body; try { // Validate amount if (isNaN(parseFloat(amount)) || amount <= 0) { return res.status(400).json({ error: 'Invalid amount' }); } // Create payment reference const response = await eupago.createPaymentReference( amount, orderId, paymentMethod, phoneNumber // Required for 'mbway' method ); if (response.sucesso) { res.json({ success: true, reference: response.referencia, entity: response.entidade, amount: response.valor }); } else { res.status(400).json({ success: false, error: response.resposta }); } } catch (error) { res.status(500).json({ success: false, error: error.message }); } }); app.listen(3000, () => { console.log('Server running on port 3000'); }); ``` -------------------------------- ### Configure EuPago Environment Variables Source: https://context7.com/rafaelferreiratvd/eupago-integration/llms.txt Set the required API key and optional configuration variables in your environment. ```bash # Required export EUPAGO_API_KEY=xxxx-xxxx-xxxx-xxxx-xxxx # Optional (with defaults shown) export EUPAGO_REST_API_URL=https://clientes.eupago.pt/clientes/rest_api export EUPAGO_DESCRIPTION_MBWAY="Your purchase at Store" export EUPAGO_ALLOW_DUPLICATED_PAYMENTS=0 ``` -------------------------------- ### Create Payment Reference Source: https://github.com/rafaelferreiratvd/eupago-integration/blob/master/README.md Use the eupago-integration library to create a payment reference. Ensure you have configured your EUPAGO_API_KEY. ```javascript const eupago = require('eupago-integration')(); eupago.createPaymentReference(totalAmount, yourReference, method, mobilePhoneNumber).then((response) => { console.log(response) }); ``` -------------------------------- ### Define Payment Method Configurations Source: https://context7.com/rafaelferreiratvd/eupago-integration/llms.txt View the internal configuration mapping for supported payment methods and their respective API endpoints. ```javascript // Payment method configurations const paymentMethods = { // Multibanco (Portuguese ATM network) mb: { endpoint: '/multibanco/create', fields: ['data_inicio', 'data_fim', 'valor_minimo', 'valor_maximo', 'per_dup'] }, // MB WAY (Mobile payments) mbway: { endpoint: '/mbway/create', fields: ['alias', 'descricao'] // alias = phone number }, // Payshop (Payment terminals) payshop: { endpoint: '/payshop/create', fields: [] }, // PaySafeCard (Prepaid vouchers) paysafecard: { endpoint: '/paysafecard/create', fields: ['url_retorno'] // return URL after payment } }; ``` -------------------------------- ### Create Payment References Source: https://context7.com/rafaelferreiratvd/eupago-integration/llms.txt Generate payment references for different methods using the createPaymentReference function. ```javascript const eupago = require('eupago-integration')(); // Create a Multibanco payment reference eupago.createPaymentReference(29.99, 'ORDER-12345', 'mb') .then((response) => { console.log('Multibanco Reference:', response); // Expected response: // { // sucesso: true, // estado: 0, // resposta: 'OK', // referencia: '123 456 789', // entidade: '12345', // valor: 29.99 // } }) .catch((error) => { console.error('Payment creation failed:', error.message); }); // Create an MB WAY payment reference with phone number eupago.createPaymentReference(15.50, 'ORDER-67890', 'mbway', '351912345678') .then((response) => { console.log('MB WAY Reference:', response); // Expected response: // { // sucesso: true, // estado: 0, // resposta: 'OK', // referencia: 'MBWAY-REF-123', // valor: 15.50 // } }) .catch((error) => { console.error('MB WAY payment failed:', error.message); }); // Create a Payshop payment reference eupago.createPaymentReference(50.00, 'ORDER-11111', 'payshop') .then((response) => { console.log('Payshop Reference:', response); }) .catch((error) => { console.error('Payshop payment failed:', error.message); }); // Create a PaySafeCard payment reference eupago.createPaymentReference(100.00, 'ORDER-22222', 'paysafecard') .then((response) => { console.log('PaySafeCard Reference:', response); }) .catch((error) => { console.error('PaySafeCard payment failed:', error.message); }); ``` -------------------------------- ### createPaymentReference Source: https://context7.com/rafaelferreiratvd/eupago-integration/llms.txt Generates a payment reference for a specified payment method using the EuPago API. ```APIDOC ## createPaymentReference ### Description Creates a payment reference for the specified payment method (Multibanco, MB WAY, Payshop, or PaySafeCard). ### Parameters - **amount** (number) - Required - The payment amount. - **referenceId** (string) - Required - Internal reference ID. - **method** (string) - Required - Payment method: 'mb', 'mbway', 'payshop', or 'paysafecard'. - **alias** (string) - Optional - Phone number alias for MB WAY payments. ### Response #### Success Response (200) - **sucesso** (boolean) - Indicates if the request was successful. - **estado** (number) - Status code. - **resposta** (string) - Response message. - **referencia** (string) - Generated payment reference. - **entidade** (string) - Entity code (for Multibanco). - **valor** (number) - The payment amount. ### Response Example { "sucesso": true, "estado": 0, "resposta": "OK", "referencia": "123 456 789", "entidade": "12345", "valor": 29.99 } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.