Changeset 3047124
- Timestamp:
- 03/07/2024 01:18:17 PM (2 years ago)
- Location:
- mono-checkout
- Files:
-
- 4 edited
- 22 copied
-
tags/1.8.1 (copied) (copied from mono-checkout/trunk)
-
tags/1.8.1/css (copied) (copied from mono-checkout/trunk/css)
-
tags/1.8.1/css/admin-method.css (copied) (copied from mono-checkout/trunk/css/admin-method.css)
-
tags/1.8.1/css/mono-admin.css (copied) (copied from mono-checkout/trunk/css/mono-admin.css)
-
tags/1.8.1/css/mono-btn.css (copied) (copied from mono-checkout/trunk/css/mono-btn.css)
-
tags/1.8.1/images (copied) (copied from mono-checkout/trunk/images)
-
tags/1.8.1/includes (copied) (copied from mono-checkout/trunk/includes)
-
tags/1.8.1/includes/MonoApi.php (copied) (copied from mono-checkout/trunk/includes/MonoApi.php) (2 diffs)
-
tags/1.8.1/includes/class.gateway.php (copied) (copied from mono-checkout/trunk/includes/class.gateway.php) (4 diffs)
-
tags/1.8.1/includes/class.mono.php (copied) (copied from mono-checkout/trunk/includes/class.mono.php)
-
tags/1.8.1/js (copied) (copied from mono-checkout/trunk/js)
-
tags/1.8.1/js/admin-handlers.js (copied) (copied from mono-checkout/trunk/js/admin-handlers.js)
-
tags/1.8.1/js/frontend-handlers.js (copied) (copied from mono-checkout/trunk/js/frontend-handlers.js)
-
tags/1.8.1/languages (copied) (copied from mono-checkout/trunk/languages)
-
tags/1.8.1/languages/mono-checkout-uk.mo (copied) (copied from mono-checkout/trunk/languages/mono-checkout-uk.mo)
-
tags/1.8.1/languages/mono-checkout-uk.po (copied) (copied from mono-checkout/trunk/languages/mono-checkout-uk.po)
-
tags/1.8.1/languages/mono-checkout.pot (copied) (copied from mono-checkout/trunk/languages/mono-checkout.pot)
-
tags/1.8.1/mono.php (copied) (copied from mono-checkout/trunk/mono.php) (1 diff)
-
tags/1.8.1/readme.txt (copied) (copied from mono-checkout/trunk/readme.txt) (3 diffs)
-
tags/1.8.1/templates (copied) (copied from mono-checkout/trunk/templates)
-
tags/1.8.1/templates/base_button.php (copied) (copied from mono-checkout/trunk/templates/base_button.php)
-
tags/1.8.1/templates/button_error.php (copied) (copied from mono-checkout/trunk/templates/button_error.php)
-
trunk/includes/MonoApi.php (modified) (2 diffs)
-
trunk/includes/class.gateway.php (modified) (4 diffs)
-
trunk/mono.php (modified) (1 diff)
-
trunk/readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
mono-checkout/tags/1.8.1/includes/MonoApi.php
r3045127 r3047124 9 9 public $last_raw_response; 10 10 public $last_error; 11 public $pub_key; 11 12 12 public function __construct($token, $url) { 13 $this->token = $token; 14 $this->url = $url; 13 public static function fetch_pub_key( $token, $url ) { 14 $pub_key_url = str_replace('personal/checkout/order/', 'personal/checkout/signature/public/key', $url); 15 $r = json_decode(self::send_request( $pub_key_url, 'GET', $token ), true); 16 if ($r) { return $r['key']; } 17 return null; 15 18 } 16 19 17 public function create_order( $request ) { 18 return $this->do_request( $this->url, 'POST', wp_json_encode($request) ); 19 } 20 21 public function update_order( $mono_order_id ) { 22 return $this->do_request( $this->url . '/' . $mono_order_id ); 23 } 24 25 protected function do_request( $url, $method = 'GET', $postdata = null ) { 20 protected static function send_request( $url, $method, $token, $postdata = null ) { 26 21 $headers = [ 27 22 'Content-Type: application/json', 28 'X-Token: ' . $t his->token,23 'X-Token: ' . $token, 29 24 ]; 30 25 if (extension_loaded("curl")) { … … 57 52 $resultRaw = file_get_contents($url, false, $context); 58 53 } 54 return $resultRaw; 55 } 56 57 public function __construct($token, $url, $pub_key) { 58 $this->token = $token; 59 $this->url = $url; 60 $this->pub_key = $pub_key; 61 } 62 63 public function create_order( $request ) { 64 return $this->do_request( $this->url, 'POST', wp_json_encode($request) ); 65 } 66 67 public function update_order( $mono_order_id ) { 68 return $this->do_request( $this->url . '/' . $mono_order_id ); 69 } 70 71 public function validate_webhook( $xSignHeader, $data ) { 72 $pubKeyBase64 = $this->pub_key; 73 74 // value from X-Sign header in webhook request 75 $xSignBase64 = $xSignHeader; 76 77 $message = $data; 78 $signature = base64_decode($xSignBase64); 79 $publicKey = openssl_get_publickey(base64_decode($pubKeyBase64)); 80 81 $result = openssl_verify($message, $signature, $publicKey, OPENSSL_ALGO_SHA256); 82 83 return $result === 1; 84 } 85 86 protected function do_request( $url, $method = 'GET', $postdata = null ) { 87 $resultRaw = self::send_request( $url, $method, $this->token, $postdata ); 59 88 $this->last_raw_response = $resultRaw; 60 89 $result = rest_sanitize_object(json_decode($resultRaw, true)); -
mono-checkout/tags/1.8.1/includes/class.gateway.php
r3045127 r3047124 5 5 class Mono_Gateway extends \WC_Payment_Gateway { 6 6 7 /** 8 * @var MonoApi 9 */ 7 10 public $api; 8 11 … … 717 720 $url = $this->get_option( 'base_url' ); 718 721 $token = $this->get_option( 'token' ); 719 $this->api = new MonoApi( $token, $url ); 722 $pub_key = $this->get_option( 'pub_key' ); 723 if (!$pub_key) { 724 $pub_key = MonoApi::fetch_pub_key( $token, $url ); 725 if ($pub_key) { 726 $this->update_option( 'pub_key', $pub_key ); 727 } 728 } 729 $this->api = new MonoApi( $token, $url, $pub_key ); 720 730 } 721 731 return $this->api; … … 725 735 { 726 736 $json = file_get_contents('php://input'); 737 if (!$this->get_api()->validate_webhook( @$_SERVER['HTTP_X_SIGN'], $json )) { // incorrect signature 738 http_response_code(400); 739 wp_die('', '', 400); 740 } 741 727 742 $data = rest_sanitize_object(json_decode($json, true)); 728 743 if ($data) { … … 734 749 /** @var \WC_Cart $cart */ 735 750 $cart = $session['cart']; 736 if ($cart ) {751 if ($cart and is_object($cart)) { 737 752 $cart->empty_cart(); 738 753 } -
mono-checkout/tags/1.8.1/mono.php
r3045127 r3047124 7 7 Plugin URI: https://checkout.mono.bank/woocomerce 8 8 Description: модуль Чекауту від monobank це спосіб автоматизувати процес оформлення покупки на вашому сайті. Доступний функціонал: предзаповнення даних отримувача, рекомендації по доставці та оплаті, всі доступні способи оплати від monobank: еквайринг, Покупка частинами та оплата при отриманні. Має бути підключений інтернет-еквайринг від monobank 9 Version: 1.8. 09 Version: 1.8.1 10 10 Requires at least: 5.8 11 11 Requires PHP: 7.4 -
mono-checkout/tags/1.8.1/readme.txt
r3045127 r3047124 4 4 Requires at least: 5.8 5 5 Tested up to: 6.4 6 Stable tag: 1.8. 06 Stable tag: 1.8.1 7 7 Requires PHP: 7.4 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html 10 10 11 модуль Чекауту від monobank це спосіб автоматизувати процес оформлення покупки на вашому сайті11 Модуль Чекауту від monobank це спосіб автоматизувати процес оформлення покупки на вашому сайті 12 12 13 13 == Description == 14 14 15 модуль Чекауту від monobank це спосіб автоматизувати процес оформлення покупки на вашому сайті. Доступний функціонал: предзаповнення даних отримувача, рекомендації по доставці та оплаті, всі доступні способи оплати від monobank: еквайринг, Покупка частинами та оплата при отриманні. Має бути підключений інтернет-еквайринг від monobank.15 Модуль Чекауту від monobank це спосіб автоматизувати процес оформлення покупки на вашому сайті. Доступний функціонал: предзаповнення даних отримувача, рекомендації по доставці та оплаті, всі доступні способи оплати від monobank: еквайринг, Покупка частинами та оплата при отриманні. Має бути підключений інтернет-еквайринг від monobank. 16 16 17 Даний модуль використовує сервіс чекауту monobank для отримання платежів за замовлення. Детальніше про сервіс можна подивитись за посиланням https://api.monobank.ua/. Умови використання - https://www.monobank.ua/terms17 Даний модуль використовує сервіс чекауту monobank для отримання платежів за замовлення. Детальніше про сервіс можна подивитись за [посиланням](https://api.monobank.ua/). Умови використання - [https://www.monobank.ua/terms](https://www.monobank.ua/terms) 18 18 19 19 Що робить цей плагін: … … 39 39 = Де взяти токен? = 40 40 41 В web-кабінеті https://web.monobank.ua/, в налаштуваннях інтернет-еквайрингу.41 В web-кабінеті [https://web.monobank.ua/](https://web.monobank.ua/), в налаштуваннях інтернет-еквайрингу. 42 42 43 43 == Screenshots == … … 49 49 50 50 == Changelog == 51 52 = 1.8.1 = 53 * Покращення безпеки 51 54 52 55 = 1.8.0 = -
mono-checkout/trunk/includes/MonoApi.php
r3045127 r3047124 9 9 public $last_raw_response; 10 10 public $last_error; 11 public $pub_key; 11 12 12 public function __construct($token, $url) { 13 $this->token = $token; 14 $this->url = $url; 13 public static function fetch_pub_key( $token, $url ) { 14 $pub_key_url = str_replace('personal/checkout/order/', 'personal/checkout/signature/public/key', $url); 15 $r = json_decode(self::send_request( $pub_key_url, 'GET', $token ), true); 16 if ($r) { return $r['key']; } 17 return null; 15 18 } 16 19 17 public function create_order( $request ) { 18 return $this->do_request( $this->url, 'POST', wp_json_encode($request) ); 19 } 20 21 public function update_order( $mono_order_id ) { 22 return $this->do_request( $this->url . '/' . $mono_order_id ); 23 } 24 25 protected function do_request( $url, $method = 'GET', $postdata = null ) { 20 protected static function send_request( $url, $method, $token, $postdata = null ) { 26 21 $headers = [ 27 22 'Content-Type: application/json', 28 'X-Token: ' . $t his->token,23 'X-Token: ' . $token, 29 24 ]; 30 25 if (extension_loaded("curl")) { … … 57 52 $resultRaw = file_get_contents($url, false, $context); 58 53 } 54 return $resultRaw; 55 } 56 57 public function __construct($token, $url, $pub_key) { 58 $this->token = $token; 59 $this->url = $url; 60 $this->pub_key = $pub_key; 61 } 62 63 public function create_order( $request ) { 64 return $this->do_request( $this->url, 'POST', wp_json_encode($request) ); 65 } 66 67 public function update_order( $mono_order_id ) { 68 return $this->do_request( $this->url . '/' . $mono_order_id ); 69 } 70 71 public function validate_webhook( $xSignHeader, $data ) { 72 $pubKeyBase64 = $this->pub_key; 73 74 // value from X-Sign header in webhook request 75 $xSignBase64 = $xSignHeader; 76 77 $message = $data; 78 $signature = base64_decode($xSignBase64); 79 $publicKey = openssl_get_publickey(base64_decode($pubKeyBase64)); 80 81 $result = openssl_verify($message, $signature, $publicKey, OPENSSL_ALGO_SHA256); 82 83 return $result === 1; 84 } 85 86 protected function do_request( $url, $method = 'GET', $postdata = null ) { 87 $resultRaw = self::send_request( $url, $method, $this->token, $postdata ); 59 88 $this->last_raw_response = $resultRaw; 60 89 $result = rest_sanitize_object(json_decode($resultRaw, true)); -
mono-checkout/trunk/includes/class.gateway.php
r3045127 r3047124 5 5 class Mono_Gateway extends \WC_Payment_Gateway { 6 6 7 /** 8 * @var MonoApi 9 */ 7 10 public $api; 8 11 … … 717 720 $url = $this->get_option( 'base_url' ); 718 721 $token = $this->get_option( 'token' ); 719 $this->api = new MonoApi( $token, $url ); 722 $pub_key = $this->get_option( 'pub_key' ); 723 if (!$pub_key) { 724 $pub_key = MonoApi::fetch_pub_key( $token, $url ); 725 if ($pub_key) { 726 $this->update_option( 'pub_key', $pub_key ); 727 } 728 } 729 $this->api = new MonoApi( $token, $url, $pub_key ); 720 730 } 721 731 return $this->api; … … 725 735 { 726 736 $json = file_get_contents('php://input'); 737 if (!$this->get_api()->validate_webhook( @$_SERVER['HTTP_X_SIGN'], $json )) { // incorrect signature 738 http_response_code(400); 739 wp_die('', '', 400); 740 } 741 727 742 $data = rest_sanitize_object(json_decode($json, true)); 728 743 if ($data) { … … 734 749 /** @var \WC_Cart $cart */ 735 750 $cart = $session['cart']; 736 if ($cart ) {751 if ($cart and is_object($cart)) { 737 752 $cart->empty_cart(); 738 753 } -
mono-checkout/trunk/mono.php
r3045127 r3047124 7 7 Plugin URI: https://checkout.mono.bank/woocomerce 8 8 Description: модуль Чекауту від monobank це спосіб автоматизувати процес оформлення покупки на вашому сайті. Доступний функціонал: предзаповнення даних отримувача, рекомендації по доставці та оплаті, всі доступні способи оплати від monobank: еквайринг, Покупка частинами та оплата при отриманні. Має бути підключений інтернет-еквайринг від monobank 9 Version: 1.8. 09 Version: 1.8.1 10 10 Requires at least: 5.8 11 11 Requires PHP: 7.4 -
mono-checkout/trunk/readme.txt
r3045127 r3047124 4 4 Requires at least: 5.8 5 5 Tested up to: 6.4 6 Stable tag: 1.8. 06 Stable tag: 1.8.1 7 7 Requires PHP: 7.4 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html 10 10 11 модуль Чекауту від monobank це спосіб автоматизувати процес оформлення покупки на вашому сайті11 Модуль Чекауту від monobank це спосіб автоматизувати процес оформлення покупки на вашому сайті 12 12 13 13 == Description == 14 14 15 модуль Чекауту від monobank це спосіб автоматизувати процес оформлення покупки на вашому сайті. Доступний функціонал: предзаповнення даних отримувача, рекомендації по доставці та оплаті, всі доступні способи оплати від monobank: еквайринг, Покупка частинами та оплата при отриманні. Має бути підключений інтернет-еквайринг від monobank.15 Модуль Чекауту від monobank це спосіб автоматизувати процес оформлення покупки на вашому сайті. Доступний функціонал: предзаповнення даних отримувача, рекомендації по доставці та оплаті, всі доступні способи оплати від monobank: еквайринг, Покупка частинами та оплата при отриманні. Має бути підключений інтернет-еквайринг від monobank. 16 16 17 Даний модуль використовує сервіс чекауту monobank для отримання платежів за замовлення. Детальніше про сервіс можна подивитись за посиланням https://api.monobank.ua/. Умови використання - https://www.monobank.ua/terms17 Даний модуль використовує сервіс чекауту monobank для отримання платежів за замовлення. Детальніше про сервіс можна подивитись за [посиланням](https://api.monobank.ua/). Умови використання - [https://www.monobank.ua/terms](https://www.monobank.ua/terms) 18 18 19 19 Що робить цей плагін: … … 39 39 = Де взяти токен? = 40 40 41 В web-кабінеті https://web.monobank.ua/, в налаштуваннях інтернет-еквайрингу.41 В web-кабінеті [https://web.monobank.ua/](https://web.monobank.ua/), в налаштуваннях інтернет-еквайрингу. 42 42 43 43 == Screenshots == … … 49 49 50 50 == Changelog == 51 52 = 1.8.1 = 53 * Покращення безпеки 51 54 52 55 = 1.8.0 =
Note: See TracChangeset
for help on using the changeset viewer.