ohansyah/jokul-php-library

Jokul PHP Library

v0.1.0 2022-10-18 14:09 UTC

This package is auto-updated.

Last update: 2024-10-18 18:50:09 UTC


README

This is fork of Jokul PHP Library

Table of Contents

Payment Channels Supported

Virtual Account => Channel Name

  • BCA = bca-virtual-account
  • Mandiri = mandiri-virtual-account
  • Bank Syariah Indonesia (BSI)= bsm-virtual-account
  • DOKU = doku-virtual-account
  • BRI = bri-virtual-account
  • CIMB = cimb-virtual-account
  • Permata = permata-virtual-account
  • BNI = bni-virtual-account
  • Danamon = danamon-virtual-account

Requirements

  • PHP 7.2 or above

Installation

If you are using Composer, you can install via composer CLI:

composer require doku/jokul-php-library

or

add this require line to your composer.json file:

example

{
    "require": {
        "doku/jokul-php-library": "2.1.0"
    }
}

and run composer install on your terminal.

Usage

Setup Configuration

Get your Client ID and Shared Key from Jokul Back Office. Sandbox Jokul Back Office (for testing purpose) / Production Jokul Back Office (for real payments)

Setup your configuration:

// Instantiate class
$DOKUClient = new DOKU\Client;
// Set your Client ID
$DOKUClient->setClientID('[YOUR_CLIENT_ID]');
// Set your Shared Key
$DOKUClient->setSharedKey('[YOUR_SHARED_KEY]');
// Call this function for production use
$DOKUClient->isProduction(true);

If you want to hit to Sandbox, change to $DOKUClient->isProduction(false);.

Virtual Account

First prepare your payment request data:

// Setup VA payment request data
$params = array(
    'customerEmail' => $arr["email"],
    'customerName' => $arr["customerName"],
    'amount' => $arr["amount"],
    'invoiceNumber' => random_strings(20),
    'expiryTime' => $arr["expiredTime"],
    'info1' => $arr["info1"],
    'info2' => $arr["info2"],
    'info3' => $arr["info3"],
    'reusableStatus' => $arr["reusableStatus"]
);

For further details of each parameter, please refer to our Jokul Docs.

Virtual Account

After preparing the payment request above, call this function to generate BCA VA:

// Set channel Virtual Account
$DOKUClient->setChannelVA("bca-virtual-account");

// Call this function to generate Virtual Account
$DOKUClient->generateVA($params);

Handling HTTP Notification

For async payment from these channels:

  • Virtual Account

We will send the HTTP Notification after the payment made from your customers. Therefore, you will need to handle the notification to update the transaction status on your end. Here is the steps:

  1. Create notification URL (endpoint) on your server to receieve HTTP POST notification from Jokul. The notification will be sent to you whenever the transaction status is updated on Jokul side. The sample code available in Jokul Java Example.
  2. Setup the notification URL that you made to the Payment Configuration on Jokul Back Office. Sandbox Jokul Back Office (for testing purpose) / Production Jokul Back Office (for real payments)
  3. Test the payment with our Payment Simulator (for testing purpose)

Here is the sample of the notification endpoint that you need to setup:

// Mapping the notification received from Jokul
$notifyHeaders = getallheaders();
$notifyBody = json_decode(file_get_contents('php://input'), true); // You can use to parse the value from the notification body
$targetPath = '/payments/notifications'; // Put this value with your payment notification path
$secretKey = 'SK-xxxxxxx'; // Put this value with your Secret Key

// Prepare Signature to verify the notification authenticity
$signature = \DOKU\Common\Utils::generateSignature($notifyHeaders, $targetPath, file_get_contents('php://input'), $secretKey);

// Verify the notification authenticity
if ($signature == $notifyHeaders['Signature']) {
    http_response_code(200); // Return 200 Success to Jokul if the Signature is match
    // TODO update transaction status on your end to 'SUCCESS'
} else {
    http_response_code(401); // Return 401 Unauthorized to Jokul if the Signature is not match
    // TODO Do Not update transaction status on your end yet
}

For further reference, please refer to our Jokul Docs.

Help and Support

Got any issues? Found a bug? Have a feature requests? You can open new issue.

For further information, you can contact us on care@doku.com.