Payment Processing Guide
Comprehensive guide for implementing Bitcoin and Lightning payments using BLGV's payment infrastructure.
๐ณ Payment Methodsโ
Supported Payment Typesโ
- On-chain Bitcoin: Traditional Bitcoin transactions
- Lightning Network: Instant, low-fee payments
- BTCPay Server: Self-hosted payment processing
- Cross-platform: Unified payment experience
โก Lightning Paymentsโ
Creating Lightning Invoicesโ
import { PaymentProcessor } from '@blgv/payments';
const payments = new PaymentProcessor({
lightning: true,
btcpay: {
serverUrl: 'https://btc.gdyup.xyz',
apiKey: process.env.BTCPAY_API_KEY
}
});
// Create Lightning invoice
const invoice = await payments.createLightningInvoice({
amount: 100000, // satoshis
description: 'BLGV Service Payment',
expiry: 3600
});
Processing Paymentsโ
// Listen for payment confirmations
payments.on('payment_received', (payment) => {
console.log('Payment received:', payment);
// Update order status, deliver goods, etc.
});
// Handle payment failures
payments.on('payment_failed', (payment) => {
console.log('Payment failed:', payment);
// Notify user, retry, etc.
});
๐ช BTCPay Integrationโ
Store Setupโ
const storeConfig = {
name: 'BLGV Store',
website: 'https://blgvbtc.com',
defaultCurrency: 'USD',
invoiceExpiration: 3600,
lightningEnabled: true
};
const store = await payments.createStore(storeConfig);
Webhook Handlingโ
app.post('/btcpay-webhook', (req, res) => {
const { type, data } = req.body;
switch (type) {
case 'InvoiceSettled':
handlePaymentComplete(data);
break;
case 'InvoiceExpired':
handlePaymentExpired(data);
break;
}
res.status(200).send('OK');
});
๐ Security Best Practicesโ
Payment Verificationโ
- Always verify payment amounts
- Check payment confirmations
- Implement proper webhook authentication
- Use HTTPS for all payment endpoints
Error Handlingโ
try {
const payment = await payments.processPayment(paymentData);
return { success: true, payment };
} catch (error) {
console.error('Payment processing error:', error);
return { success: false, error: error.message };
}
Need help? Check our BTCPay Integration documentation.