Accept Payments via API
Integrate payment recording from your app, e-commerce platform, or payment gateway into SyncBooks.
Use Case: E-commerce Payment Webhook
Your online store receives a payment → your backend records it in SyncBooks:
Node.js — Payment Webhook Handler
// Your e-commerce webhook handler
app.post('/webhooks/payment-received', async (req, res) => {
const { orderId, amount, customerEmail, transactionRef } = req.body;
// 1. Find the customer in SyncBooks
const customers = await fetch(
`https://api.syncbooksapp.com/api/v1/customers?search=${customerEmail}`,
{ headers: { Authorization: `Bearer ${API_KEY}` } }
).then(r => r.json());
const customerId = customers.data[0]?._id;
if (!customerId) {
// Create customer if not found
const newCustomer = await fetch('https://api.syncbooksapp.com/api/v1/customers', {
method: 'POST',
headers: { Authorization: `Bearer ${API_KEY}`, 'Content-Type': 'application/json' },
body: JSON.stringify({ name: req.body.customerName, email: customerEmail })
}).then(r => r.json());
customerId = newCustomer.data._id;
}
// 2. Find the invoice (if exists)
const invoices = await fetch(
`https://api.syncbooksapp.com/api/v1/invoices?customerId=${customerId}&status=sent`,
{ headers: { Authorization: `Bearer ${API_KEY}` } }
).then(r => r.json());
const invoiceId = invoices.data[0]?._id; // Match to first open invoice
// 3. Record the payment
await fetch('https://api.syncbooksapp.com/api/v1/payments', {
method: 'POST',
headers: { Authorization: `Bearer ${API_KEY}`, 'Content-Type': 'application/json' },
body: JSON.stringify({
customerId,
invoiceId,
amount,
paymentMethod: 'online_payment',
paymentDate: new Date().toISOString().split('T')[0],
reference: transactionRef
})
});
res.status(200).send('OK');
});Partial Payments
Customers can make partial payments. Each payment reduces the invoice balance:
Partial Payment
// Invoice totalAmount: 5000, already paid: 2000
// This records GHS 1500 more
{
"customerId": "...",
"invoiceId": "...",
"amount": 1500,
"paymentMethod": "bank_transfer",
"paymentDate": "2026-06-10"
}
// After: paidAmount = 3500, balance = 1500, status = "sent" (still open)
// Final payment
{ "amount": 1500 }
// After: paidAmount = 5000, balance = 0, status = "paid" (auto-closed)Payment Methods
Supported payment methods in the API:
cashcardbank_transfermobile_moneychequeonline_paymentpaystackstripepaypalgift_cardother