Git Product home page Git Product logo

omnipay-sberbank's Introduction

Sberbank acquiring for PHP

Build Status Latest Stable Version Total Downloads License

Introduction

This library implements the work with Sberbank acquiring api via theleague Omnipay processing library for PHP. It has a clear and consistent API, is fully unit tested.

This package supports PHP 7.1 and higher

Download

Composer

// This assumes that you have composer installed globally
composer require andrewnovikof/omnipay-sberbank

Solving problems with minimal stability

Add to your composer.json

{
  "minimum-stability":"dev",
  "prefer-stable": true
}

Simple Example

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 * 100, // The amount of payment in kopecks (or cents)
       '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();

} 

Payment Methods

Order registration without pre-authorization

More about this request you'll see in Sberbank official documentation or in our source code

use Omnipay\Omnipay;

$gateway = Omnipay::create('Sberbank');
$response = $gateway->authorize(
    [
       'orderNumber' => $localOrderNumber, // local order number
       'amount' => $order_amount * 100, // The amount of payment in kopecks (or cents)
       '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();

} 

Order registration with pre-authorization

More about this request you'll see in Sberbank official documentation or in our source code

use Omnipay\Omnipay;

$gateway = Omnipay::create('Sberbank');
$response = $gateway->authorize(
    [
       'orderNumber' => $localOrderNumber, // local order number
       'amount' => $order_amount * 100, // The amount of payment in kopecks (or cents)
       '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();

} 

Order completion after pre-authorization

More about this request you'll see in Sberbank official documentation or in our source code

use Omnipay\Omnipay;

$gateway = Omnipay::create('Sberbank');
$response = $gateway->capture(
    [
       'orderId' => $localOrderNumber, // gateway order number
       'amount' => $order_amount * 100, // The amount of payment in kopecks (or cents)
    ]
)->setUserName('merchant_login')
 ->setPassword('merchant_password')
 ->send();

// Process response
if ($response->isSuccessful()) {

    // Get response code
    $code = $response->getCode();
} else {
 
     // Payment failed
     echo $response->getMessage();
}

Orders status

More about this request you'll see in Sberbank official documentation or in our source code

This method work for completeAuthorize() and completePurchase() requests of Omnipay.

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();
}

Extended order status

More about this request you'll see in Sberbank official documentation or in our source code

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();
}

Void order

More about this request you'll see in Sberbank official documentation or in our source code

To request cancellation of payment for an order, use the request reverse.do. The cancellation function is available for a limited time after payment, the exact terms should be specified in the Bank.

The cancellation operation can only be performed once. If it ends with an error, then the repeated cancellation operation will fail.

This function is available to stores in consultation with the Bank. To perform the cancellation operation, the user must have the appropriate rights.

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();
}

Refund for an order payment

More about this request you'll see in Sberbank official documentation or in our source code

For this request, the funds will be returned to the payer on the specified order. The request will end with an error if the funds for this order were not written off. The system allows you to return funds more than once, but in total no more than the original amount of write-off.

To perform a return operation, you must have the appropriate rights in the system.

use Omnipay\Omnipay;

$gateway = Omnipay::create('Sberbank');
$response = $gateway->refund(
    [
       'orderId' => $localOrderNumber, // gateway order number
       'language' => 'en',
       'amount' => $oder_amount // The amount of payment in kopecks (or cents)
    ]
)->setUserName('merchant_login')
 ->setPassword('merchant_password')
 ->send();
 
// Process response
if ($response->isSuccessful()) {

    // Get response code
    $code = $response->getCode();
} else {

     // Payment failed
     echo $response->getMessage();
}

Verify the involvement of the map in 3DS

More about this request you'll see in Sberbank official documentation or in our source code

use Omnipay\Omnipay;

$gateway = Omnipay::create('Sberbank');
$response = $gateway->verifyEnrollment(
    [
       'pan' => $cardPan
    ]
)->setUserName('merchant_login')
 ->setPassword('merchant_password')
 ->send();
 
// Process response
if ($response->isSuccessful()) {

    // Get response code
    $code = $response->getCode();
    
    $emitter_country_name = $response->getEmitterName();
    $emitter_country_code = $response->getEmitterCountryCode();
    $enrolled = $response->getEnrolled();
} else {

     // Payment failed
     echo $response->getMessage();
}

Statistics on payments for the period

More about this request you'll see in Sberbank official documentation or in our source code

use Omnipay\Omnipay;

$gateway = Omnipay::create('Sberbank');
$response = $gateway->getLastOrdersForMerchants(
    [
       'size' => $size,
       'from' => $from,
       'to' => $to,
       'transactionStates' => $transactionStates,
       'merchants' => $merchants
    ]
)->setUserName('merchant_login')
 ->setPassword('merchant_password')
 ->send();
 
// Process response
if ($response->isSuccessful()) {

    // Get response code
    $code = $response->getCode();
    
    $total_count = $response->getTotalCount();
    $page = $response->getPage();
    $page_size = $response->getPageSize();

    // Available getters
    $response->getOrderErrorCode($orderIndex);
    $response->getOrderNumber($orderIndex);
    $response->getOrderStatus($orderIndex);
    $response->getActionCode($orderIndex);
    $response->getActionCodeDescription($orderIndex);
    $response->getAmount($orderIndex);
    $response->getCurrency($orderIndex);
    $response->getDate($orderIndex);
    $response->getOrderDescription($orderIndex);
    $response->getIp($orderIndex);
    $response->getMerchantOrderParamName($orderIndex, $paramIndex);
    $response->getMerchantOrderParamValue($orderIndex, $paramIndex);
    $response->getAttributesName($orderIndex, $attributeIndex);
    $response->getAttributesValue($orderIndex, $attributeIndex);
    $response->getExpiration($orderIndex);
    $response->getCardholderName($orderIndex);
    $response->getApprovalCode($orderIndex);
    $response->getPan($orderIndex);
    $response->getClientId($orderIndex);
    $response->getBindingId($orderIndex);
    $response->getAuthDateTime($orderIndex);
    $response->getTerminalId($orderIndex);
    $response->getAuthRefNum($orderIndex);
    $response->getPaymentState($orderIndex);
    $response->getApprovedAmount($orderIndex);
    $response->getDepositedAmount($orderIndex);
    $response->getRefundedAmount($orderIndex);
    $response->getBankName($orderIndex);
    $response->getBankCountryName($orderIndex);
    $response->getBankCountryCode($orderIndex);
} else {

     // Payment failed
     echo $response->getMessage();
}

Add a card to the list of SSL-cards

More about this request you'll see in Sberbank official documentation or in our source code

use Omnipay\Omnipay;

$gateway = Omnipay::create('Sberbank');
$response = $gateway->verifyEnrollment(
    [
       'mdorder' => $mdorder
    ]
)->setUserName('merchant_login')
 ->setPassword('merchant_password')
 ->send();
 
// Process response
if ($response->isSuccessful()) {

    // Get response code
    $code = $response->getCode();
} else {

     // Payment failed
     echo $response->getMessage();
}

omnipay-sberbank's People

Contributors

agelxnash avatar andrewnovikof avatar padavvan avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.