PHP code example of descom / redsys

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


use Descom\Redsys\Redsys;

$redsys = Redsys::sandbox([
    'code' => 999008881,
    'terminal' => 1,
    'signatureKey' => 'sq7HjrUOBfKmC576ILgskD5srU870gJ7',
]);

$orderId = '123456';
$amount = 12.05;


echo $redsys
    ->redirect()
    ->generateRedirectPayment($orderId, $amount, 'http://localhost:8000')
    // ->description('description about the order products') optional DS_MERCHANT_PRODUCTDESCRIPTION
    // ->merchantName('rename merchant name') optional DS_MERCHANT_MERCHANTNAME
    // ->data('internal data, to read in response') optional DS_MERCHANT_MERCHANTDATA
    // ->merchantPaymethods('z') // optional payment with Bizum
    ->redirect();

use Descom\Redsys\Redsys;

$redsys = Redsys::sandbox([
    'code' => 999008881,
    'terminal' => 1,
    'signatureKey' => 'sq7HjrUOBfKmC576ILgskD5srU870gJ7',
]);

$response = $redsys->redirect()->capturePaymentNotification($_POST);

if (! $response->successful()) {
    $orderId = $response->orderId;
    $errorCode = $response->errorCode;
    $responseCode = $response->responseCode;
    // $responseData = $response->toArray();

    throw new \Exception("Error processing payment [$orderId]  [$errorCode]", $responseCode);
}

$orderId = $response->orderId;
$authorizationCode = $response->authorizationCode;
$amount = $response->amount;

//