PHP code example of ohansyah / jokul-php-library

1. Go to this page and download the library: Download ohansyah/jokul-php-library library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ohansyah / jokul-php-library example snippets


// 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);

// 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"]
);

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

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

// 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
}

composer