PHP code example of andrewnovikof / omnipay-sberbank
1. Go to this page and download the library: Download andrewnovikof/omnipay-sberbank 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/ */
andrewnovikof / omnipay-sberbank example snippets
use Omnipay\Omnipay;
// Setup payment gateway
$gateway = Omnipay::create('Sberbank');
// Set params for authorize request
$gateway->authorize(
[
'orderNumber' => $localOrderNumber, // local order number
'amount' => $order_amount, // The amount of payment (you can use decimal with 2 precisions for copecs or string equal to decimal)
'returnUrl' => $callback_url // succesfull callback url
]
);
// Enable test mode
$gateway->setTestMode(true);
// You can set parameters via setters, for example:
$gateway->setUserName('merchant_login')
->setPassword('merchant_password')
->setOrderNumber($localOrderNumber)
->setLanguage('en');
// Send request
$response = $gateway->send();
// Process response
if ($response->isSuccessful()) {
// Payment was successful
print_r($response);
// Get gateway orderId
$gatewayOrderId = $response->getOrderId();
// Get manualy get redirect url to offsite payment gateway
$offsiteGateway = $response->getRedirectUrl();
} else {
// Payment failed
echo $response->getMessage();
}
// Work with redirect
if ($response->isRedirect()) {
// Redirect to offsite payment gateway
$response->redirect();
}
use Omnipay\Omnipay;
$gateway = Omnipay::create('Sberbank');
$response = $gateway->authorize(
[
'orderNumber' => $localOrderNumber, // local order number
'amount' => $order_amount, // The amount of payment (you can use decimal with 2 precisions for copecs or string equal to decimal)
'returnUrl' => $callback_url, // succesfull callback url
'description' => 'Order Description'
]
)->setUserName('merchant_login')
->setPassword('merchant_password')
->send();
// Process response
if ($response->isSuccessful()) {
// Payment was successful
print_r($response);
// Get gateway orderId
$gatewayOrderId = $response->getOrderId();
// Get manualy get redirect url to offsite payment gateway
$offsiteGateway = $response->getRedirectUrl();
} else {
// Payment failed
echo $response->getMessage();
}
// Work with redirect
if ($response->isRedirect()) {
// Redirect to offsite payment gateway
$response->redirect();
}
use Omnipay\Omnipay;
$gateway = Omnipay::create('Sberbank');
$response = $gateway->authorize(
[
'orderNumber' => $localOrderNumber, // local order number
'amount' => $order_amount, // The amount of payment (you can use decimal with 2 precisions for copecs or string equal to decimal)
'returnUrl' => $callback_url, // succesfull callback url
'description' => 'Order Description'
]
)->setTwoStage(true)
->setUserName('merchant_login')
->setPassword('merchant_password')
->send();
// Process response
if ($response->isSuccessful()) {
// Payment was successful
print_r($response);
// Get gateway orderId
$gatewayOrderId = $response->getOrderId();
// Get manualy get redirect url to offsite payment gateway
$offsiteGateway = $response->getRedirectUrl();
} else {
// Payment failed
echo $response->getMessage();
}
// Work with redirect
if ($response->isRedirect()) {
// Redirect to offsite payment gateway
$response->redirect();
}
use Omnipay\Omnipay;
$gateway = Omnipay::create('Sberbank');
$response = $gateway->capture(
[
'orderId' => $localOrderNumber, // gateway order number
'amount' => $order_amount, // The amount of payment (you can use decimal with 2 precisions for copecs or string equal to decimal)
]
)->setUserName('merchant_login')
->setPassword('merchant_password')
->send();
// Process response
if ($response->isSuccessful()) {
// Get response code
$code = $response->getCode();
} else {
// Payment failed
echo $response->getMessage();
}
use Omnipay\Omnipay;
$gateway = Omnipay::create('Sberbank');
$response = $gateway->orderStatus( // It will be similar to calling methods `completeAuthorize()` and `completePurchase()`
[
'orderId' => $localOrderNumber, // gateway order number
'language' => 'en'
]
)->setUserName('merchant_login')
->setPassword('merchant_password')
->send();
// Process response
if ($response->isSuccessful()) {
// Get response code
$code = $response->getCode();
// Get paid amount
$paid_amount = $response->getAmount();
// Get other data
$order_status = $response->getOrderStatus();
$order_number = $response->getOrderNumber();
$order_pan = $response->getPan();
$order_expiration = $response->getExpiration();
$order_cardholder_name = $response->getCardHolderName();
$order_currency = $response->getCurrency();
$order_approval_code = $response->getApprovalCode();
$order_ip = $response->getIp();
$order_client_id = $response->getClientId();
$order_binding_id = $response->getBindingId();
} else {
// Payment failed
echo $response->getMessage();
}
use Omnipay\Omnipay;
$gateway = Omnipay::create('Sberbank');
$response = $gateway->extendedOrderStatus(
[
'orderId' => $localOrderNumber, // gateway order number
'language' => 'en'
]
)->setOrderNumber($localORderNumber) // You can set local orderNumber Instead of an orderId of gateway system
->setUserName('merchant_login')
->setPassword('merchant_password')
->send();
// Process response
if ($response->isSuccessful()) {
// Get response code
$code = $response->getCode();
// Get paid amount
$paid_amount = $response->getAmount();
// Get other data
$order_status = $response->getOrderStatus();
$order_number = $response->getOrderNumber();
$order_pan = $response->getPan();
$order_expiration = $response->getExpiration();
$order_cardholder_name = $response->getCardHolderName();
$order_currency = $response->getCurrency();
$order_approval_code = $response->getApprovalCode();
$order_ip = $response->getIp();
$order_client_id = $response->getClientId();
$order_binding_id = $response->getBindingId();
$order_merchant_order_params = $response->getMerchantOrderParams();
$order_eci = $response->getEci();
$order_cavv = $response->getCavv();
$order_xid = $response->getXid();
$order_auth_date_time = $response->getAuthDateTime();
$order_auth_ref_num = $response->getAuthRefNum();
$order_terminal_id = $response->getTerminalId();
$order_approved_amount = $response->getApprovedAmount();
$order_deposited_amount = $response->getDepositedAmount();
$order_refunded_amount = $response->getRefundedAmount();
$order_payment_state = $response->getPaymentState();
$order_bank_name = $response->getBankName();
$order_bank_country_code = $response->getBankCountryCode();
$order_band_country_name = $response->getBankCountryName();
} else {
// Payment failed
echo $response->getMessage();
}
use Omnipay\Omnipay;
$gateway = Omnipay::create('Sberbank');
$response = $gateway->void(
[
'orderId' => $localOrderNumber, // gateway order number
'language' => 'en'
]
)->setUserName('merchant_login')
->setPassword('merchant_password')
->send();
// Process response
if ($response->isSuccessful()) {
// Get response code
$code = $response->getCode();
} else {
// Payment failed
echo $response->getMessage();
}
use Omnipay\Omnipay;
$gateway = Omnipay::create('Sberbank');
$response = $gateway->refund(
[
'orderId' => $localOrderNumber, // gateway order number
'language' => 'en',
'amount' => $oder_amount // // The amount of payment (you can use decimal with 2 precisions for copecs or string equal to decimal)
]
)->setUserName('merchant_login')
->setPassword('merchant_password')
->send();
// Process response
if ($response->isSuccessful()) {
// Get response code
$code = $response->getCode();
} else {
// Payment failed
echo $response->getMessage();
}