dven84 / sberbank-acquiring-client

PHP client for the Sberbank's acquiring REST API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

sberbank-acquiring-client Build Status

PHP client for Sberbank's acquiring REST API.

Installation

composer require 'voronkovich/sberbank-acquiring-client'

Usage

Instantiating a client

In most cases to instantiate a client you need to pass your username and password to a constructor:

<?php

use Voronkovich\SberbankAcquiring\Client;

/** @var Client $client */
$client = new Client([ 'userName' => 'YourUserName', 'password' => 'YourPassword' ]);

More advanced example:

<?php

use Voronkovich\SberbankAcquiring\Client;
use Voronkovich\SberbankAcquiring\Currency;

/** @var Client $client */
$client = new Client([
    'userName' => 'userName',
    'password' => 'password',

    // A language code in ISO 639-1 format.
    // Use this option to set a language of error messages.
    'language' => 'ru',

    // A currency code in ISO 4217 format.
    // Use this option to set a currency used by default.
    'currency' => Currency::RUB,

    // An uri to send requests.
    // Use this option if you want to use the Sberbank's test server.
    'apiUri' => Client::API_URI_TEST,

    // An HTTP method to use in requests.
    // Must be "GET" or "POST" ("POST" is used by default).
    'httpMethod' => 'GET',

    // An HTTP client for sending requests.
    // Use this option when you don't want to use
    // a default HTTP client implementation distributed
    // with this package (for example, when you have'nt
    // a CURL extension installed in your server).
    'httpClient' => new YourCustomHttpClient(),
]);

Also you can use an adapter for the Guzzle:

<?php

use Voronkovich\SberbankAcquiring\Client;
use Voronkovich\SberbankAcquiring\HttpClient\GuzzleAdapter;

use GuzzleHttp\Client as Guzzle

/** @var Client $client */
$client = new Client([
    'userName' => 'userName',
    'password' => 'password',

    'httpClient' => new GuzzleAdapter(new Guzzle()),
]);

Creating a new order

<?php

use Voronkovich\SberbankAcquiring\Client;
use Voronkovich\SberbankAcquiring\Currency;

/** @var Client $client */
$client = new Client([ 'userName' => 'userName', 'password' => 'password' ]);

// Required arguments
$orderId     = 1234;
$orderAmount = 1000;
$returnUrl   = 'http://mycoolshop.local/payment-success';

// You can pass additional parameters like a currency code and etc.
$params['currency'] = Currency::EUR;
$params['failUrl']  = 'http://mycoolshop.local/payment-failure';

$result = $client->registerOrder($orderId, $orderAmount, $returnUrl, $params);

$paymentOrderId = $result['orderId'];
$paymentFormUrl = $result['formUrl'];

header('Location: ' . $paymentFormUrl);

Use a registerOrderPreAuth method to create a 2-step order.

Getting a status of an exising order

Never use this method, because a Sberbank's gateway does'nt handle it properly, use a getOrderStatusExtended instead. For more information see a Sberbank's documentation.

<?php

use Voronkovich\SberbankAcquiring\Client;
use Voronkovich\SberbankAcquiring\OrderStatus;

/** @var Client $client */
$client = new Client([ 'userName' => 'userName', 'password' => 'password' ]);

$result = $client->getOrderStatus($orderId);

if (OrderStatus::isDeposited($result['orderStatus'])) {
    echo "Order #$orderId is deposited!";
}

Getting an extended status of an exising order

<?php

use Voronkovich\SberbankAcquiring\Client;
use Voronkovich\SberbankAcquiring\OrderStatus;

/** @var Client $client */
$client = new Client([ 'userName' => 'userName', 'password' => 'password' ]);

$result = $client->getOrderStatusExtended($orderId);

if (OrderStatus::isDeclined($result['orderStatus'])) {
    echo "Order #$orderId was declined!";
}

Reversing an exising order

<?php

use Voronkovich\SberbankAcquiring\Client;

/** @var Client $client */
$client = new Client([ 'userName' => 'userName', 'password' => 'password' ]);

$result = $client->reverseOrder($orderId);

Refunding an exising order

<?php

use Voronkovich\SberbankAcquiring\Client;

/** @var Client $client */
$client = new Client([ 'userName' => 'userName', 'password' => 'password' ]);

$result = $client->refundOrder($orderId, $amountToRefund);

See Client source code to find methods for payment bindings and dealing with 2-step payments.

License

Copyright (c) Voronkovich Oleg. Distributed under the MIT.

About

PHP client for the Sberbank's acquiring REST API

License:MIT License


Languages

Language:PHP 100.0%