Skip to main content

Overview

This guide walks through integrating CrediBill payment infrastructure into your SaaS application. We’ll cover:
  1. Setting up payment providers
  2. Creating subscriptions
  3. Handling webhooks
  4. Managing customer payments
  5. Monitoring and debugging

Prerequisites

  • Active CrediBill account
  • Secret API key from dashboard
  • Payment provider account (Flutterwave, PawaPay, Pesapal, or DPO)
  • Backend server (Node.js, Python, etc.)
  • Basic understanding of webhooks

1. Setup

Store API Key in Environment

API Base URL

All requests must include your API key in the Authorization header:

2. Configure Payment Providers

Step 1: Get Provider Credentials

Follow the Provider Setup Guide to obtain credentials for your chosen provider.

Step 2: Add to CrediBill Dashboard

  1. Go to Settings → Payment Providers
  2. Click Add Provider
  3. Select provider (Flutterwave, PawaPay, Pesapal, or DPO)
  4. Enter credentials obtained from provider
  5. Set environment (Test or Live)
  6. Click Save & Test Connection

Step 3: Verify Connection

Response:
Add providers via API:

3. Create Customers

Basic Customer Creation

Response:

With Payment Method

4. Create Subscriptions

Simple Subscription

Response:

With Usage-Based Pricing

Subscription Lifecycle

5. Handle Webhooks

Set Up Webhook Endpoint

Handle Payment Success

Handle Payment Failure

Handle Subscription Events

6. Test Your Integration

Test Mode

Use provider test credentials to test without real payments. Prefer testing by calling the CrediBill API from your server (App Router) or using cURL.

Test Webhooks Locally

Use ngrok to receive webhooks locally:
Update webhook URL in CrediBill dashboard:
  1. Go to Settings → Webhooks
  2. Update URL to: https://your-ngrok-url.ngrok.io/webhooks/credibill
  3. Send test webhook from dashboard

Test Webhook Handling

7. Go Live Checklist

Provider Setup

  • Live merchant accounts created
  • Business verification completed
  • Live API credentials obtained
  • Webhook URLs configured in provider dashboards
  • Test payment successful with real provider
  • Webhook delivery confirmed

CrediBill Configuration

  • Primary provider configured in dashboard
  • Backup provider configured (optional but recommended)
  • Environment set to Live (not Test)
  • Webhook secret saved securely
  • Webhook URL points to production
  • HTTPS certificate valid (not self-signed)

Code Review

  • Webhook signature verification implemented
  • Timing-safe comparison used
  • Timestamp validation implemented
  • Idempotency checks in place
  • No credentials hardcoded
  • All secrets in environment variables
  • Error messages don’t expose credentials
  • Logging doesn’t log sensitive data

Testing

  • End-to-end payment test successful
  • Failed payment handling tested
  • Webhook delivery tested
  • Signature verification works
  • Idempotency handling works
  • Multiple payment methods tested

Monitoring

  • Error alerts configured
  • Payment success metrics tracked
  • Webhook delivery monitored
  • Failed payments monitored
  • Unusual activity alerts set up
  • Daily reconciliation process established

Deployment

  • Code deployed to production
  • Configuration deployed (env vars)
  • Webhooks configured in production
  • First payment tested end-to-end
  • Monitor logs for first 24 hours
  • Team on standby for issues

8. Common Integration Issues

Issue: Webhook Signature Verification Fails

Cause: Using parsed JSON body instead of raw body Solution:

Issue: Webhooks Not Received

Checklist:
  • Webhook URL is publicly accessible (not localhost)
  • HTTPS certificate is valid
  • Firewall allows traffic from CrediBill
  • Endpoint returns 200 OK
  • Endpoint responds within 10 seconds
  • Check webhook logs in CrediBill dashboard

Issue: Payment Stuck in Pending

Cause: Provider API slow or webhook delivery delayed Solution:
  • Wait 5-10 minutes (mobile money can be slow)
  • Check provider dashboard for payment status
  • Check CrediBill webhook logs for delivery attempts
  • Contact provider support if stuck > 30 minutes

Issue: Customer Charged Multiple Times

Cause: Duplicate payment initiation or missing idempotency Solution:
  • Implement idempotency keys (see code above)
  • Check webhook idempotency handling
  • Use database unique constraints on transaction IDs
  • Check for double form submissions in UI

Next Steps