Skip to main content
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.
Two Bitcoin Delivery Options:
  • Internal Wallet (autopayout: false): Bitcoin is credited to your Mavapay wallet. The beneficiary field 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

  1. Fixed Fiat Amount: User wants to spend exactly ₦5,000
  2. Fixed Bitcoin Amount: User wants to receive exactly 10,000 sats
  3. Instant Delivery: Bitcoin sent immediately to user’s Lightning wallet

Understanding Payment Currency

The paymentCurrency 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)
This allows you to support both “I want to spend ₦5,000” and “I want to buy 10,000 sats” use cases with the same API.

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:
The response tells you how much Bitcoin they’ll receive.

Option B: User Specifies Bitcoin Amount

When a user wants to receive exactly 10,000 sats:
The response tells you how much Naira they need to pay.
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:
Example UI:
Quotes expire after approximately 10 minutes for bank transfers and 5 minutes for lightning invoice payments. Display a countdown timer and prompt users to complete payment quickly.

Step 3: Wait for Payment Confirmation

You’ll receive a payment.received webhook when the user makes the bank transfer:
See Webhook Examples for complete payload details.

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 beneficiary field is ignored when autopayout is 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.received and payment.sent webhooks
  • User receives Bitcoin within seconds

Auto Payout with Lightning Invoice

For instant Bitcoin delivery, set autopayout: true and provide a Lightning invoice:

Requirements for Autopayout

  • autopayout can only be true when paymentCurrency equals the target currency (BTCSAT)
  • A valid beneficiary with Lightning invoice or Lightning address must be provided
  • For Lightning invoices: The invoice amount must match the amount field in the request
  • For Lightning addresses: Amount matching is not required since the invoice is generated on the fly

Webhooks Flow

  1. payment.received - Naira payment confirmed
  2. 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:
Use the Simulation endpoint to test payment flows without real money:

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)
Coming soon:
  • KESCENT => BTCSAT (Kenyan Shilling to Bitcoin)
  • ZARCENT => BTCSAT (South African Rand to Bitcoin)

Troubleshooting

Quote Creation Fails

Error: “Invalid payment currency”
  • Ensure paymentCurrency is either sourceCurrency or targetCurrency
  • For buying BTC, use NGNKOBO or BTCSAT
Error: “Amount too small”
  • 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 beneficiary field
Error: “Invoice amount mismatch”
  • The Lightning invoice amount must exactly match the amount field
  • 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 orderId for 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.