PHP code example of descom / omnipay-redsys

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

    

descom / omnipay-redsys example snippets


use Omnipay\Omnipay;

$gateway = Omnipay::create('Redsys');

$gateway->initialize([
    'merchantCode' => '999008881',
    'merchantTerminal' => '1',
    'merchantSignatureKey' => 'sq7HjrUOBfKmC576ILgskD5srU870gJ7',
    'testMode' => true,
]);

$request = $gateway->purchase([
                'amount' => 12.50,
                'description' => 'Test purchase',
                'transactionId' => 1,
                'notifyUrl' => 'http://localhost:8080/gateway/notify',
            ])->send();

$response->redirect();

use Omnipay\Omnipay;

$gateway = Omnipay::create('Bizum');

$gateway->initialize([
    'merchantCode' => '999008881',
    'merchantTerminal' => '1',
    'merchantSignatureKey' => 'sq7HjrUOBfKmC576ILgskD5srU870gJ7',
    'testMode' => true,
    'merchantPaymethods' => 'z',
]);

$request = $gateway->purchase([
                'amount' => 12.50,
                'description' => 'Test purchase',
                'transactionId' => 1,
                'notifyUrl' => 'http://localhost:8080/gateway/notify',
            ])->send();

$response->redirect();

use Omnipay\Omnipay;

$gateway = Omnipay::create('Redsys');

$gateway->initialize([
    'merchantCode' => '999008881',
    'merchantTerminal' => '1',
    'merchantSignatureKey' => 'sq7HjrUOBfKmC576ILgskD5srU870gJ7',
    'testMode' => true,
]);

$request = $this->gateway->completePurchase();

/*
Redsys notification payment
$_POST = [
    'Ds_SignatureVersion' => 'HMAC_SHA256_V1',
    'Ds_MerchantParameters' => '...',
    'Ds_Signature' => '...',
];
*/
$redsysNotificationData = $_POST;

$response = $request->sendData($redsysNotificationData);


if ($response->isSuccessful()) {
    // $dsOrder = $response->transactionId();
    // $dsAuthorizationCode = $response->transactionReference();
}  else {
    // $dsResponse = $response->getCode();
}