korobovn / cloud-payments
Cloud Payments PHP-client
Requires
- php: ^7.1.3
- ext-json: *
- guzzlehttp/guzzle: ~6.0
- illuminate/support: ^5.5 || ^6.0
- psr/http-client: ~1.0
- tarampampam/wrappers-php: ^1.2
Requires (Dev)
- fzaninotto/faker: ^1.9
- laravel/laravel: ^5.5 || ^6.0
- phpstan/phpstan: ^0.11.19
- phpunit/phpunit: ~7.5 || ^8
This package is auto-updated.
Last update: 2025-04-29 01:21:09 UTC
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
composer
is 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.