1. Go to this page and download the library: Download iamtime/uzpay 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/ */
iamtime / uzpay example snippets
final class Keys implements Uzpay\Contracts\Gateway
{
public function __construct(private array $keys, private bool $test = false) {}
public function credential(string $key): ?string { return $this->keys[$key] ?? null; }
public function testMode(): bool { return $this->test; }
}
$payme = new Keys(['merchant_id' => getenv('PAYME_MERCHANT_ID'), 'key' => getenv('PAYME_KEY'), 'test_key' => getenv('PAYME_TEST_KEY')]);
use Uzpay\Click\Shop;
use Uzpay\Octo;
use Uzpay\Payme\Merchant;
use Uzpay\Paynet\Merchant as Paynet;
use Uzpay\Uzum\Merchant as Uzum;
$body = json_decode(file_get_contents('php://input'), true) ?? [];
$auth = $_SERVER['HTTP_AUTHORIZATION'] ?? null;
// POST /payme - ответ всегда HTTP 200
$answer = (new Merchant($store, $orders))->handle($body, $auth, $paymeKeys);
// POST /click - Prepare и Complete на один адрес
$answer = (new Shop($store, $orders))->handle($_POST, $clickKeys);
// POST /uzum/{action} - Uzum добавляет к адресу /check, /create, /confirm, /reverse, /status
$answer = (new Uzum($store, $orders))->handle($action, $body, $auth, $uzumKeys);
http_response_code(Uzum::httpStatus($answer));
// POST /paynet - колбэк сохраняет новый пароль, если Paynet его сменит (без колбэка смена отклоняется)
$answer = (new Paynet($store, $orders, changePassword: fn (string $password) => $keys->save('password', $password)))
->handle($body, $auth, $paynetKeys);
// POST /octo - notify_url
$answer = (new Octo\Notifications($store))->handle($body, $octoKeys);
http_response_code(Octo\Notifications::httpStatus($answer));
header('Content-Type: application/json');
echo json_encode($answer);
use Uzpay\Money;
$tiyin = Money::tiyin($order->paymentAmount());
$url = Uzpay\Payme\Checkout::url($merchantId, 'order_id', $order->paymentKey(), $tiyin, $returnUrl, test: false);
$url = Uzpay\Click\Checkout::url($serviceId, $clickMerchantId, $order->paymentAmount(), $order->paymentKey(), $returnUrl);
$url = Uzpay\Uzum\Checkout::url($serviceId, 'order_id', $order->paymentKey(), $tiyin, $returnUrl);
$url = Uzpay\Paynet\Checkout::url($paynetMerchant, $order->paymentKey(), $tiyin);
// Octo: запрос к Octo, в ответ - страница оплаты. Описание по умолчанию - «Заказ №<номер>», страница на русском;
// и то и другое меняется через $options ('description', 'language').
$url = (new Uzpay\Octo\Payments($store, new Uzpay\Octo\Client($octoKeys)))->start($order, $returnUrl, 'https://shop.example/octo');
use Uzpay\Payme\ReceiptState;
use Uzpay\Payme\Subscribe;
use Uzpay\Payme\SubscribeException;
$payme = new Subscribe($paymeKeys);
$card = $payme->checkCard($tokenFromBrowser);
if (! $card->verified || ! $card->recurrent) {
// не сохраняем: карта не подтверждена или токен одноразовый
}
$customer->saveCard($card->token, $card->number); // "860006******6311"
try {
// номер заказа уходит в поле order_id: то же поле, по которому ищет заказы ваш Merchant API
$receipt = $payme->charge($invoice, $customer->cardToken, accountKey: 'order_id', description: 'Подписка');
ReceiptState::from($receipt['state']); // Paid (4); заказ уже оплачен через Merchant API
} catch (SubscribeException $e) {
// Payme отказал (недостаточно средств, карта заблокирована...): чек отменён, $e->getCode(), $e->messages['uz']
} catch (Uzpay\Http\TransportException $e) {
// ответа нет - исход неизвестен: проверьте $payme->checkReceipt($id) прежде чем списывать снова
}
use Uzpay\Sandbox\Emulator;
use Uzpay\Testing\InMemoryTransactions;
$store = new InMemoryTransactions;
$merchant = new Merchant($store, $orders);
$log = Emulator::payme(fn ($body, $auth) => $merchant->handle($body, $auth, $paymeKeys), 'test-key', 'order_id', $order, approve: true);
use Uzpay\Fiscal\Receipt;
$receipt = Receipt::make()
->item('Чехол для телефона', '50000', 2, '06109001001000000', '1503426', 12)
->shipping('Доставка', '15000')
->discount('Скидка', '5000');
$receipt->problems(); // [] или ["items.0.code", ...] - что не примет налоговая
$order->fiscalDetail(); // верните $receipt->toArray()
$body = json_decode(file_get_contents('php://input'), true) ?? [];
$auth = $_SERVER['HTTP_AUTHORIZATION'] ?? null;
$answer = (new Uzpay\Payme\Merchant($store, $orders))->handle($body, $auth, $paymeKeys); // POST /payme, always HTTP 200
$answer = (new Uzpay\Click\Shop($store, $orders))->handle($_POST, $clickKeys); // POST /click, Prepare and Complete
$answer = (new Uzpay\Uzum\Merchant($store, $orders))->handle($action, $body, $auth, $uzumKeys); // POST /uzum/{action}
http_response_code(Uzpay\Uzum\Merchant::httpStatus($answer));
$answer = (new Uzpay\Paynet\Merchant($store, $orders, changePassword: fn ($password) => $keys->save('password', $password)))
->handle($body, $auth, $paynetKeys); // POST /paynet
$answer = (new Uzpay\Octo\Notifications($store))->handle($body, $octoKeys); // POST /octo (notify_url)
http_response_code(Uzpay\Octo\Notifications::httpStatus($answer));
header('Content-Type: application/json');
echo json_encode($answer);
use Uzpay\Payme\Subscribe;
use Uzpay\Payme\SubscribeException;
$payme = new Subscribe($paymeKeys);
$card = $payme->checkCard($tokenFromBrowser); // never trust flags sent by the browser
if ($card->verified && $card->recurrent) {
$customer->saveCard($card->token, $card->number); // "860006******6311"
}
try {
// the order number goes to "order_id": the field your Merchant API finds orders by
$receipt = $payme->charge($invoice, $customer->cardToken, accountKey: 'order_id', description: 'Subscription');
} catch (SubscribeException $e) {
// Payme refused (no money, card blocked...): the receipt is canceled; $e->getCode(), $e->messages['en']
} catch (Uzpay\Http\TransportException $e) {
// no answer - the outcome is unknown: check $payme->checkReceipt($id) before charging again
}