axcherednikov/cloudpayments-php-client

cloudpayments api客户端

3.2.1 2024-09-03 17:46 UTC

README

目录

前言

flowwow/cloudpayments-php-client包失去了及时支持,因此决定创建此包的分支以支持更现代的PHP版本和包,以支持新的PHP版本。

要求

  • php 8.1

安装

可以使用composer安装此库。

$ composer require axcherednikov/cloudpayments-php-client

入门

$publicId = /*...*/;
$pass = /*...*/;
$apiClient = new \Excent\Cloudpayments\Library($publicId, $pass);

$response = $apiClient->paymentsCardsCharge(new \Excent\Cloudpayments\Request\CardsPayment(
    100,
    'RUB',
    '123.123.123.123',
    '01492500008719030128SMfLeYdKp5dSQVIiO5l6ZCJiPdel4uDjdFTTz1UnXY'
));

echo $response->success;

支持的方法

该库支持大量的API方法(https://developers.cloudpayments.ru/#api)。对于请求和响应,支持对象包装器。

$apiClient = new \Excent\Cloudpayments\Library(\*...*\);
$apiClient->paymentsCardsCharge(\*...*\);

请求参数

请求参数被包装在dto对象中

...
$validationUrl = 'https://apple-pay-gateway.apple.com/paymentservices/startSession';
$request = new \Excent\Cloudpayments\Request\ApplepayStartSession($validationUrl);
$apiClient->startSession($request);

在构建request对象时,库可能抛出BadTypeException错误

try {
    ...
    $validationUrl = 'https://apple-pay-gateway.apple.com/paymentservices/startSession';
    $request = new \Excent\Cloudpayments\Request\ApplepayStartSession($validationUrl);
    ...
} catch (\Excent\Cloudpayments\Exceptions\BadTypeException $e) {
    var_dump($e->getMessage());
}

响应参数

响应参数也包装在dto对象中。 CloudResponse有3个属性:successmessagemodel

model属性中记录所需实体,具体取决于请求。

支持实体的列表

  • AppleSessionModel
  • NotificationModel
  • SubscriptionModel
  • TokenModel
  • TransactionModel
  • TransactionWith3dsModel

通知

库包括用于参数webhooks的dto对象

$hookData = new \Excent\Cloudpayments\Hook\HookPay($_POST);
echo $hookData->transactionId;

所有通知的列表 - https://developers.cloudpayments.ru/#check

幂等性

库支持幂等请求

...
$apiClient = new \Excent\Cloudpayments\Library(\*...*\);
$apiClient->setIdempotency(true);
$apiClient->createPaymentByCard2Step(\*...*\);
...

许可证

MIT