PHP code example of parazeet / paymaster_api_php_sdk
1. Go to this page and download the library: Download parazeet/paymaster_api_php_sdk 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/ */
parazeet / paymaster_api_php_sdk example snippets
use parazeet\PayMaster\PayMasterApi;
use parazeet\PayMaster\Config\Config;
use parazeet\PayMaster\Validator\ResponseValidator;
use Ramsey\Uuid\Uuid;
$api = new PayMasterApi(
new Config('YOUR_API_KEY', Uuid::uuid4()->toString()),
new ResponseValidator()
);
use parazeet\PayMaster\Requests\InvoiceRequest;
$invoice = (new InvoiceRequest())
->merchantId('YOUR_MERCHANT_ID')
->testMode(true)
->invoice(['description' => 'test payment'])
->amount(['value' => 11, 'currency' => 'RUB'])
->paymentMethod('BankCard')
->protocol([
'returnUrl' => 'https://example.com/return',
'callbackUrl' => 'https://example.com/callback',
])
->customer([
'email' => '[email protected] ',
'phone' => '79081234567',
'account' => 'user-1',
]);
$response = $api->post($invoice);
// $response->invoice->paymentId, $response->invoice->url
use parazeet\PayMaster\Requests\PaymentRequest;
$payment = (new PaymentRequest())
->merchantId('YOUR_MERCHANT_ID')
->invoice(['description' => 'test payment'])
->amount(['value' => 10.50, 'currency' => 'RUB'])
->paymentData([
'paymentMethod' => 'BankCard',
'token' => ['id' => 'TOKEN_ID'],
])
->protocol([
'returnUrl' => 'https://example.com/return',
'callbackUrl' => 'https://example.com/callback',
'threeDSCompleteUrl' => 'https://example.com/3ds-complete',
]);
$response = $api->post($payment);
$response = $api->getId(new PaymentRequest(), '12769');
// $response->payments->completed — дата завершения (если есть)
$list = $api->getQuery(new PaymentRequest(), [
'merchantId' => 'YOUR_MERCHANT_ID',
'start' => '2021-08-01T06:00:00Z',
'end' => '2021-08-01T06:30:00Z',
]);
// $list->payments — массив Payment
// $list->cursor — указатель следующей страницы или null
// Следующая страница:
if ($list->cursor !== null) {
$list = $api->getQuery(new PaymentRequest(), [
'merchantId' => 'YOUR_MERCHANT_ID',
'start' => '2021-08-01T06:00:00Z',
'end' => '2021-08-01T06:30:00Z',
'cursor' => $list->cursor,
]);
}
// Complete — API возвращает детали платежа
$complete = (new PaymentRequest())->completeData([
'PARes' => '...',
// или: 'cres', 'code', 'threeDSCompInd'
]);
$paymentResponse = $api->put($complete, '12769', 'complete');
// Confirm (capture) — пустой 200 → true
$confirm = (new PaymentRequest())->confirmData([
'amount' => ['value' => 10.50, 'currency' => 'RUB'],
]);
$ok = $api->put($confirm, '12769', 'confirm');
// Cancel
$ok = $api->put(new PaymentRequest(), '12769', 'cancel');
use parazeet\PayMaster\Requests\TokenizationRequest;
$tokenLink = (new TokenizationRequest())
->merchantId('YOUR_MERCHANT_ID')
->type('recurring')
->purpose('Подписка')
->paymentMethod('bankcard')
->customer(['account' => 'user-1']);
$response = $api->post($tokenLink);
// $response->tokenization->tokenId, $response->tokenization->url
use parazeet\PayMaster\Requests\PaymentTokenRequest;
// Create
$create = (new PaymentTokenRequest())
->merchantId('YOUR_MERCHANT_ID')
->type('recurring')
->purpose('Подписка')
->paymentData(['paymentMethod' => 'sbp'])
->customer(['account' => 'user-1'])
->protocol([
'returnUrl' => 'https://example.com/return',
'callbackUrl' => 'https://example.com/token-callback',
]);
$tokenResponse = $api->post($create);
// $tokenResponse->paymentToken->id
// $tokenResponse->paymentToken->status
// $tokenResponse->paymentToken->confirmation // External / 3DS и т.д.
// Get
$tokenResponse = $api->getId(new PaymentTokenRequest(), 'TOKEN_ID');
// Complete (3DS)
$complete = (new PaymentTokenRequest())->completeData(['PARes' => '...']);
$tokenResponse = $api->put($complete, 'TOKEN_ID', 'complete');
// Revoke
$ok = $api->put(new PaymentTokenRequest(), 'TOKEN_ID', 'revoke');
use parazeet\PayMaster\Requests\ReceiptRequest;
$receipt = (new ReceiptRequest())
->paymentId('13167')
->amount(['value' => 10, 'currency' => 'RUB'])
->type('Payment')
->client(['email' => '[email protected] '])
->items([
[
'name' => 'Услуга',
'quantity' => 1,
'price' => 10,
'vatType' => 'None',
'paymentSubject' => 'Service',
'paymentMethod' => 'FullPrepayment',
],
// ...дополнительные позиции
])
->settlements([
'cashless' => 10,
// 'advance' => 0,
// 'loan' => 0,
// 'consideration' => 0,
]);
$response = $api->post($receipt);
// $response->receipt->providerOperationId
// $response->receipt->fiscalData // fiscalDeviceId, shiftNumber, receiptNumber, ...
// Одна позиция также поддерживается (будет обёрнута в массив):
// ->items(['name' => '...', 'quantity' => 1, ...])
use parazeet\PayMaster\Requests\StickerRequest;
$sticker = (new StickerRequest())
->merchantId('YOUR_MERCHANT_ID')
->stickerType('Sbp')
->paymentPurpose('Оплата товара')
->amount(['value' => 39.90, 'currency' => 'RUB']);
$response = $api->post($sticker);
// $response->sticker->id, $response->sticker->payload
// Activate / deactivate: PUT /stickers/{id} с body {"active": bool}
$ok = $api->put((new StickerRequest())->active(true), $stickerId);
$ok = $api->put((new StickerRequest())->active(false), $stickerId);
use parazeet\PayMaster\Requests\RefundRequest;
$refund = (new RefundRequest())
->paymentId('12870')
->amount(['value' => 5.5, 'currency' => 'RUB']);
$response = $api->post($refund);
bash
composer