PHP code example of eseperio / omnipay-redsys

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

    

eseperio / omnipay-redsys example snippets


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

$gateway->setMerchantCode('my_merchant_code');
$gateway->setMerchantKey('my_merchant_key');
$gateway->setTransactionType(\Omnipay\Redsys\Dictionaries\TransactionTypes::AUTHORIZATION);
$gateway->setCurrency('my_currency');
$gateway->setMerchantName('my_shop_name');
$gateway->setMerchantPaymethod('my_pay_method');
$gateway->setSignatureMode('my_signature_mode');
$gateway->setConsumerLanguage(0);
$gateway->setTerminal('my_terminal');

$request = $gateway->purchase()
            // Define the urls
            ->setCancelUrl('my_cancel_url')
            ->setReturnUrl('my_return_url')
            ->setMerchantUrl('my_merchant_url')
            // Define the transaction
            ->setTitular('my_company_name')
            ->setAmount('my_total_amount')
            ->setTransactionId('my_transaction_id')
            ->setOrder('my_order_id')
            ->setTransactionReference('my_transaction_reference')
            ->setDescription('my_order_description')
            
            // Optional. 
            ->setConsumerLanguage(\Omnipay\Redsys\Dictionaries\Languages::SPANISH);

    ],
]);

 $gateway = Omnipay::create('Redsys');
 $gateway->initialize([
    'merchantId' => '123456789',
    'merchantKey' => 'sq7HjrUOBfKmC576ILgskD5srU870gJ7',
    ...
 ]);
 $notification = $gateway->acceptNotification();
 if ($notification->getTransactionStatus() === NotificationInterface::STATUS_COMPLETED) {
    // Payment was successful
   $transactionReference = $notification->getTransactionReference();
  // Do your stuff here
 } else {
   // Payment failed
 $message = $notification->getMessage();
 // Do your stuff here
 }
 
 
$gateway = Omnipay::create('Sermepa');
$response = $gateway->completePurchase()->send();
if($response->isSuccessful()){
    // The payment was successful
    // Confirm your order or other stuff
    
    $orderId = $response->getTransactionId();
    
    // ...
}

// Set the payment method to BIZUM
$request->setPayMethod(PayMethods::PAY_METHOD_BIZUM);
// Bizum is only compatible with AUTHORIZATION transactions
$gateway->setTransactionType(TransactionTypes::AUTHORIZATION);