Getting Started with NakaPay
Welcome to NakaPay! This guide will walk you through the essential steps to integrate our Bitcoin Lightning payment solution into your application, enabling you to accept Bitcoin payments quickly and easily.
Overview
NakaPay provides a developer-friendly API and tools to create and manage Bitcoin Lightning payment requests. Our service is non-custodial, meaning payments go directly to your configured Lightning wallet.
Non-Custodial Solution
This guide covers:
- Obtaining your API Key.
- Setting up the NakaPay SDK or making direct API calls.
- Creating your first payment request.
- Checking the status of a payment.
Prerequisites
- A NakaPay account. If you don't have one, sign up here.
- Your NakaPay API Key (found in your dashboard after login).
- For SDK usage: A Node.js environment if you plan to use our server-side SDK.
- Familiarity with making HTTP requests if you plan to interact with the API directly.
Step 1: Obtain Your API Key
Your API key is crucial for authenticating your requests to the NakaPay API.
- Log in to your NakaPay Dashboard.
- Navigate to the API Keys section.
- Copy your secret API key. Treat this key like a password and keep it secure.
API Key Security
Step 2: SDK Setup or API Integration
You can integrate with NakaPay using our official Node.js SDK nakapay-sdk
or make direct API calls. The SDK provides convenience methods and TypeScript support, while direct API calls offer maximum flexibility.
SDK vs Direct API
To use the SDK, install it from npm:
1npm install nakapay-sdk
2# or
3yarn add nakapay-sdk
Then initialize the client:
1// SDK Initialization
2import { NakaPay } from 'nakapay-sdk';
3
4const nakaPayClient = new NakaPay('YOUR_SECRET_API_KEY');
For direct API calls, ensure you set the Authorization
header correctly as described in our API Reference.
Step 3: Create a Payment Request
To receive a payment, you first need to create a payment request. This will typically generate a Lightning invoice.
Lightning Invoice Generation
You'll make a POST
request to the /api/v1/payment-requests
endpoint. See the API Reference for Create Payment Request for full details on the request body and response.
Example using fetch
on a server:
1async function createNakaPayInvoice() {
2 const apiKey = 'YOUR_SECRET_API_KEY'; // Store securely, do not hardcode in client-side
3 const nakaPayApiBase = 'https://api.nakapay.app'; // NakaPay API base URL
4
5 try {
6 const response = await fetch(`${nakaPayApiBase}/api/v1/payment-requests`, {
7 method: 'POST',
8 headers: {
9 'Content-Type': 'application/json',
10 'Authorization': `Bearer ${apiKey}`
11 },
12 body: JSON.stringify({
13 amount: 5000, // Amount in satoshis
14 description: 'Coffee for Cline',
15 metadata: { orderId: 'order_123' }
16 })
17 });
18
19 if (!response.ok) {
20 const errorData = await response.json();
21 throw new Error(errorData.message || `HTTP error! status: ${response.status}`);
22 }
23
24 const paymentData = await response.json();
25 console.log('Payment Request Created:', paymentData);
26 // paymentData will contain { id, invoice, status, etc. }
27 // Use paymentData.invoice to display a QR code or provide to the user.
28 return paymentData;
29
30 } catch (error) {
31 console.error('Error creating payment request:', error);
32 // Handle errors appropriately in your application
33 }
34}
35
36// Example usage:
37// createNakaPayInvoice().then(data => {
38// if (data) { /* Display QR from data.invoice */ }
39// });
Step 4: Check Payment Status
After creating a payment request, you might want to check its status (e.g., pending, completed, expired). You can do this by making a GET
request to /api/v1/payment-requests/:id/status
or /api/v1/payment-requests/:id
for full details.
Refer to the Get Payment Status and Get Payment Request by ID sections in the API reference.
Webhooks vs Polling
Alternatively, and often preferably, you can use Webhooks to be notified automatically when a payment status changes.
Next Steps
Congratulations!
Here are some resources to dive deeper:
- Live Examples: See complete implementations like our LightMarket showcase.
- Full API Reference: Detailed information for all API endpoints.
- SDK Guide: (If applicable) Learn how to use our official SDKs.
- Webhooks Guide: Set up and handle real-time payment notifications.
- React Components: (If applicable) Explore ready-to-use UI components for your React application.
- FAQ: Find answers to common questions.
If you have any further questions or need assistance, please don't hesitate to contact our support team.