PHP code example of ssheduardo / redsys-laravel

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

    

ssheduardo / redsys-laravel example snippets


Ssheduardo\Redsys\RedsysServiceProvider::class

'Redsys'    => Ssheduardo\Redsys\Facades\Redsys::class,


Route::controller(RedsysController::class)->prefix('redsys')
    ->group(function () {
        Route::get('/', 'index');
    });

  $key = config('redsys.key');
  $parameters = Redsys::getMerchantParameters($request->input('Ds_MerchantParameters'));
  $DsResponse = $parameters["Ds_Response"];
  $DsResponse += 0;

  if (Redsys::check($key, $request->input()) && $DsResponse <= 99) {
      // lo que quieras que haya si es positiva la confirmación de redsys


  } else {
      //lo que quieras que haga si no es positivo

  }

bash
php artisan vendor:publish --tag="redsys-config"
 php


namespace App\Http\Controllers;

use Exception;
use Illuminate\Http\Request;
use Ssheduardo\Redsys\Facades\Redsys;

class RedsysController extends Controller
{
    public function index()
    {
        try {
            $key = config('redsys.key');
            $code = config('redsys.merchantcode');

            Redsys::setAmount(rand(10, 600));
            Redsys::setOrder(time());
            Redsys::setMerchantcode($code); //Reemplazar por el código que proporciona el banco
            Redsys::setCurrency('978');
            Redsys::setTransactiontype('0');
            Redsys::setTerminal('1');
            Redsys::setMethod('T'); //Solo pago con tarjeta, no mostramos iupay
            Redsys::setNotification(config('redsys.url_notification')); //Url de notificacion
            Redsys::setUrlOk(config('redsys.url_ok')); //Url OK
            Redsys::setUrlKo(config('redsys.url_ko')); //Url KO
            Redsys::setVersion('HMAC_SHA256_V1');
            Redsys::setTradeName('Tienda S.L');
            Redsys::setTitular('Pedro Risco');
            Redsys::setProductDescription('Compras varias');
            Redsys::setEnviroment('test'); //Entorno test

            $signature = Redsys::generateMerchantSignature($key);
            Redsys::setMerchantSignature($signature);

            $form = Redsys::createForm();
        } catch (Exception $e) {
            echo $e->getMessage();
        }
        return view('redsys', compact('form'));
    }
}