Ejemplos de Código
Ejemplos de código listos para producción para pagos, wallets, WhatsApp y automatización.
Ejemplos de pagos
Aceptar pago Bre-B
const payment = await orangepill.payments.create({
amount: 50000,
currency: 'COP',
payment_method_types: ['bre_b'],
success_url: 'https://example.com/success',
cancel_url: 'https://example.com/cancel'
});
// Redirect customer to payment.url
Manejar confirmación por webhook
app.post('/webhooks/orangepill', (req, res) => {
const event = req.body;
if (event.type === 'payment.succeeded') {
const payment = event.data;
// Fulfill order for payment.metadata.order_id
}
res.sendStatus(200);
});
Ejemplos de WhatsApp
Enviar enlace de checkout
const session = await orangepill.whatsapp.checkout.create({
phone: '+573001234567',
items: [{ product_id: 'prod_abc', quantity: 1 }]
});
await orangepill.whatsapp.messages.send({
to: '+573001234567',
type: 'text',
text: { body: `Tu checkout: ${session.url}` }
});
Ejemplos de wallets
Crear wallet de lealtad
const wallet = await orangepill.wallets.create({
customer_id: 'cust_abc',
type: 'loyalty_points',
currency: 'POINTS'
});
// Award points
await orangepill.wallets.transactions.create({
wallet_id: wallet.id,
amount: 100,
type: 'credit',
description: 'Purchase reward'
});
Repositorios de ejemplo
Aplicaciones de muestra completas en GitHub:
Próximos pasos
- Primeros Pasos - Configuración de la API
- SDKs - Librerías cliente
- Webhooks - Manejo de eventos