Changeset 3844098
- Timestamp:
- 12/04/2026 09:40:26 AM (3 hours ago)
- Location:
- tiptoppay-gateway-for-woocommerce
- Files:
-
- 27 added
- 3 edited
-
tags/1.0.6 (added)
-
tags/1.0.6/assets (added)
-
tags/1.0.6/assets/admin-scripts.js (added)
-
tags/1.0.6/assets/admin-styles.css (added)
-
tags/1.0.6/assets/blocks (added)
-
tags/1.0.6/assets/blocks/blocks.asset.php (added)
-
tags/1.0.6/assets/blocks/blocks.js (added)
-
tags/1.0.6/assets/scripts.js (added)
-
tags/1.0.6/assets/style.css (added)
-
tags/1.0.6/assets/widget-init.js (added)
-
tags/1.0.6/inc (added)
-
tags/1.0.6/inc/blocks (added)
-
tags/1.0.6/inc/blocks/wc-tiptoppay-blocks.php (added)
-
tags/1.0.6/inc/class-tiptoppay-api.php (added)
-
tags/1.0.6/inc/class-tiptoppay-init.php (added)
-
tags/1.0.6/inc/wc-tiptoppay-gateway.php (added)
-
tags/1.0.6/readme.txt (added)
-
tags/1.0.6/templates (added)
-
tags/1.0.6/templates/payment-fields-checkout.php (added)
-
tags/1.0.6/templates/tiptoppay-widget.php (added)
-
tags/1.0.6/tiptoppay_gateway_for_wc.php (added)
-
tags/1.0.6/visa-mastercard.png (added)
-
trunk/assets/blocks (added)
-
trunk/assets/blocks/blocks.asset.php (added)
-
trunk/assets/blocks/blocks.js (added)
-
trunk/inc/blocks (added)
-
trunk/inc/blocks/wc-tiptoppay-blocks.php (added)
-
trunk/inc/class-tiptoppay-api.php (modified) (9 diffs)
-
trunk/readme.txt (modified) (1 diff)
-
trunk/tiptoppay_gateway_for_wc.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
tiptoppay-gateway-for-woocommerce/trunk/inc/class-tiptoppay-api.php
r3303671 r3844098 5 5 class TipTopPay_Api 6 6 { 7 private $enabledDMS; 8 private $status_chancel; 9 private $status_pay; 10 private $api_pass; 11 private $DMS_AU_status; 12 private $public_id; 7 13 8 14 public function __construct($enabledDMS, $statusChancel, $statusPay, $apiPass, $DMS_AU_status, $publicID) … … 18 24 public function processRequest() 19 25 { 20 $action = sanitize_text_field($_GET['action']); 26 if (!$this->hasValidSignature()) { 27 exit('{"error":"access denied"}'); 28 } 29 30 if (empty($_POST)) { 31 exit('{"error":"empty request"}'); 32 } 33 34 $action = sanitize_text_field($_GET['action'] ?? ''); 21 35 $request = [ 22 'Data' => sanitize_text_field($_POST['Data'] ),23 'TransactionId' => sanitize_text_field($_POST['TransactionId'] ),24 'AccountId' => sanitize_text_field($_POST['AccountId'] ),25 'CardExpDate' => sanitize_text_field($_POST['CardExpDate'] ),26 'CardLastFour' => sanitize_text_field($_POST['CardLastFour'] ),27 'CardType' => sanitize_text_field($_POST['CardType'] ),28 'Token' => sanitize_text_field($_POST['Token'] ),29 'InvoiceId' => sanitize_text_field($_POST['InvoiceId'] ),30 'Type' => sanitize_text_field($_POST['Type'] ),31 'Url' => sanitize_text_field($_POST['Url'] ),32 'Amount' => sanitize_text_field($_POST['Amount'])36 'Data' => sanitize_text_field($_POST['Data'] ?? ''), 37 'TransactionId' => sanitize_text_field($_POST['TransactionId'] ?? ''), 38 'AccountId' => sanitize_text_field($_POST['AccountId'] ?? ''), 39 'CardExpDate' => sanitize_text_field($_POST['CardExpDate'] ?? ''), 40 'CardLastFour' => sanitize_text_field($_POST['CardLastFour'] ?? ''), 41 'CardType' => sanitize_text_field($_POST['CardType'] ?? ''), 42 'Token' => sanitize_text_field($_POST['Token'] ?? ''), 43 'InvoiceId' => sanitize_text_field($_POST['InvoiceId'] ?? ''), 44 'Type' => sanitize_text_field($_POST['Type'] ?? ''), 45 'Url' => sanitize_text_field($_POST['Url'] ?? ''), 46 'Amount' => $_POST['Amount'] ?? '' 33 47 ]; 34 35 if (empty($request)) 36 exit('{"error":"empty request"}'); 37 48 38 49 switch ($action) { 39 50 case 'check': … … 63 74 die(); 64 75 } 76 77 private function hasValidSignature() 78 { 79 $signature = $_SERVER['HTTP_CONTENT_HMAC'] ?? ''; 80 if (($_SERVER['REQUEST_METHOD'] ?? '') !== 'POST' || !is_string($signature) || $signature === '' || !is_string($this->api_pass) || $this->api_pass === '') { 81 return false; 82 } 83 84 $body = file_get_contents('php://input'); 85 if ($body === false || $body === '') { 86 return false; 87 } 88 89 $expected = base64_encode(hash_hmac('sha256', $body, $this->api_pass, true)); 90 91 return hash_equals($expected, $signature); 92 } 65 93 66 94 public function processCheckAction($request) 67 95 { 68 69 if (!empty($request['Data'])) { 70 $request_data = json_decode(stripslashes($request['Data']), true); 71 72 if (isset($request_data['add_payment_method']) && $request_data['add_payment_method'] == 1) { 73 echo json_encode(array('code' => 0)); 74 75 return; 76 } 96 if (($request['InvoiceId'] ?? '') === '' && $this->isCardBinding($request)) { 97 echo json_encode(array('code' => 0)); 98 return; 77 99 } 78 100 … … 80 102 81 103 if (!$order) { 82 die(); 104 echo json_encode(array('code' => 10)); 105 return; 83 106 } 84 107 … … 118 141 private function processSuccessAction($request) 119 142 { 120 121 $order = $this->getOrder($request); 122 $DMS_TYPE = $this->enabledDMS; 123 124 if ($DMS_TYPE == 'yes') { 125 if ($order) { 143 $isCardBinding = $request['InvoiceId'] === '' && !empty($request['AccountId']) && $this->isCardBinding($request); 144 145 if (!$isCardBinding) { 146 $order = $this->getOrder($request); 147 if (!$order) { 148 echo json_encode(array('code' => 10)); 149 return; 150 } 151 152 if (!$this->isCorrectSum($request, $order)) { 153 echo json_encode(array('code' => 12)); 154 return; 155 } 156 157 if ($this->enabledDMS == 'yes') { 126 158 $order->update_status($this->DMS_AU_status); 127 } 128 } else {129 $order->update_status($this->status_pay);130 $order->payment_complete();131 $order->add_order_note(sprintf('Payment approved (TransactionID: %s)', json_encode($request['TransactionId'])));159 } else { 160 $order->update_status($this->status_pay); 161 $order->payment_complete(); 162 $order->add_order_note(sprintf('Payment approved (TransactionID: %s)', json_encode($request['TransactionId']))); 163 } 132 164 } 133 165 … … 174 206 } 175 207 176 $request_data = json_decode(stripslashes($request['Data']), true); 177 178 if (isset($request_data['add_payment_method']) && $request_data['add_payment_method'] == 1) { 179 if ($request['Data']) { 180 $auth = base64_encode($this->public_id . ":" . $this->api_pass); 181 wp_remote_post('https://api.tiptoppay.kz/payments/void', array( 182 'timeout' => 30, 183 'redirection' => 5, 184 'httpversion' => '1.0', 185 'blocking' => true, 186 'headers' => array('Authorization' => 'Basic ' . $auth, 'Content-Type' => 'application/json'), 187 'body' => json_encode(array('TransactionId' => $request['TransactionId'])), 188 'cookies' => array() 189 )); 190 } 191 } 192 193 208 if ($isCardBinding) { 209 $auth = base64_encode($this->public_id . ":" . $this->api_pass); 210 wp_remote_post('https://api.tiptoppay.kz/payments/void', array( 211 'timeout' => 30, 212 'redirection' => 5, 213 'httpversion' => '1.0', 214 'blocking' => true, 215 'headers' => array('Authorization' => 'Basic ' . $auth, 'Content-Type' => 'application/json'), 216 'body' => json_encode(array('TransactionId' => $request['TransactionId'])), 217 'cookies' => array() 218 )); 219 } 220 194 221 } 195 222 … … 212 239 { 213 240 $order = self::getOrder($request); 214 if ($order) { 215 $order->update_status($this->status_pay); 216 } 217 $data['code'] = 0; 218 echo json_encode($data); 241 if (!$order) { 242 echo json_encode(array('code' => 10)); 243 return; 244 } 245 246 if (!$this->isCorrectSum($request, $order)) { 247 echo json_encode(array('code' => 12)); 248 return; 249 } 250 251 $order->update_status($this->status_pay); 252 echo json_encode(array('code' => 0)); 219 253 } 220 254 221 255 public static function getOrder($request) 222 256 { 223 global $woocommerce; 224 $order = new WC_Order($request['InvoiceId']); 225 226 return $order; 257 $invoiceId = $request['InvoiceId'] ?? ''; 258 if ((!is_string($invoiceId) && !is_int($invoiceId)) || !ctype_digit((string) $invoiceId) || (int) $invoiceId <= 0) { 259 return false; 260 } 261 262 $order = wc_get_order($invoiceId); 263 264 return $order instanceof WC_Order ? $order : false; 227 265 } 228 266 … … 238 276 $note = 'Ссылка на чек ' . $Type . ': ' . esc_url($url); 239 277 $order = self::getOrder($request); 278 if (!$order) { 279 echo json_encode(array('code' => 10)); 280 return; 281 } 240 282 $var = $order->add_order_note($note, 1); 241 283 $order->save(); … … 247 289 private function isCorrectSum($request, $order) 248 290 { 249 $sum = $request['Amount']; 250 $paymentSum = $order->get_total(); 251 252 return round($paymentSum, 2) == round($sum, 2); 291 $sum = $request['Amount'] ?? ''; 292 if (!is_string($sum) || !preg_match('/\A[0-9]+(?:\.[0-9]{1,2})?\z/', $sum)) { 293 return false; 294 } 295 296 return round((float) $order->get_total(), 2) === (float) $sum; 297 } 298 299 private function isCardBinding($request) 300 { 301 $data = json_decode(stripslashes($request['Data'] ?? ''), true); 302 303 $marker = $data['Metadata']['add_payment_method'] ?? $data['add_payment_method'] ?? null; 304 305 return $marker === 1 || $marker === '1'; 253 306 } 254 307 -
tiptoppay-gateway-for-woocommerce/trunk/readme.txt
r3464118 r3844098 5 5 Requires at least: 4.9.7 6 6 Tested up to: 6.7.1 7 Stable tag: 1.0. 57 Stable tag: 1.0.6 8 8 Requires PHP: 7.4 9 9 License: GPLv2 or later -
tiptoppay-gateway-for-woocommerce/trunk/tiptoppay_gateway_for_wc.php
r3464118 r3844098 4 4 * Plugin URI: https://tiptoppay.kz/ 5 5 * Description: Extends WooCommerce with TipTopPay Gateway. 6 * Version: 1.0. 46 * Version: 1.0.6 7 7 * Author: TipTop Pay 8 8 * Author URI: https://tiptoppay.kz/
Note:
See TracChangeset
for help on using the changeset viewer.