Cómo integrar pagos Fiat en tu plataforma Web3
Aprende los fundamentos para conectar rampas de acceso fiat a tus DApps utilizando nuestra API.
checklist Requisitos previos
- Node.js 18+ instalado.
- Una cuenta en Bridflow Sandbox.
- Tus credenciales de API (
API_KEYyAPI_SECRET).
Learn the fundamentals to connect fiat on-ramps to your DApps using our API.
Step 1: API Authentication
Before you can interact with Bridflow, you need to authenticate your API calls using the SDK or including your API key in the headers. In this example, we will install and configure the Node.js SDK.
npm install @bridflow/node-sdkThen, initialize the client with your secret key. Make sure never to expose your API_SECRET on the frontend.
import { Bridflow } from '@bridflow/node-sdk';
const bridflow = new Bridflow({
apiKey: process.env.BRIDFLOW_API_KEY,
});Step 2: Create payment intent
When your user is ready to pay in the cart, make a request to your backend to generate a PaymentIntent. This intent locks the amount and provides a client_secret to the frontend to complete the flow invulnerable to client-side manipulation.
const paymentIntent = await bridflow.payments.createIntent({
amount: 15000, // 150.00 EUR expresado en céntimos
currency: 'EUR',
accepted_cryptos: ['USDC'],
settlement_currency: 'EUR',
metadata: { order_id: 'ORD-8910' }
});
res.json({ clientSecret: paymentIntent.client_secret });Step 3: Render Checkout in React
On the client side (frontend), use the React SDK to display the payment component. The interactive cashier takes care of showing the address, the QR code and detecting the transaction on the blockchain automatically.
import { CryptoCheckout, Elements } from '@bridflow/react-crypto';
export default function CheckoutPage({ clientSecret }) {
return (
<Elements options={ { clientSecret } }>
<CryptoCheckout
onSuccess={ () => console.log('¡Pago recibido!') }
/>
</Elements>
);
}Step 4: Webhooks (Recommended)
To ensure you process the order correctly asynchronously, we strongly recommend configuring an endpoint to receive webhooks from Bridflow. Listen for the payment_intent.succeeded event.
app.post('/webhook', express.raw({type: 'application/json'}), (req, res) => {
const signature = req.headers['bridflow-signature'];
let event;
try {
event = bridflow.webhooks.constructEvent(
req.body,
signature,
process.env.WEBHOOK_SECRET
);
} catch (err) {
return res.status(400).send(`Webhook Error: ${err.message}`);
}
if (event.type === 'payment_intent.succeeded') {
// Cumple el pedido, por ejemplo actualiza la BBDD
fulfillOrder(event.data.object);
}
res.json({received: true});
});And that's it! You have enabled USDC payments on your platform that will reach you immediately converted to Euros, without having exposure to cryptocurrency volatility.
auto_awesome Recommended in Tutorial
Webhooks Avanzados: Retry policies y testing
Mejores prácticas para manejar webhooks de manera confiable con políticas de reintento.
Automatiza el onboarding KYC en 15 minutos
Flujo paso a paso para verificar la identidad de tus usuarios usando el flujo de Webhooks de Bridflow.