diff --git a/src/Client/AbstractCloudPayments.php b/src/Client/AbstractCloudPayments.php new file mode 100644 index 0000000..aa0a5e5 --- /dev/null +++ b/src/Client/AbstractCloudPayments.php @@ -0,0 +1,109 @@ +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); + } +} diff --git a/src/Client/CloudKassir.php b/src/Client/CloudKassir.php new file mode 100644 index 0000000..08d7e78 --- /dev/null +++ b/src/Client/CloudKassir.php @@ -0,0 +1,106 @@ +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); + } +} diff --git a/src/Client/CloudPayments.php b/src/Client/CloudPayments.php index 2f7cb22..6f45d88 100644 --- a/src/Client/CloudPayments.php +++ b/src/Client/CloudPayments.php @@ -4,14 +4,12 @@ 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 @@ -19,96 +17,9 @@ * @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. * diff --git a/src/Util/CloudKassirErrorCode.php b/src/Util/CloudKassirErrorCode.php new file mode 100644 index 0000000..aad6444 --- /dev/null +++ b/src/Util/CloudKassirErrorCode.php @@ -0,0 +1,49 @@ +