1. Go to this page and download the library: Download yourpayments/php-api-client 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/ */
yourpayments / php-api-client example snippets
$merchant = new Merchant('MERCHANT_CODE', 'SECRET_KEY'); // Коды подключения API
$merchantPaymentReference = 123; // Номер заказа в вашей системе
$billing = (new Billing)
->setCountryCode('RU') // Страна Плательщика
->setFirstName('Иван') // Имя Плательщика
->setLastName('Петров') // Фамилия Плательщика
->setEmail('[email protected]') // Почта Плательщика
->setPhone('+74996492009') // Телефон Плательщика
->setCity('Москва'); // Город Плательщика
$client = (new Client)->setBilling($billing);
$payment = (new Payment)
->addProduct(new Product([
'name' => 'Заказ №' . $merchantPaymentReference, // Наименование товарной позиции
'sku' => 'test_artikul', // Артикул
'unitPrice' => 20.42, // Стоимость единицы
'quantity' => 1, // Количество
]));
$payment_method = $_GET['method'] ?? PaymentMethods::CCVISAMC; // Определим платёжный метод
$authorization = new Authorization($payment_method, true);
$payment->setAuthorization($authorization);
$payment->setMerchantPaymentReference($merchantPaymentReference);
$payment->setSuccessUrl('https://' . $_SERVER['HTTP_HOST'] . '/?status=success'); // Редирект после успешной оплаты
$payment->setFailUrl('https://' . $_SERVER['HTTP_HOST'] . '/?status=success'); // Редирект в случае неоплаты
$payment->setClient($client);
$apiRequest = new ApiRequest($merchant);
$responseData = $apiRequest->sendAuthRequest($payment, $merchant);
$responseData = json_decode((string) $responseData["response"], true); // Отправка запроса и обработка ответа
if (isset($responseData["paymentResult"])) {
if (!empty($responseData['paymentResult']['bankResponseDetails']['customBankNode']['qr'])) {
$qr = $responseData['paymentResult']['bankResponseDetails']['customBankNode']['qr'];
}
// Выведем кнопку оплаты (рекомендуется)
echo Std::drawYpmnButton([
'qr' => ($qr ?? null),
'url' => $responseData['paymentResult']['url'] ?? '',
'sum' => $payment->sumProductsAmount() ?? 0,
'payment_method' => $payment_method ?? null,
'newpage' => true,
]);
// .. или сделаем редирект на форму оплаты (опционально)
// Std::redirect($responseData["paymentResult"]['url']);
}
shell
composer
shell
php -S localhost:8080 index.php
shell
composer update yourpayments/php-api-client
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.