PHP code example of omnilesolutions / theteller-php-sdk

1. Go to this page and download the library: Download omnilesolutions/theteller-php-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/ */

    

omnilesolutions / theteller-php-sdk example snippets



// Get the teller instance.
 
$teller = new TheTeller\TheTeller($username, $apiKey)
 
// There is a third argument for mode which is LIVE by default. If you want to
// use this sdk in test mode, instantiate the teller as
// $teller = new TheTeller\TheTeller($username, $apiKey, TheTeller\TheTeller::THETELLER_MODE_TEST)
 
// Create order payload
$order = [
    'merchant_id' => 'YOUR-MERCHANT-ID', // available on TheTeller dashboard, under My Account.
    'transaction_id' => 'A UNIQUE TRANSACTION ID',
    'desc' => 'DESCRIPTION OF YOUR ORDER',
    'amount' => '20', // Amount to charge the customer
    'redirect_url' => 'YOUR REDIRECT URL',
    'email' => 'EMAIL ADDRESS OF CUSTOMER'
];

// Process the checkout
$checkout = $teller->requestPaymentToken($order);

// If successful, the returned $checkout will be an instance of TheTeller\Checkout\Checkout

// You now have to redirect the customer to TheTeller to make payment.
// This will take the customer to TheTeller.
$checkout->proceedToPayment();

// When the payment is completed by the customer, TheTeller will
// redirect them back to your provided 'redirect_url' in the order
// with query parameters indicating the status of the payment.

// The response looks like this:
// https://redirect_url?code=000&status=successful&reason=transaction20%successful&transaction_id=000000000000

 


// Get the teller instance.

$teller = new TheTeller\TheTeller($username, $apiKey);
// There is a third argument for mode which is LIVE by default. If you want to
// use this sdk in test mode, instantiate the teller as
// $teller = new TheTeller\TheTeller($username, $apiKey, TheTeller\TheTeller::THETELLER_MODE_TEST)

// Create transfer payload
$payload = [
    'amount' => '20', // The transfer amount
    'merchant_id' => 'YOUR-MERCHANT-ID', // available on TheTeller dashboard, under My Account.
    'account_number' => '0240000000', // The mobile account number
    'account_issuer' => 'MTN', // The mobile money network
    'transaction_id' => 'A UNIQUE TRANSACTION ID',
    'desc' => 'DESCRIPTION OF TRANSFER',
    'pass_code' => 'UNIQUE FLOAT ACCOUNT PASSCODE'
]

// Process the transfer
try{

    $teller->transfer('mobile-money', $payload);

    // Transfer is successful

}catch(\Exception $e){
    var_dump($e->getMessage()); // The reason for the failure
}



// Get the teller instance.

$teller = new TheTeller\TheTeller($username, $apiKey);
// There is a third argument for mode which is LIVE by default. If you want to
// use this sdk in test mode, instantiate the teller as
// $teller = new TheTeller\TheTeller($username, $apiKey, TheTeller\TheTeller::THETELLER_MODE_TEST)

// Create transfer payload
$payload = [
    'amount' => '20', // The transfer amount
    'merchant_id' => 'YOUR-MERCHANT-ID', // available on TheTeller dashboard, under My Account.
    'account_bank' => 'GCB', // List of supported banks [here](https://theteller.net/documentation#theTeller_Standard)
    'account_number' => '0082000141685300', // The bank account number
    'transaction_id' => 'A UNIQUE TRANSACTION ID',
    'desc' => 'DESCRIPTION OF TRANSFER',
    'pass_code' => 'UNIQUE FLOAT ACCOUNT PASSCODE'
]

// Process the transfer
try{

    // This step performs an enquiry of the bank account

    $transfer = $teller->transfer('bank', $payload);

    // Enquiry was successfull.
    // You can get the bank account name to ensure
    // that the transfer is going to the intended account.
    $name = $transfer->getAccountName();

    // Complete the transfer
    $transfer->confirm($merchantId); // Your TheTeller Merchant ID

}catch(\Exception $e){
    var_dump($e->getMessage()); // The reason for the failure
}


// Get the teller instance.

$teller = new TheTeller\TheTeller($username, $apiKey);
// There is a third argument for mode which is LIVE by default. If you want to
// use this sdk in test mode, instantiate the teller as
// $teller = new TheTeller\TheTeller($username, $apiKey, TheTeller\TheTeller::THETELLER_MODE_TEST)

// Get status
try{

    $response = $teller->getTransactionStatus($transactionId, $merchantId);

}catch(\Exception $e){
    var_dump($e->getMessage()); // The reason for the failure
}

composer