korobovn/cloud-payments
Composer 安装命令:
composer require korobovn/cloud-payments
包简介
Cloud Payments PHP-client
关键字:
README 文档
README
Cloud Payments PHP-client
The package for easy use Cloud Payments API.
Install
Require this package with composer using the following command:
$ composer require korobovn/cloud-payments
Installed
composeris required (how to install composer).
Frameworks integration
Laravel 5
Laravel 5.5 and above uses Package Auto-Discovery, so doesn't require you to manually register the service-provider. Otherwise you must add the service provider to the providers array in ./config/app.php:
'providers' => [ // ... Korobovn\CloudPayments\CloudPaymentsServiceProvider::class, ]
Usage
How to get a client instance
If using Laravel framework, then you can get an instance of ClientInterface using make method to resolve.
$client = $this->app->make(Korobovn\CloudPayments\Client\ClientInterface::class);
You can send a request using the send method:
$client->send($request);
Where $request is an instance of RequestInterface.
You can also call the send method on the RequestInterface instance.
Before that, you must call the setClient method on the RequestInterface with ClientInterface
$request->setClient($client)->send();
You can choose the way you like.
How to create a request
List of available requests:
Cryptogram payment
CryptogramPaymentOneStepRequest - for one-step payment;
CryptogramPaymentTwoStepRequest - for two-step payment.
Creating and sending a request:
<?php use Korobovn\CloudPayments\Client\ClientInterface; use Korobovn\CloudPayments\Message\Request\CryptogramPaymentOneStepRequest; use Korobovn\CloudPayments\Message\Request\CryptogramPaymentTwoStepRequest; use Korobovn\CloudPayments\Message\Response\Cryptogram3dSecureAuthRequiredResponse; use Korobovn\CloudPayments\Message\Response\CryptogramTransactionAcceptedResponse; use Korobovn\CloudPayments\Message\Response\CryptogramTransactionRejectedResponse; use Korobovn\CloudPayments\Message\Response\InvalidRequestResponse; /** @var ClientInterface $client */ $client = $this->app->make(ClientInterface::class); $request = CryptogramPaymentOneStepRequest::create(); /* or we can also use: $request = new CryptogramPaymentTwoStepRequest; */ $request ->getModel() ->setAmount(100.0) ->setCurrency('RUB') ->setIpAddress('127.0.0.1') ->setName('CARDHOLDER NAME') ->setCardCryptogramPacket('CARD_CRYPTOGRAM_PACKET'); /** @var InvalidRequestResponse|Cryptogram3dSecureAuthRequiredResponse|CryptogramTransactionRejectedResponse|CryptogramTransactionAcceptedResponse $response */ $response = $request->setClient($client)->send();
Before calling the send method to send a request, we must fill out the request data model. To do that, call the getModel method on RequestInterface and use setters to set values. Use autocomplete of your IDE for to access setters.
The $response must be an instance of one of the classes: InvalidRequestResponse, Cryptogram3dSecureAuthRequiredResponse, CryptogramTransactionRejectedResponse, CryptogramTransactionAcceptedResponse
The $response (an instance of ResponseInterface) also has its own data model. Use the getModel method and getters to access the data.
Checking the type of response and accessing the response data model fields:
<?php use Korobovn\CloudPayments\Message\Response\CryptogramTransactionAcceptedResponse; if ($response instanceof CryptogramTransactionAcceptedResponse) { $transaction_id = $response->getModel()->getTransactionId(); $status_code = $response->getModel()->getStatusCode(); $token = $response->getModel()->getToken(); }
3-D Secure Processing
3-D Secure Processing docs here.
CompletionOf3dSecureRequest - for to complete the 3-D Secure payment.
Possible answers: InvalidRequestResponse, Cryptogram3dSecureAuthRequiredResponse, CryptogramTransactionRejectedResponse, CryptogramTransactionAcceptedResponse
Token Payment
TokenPaymentOneStepRequest - for one-step payment;
TokenPaymentTwoStepRequest - for two-step payment.
Possible answers: InvalidRequestResponse, CryptogramTransactionRejectedResponse, CryptogramTransactionAcceptedResponse
Cancel payment
CancelPaymentRequest - сancel payment for two-step payment request
Possible answers: InvalidRequestResponse, SuccessResponse
Refund payment
RefundPaymentRequest - refund for payment made
Possible answers: InvalidRequestResponse, RefundPaymentResponse
Create a recurring payment subscription
Create a recurring payment subscription docs here.
CreateSubscriptionRequest - creating a subscription for payments that will be made in the future
Possible answers: InvalidRequestResponse, SubscriptionResponse
Request Subscription Information
Request Subscription Information docs here.
GetSubscriptionRequest
Possible answers: InvalidRequestResponse, SubscriptionResponse
Search Subscriptions
Search Subscriptions docs here.
FindSubscriptionRequest
Possible answers: InvalidRequestResponse, SubscriptionsResponse
Change subscription
Change subscription docs here.
UpdateSubscriptionRequest
Possible answers: InvalidRequestResponse, SubscriptionResponse
Cancel subscription
Cancel subscription docs here.
CancelSubscriptionRequest
Possible answers: InvalidRequestResponse, SuccessResponse
Usage example without Laravel framework:
<?php use GuzzleHttp\Client as GuzzleHttpClient; use Korobovn\CloudPayments\Client\Client; use Korobovn\CloudPayments\Message\Request\CryptogramPaymentOneStepRequest; use Korobovn\CloudPayments\Message\Response\CryptogramTransactionAcceptedResponse; use Korobovn\CloudPayments\Message\Response\InvalidRequestResponse; $public_key = ''; $private_key = ''; $client = new Client( new GuzzleHttpClient(), $public_key, $private_key ); $request = CryptogramPaymentOneStepRequest::create(); $request ->getModel() ->setAmount(100.0) ->setCurrency('RUB') ->setIpAddress('127.0.0.1') ->setName('CARDHOLDER NAME') ->setCardCryptogramPacket('CARD_CRYPTOGRAM_PACKET'); $response = $request->setClient($client)->send(); if ($response instanceof CryptogramTransactionAcceptedResponse) { $transaction_id = $response->getModel()->getTransactionId(); } elseif ($response instanceof InvalidRequestResponse) { $error_message = $response->getMessage(); }
How to get CARD_CRYPTOGRAM_PACKET?
Testing
For package testing we use phpunit framework. Just write into your terminal:
$ git clone https://github.com/korobovn/CloudPayments.git ./CloudPayments && cd $_ $ make build $ make composer-install $ make unit-tests
Changes log
Changes log can be found here.
Support
If you will find any package errors, please, make an issue in current repository.
License
This is open-sourced software licensed under the MIT License.
korobovn/cloud-payments 适用场景与选型建议
korobovn/cloud-payments 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 9 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 11 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「cloud-payments」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 korobovn/cloud-payments 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 korobovn/cloud-payments 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 korobovn/cloud-payments 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
统计信息
- 总下载量: 9
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-11-18