PHP code example of tcgunel / omnipay-moka

1. Go to this page and download the library: Download tcgunel/omnipay-moka 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/ */

    

tcgunel / omnipay-moka example snippets


use Omnipay\Omnipay;

$gateway = Omnipay::create('Moka');
$gateway->setMerchantId('YOUR_DEALER_CODE');
$gateway->setMerchantUser('YOUR_USERNAME');
$gateway->setMerchantPassword('YOUR_PASSWORD');
$gateway->setTestMode(true); // uses https://service.refmoka.com

$response = $gateway->purchase([
    'amount'        => '1.50',
    'currency'      => 'TRY',
    'transactionId' => 'ORDER-12345',
    'installment'   => 1,
    'clientIp'      => '127.0.0.1',
    'card'          => [
        'firstName'   => 'John',
        'lastName'    => 'Doe',
        'number'      => '5269111122223332',
        'expiryMonth' => '01',
        'expiryYear'  => '2030',
        'cvv'         => '123',
    ],
])->send();

if ($response->isSuccessful()) {
    $transactionReference = $response->getTransactionReference(); // VirtualPosOrderId
}

$response = $gateway->purchase([
    'amount'        => '1.50',
    'currency'      => 'TRY',
    'transactionId' => 'ORDER-12345',
    'installment'   => 1,
    'clientIp'      => '127.0.0.1',
    'secure'        => true,
    'returnUrl'     => 'https://yoursite.com/callback',
    'card'          => [
        'firstName'   => 'John',
        'lastName'    => 'Doe',
        'number'      => '5269111122223332',
        'expiryMonth' => '01',
        'expiryYear'  => '2030',
        'cvv'         => '123',
    ],
])->send();

if ($response->isRedirect()) {
    $response->redirect(); // redirects to Moka 3D page
}

$response = $gateway->completePurchase([
    'otherTrxCode'  => $_POST['OtherTrxCode'],  // orderNumber
    'trxCode'       => $_POST['trxCode'],        // transactionId
    'resultCode'    => $_POST['resultCode'] ?? null,
    'resultMessage' => $_POST['resultMessage'] ?? null,
])->send();

if ($response->isSuccessful()) {
    // Payment verified
}

$response = $gateway->void([
    'virtualPosOrderId' => 'MOKA_ORDER_ID',
    'transactionId'     => 'ORDER-12345',
    'clientIp'          => '127.0.0.1',
])->send();

if ($response->isSuccessful()) {
    // Void successful
}

$response = $gateway->refund([
    'virtualPosOrderId' => 'MOKA_ORDER_ID',
    'transactionId'     => 'ORDER-12345',
    'amount'            => '9.99',
])->send();

if ($response->isSuccessful()) {
    // Refund successful
}

$response = $gateway->binLookup([
    'binNumber' => '526911',
])->send();

if ($response->isSuccessful()) {
    $creditType           = $response->getCreditType();           // e.g. "CreditCard"
    $maxInstallmentNumber = $response->getMaxInstallmentNumber(); // e.g. 12
}

$response = $gateway->installmentQuery([
    'binNumber'   => '526911',
    'amount'      => '100.00',
    'currency'    => 'TRY',
    'installment' => 3,
    'isThreeD'    => 0,
])->send();

if ($response->isSuccessful()) {
    $paymentAmount = $response->getPaymentAmount(); // total with commission
}