PHP code example of axcherednikov / cloudpayments-php-client
1. Go to this page and download the library: Download axcherednikov/cloudpayments-php-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/ */
axcherednikov / cloudpayments-php-client example snippets
declare(strict_types=1);
use Excent\Cloudpayments\Library;
use Excent\Cloudpayments\Request\CardsPayment;
= new CardsPayment(
100.00,
'RUB',
'127.0.0.1',
'CARD_CRYPTOGRAM_PACKET'
);
$response = $client->paymentsCardsCharge($request);
if ($response->success) {
echo $response->model->transactionId;
}
$client = new Library($publicId, $apiPassword, $customApiUrl);
use Excent\Cloudpayments\Request\Post3DS;
$response = $client->paymentsCardsCharge($request);
if ($response->is3dsError()) {
$acsUrl = $response->model->acsUrl;
$paReq = $response->model->paReq;
$transactionId = $response->model->transactionId;
// Передайте пользователя на страницу ACS банка, затем обработайте PaRes.
$client->post3Ds(new Post3DS($transactionId, 'PARES_FROM_ACS'));
}
use Excent\Cloudpayments\Request\ApplepayStartSession;
$request = new ApplepayStartSession(
'https://apple-pay-gateway.apple.com/paymentservices/startSession'
);
$response = $client->startSession($request);
use Excent\Cloudpayments\Request\NotificationsUpdate;
$request = new NotificationsUpdate();
$request->type = 'pay';
$request->isEnabled = true;
$request->address = 'https://example.com/cloudpayments/pay';
$client->siteNotificationsUpdate($request);
$extra = $response->model->getAdditionalProperties();
use Excent\Cloudpayments\Hook\HookPay;
$hook = new HookPay($_POST);
echo $hook->transactionId;
$client->setIdempotency(true);
$response = $client->createPaymentByCard2Step($request);
$client->setIdempotencyKey('order-100500-auth');
$response = $client->createPaymentByCard2Step($request);
use Excent\Cloudpayments\Exceptions\BadTypeException;
use GuzzleHttp\Exception\GuzzleException;
try {
$response = $client->paymentsRefund($request);
} catch (BadTypeException $exception) {
// Некорректные параметры request DTO.
} catch (GuzzleException $exception) {
// Ошибка HTTP-запроса.
} catch (JsonException $exception) {
// Ответ API не удалось разобрать как JSON.
}
bash
composer