Skip to content

Commit

Permalink
Change code style to PSR-12 and remove duplicated method
Browse files Browse the repository at this point in the history
  • Loading branch information
asrorbekh committed Jan 13, 2024
1 parent d4cc2b3 commit c2f6828
Showing 1 changed file with 96 additions and 53 deletions.
149 changes: 96 additions & 53 deletions src/Client/CloudPayments.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,12 @@ class CloudPayments
* @param string $apiUrl
* @param bool $enableSSL
*/
public function __construct(string $publicKey, string $apiSecret, string $apiUrl = self::CLOUD_PAYMENTS_RU_URL, bool $enableSSL = true)
{
public function __construct(
string $publicKey,
string $apiSecret,
string $apiUrl = self::CLOUD_PAYMENTS_RU_URL,
bool $enableSSL = true
) {
$this->httpClient = new HttpClient($publicKey, $apiSecret, $apiUrl, $enableSSL);
}

Expand Down Expand Up @@ -185,8 +189,8 @@ public function makeTokenPayment(array|object $tokenPaymentData, bool $requireCo
*
* @param string $transactionId
* @param string $paRes
* @link https://developers.cloudpayments.ru/en/#3-d-secure-processing
* @return object The response from the CloudPayments API.
* @link https://developers.cloudpayments.ru/en/#3-d-secure-processing
*/
public function complete3DSecurePayment(string $transactionId, string $paRes): object
{
Expand All @@ -203,8 +207,8 @@ public function complete3DSecurePayment(string $transactionId, string $paRes): o
*
* @param string $transactionId
* @param float $amount
* @link https://developers.cloudpayments.ru/en/#payment-by-a-token-recurring
* @return object
* @link https://developers.cloudpayments.ru/en/#payment-by-a-token-recurring
*/
public function confirmPayment(string $transactionId, float $amount): object
{
Expand All @@ -220,8 +224,8 @@ public function confirmPayment(string $transactionId, float $amount): object
* Void a payment with a specific transaction ID.
*
* @param string $transactionId
* @link https://developers.cloudpayments.ru/en/#payment-confirmation
* @return object
* @link https://developers.cloudpayments.ru/en/#payment-confirmation
*/
public function voidPayment(string $transactionId): object
{
Expand All @@ -237,8 +241,8 @@ public function voidPayment(string $transactionId): object
*
* @param string $transactionId
* @param float $amount
* @link https://developers.cloudpayments.ru/en/#refund
* @return object
* @link https://developers.cloudpayments.ru/en/#refund
*/
public function refundPayment(string $transactionId, float $amount): object
{
Expand Down Expand Up @@ -273,11 +277,18 @@ public function initiatePayout(array|object $payoutData): object
* @param string|null $payer
* @param string|null $receiver
* @param string|null $invoiceId
* @link https://developers.cloudpayments.ru/en/#payout-by-a-token
* @return object
* @link https://developers.cloudpayments.ru/en/#payout-by-a-token
*/
public function initiatePayoutByToken(string $token, float $amount, string $accountId, string $currency, ?string $payer = null, ?string $receiver = null, ?string $invoiceId = null): object
{
public function initiatePayoutByToken(
string $token,
float $amount,
string $accountId,
string $currency,
?string $payer = null,
?string $receiver = null,
?string $invoiceId = null
): object {
$endpoint = '/payments/token/topup';
$requestData = [
"Token" => $token,
Expand All @@ -295,8 +306,8 @@ public function initiatePayoutByToken(string $token, float $amount, string $acco
* Get details for a specific transaction.
*
* @param string $transactionId
* @link https://developers.cloudpayments.ru/en/#transaction-details
* @return object
* @link https://developers.cloudpayments.ru/en/#transaction-details
*/
public function getTransactionDetails(string $transactionId): object
{
Expand All @@ -311,8 +322,8 @@ public function getTransactionDetails(string $transactionId): object
* Check the status of a payment using the invoice ID.
*
* @param string $invoiceId
* @link https://developers.cloudpayments.ru/en/#payment-status-check
* @return object
* @link https://developers.cloudpayments.ru/en/#payment-status-check
*/
public function checkPaymentStatus(string $invoiceId): object
{
Expand All @@ -328,8 +339,8 @@ public function checkPaymentStatus(string $invoiceId): object
*
* @param string $date
* @param string $timeZone
* @link https://developers.cloudpayments.ru/en/#transaction-list
* @return object
* @link https://developers.cloudpayments.ru/en/#transaction-list
*/
public function getTransactionsForDay(string $date, string $timeZone = "UTC"): object
{
Expand All @@ -349,11 +360,16 @@ public function getTransactionsForDay(string $date, string $timeZone = "UTC"): o
* @param int $pageNumber
* @param string $timeZone
* @param array $statuses
* @link https://developers.cloudpayments.ru/en/#transaction-list
* @return object
* @link https://developers.cloudpayments.ru/en/#transaction-list
*/
public function getTransactionsForPeriod(string $startDate, string $endDate, int $pageNumber, string $timeZone = "UTC", array $statuses = []): object
{
public function getTransactionsForPeriod(
string $startDate,
string $endDate,
int $pageNumber,
string $timeZone = "UTC",
array $statuses = []
): object {
$endpoint = '/v2/payments/list';
$requestData = [
"CreatedDateGte" => $startDate,
Expand All @@ -369,8 +385,8 @@ public function getTransactionsForPeriod(string $startDate, string $endDate, int
* Get a list of payment tokens.
*
* @param int $pageNumber
* @link https://developers.cloudpayments.ru/en/#token-list
* @return object
* @link https://developers.cloudpayments.ru/en/#token-list
*/
public function getPaymentTokens(int $pageNumber): object
{
Expand All @@ -396,11 +412,23 @@ public function getPaymentTokens(int $pageNumber): object
* @param int $period
* @param int|null $maxPeriods
* @param string|null $customerReceipt
* @link https://developers.cloudpayments.ru/en/#creation-of-subscriptions-on-recurrent-payments
* @return object
* @link https://developers.cloudpayments.ru/en/#creation-of-subscriptions-on-recurrent-payments
*/
public function createSubscription(string $token, string $accountId, string $description, string $email, float $amount, string $currency, bool $requireConfirmation, string $startDate, string $interval, int $period, ?int $maxPeriods = null, ?string $customerReceipt = null): object
{
public function createSubscription(
string $token,
string $accountId,
string $description,
string $email,
float $amount,
string $currency,
bool $requireConfirmation,
string $startDate,
string $interval,
int $period,
?int $maxPeriods = null,
?string $customerReceipt = null
): object {
$endpoint = '/subscriptions/create';
$requestData = [
"Token" => $token,
Expand All @@ -423,8 +451,8 @@ public function createSubscription(string $token, string $accountId, string $des
* Get information about a subscription.
*
* @param string $subscriptionId
* @link https://developers.cloudpayments.ru/en/#subscription-details
* @return object
* @link https://developers.cloudpayments.ru/en/#subscription-details
*/
public function getSubscriptionInfo(string $subscriptionId): object
{
Expand All @@ -439,8 +467,8 @@ public function getSubscriptionInfo(string $subscriptionId): object
* Find subscriptions for a specific account ID.
*
* @param string $accountId
* @link https://developers.cloudpayments.ru/en/#subscriptions-search
* @return object
* @link https://developers.cloudpayments.ru/en/#subscriptions-search
*/
public function findSubscriptions(string $accountId): object
{
Expand All @@ -464,11 +492,21 @@ public function findSubscriptions(string $accountId): object
* @param int|null $period
* @param int|null $maxPeriods
* @param string|null $customerReceipt
* @link https://developers.cloudpayments.ru/en/#recurrent-payments-subscription-change
* @return object
* @link https://developers.cloudpayments.ru/en/#recurrent-payments-subscription-change
*/
public function updateSubscription(string $subscriptionId, ?string $description = null, ?float $amount = null, ?string $currency = null, ?bool $requireConfirmation = null, ?string $startDate = null, ?string $interval = null, ?int $period = null, ?int $maxPeriods = null, ?string $customerReceipt = null): object
{
public function updateSubscription(
string $subscriptionId,
?string $description = null,
?float $amount = null,
?string $currency = null,
?bool $requireConfirmation = null,
?string $startDate = null,
?string $interval = null,
?int $period = null,
?int $maxPeriods = null,
?string $customerReceipt = null
): object {
$endpoint = '/subscriptions/update';
$requestData = [
"Id" => $subscriptionId,
Expand All @@ -490,8 +528,8 @@ public function updateSubscription(string $subscriptionId, ?string $description
* Cancel a subscription.
*
* @param string $subscriptionId
* @link https://developers.cloudpayments.ru/en/#subscription-on-recurrent-payments-cancellation
* @return object
* @link https://developers.cloudpayments.ru/en/#subscription-on-recurrent-payments-cancellation
*/
public function cancelSubscription(string $subscriptionId): object
{
Expand Down Expand Up @@ -521,11 +559,27 @@ public function cancelSubscription(string $subscriptionId): object
* @param string|null $successRedirectUrl
* @param string|null $failRedirectUrl
* @param array|null $jsonData
* @link https://developers.cloudpayments.ru/en/#invoice-creation-on-email
* @return object
* @link https://developers.cloudpayments.ru/en/#invoice-creation-on-email
*/
public function createInvoice(float $amount, string $currency, string $description, string $email, bool $requireConfirmation, bool $sendEmail, ?string $invoiceId = null, ?string $accountId = null, ?string $offerUri = null, ?string $phone = null, ?bool $sendSms = null, ?bool $sendViber = null, ?string $subscriptionBehavior = null, ?string $successRedirectUrl = null, ?string $failRedirectUrl = null, ?array $jsonData = null): object
{
public function createInvoice(
float $amount,
string $currency,
string $description,
string $email,
bool $requireConfirmation,
bool $sendEmail,
?string $invoiceId = null,
?string $accountId = null,
?string $offerUri = null,
?string $phone = null,
?bool $sendSms = null,
?bool $sendViber = null,
?string $subscriptionBehavior = null,
?string $successRedirectUrl = null,
?string $failRedirectUrl = null,
?array $jsonData = null
): object {
$endpoint = '/orders/create';
$requestData = [
"Amount" => $amount,
Expand Down Expand Up @@ -553,8 +607,8 @@ public function createInvoice(float $amount, string $currency, string $descripti
* Cancel an order for a one-time payment.
*
* @param string $orderId
* @link https://developers.cloudpayments.ru/en/#created-invoice-cancellation
* @return object
* @link https://developers.cloudpayments.ru/en/#created-invoice-cancellation
*/
public function cancelOrder(string $orderId): object
{
Expand All @@ -569,8 +623,8 @@ public function cancelOrder(string $orderId): object
* View notification settings for a specific notification type.
*
* @param string $notificationType
* @link https://developers.cloudpayments.ru/en/#view-of-notification-settings
* @return object
* @link https://developers.cloudpayments.ru/en/#view-of-notification-settings
*/
public function viewNotificationSettings(string $notificationType): object
{
Expand All @@ -590,11 +644,17 @@ public function viewNotificationSettings(string $notificationType): object
* @param string|null $httpMethod HTTP method for the notification.
* @param string|null $encoding Encoding for the notification.
* @param string|null $format Format of the notification.
* @link https://developers.cloudpayments.ru/en/#change-of-notification-settings
* @return object Response from the CloudPayments API.
* @link https://developers.cloudpayments.ru/en/#change-of-notification-settings
*/
public function updateNotificationSettings(string $notificationType, bool $isEnabled = null, string $address = null, string $httpMethod = null, string $encoding = null, string $format = null): object
{
public function updateNotificationSettings(
string $notificationType,
bool $isEnabled = null,
string $address = null,
string $httpMethod = null,
string $encoding = null,
string $format = null
): object {
$endpoint = "/site/notifications/$notificationType/update";
$requestData = [
"Type" => $notificationType,
Expand All @@ -612,8 +672,8 @@ public function updateNotificationSettings(string $notificationType, bool $isEna
*
* @param string $validationUrl Validation URL for Apple Pay.
* @param string|null $paymentUrl Payment URL for Apple Pay.
* @link https://developers.cloudpayments.ru/en/#start-of-apple-pay-session
* @return object Response from the CloudPayments API.
* @link https://developers.cloudpayments.ru/en/#start-of-apple-pay-session
*/
public function startApplePaySession(string $validationUrl, string|null $paymentUrl = null): object
{
Expand All @@ -629,8 +689,8 @@ public function startApplePaySession(string $validationUrl, string|null $payment
* Sets the localization for the API requests.
*
* @param string $cultureName The culture name for localization.
* @link https://developers.cloudpayments.ru/en/#localization
* @return void
* @link https://developers.cloudpayments.ru/en/#localization
*/
public function setLocalization(string $cultureName): void
{
Expand All @@ -656,21 +716,4 @@ public function createLongRecord(string $ticketNumber, string $bookingRef, array
"Passengers" => $passengers,
];
}

/**
* Cancels a payment transaction.
*
* @param string $transactionId Transaction ID to cancel.
* @link https://developers.cloudpayments.ru/en/#payment-cancellation
* @return object Response from the CloudPayments API.
*/
public function cancelPayment(string $transactionId): object
{
$endpoint = '/payments/void';
$requestData = [
"TransactionId" => $transactionId,
];

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

0 comments on commit c2f6828

Please sign in to comment.