NetPayBD API Documentation

A simple and secure way to integrate payments into your website.

Introduction

Welcome to the NetPayBD API documentation. This guide will walk you through the process of integrating our payment gateway into your website. The process is straightforward and involves redirecting the user to our payment page with specific parameters.

Getting Started

To start using our API, you need two essential credentials which will be provided to you upon registration:

  • Username: Your unique merchant username.
  • API Key: Your secret key for authenticating requests.

1. Initiating a Payment

To initiate a payment, you need to redirect the user to our payment gateway URL with the required parameters. The request should be a simple `GET` request.

Base URL

https://pay.netpaybd.com/

Request Parameters

Parameter Type Required Description
username String Yes Your unique merchant username.
api String Yes Your merchant API Key.
amount Number Yes The amount to be paid (e.g., 50.00).
success_url URL Yes The URL to which the user will be redirected after a successful payment.
callback_url URL Yes The URL our server will send a `POST` request to (IPN) after a successful payment.

Example: Building the Payment URL in PHP

Here's how you can construct the full payment URL and redirect the user.

<?php
$username = 'YOUR_USERNAME';
$api_key = 'YOUR_API_KEY';
$amount = 50.00;
$success_url = 'https://yourwebsite.com/payment_success.php';
$callback_url = 'https://yourwebsite.com/payment_callback.php';
$gateway_url = "https://pay.netpaybd.com/";
$payment_params = [
    'username' => $username,
    'api' => $api_key,
    'amount' => $amount,
    'success_url' => $success_url,
    'callback_url' => $callback_url
];
$redirect_url = $gateway_url . '?' . http_build_query($payment_params);
header('Location: ' . $redirect_url);
exit;
?>

2. Handling the Callback (IPN)

After a payment is successfully verified, our server will send an automated `POST` request to your callback_url. This is known as an Instant Payment Notification (IPN). This is the most reliable way to confirm a payment and update your database (e.g., mark an order as paid).

Your callback script should be prepared to receive the following `POST` data:

Callback Parameters

Parameter Type Description
status String Will always be "success" for a successful transaction.
transaction_id String The unique transaction ID (TrxID) from our system.
amount Number The amount that was paid.
payment_type String The payment method used (e.g., 'bKash', 'NAGAD').
username String The merchant username who received the payment.
timestamp Unix Timestamp The time the transaction was completed.

Example: Callback Handler in PHP

Create a file at your callback_url (e.g., payment_callback.php) to process the data.

<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $status = $_POST['status'];
    $transaction_id = $_POST['transaction_id'];
    $amount = $_POST['amount'];
    
    $log_data = json_encode($_POST, JSON_PRETTY_PRINT);
    file_put_contents('payment_log.txt', $log_data . "\n", FILE_APPEND);
    
    http_response_code(200);
    echo "Callback received successfully.";

} else {
    http_response_code(405);
    echo "Method Not Allowed.";
}
?>

3. Handling the Success Redirect

After the user completes the payment, their browser will be redirected to your success_url. We will append the transaction ID and amount as `GET` parameters to this URL, so you can display a confirmation message to the user.

Example Success URL

https://yourwebsite.com/payment_success.php?trx_id=TXN1234567890&amount=50.00

Example: Success Page in PHP

At your success_url, you can retrieve the data to show a message.

<?php
if (isset($_GET['trx_id']) && isset($_GET['amount'])) {
    $transaction_id = htmlspecialchars($_GET['trx_id']);
    $amount = htmlspecialchars($_GET['amount']);

    echo "<h1>Payment Successful!</h1>";
    echo "<p>Thank you for your payment.</p>";
    echo "<p>Transaction ID: " . $transaction_id . "</p>";
    echo "<p>Amount Paid: ৳" . $amount . "</p>";

} else {
    echo "<h1>Thank you!</h1>";
}
?>