diff --git a/rbkmoney-payment.php b/rbkmoney-payment.php index 421e71e..57dc3af 100644 --- a/rbkmoney-payment.php +++ b/rbkmoney-payment.php @@ -72,13 +72,17 @@ function gateway_rbkmoney_payment($separator, $sessionid) try { $rbk_api = new RBKmoneyPayment($params); - $invoice_id = $rbk_api->create_invoice(); - $invoice_access_token = $rbk_api->create_access_token($invoice_id); + $response = $rbk_api->create_invoice(); + $response_decode = json_decode($response['body'], true); + $invoice_id = !empty($response_decode['invoice']['id']) ? $response_decode['invoice']['id'] : ''; + $invoice_access_token = !empty($response_decode['invoiceAccessToken']['payload']) ? $response_decode['invoiceAccessToken']['payload'] : ''; } catch (Exception $ex) { echo $ex->getMessage(); exit(); } + + $output = ' @@ -90,18 +94,17 @@ function gateway_rbkmoney_payment($separator, $sessionid) data-invoice-id="' . $invoice_id . '" data-invoice-access-token="' . $invoice_access_token . '" ' . $company_name . ' - ' . $company_logo . ' ' . $button_label . ' ' . $description . ' > '; - echo $output; exit(); } + /** * e.g. http{s}://{your-site}/?rbkmoney_payment_callback */ @@ -158,7 +161,7 @@ function nzshpcrt_rbkmoney_payment_callback() } } - $current_shop_id = (int)trim(get_option('rbkmoney_payment_shop_id')); + $current_shop_id = trim(get_option('rbkmoney_payment_shop_id')); if ($current_shop_id != $data[$invoice][RBKmoneyPayment::SHOP_ID]) { _rbkmoney_payment_response_with_code_and_message( RBKmoneyPayment::HTTP_CODE_BAD_REQUEST, @@ -337,14 +340,7 @@ function form_rbkmoney_payment()

- - " . __('Logo in payment form', 'wp-e-commerce') . " - - -

- " . __('Your logo for payment form', 'wp-e-commerce') . " -

- + " . __('Company name in payment form', 'wp-e-commerce') . " diff --git a/rbkmoney-payment/RBKmoneyPayment.php b/rbkmoney-payment/RBKmoneyPayment.php index 2a15f44..bef9e5f 100644 --- a/rbkmoney-payment/RBKmoneyPayment.php +++ b/rbkmoney-payment/RBKmoneyPayment.php @@ -33,7 +33,7 @@ class RBKmoneyPayment const SESSION_ID = 'session_id'; const EVENT_TYPE = 'event_type'; - private $api_url = 'https://api.rbk.money/v1/'; + private $api_url = 'https://api.rbk.money/v2/'; private $merchant_private_key = ''; private $shop_id = ''; @@ -254,7 +254,7 @@ class RBKmoneyPayment ]); $data = [ - 'shopID' => (int)$this->getShopId(), + 'shopID' => $this->getShopId(), 'amount' => (int)$this->getAmount(), 'metadata' => $this->prepare_metadata($this->getOrderId(), $this->getSessionId()), 'dueDate' => $this->prepare_due_date(), @@ -263,15 +263,19 @@ class RBKmoneyPayment 'description' => $this->getDescription(), ]; + $this->validate(); $url = $this->prepare_api_url('processing/invoices'); $headers = $this->headers(); $response = $this->send($url, static::HTTP_METHOD_POST, $headers, json_encode($data, true)); $response_decode = json_decode($response['body'], true); - $invoice_id = !empty($response_decode['id']) ? $response_decode['id'] : ''; - return $invoice_id; + $invoice_id = !empty($response_decode['invoice']['id']) ? $response_decode['invoice']['id'] : ''; + $access_token = !empty($response_decode['invoiceAccessToken']['payload']) ? $response_decode['invoiceAccessToken']['payload'] : ''; + return $response; } + + private function headers() { $headers = []; $headers[] = 'X-Request-ID: ' . uniqid(); @@ -281,24 +285,7 @@ class RBKmoneyPayment return $headers; } - public function create_access_token($invoice_id) - { - if (empty($invoice_id)) { - throw new Exception('Не передан обязательный параметр invoice_id'); - } - - $url = $this->prepare_api_url('processing/invoices/' . $invoice_id . '/access_tokens'); - $headers = $this->headers(); - $response = $this->send($url, static::HTTP_METHOD_POST, $headers); - - if ($response['http_code'] != static::HTTP_CODE_CREATED) { - throw new Exception('Возникла ошибка при создании токена для инвойса'); - } - $response_decode = json_decode($response['body'], true); - $access_token = !empty($response_decode['payload']) ? $response_decode['payload'] : ''; - return $access_token; - } - + private function send($url, $method, $headers = [], $data = '') { if (empty($url)) { diff --git a/rbkmoney-payment/images/rbkmoney_payment.png b/rbkmoney-payment/images/rbkmoney_payment.png index b67e4fd..7096310 100644 Binary files a/rbkmoney-payment/images/rbkmoney_payment.png and b/rbkmoney-payment/images/rbkmoney_payment.png differ