PHP code example of buuum / redsys

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

    

buuum / redsys example snippets


$redsys = new \Buuum\Redsys($redsys_key);

try {
    $redsys->setMerchantcode($redsys_merchant_code);
    $redsys->setAmount($amount);
    $redsys->setOrder($order);
    $redsys->setTerminal($redsys_merchant_terminal);
    $redsys->setCurrency(978);

    $redsys->setTransactiontype('0');
    $redsys->setMethod('C');

    $redsys->setNotification('http://localhost/notification.php'); //Url de notificacion
    $redsys->setUrlOk('http://localhost/payment_ok.php');
    $redsys->setUrlKo('http://localhost/payment_ko.php');

    $redsys->setTradeName('Store S.L');
    $redsys->setTitular('John Doe');
    $redsys->setProductDescription('Product description');

    $form = $redsys->createForm();

} catch (Exception $e) {
    echo $e->getMessage();
    die;
}

echo $form;


$redsys = new \Buuum\Redsys($redsys_key);

try {
    $redsys->setMerchantcode($redsys_merchant_code);
    $redsys->setAmount($amount);
    $redsys->setOrder($order);
    $redsys->setTerminal($redsys_merchant_terminal);
    $redsys->setCurrency(978);

    $redsys->setPan($visa_number);
    $redsys->setExpiryDate($visa_expiry);
    $redsys->setCVV($visa_cvv);
    $redsys->setMerchantDirectPayment(true);

    $redsys->setTransactiontype('0');
    $redsys->setMethod('C');

    $redsys->setNotification('http://localhost/notification.php'); //Url de notificacion
    $redsys->setUrlOk('http://localhost/payment_ok.php');
    $redsys->setUrlKo('http://localhost/payment_ko.php');

    $redsys->setTradeName('Store S.L');
    $redsys->setTitular('John Doe');
    $redsys->setProductDescription('Product description');

    $form = $redsys->createForm();

} catch (Exception $e) {
    echo $e->getMessage();
    die;
}

echo $form;


$redsys = new \Buuum\Redsys($redsys_key);

try{
    $result = $redsys->checkPaymentResponse($_POST);
catch (Exception $e) {
    echo $e->getMessage();
    die;
}

var_dump($result);

array (
  'error' => true,
  'code' => 'SIS041',
  'Ds_Date' => '05/03/2017',
  'Ds_Hour' => '08:40',
  'Ds_SecurePayment' => '1',
  'Ds_Card_Country' => '724',
  'Ds_Amount' => '1000',
  'Ds_Currency' => '978',
  'Ds_Order' => '99699629',
  'Ds_MerchantCode' => 'xxxxxx',
  'Ds_Terminal' => '001',
  'Ds_Response' => '0000',
  'Ds_MerchantData' => '',
  'Ds_TransactionType' => '0',
  'Ds_ConsumerLanguage' => '1',
  'Ds_AuthorisationCode' => '875284',
)

array (
  'error' => false,
  'code' => 0,
  'Ds_Date' => '05/03/2017',
  'Ds_Hour' => '08:40',
  'Ds_SecurePayment' => '1',
  'Ds_Card_Country' => '724',
  'Ds_Amount' => '1000',
  'Ds_Currency' => '978',
  'Ds_Order' => '99699629',
  'Ds_MerchantCode' => 'xxxxxxx',
  'Ds_Terminal' => '001',
  'Ds_Response' => '0000',
  'Ds_MerchantData' => '',
  'Ds_TransactionType' => '0',
  'Ds_ConsumerLanguage' => '1',
  'Ds_AuthorisationCode' => '875284',
)

$redsys = new \Buuum\Redsys($redsys_key);

try {
    $redsys->setMerchantcode($redsys_merchant_code);
    $redsys->setAmount($amount);
    $redsys->setOrder($order);
    $redsys->setTerminal($redsys_merchant_terminal);
    $redsys->setCurrency(978);
    $redsys->setPan($visa_number);
    $redsys->setExpiryDate($visa_expiry);
    $redsys->setCVV($visa_cvv);
    $redsys->setTransactiontype('A');
    $redsys->setIdentifier('REQUIRED');
    $result = $redsys->firePayment();

} catch (Exception $e) {
    echo $e->getMessage();
    die;
}

var_dump($result);



$redsys = new \Buuum\Redsys($redsys_key);

try {
    $redsys->setMerchantcode($redsys_merchant_code);
    $redsys->setAmount($amount);
    $redsys->setOrder($order);
    $redsys->setTerminal($redsys_merchant_terminal);
    $redsys->setCurrency(978);
    $redsys->setTransactiontype('A');
    $redsys->setIdentifier($client_identifier);
    $result = $redsys->firePayment();
} catch (Exception $e) {
    echo $e->getMessage();
    die;
}


$redsys = new \Buuum\Redsys($redsys_key);

try {
    $redsys->setMerchantcode($redsys_merchant_code);
    $redsys->setAmount($amount);
    $redsys->setOrder($order);
    $redsys->setTerminal($redsys_merchant_terminal);
    $redsys->setCurrency(978);
    $redsys->setTransactiontype(3);
    $result = $redsys->firePayment();
    
} catch (Exception $e) {
    echo $e->getMessage();
    die;
}

array (
  'error' => true,
  'code' => 'SIS0051',
  'DS_MERCHANT_MERCHANTCODE' => 'xxxxx',
  'DS_MERCHANT_AMOUNT' => '1000',
  'DS_MERCHANT_ORDER' => '9932453',
  'DS_MERCHANT_TERMINAL' => '001',
  'DS_MERCHANT_CURRENCY' => '978',
  'DS_MERCHANT_PAN' => '4548812049400004',
  'DS_MERCHANT_EXPIRYDATE' => '2012',
  'DS_MERCHANT_CVV2' => '123',
  'DS_MERCHANT_TRANSACTIONTYPE' => 'A',
  'DS_MERCHANT_IDENTIFIER' => 'REQUIRED',
)

array (
  'error' => false,
  'code' => '0',
  'Ds_Amount' => '1000',
  'Ds_Currency' => '978',
  'Ds_Order' => '1234524534',
  'Ds_Signature' => 'Xfh84TG95t7XRKQV/UGyhH+lXd6PFuGPeU25fgNpGUc=',
  'Ds_MerchantCode' => 'xxxxxx',
  'Ds_Terminal' => '1',
  'Ds_Response' => '0000',
  'Ds_AuthorisationCode' => '415446',
  'Ds_TransactionType' => 'A',
  'Ds_SecurePayment' => '0',
  'Ds_Language' => '1',
  'Ds_ExpiryDate' => '2012',
  'Ds_Merchant_Identifier' => '4597a931b735a7d8e55252e25894fa6dd3a9bed4',
  'Ds_MerchantData' => array (),
  'Ds_Card_Country' => '724',
)

$error = \Redsys\Messages\Messages::getByCode($result['code']);

# error output
array (
  'code' => 'SIS0051',
  'message' => 'Ds_Merchant_Order Número de pedido repetido',
  'msg' => 'MSG0001',
  'detail' => '',
)