PHP code example of brilliant_mind / emola-sdk

1. Go to this page and download the library: Download brilliant_mind/emola-sdk 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/ */

    

brilliant_mind / emola-sdk example snippets




rilliantMind\Sdk\Emola;

$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->load();

Emola::config(
    $_ENV['EMOLA_WSDL'],
    $_ENV['EMOLA_USERNAME'],
    $_ENV['EMOLA_PASSWORD'],
    $_ENV['EMOLA_KEY'],
    $_ENV['EMOLA_PARTNER_CODE'],
    $_ENV['EMOLA_LANGUAGE'] ?? 'pt'
);

use BrilliantMind\Sdk\Emola;

Emola::config(
    config('services.emola.wsdl'),
    config('services.emola.username'),
    config('services.emola.password'),
    config('services.emola.key'),
    config('services.emola.partner_code'),
    config('services.emola.language', 'pt')
);

// config/services.php
'emola' => [
    'wsdl'         => env('EMOLA_WSDL'),
    'username'     => env('EMOLA_USERNAME'),
    'password'     => env('EMOLA_PASSWORD'),
    'key'          => env('EMOLA_KEY'),
    'partner_code' => env('EMOLA_PARTNER_CODE'),
    'language'     => env('EMOLA_LANGUAGE', 'pt'),
],

$transactionID        = strtoupper(bin2hex(random_bytes(8)));
$transactionReference = strtoupper(bin2hex(random_bytes(8)));

$response = Emola::c2b(
    10,            // amount
    '877777777',   // msisdn (prefix 86/87)
    $transactionID,
    $transactionReference,
    'SMS content shown to the customer (without amount)'
);

print_r($response->toArray());

$transactionID = strtoupper(bin2hex(random_bytes(8)));

$response = Emola::b2c(
    10,            // amount
    '877777777',   // msisdn (prefix 86/87)
    $transactionID,
    'Disbursement remark'
);

print_r($response->toArray());

// Transaction status. transType: C2B | B2C | QUERY_TXN | QUERY_CUS | QUERY_BEN
Emola::transaction($transactionID, 'C2B');

// Beneficiary name
Emola::beneficiary('877777777', $transactionID);

// Partner account balance
Emola::accountBalance($transactionID);

Emola::fake();            // success by default
// Emola::fake('1');      // simulate a failure

$response = Emola::c2b(10, '877777777', $transactionID, $transactionReference, 'SMS CONTENT');
print_r($response->toArray());

[
    'error'     => 0,                  // gateway error code (0 = success)
    'original'  => [
        'errorCode' => 0,              // business error code
        'message'   => 'Successfully',
        'requestId' => '00204020210425143336',
    ],
    'gwtransid' => '20210324093455711185',
]