Skip to content

Commit

Permalink
Added CloudKassir class and updated access modifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
asrorbekh committed Jan 23, 2024
1 parent d7ffddb commit c1664ca
Show file tree
Hide file tree
Showing 4 changed files with 265 additions and 90 deletions.
109 changes: 109 additions & 0 deletions src/Client/AbstractCloudPayments.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?php

declare(strict_types=1);

namespace CloudPaymentsSDK\Client;

use CloudPaymentsSDK\Http\HttpClient;
use CloudPaymentsSDK\Util\Localization;

/**
* Class AbstractCloudPayments
* @package CloudPaymentsSDK\Client
*/
abstract class AbstractCloudPayments
{
/**
* Base url of cloud payments UZ domain
* @const string
*/
public const CLOUD_PAYMENTS_UZ_URL = 'https://api.cloudpayments.uz';

/**
* Base url of cloud payments EU domain
* @const string
*/
public const CLOUD_PAYMENTS_EU_URL = 'https://api.cloudpayments.eu';

/**
* Base url of cloud payments RU domain
* @const string
* @default Url of this SDK
*/
public const CLOUD_PAYMENTS_RU_URL = 'https://api.cloudpayments.ru';

/**
* Test method constant.
* @const string
*/
protected const METHOD_TEST = '/test';

/**
* Capture automatic URL for onetime payment.
* @const string
*/
protected const CHARGE_CARD = '/payments/cards/charge';

/**
* Capture manual URL for onetime payment.
* @const string
*/
protected const AUTH_CARD = '/payments/cards/auth';

/**
* Post 3D secure
* @const string
*/
protected const POST3D_SECURE = '/payments/cards/post3ds';

/**
* Capture automatic URL for token payment (recurring).
* @const string
*/
protected const CHARGE_TOKEN = '/payments/tokens/charge';

/**
* Capture manual URL for token payment (recurring).
* @const string
*/
protected const AUTH_TOKEN = '/payments/tokens/auth';

/**
* @var string $cultureName
* @default en-US
*/
protected string $cultureName = Localization::ENGLISH;

/**
* @var HttpClient $httpClient
*/
protected HttpClient $httpClient;

/**
* CloudPayments constructor.
*
* @param string $publicKey
* @param string $apiSecret
* @param string $apiUrl
* @param bool $enableSSL
*/
public function __construct(
string $publicKey,
string $apiSecret,
string $apiUrl = self::CLOUD_PAYMENTS_RU_URL,
bool $enableSSL = false
) {
$this->httpClient = new HttpClient($publicKey, $apiSecret, $apiUrl, $enableSSL);
}

/**
* Make a test request
*
* @param array|object $data
* @return object
*/
public function sendTestRequest(array|object $data): object
{
return $this->httpClient->sendRequest(self::METHOD_TEST, $data);
}
}
106 changes: 106 additions & 0 deletions src/Client/CloudKassir.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php

declare(strict_types=1);

namespace CloudPaymentsSDK\Client;

use CloudPaymentsSDK\Http\Response;

/**
* Class CloudKassir
* @package CloudPaymentsSDK\Client
*/
class CloudKassir extends AbstractCloudPayments
{
/**
* Fiscalize a cash register.
*
* @param array|object $fiscalizeData
* @return object
* @link https://developers.cloudkassir.ru/en/#register-fiscalization
*/
public function fiscalizeCashRegister(array|object $fiscalizeData): object
{
$endpoint = '/kkt/fiscalize';
return $this->httpClient->sendRequest($endpoint, $fiscalizeData);
}

/**
* Form a cash receipt.
*
* @param array|object $receiptData
* @return Response
* @link https://developers.cloudkassir.ru/en/#online-receipt-generation
*/
public function formCashReceipt(array|object $receiptData): Response
{
$endpoint = '/kkt/receipt';

return $this->httpClient->sendRequest($endpoint, $receiptData);
}

/**
* Get receipt status.
*
* @param array|object $statusData
* @return Response
* @link https://developers.cloudkassir.ru/en/#receipt-status-request
*/
public function getReceiptStatus(array|object $statusData): Response
{
$endpoint = '/kkt/receipt/status/get';
return $this->httpClient->sendRequest($endpoint, $statusData);
}

/**
* Get receipt details.
*
* @param array|object $detailsData
* @return Response
* @link https://developers.cloudkassir.ru/en/#receipt-details-request
*/
public function getReceiptDetails(array|object $detailsData): Response
{
$endpoint = '/kkt/receipt/get';
return $this->httpClient->sendRequest($endpoint, $detailsData);
}

/**
* Form a correction receipt.
*
* @param array|object $correctionData
* @return Response
* @link https://developers.cloudkassir.ru/#formirovanie-cheka-korrektsii
*/
public function formCorrectionReceipt(array|object $correctionData): Response
{
$endpoint = '/kkt/correction-receipt';
return $this->httpClient->sendRequest($endpoint, $correctionData);
}

/**
* Manage cash register state.
*
* @param array|object $stateData
* @return Response
* @link https://developers.cloudkassir.ru/en/#cash-register-state-change
*/
public function manageCashRegisterState(array|object $stateData): Response
{
$endpoint = '/kkt/state';
return $this->httpClient->sendRequest($endpoint, $stateData);
}

/**
* Get cash register data.
*
* @param array|object $requestData
* @return Response
* @link https://developers.cloudkassir.ru/en/#receiving-cash-register-data
*/
public function getCashRegisterData(array|object $requestData): Response
{
$endpoint = '/kkt/state/get';
return $this->httpClient->sendRequest($endpoint, $requestData);
}
}
91 changes: 1 addition & 90 deletions src/Client/CloudPayments.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,111 +4,22 @@

namespace CloudPaymentsSDK\Client;

use CloudPaymentsSDK\Http\HttpClient;
use CloudPaymentsSDK\Http\Response;
use CloudPaymentsSDK\Model\Cards\CardsModelResponse;
use CloudPaymentsSDK\Model\Cards\CardsResponse;
use CloudPaymentsSDK\Model\Cards\Confirm3DResponse;
use CloudPaymentsSDK\Model\Tokens\TokensModelResponse;
use CloudPaymentsSDK\Model\Tokens\TokensResponse;
use CloudPaymentsSDK\Util\Localization;

/**
* Class CloudPayments
* @author Asrorbek Sultanov asrorbek@asrorbek.uz
* @link https://developers.cloudpayments.ru/en/
* @package CloudPaymentsSDK\Client
*/
class CloudPayments
class CloudPayments extends AbstractCloudPayments
{

/**
* Base url of cloud payments UZ domain
* @const string
*/
public const CLOUD_PAYMENTS_UZ_URL = 'https://api.cloudpayments.uz';

/**
* Base url of cloud payments RU domain
* @const string
*/
public const CLOUD_PAYMENTS_RU_URL = 'https://api.cloudpayments.ru';

/**
* Test method constant.
* @const string
*/
private const METHOD_TEST = '/test';

/**
* Capture automatic URL for onetime payment.
* @const string
*/
private const CHARGE_CARD = '/payments/cards/charge';

/**
* Capture manual URL for onetime payment.
* @const string
*/
private const AUTH_CARD = '/payments/cards/auth';

/**
* Post 3D secure
* @const string
*/
private const POST3D_SECURE = '/payments/cards/post3ds';

/**
* Capture automatic URL for token payment (recurring).
* @const string
*/
private const CHARGE_TOKEN = '/payments/tokens/charge';

/**
* Capture manual URL for token payment (recurring).
* @const string
*/
private const AUTH_TOKEN = '/payments/tokens/auth';

/**
* @var string $cultureName
* @default en-US
*/
private string $cultureName = Localization::ENGLISH;

/**
* @var HttpClient $httpClient
*/
private HttpClient $httpClient;

/**
* CloudPayments constructor.
*
* @param string $publicKey
* @param string $apiSecret
* @param string $apiUrl
* @param bool $enableSSL
*/
public function __construct(
string $publicKey,
string $apiSecret,
string $apiUrl = self::CLOUD_PAYMENTS_RU_URL,
bool $enableSSL = false
) {
$this->httpClient = new HttpClient($publicKey, $apiSecret, $apiUrl, $enableSSL);
}

/**
* Make a test request
*
* @param array|object $data
* @return object
*/
public function sendTestRequest(array|object $data): object
{
return $this->httpClient->sendRequest(self::METHOD_TEST, $data);
}

/**
* Make a payment using card details.
*
Expand Down
49 changes: 49 additions & 0 deletions src/Util/CloudKassirErrorCode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

declare(strict_types=1);

namespace CloudPaymentsSDK\Util;

/**
* Class CloudKassirErrorCode
*
* This class defines error codes and their descriptions for CloudKassir.
*
* @package CloudPaymentsSDK\Util
* @link [CloudKassir Error Codes](#) // Insert link when available
*/
class CloudKassirErrorCode
{
// Error Codes
public const UNKNOWN_ERROR = -1;
public const MISSING_KKT = 2;
public const TAX_SYSTEM_NOT_SET = 3;
public const MISSING_AGENT_DATA = 4;
public const MISSING_SUPPLIER_INN_OR_PHONE = 5;
public const AGENT_PAYMENT_NOT_ALLOWED = 6;
public const INVALID_SUPPLIER_INN_FORMAT = 7;
public const DOCUMENT_STORAGE_EXHAUSTED = 8;
public const AGENT_DATA_ERROR = 9;
public const UNENCRYPTED_PERSONAL_DATA = 10;
public const MISSING_INN = 11;
public const MISSING_ITEMS_INFORMATION = 12;
public const PAYMENT_AMOUNT_LESS_THAN_TOTAL = 13;
public const NON_CASH_PAYMENT_GREATER_THAN_TOTAL = 14;
public const NO_SUITABLE_KKT = 15;
public const NO_KKT_WITH_MATCHING_TERMINAL = 16;
public const NO_KKT_WITH_BSO_ATTRIBUTE = 17;
public const NO_KKT_WITHOUT_BSO_ATTRIBUTE = 18;
public const NO_KKT_SUPPORTING_CASH_PAYMENT = 19;
public const NO_KKT_WITH_AGENT_ATTRIBUTE = 20;
public const NO_KKT_WITH_ADDITIONAL_USER_ATTRIBUTE = 21;
public const TEST_CHECK_LIMIT_EXCEEDED = 22;
public const INVALID_PRICE_FORMAT = 23;
public const INVALID_EMAIL_FORMAT = 24;

// Warning Codes
public const CRYPTO_PROCESSOR_ERROR = 1;
public const FISCAL_STORAGE_EXPIRED = 2;
public const OFD_SEND_QUEUE_OVERFLOW = 3;
public const FISCAL_STORAGE_BUFFER_OVERFLOW = 4;
public const CASHIER_ERROR = 5;
}

0 comments on commit c1664ca

Please sign in to comment.