PHP code example of waldson / omnipay-rede-rest-api

1. Go to this page and download the library: Download waldson/omnipay-rede-rest-api 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/ */

    

waldson / omnipay-rede-rest-api example snippets


use Omnipay\Omnipay;

$gateway = Omnipay::create('Rede');
$gateway->setMerchantId($yourCV); // Filiação
$gateway->setMerchantKey($yourToken); // Token

$card     = array('number' => '4242424242424242', 'expiryMonth' => '6', 'expiryYear' => '2030', 'cvv' => '123', 'name' => 'Holder name');
$response = $gateway->purchase(array('amount' => '10.00', 'reference' => '1', 'card' => $card))->send(); //or authorize(...)

if ($response->isSuccessful()) {
    // payment was successful: update database
    $transactionId = $response->getTransactionId();

    //with transactionId you can fetch...
    $transactionInfo = $gateway->fetchTransaction(['transactionId' => $transactionId]); //you can pass 'reference' too

    //refund...
    $response = $gateway->refund(['transactionId' => $transactionId, 'amount' => '10.00']);

    //or capture (don't work with purchase, you can only capture authorized requests)
    $response = $gateway->capture(['transactionId' => $transactionId, 'amount' => '10.00']);

} else {
    // payment failed: display message to customer
    $errorMessage = $response->getMessage();
    $errorCode    = $response->getCode();
    ...
}