PHP code example of mfauveau / omnipay-safecharge

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

    

mfauveau / omnipay-safecharge example snippets


$gateway = Omnipay::create('Safecharge');
$gateway->initialize(array(
    'username' => 'AccountTestTRX',
    'password' => 'password',
    'testMode' => true,
    'vendorId' => 'Vendor ID',
    'websiteId' => 'Website ID'
));

$cardData = [
    'name'          => 'John Doe',
    'number'        => '4000021059386316',
    'expiryMonth'   => '06',
    'expiryYear'    => '2016',
    'cvv'           => '123'
];

try {
    $response = $gateway->authorize([
        'amount' => '100.00',
        'currency' => 'USD',
        'card' => $cardData
    ])->send();

    if ($response->isSuccessful()) {
        print_r($response->getData());
    } else {
        print $response->getMessage();
    }
} catch (Exception $e) {
    print $e->getMessage();
}

$cardData = [
    'name'          => 'John Doe',
    'number'        => '4000021059386316',
    'expiryMonth'   => '06',
    'expiryYear'    => '2016',
    'cvv'           => '123'
];

try {
    $response = $gateway->purchase([
        'amount'    => '100.00',
        'currency'  => 'USD',
        'card'      => $cardData
    ])->send();

    if ($response->isSuccessful()) {
        print_r($response->getData());
    } else {
        print $response->getMessage();
    }
} catch (Exception $e) {
    print $e->getMessage();
}

try {
    $response = $gateway->purchase([
        'amount'        => '100.00',
        'currency'      => 'USD',
        'token'         => 'XXXXXXXXXXXXXXXXXXXXX',
        'transactionId' => '123456789'
    ])->send();

    if ($response->isSuccessful()) {
        print_r($response->getData());
    } else {
        print $response->getMessage();
    }
} catch (Exception $e) {
    print $e->getMessage();
}

try {
    $response = $gateway->void([
        'amount'        => '100.00',
        'currency'      => 'USD',
        'token'         => 'XXXXXXXXXXXXXXXXXXXXX',
        'transactionId' => '123456789',
        'authCode'      => '12345',
        'expMonth'      => '06',
        'expYear'       => '2016'
    ])->send();

    if ($response->isSuccessful()) {
        print_r($response->getData());
    } else {
        print $response->getMessage();
    }
} catch (Exception $e) {
    print $e->getMessage();
}

try {
    $response = $gateway->refund([
        'amount'        => '100.00',
        'currency'      => 'USD',
        'token'         => 'XXXXXXXXXXXXXXXXXXXXX',
        'transactionId' => '123456789',
        'authCode'      => '12345',
        'expMonth'      => '06',
        'expYear'       => '2016'
    ])->send();

    if ($response->isSuccessful()) {
        print_r($response->getData());
    } else {
        print $response->getMessage();
    }
} catch (Exception $e) {
    print $e->getMessage();
}