PHP code example of vguerrerobosch / redsys-php

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

    

vguerrerobosch / redsys-php example snippets




use Vguerrerobosch\Redsys\Redsys;
use Vguerrerobosch\Redsys\PaymentRequest;

Redsys::setApiKey('sq7HjrUOBfKmC576ILgskD5srU870gJ7');

$payment_request = PaymentRequest::create([
    'amount' => 2000,
    'order' => time(),
    'merchant_code' => 999008881,
    'merchant_url' => 'https://941a2b9e.ngrok.io/webhook',
    'url_ok' => 'http://redsys-php.test/ok',
    'url_ko' => 'http://redsys-php.test/ko',
]);

$sumbit_onload = false; // default true

$payment_request->form($submit_onload);

$payment_request->url; // the Redsys endpoint
$payment_request->params; // the encoded parameters
$payment_request->signature; // the calculated signature
$payment_request->signature_version // currently HMAC_SHA256_V1

use Vguerrerobosch\Redsys\Webhook as Webhook;
use Vguerrerobosch\Redsys\Exception\SignatureVerificationException;

$content_type = $_SERVER['CONTENT_TYPE'];

Webhook::setContentType($content_type); // defaults to application/x-www-form-urlencoded

$payload = $content_type == 'application/x-www-form-urlencoded' ?
    $_POST :
    @file_get_contents('php://input');

$secret_key = 'sq7HjrUOBfKmC576ILgskD5srU870gJ7';

try {
    Webhook::verifySignature($payload, $secret_key);
} catch (SignatureVerificationException $exception) {
    http_response_code(403);
    die;
}

$data = Webhook::getData($payload);

echo Webhook::response($order_id, $secret_key);
die;
bash
composer