PHP code example of korobovn / cloud-payments

1. Go to this page and download the library: Download korobovn/cloud-payments 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/ */

    

korobovn / cloud-payments example snippets


'providers' => [
    // ...
    Korobovn\CloudPayments\CloudPaymentsServiceProvider::class,
]

$client = $this->app->make(Korobovn\CloudPayments\Client\ClientInterface::class);

$client->send($request);

$request->setClient($client)->send();



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();



use Korobovn\CloudPayments\Message\Response\CryptogramTransactionAcceptedResponse;

if ($response instanceof CryptogramTransactionAcceptedResponse) {
    $transaction_id = $response->getModel()->getTransactionId();
    $status_code = $response->getModel()->getStatusCode();
    $token = $response->getModel()->getToken();
}



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();
}