Git Product home page Git Product logo

yii2-sberpay-rest's Introduction

Сбербанк REST API для Yii2

Настройка

$config = [
    'modules' => [
        'sberpay' => [
            'class' => dicr\sberpay\SberPayModule::class,
            'userName' => 'user-api',
            'password' => 'my-password',
            
            // опционально обработчик статуса платежей
            'handler' => static function(dicr\sberpay\CallbackRequest $request) {
                // сохранение статуса
            }
        ]
    ]       
];

Использование

Создание платежа

/** @var dicr\sberpay\SberPayModule $module */
$module = Yii::$app->getModule('sberpay');

/** @var dicr\sberpay\RegisterPaymentRequest $request создаем запрос */
$request = $module->registerPaymentRequest([
    'orderNumber' => '<номер заказа магазина>',
    //'amount' => 3982, // авто-вычисление
    'returnUrl' => 'https://test.ru',
    'orderBundle' => [
        'cartItems' => [
            'items' => [
                [
                    'positionId' => 1,
                    'name' => 'Русская водка',
                    'code' => 'VODKA-777',
                    'price' => 1203,
                    'quantity' => ['value' => 1.255, 'measure' => 'л'] // чекушка 1.25 литров
                    //'amount' => 1509.765 ( 1510 копеек ) авто-вычисление с округлением
                ],
                [
                    'positionId' => 2,
                    'name' => 'Пряная селедка',
                    'code' => 'СЕЛ-Д',
                    'price' => 1236, // 12.34 руб
                    'quantity' => ['value' => 2, 'measure' => 'шт'],
                    'amount' => 2472
                ],
            ]
        ]
    ]
]);

/** @var dicr\sberpay\RegisterPaymentResponse $response отправляем запрос */
$response = $request->send();

/** @var string $orderId номер заказа в системе банка */
$orderId = $response->orderId;

// переадресуем посетителя на страницу оплаты
$response->redirect();

Получение статуса платежа

/** @var dicr\sberpay\SberPayModule $module */
$module = Yii::$app->getModule('sberpay');

/** @var dicr\sberpay\OrderStatusRequest $req создаем запрос */
$req = $module->orderStatusRequest([
    'orderId' => '<номер заказа магазина>'
]);

/** @var dicr\sberpay\OrderStatusResponse $res отправляем запрос */
$res = $req->send();

/** @var int $orderStatus статус заказа */
$orderStatus = $res->orderStatus;

yii2-sberpay-rest's People

Contributors

dicrtarasov avatar

Stargazers

 avatar  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.