PHP code example of lexty / robokassa

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

    

lexty / robokassa example snippets


$payment = new \Lexty\Robokassa\Payment(
    new \Lexty\Robokassa\Auth('your_login', 'password1', 'password2', true)
);

$payment
    ->setInvoiceId($orderId)
    ->setSum($orderAmount)
    ->setCulture(Payment::CULTURE_EN)
    ->setDescription('Payment for some goods');

// redirect to payment url
header("Location: {$payment->getPaymentUrl()}");

// or show payment button on page
// <script src=" echo $payment->getFormUrl(Payment::FORM_TYPE_L); 

// somewhere in result url handler...
...
$payment = new \Lexty\Robokassa\Payment(
    new \Lexty\Robokassa\Auth('your_login', 'password1', 'password2', true)
);

if ($payment->validateResult($_GET) {

    // send answer
    echo $payment->getSuccessAnswer(); // "OK123\n"
}
...

...
$payment = new \Lexty\Robokassa\Payment(
    new \Lexty\Robokassa\Auth('your_login', 'password1', 'password2', true)
);

if ($payment->validateSuccess($_GET) {
    // payment is valid
}
...

use Lexty\Robokassa\Auth;
use Lexty\Robokassa\Client;

$client = new Client(
    new Auth('your_login', 'password1', 'password2', true)
);

$currencies = $client
	->setCulture(Client::CULTURE_EN)
	->getCurrencies();

array (
  array (
    'Code' => 'Terminals',
    'Description' => 'terminal ',
    'Items' => 
    array (
      array (
        'Label' => 'TerminalsElecsnetOceanR',
        'Alias' => 'Elecsnet',
        'Name' => 'Elecsnet',
        'MaxValue' => '15000',
      ),
    ),
  ),
  array (
    'Code' => 'EMoney',
    'Description' => 'e-wallet',
    'Items' => 
    array (
      array (
        'Label' => 'W1OceanR',
        'Alias' => 'W1',
        'Name' => 'RUR W1',
        'MaxValue' => '14999',
      ),
      array (
        'Label' => 'ElecsnetWalletR',
        'Alias' => 'ElecsnetWallet',
        'Name' => 'ElecsnetWallet',
        'MaxValue' => '14999',
      ),
    ),
  ),
)

use Lexty\Robokassa\Auth;
use Lexty\Robokassa\Client;

$client = new Client(
    new Auth('your_login', 'password1', 'password2', true)
);

$paymentMethodGroups = $client
	->setCulture(Client::CULTURE_EN)
	->getPaymentMethodGroups();

array (
  'Terminals' => 'terminal ',
  'EMoney' => 'e-wallet',
  'BankCard' => 'Bank card',
  'Bank' => 'Internet Banking',
  'Other' => 'other methods ',
)

use Lexty\Robokassa\Auth;
use Lexty\Robokassa\Client;

$client = new Client(
    new Auth('your_login', 'password1', 'password2', true)
);

$rates = $client
	->setCulture(Client::CULTURE_EN)
	->getRates(500);

array (
  array (
    'Code' => 'Terminals',
    'Description' => 'terminal ',
    'Items' => 
    array (
      array (
        'Label' => 'TerminalsElecsnetOceanR',
        'Alias' => 'Elecsnet',
        'Name' => 'Elecsnet',
        'MaxValue' => '15000',
        'ClientSum' => 534.76,
      ),
    ),
  ),
  array (
    'Code' => 'EMoney',
    'Description' => 'e-wallet',
    'Items' => 
    array (
      array (
        'Label' => 'W1OceanR',
        'Alias' => 'W1',
        'Name' => 'RUR W1',
        'MaxValue' => '14999',
        'ClientSum' => 537.63,
      ),
      array (
        'Label' => 'ElecsnetWalletR',
        'Alias' => 'ElecsnetWallet',
        'Name' => 'ElecsnetWallet',
        'MaxValue' => '14999',
        'ClientSum' => 535,
      ),
    ),
  ),
)

use Lexty\Robokassa\Auth;
use Lexty\Robokassa\Client;

$client = new Client(
    new Auth('your_login', 'password1', 'password2', true)
);

$sum = $client->calculateClientSum(500, 'TerminalsElecsnetOceanR'); // 534.76

use Lexty\Robokassa\Auth;
use Lexty\Robokassa\Client;

$client = new Client(
    new Auth('your_login', 'password1', 'password2', true)
);

$invoice = $client
    ->setCulture(Client::CULTURE_EN)
    ->getInvoice(1);

array (
  'InvoiceId' => 1,
  'StateCode' => 100,
  'RequestDate' => \DateTime object,
  'StateDate' => \DateTime object,
  'PaymentMethod' => 'HandyBankKB',
  'ClientSum' => 100,
  'ClientAccount' => 'Test account',
  'PaymentMethodCode' => 'eInvoicing',
  'PaymentMethodDescription' => 'Internet bank',
  'Currency' => 'MerchantR',
  'ShopSum' => 94.5,
)