This guide covers buying Bitcoin via Lightning Network (instant, low fees). For on-chain Bitcoin purchases, see Buying Bitcoin (On-Chain).
Overview
Mavapay allows your users to buy Bitcoin using Nigerian Naira (NGN). The API provides flexible options for how amounts are specified and how Bitcoin is delivered. To buy Bitcoin with M-Pesa or Airtel Money, use KES Collections. To collect Naira for a Bitcoin purchase, see NGN Collections.Two Bitcoin Delivery Options:
- Internal Wallet (
autopayout: false): Bitcoin is credited to your Mavapay wallet. Thebeneficiaryfield is ignored. You control when and how to deliver Bitcoin to your users. - Instant Delivery (
autopayout: true): Bitcoin is automatically sent to the provided Lightning invoice immediately after payment is received.
Use Cases
- Fixed Fiat Amount: User wants to spend exactly ₦5,000
- Fixed Bitcoin Amount: User wants to receive exactly 10,000 sats
- Instant Delivery: Bitcoin sent immediately to user’s Lightning wallet
Understanding Payment Currency
ThepaymentCurrency parameter is crucial for buy Bitcoin flows. It determines what the amount field represents:
paymentCurrency: "NGNKOBO"→ amount is in Naira (you’re specifying how much to spend)paymentCurrency: "BTCSAT"→ amount is in Bitcoin (you’re specifying how much to receive)
Integration Flow
Step 1: Create a Quote
Choose one of two approaches based on your use case:Option A: User Specifies Fiat Amount
When a user wants to spend exactly ₦5,000:Option B: User Specifies Bitcoin Amount
When a user wants to receive exactly 10,000 sats:See the Create Quote API reference for interactive examples you can test.
Step 2: Display Payment Instructions
Show the user the bank account details from the quote response:Step 3: Wait for Payment Confirmation
You’ll receive apayment.received webhook when the user makes the bank transfer:
Step 4: Credit User’s Account
You have two options for delivering Bitcoin:Manual Payout (autopayout: false)
- Bitcoin is credited to your Mavapay wallet
- The
beneficiaryfield is ignored whenautopayoutis false - You handle crediting user’s account in your system
- Later withdraw to user’s wallet using the Withdraw BTC API
Auto Payout (autopayout: true)
- Bitcoin is automatically sent to the provided Lightning invoice
- You receive both
payment.receivedandpayment.sentwebhooks - User receives Bitcoin within seconds
Auto Payout with Lightning Invoice
For instant Bitcoin delivery, setautopayout: true and provide a Lightning invoice:
Requirements for Autopayout
Webhooks Flow
- payment.received - Naira payment confirmed
- payment.sent - Bitcoin delivered to invoice
Implementation Examples
Example 1: Basic Buy Bitcoin (No Autopayout)
Example 2: Instant Bitcoin Delivery
Important Considerations
Quote Expiration
Quotes are valid for approximately 10 minutes for bank transfers and 5 minutes for lightning invoice payments. If a user pays after expiration:- Payment may be refunded
- Or applied manually by contacting support
- Always display a clear countdown timer
Exchange Rate Volatility
Exchange rates update frequently. For the best rate:- Create a fresh quote each time
- Don’t cache quotes for long periods
- Explain to users that rates may change
Amount Validation
When using autopayout with Lightning invoices:Testing
Test your integration in the staging environment:Best Practices
1. Show Real-Time Rates
Create new quotes to show current exchange rates:2. Display Expiry Prominently
3. Handle Webhooks Idempotently
The same webhook may be sent multiple times:4. Provide Status Updates
Keep users informed throughout the process:5. Handle Errors Gracefully
Supported Currencies
Currently available:- NGNKOBO => BTCSAT (Nigerian Naira to Bitcoin)
- KESCENT => BTCSAT (Kenyan Shilling to Bitcoin)
- ZARCENT => BTCSAT (South African Rand to Bitcoin)
Related Resources
- Create Quote API - Interactive API documentation
- Withdraw Bitcoin API - Manual Bitcoin payouts
- Webhook Examples - Complete webhook payloads
- Beneficiary Formats - Beneficiary object structures
- Payment Simulation - Testing in staging
Troubleshooting
Quote Creation Fails
Error: “Invalid payment currency”- Ensure
paymentCurrencyis eithersourceCurrencyortargetCurrency - For buying BTC, use
NGNKOBOorBTCSAT
- Check minimum amounts in the API response
- Amounts are in the lowest denomination (kobo for NGN, satoshis for BTC)
Autopayout Not Working
Error: “Autopayout requires payment currency to be target currency”- Set
paymentCurrency: "BTCSAT"when buying BTC with autopayout - Provide a valid Lightning invoice in the
beneficiaryfield
- The Lightning invoice amount must exactly match the
amountfield - Decode invoice and verify before creating quote
Payment Not Detected
- Ensure webhook is registered and publicly accessible
- Check that user sent the exact amount shown in the quote
- Verify payment was sent to the correct bank account
- Contact support with the
orderIdfor manual verification
FAQ
Q: What’s the minimum amount I can buy?A: Minimum amounts vary. Check the API response for current limits. Q: How long does autopayout take?
A: Usually within seconds of receiving Naira or Bitcoin payment. Q: Can I use on-chain addresses instead of Lightning?
A: Yes! See Buying Bitcoin (On-Chain) for on-chain integration with standard Bitcoin addresses. Q: What happens if the user pays after the quote expires?
A: The payment may be refunded or processed manually. Contact support with the order ID. Q: Can I set my own exchange rate markup?
A: Yes, use the
customerInternalFee field to add your margin.
Q: How do I handle partial payments?A: Partial payments are not automatically processed. Contact support for manual handling.
