Changeset 2216770
- Timestamp:
- 12/23/2019 08:11:28 AM (6 years ago)
- Location:
- woo-sagepay-addon/trunk
- Files:
-
- 2 edited
-
README.txt (modified) (2 diffs)
-
woo-sagepay-addon.php (modified) (48 diffs)
Legend:
- Unmodified
- Added
- Removed
-
woo-sagepay-addon/trunk/README.txt
r2212885 r2216770 3 3 Tags: woocommerce, Sage Pay, payment gateway, credit card, ecommerce, e-commerce, commerce, cart, checkout, Sage Pay addon,refund,credit cards payment Sage Pay and woocommerce, Sage Pay for woocommerce, Sage Pay payment gateway for woocommerce, Sage Pay payment in wordpress, Sage Pay payment refunds, Sage Pay plugin for woocommerce, Sage Pay woocommerce addon, free Sage Pay woocommerce plugin, woocommerce credit cards payment with Sage Pay, woocommerce plugin Sage Pay. 4 4 Requires at least: 4.0 & WooCommerce 2.3+ 5 Tested up to: 5.3 & Woocommerce 3.8.15 Tested up to: 5.3.2 & Woocommerce 3.8.1 6 6 Stable tag: trunk 7 7 License: GPLv3 … … 109 109 = 1.0.3 = 110 110 * Fix - Payment method reduce issue 111 = 1.0. 4=112 * Fix - Remove depricated funcations111 = 1.0.5 = 112 * Fix - Made funcation changes. 113 113 == Upgrade Notice == -
woo-sagepay-addon/trunk/woo-sagepay-addon.php
r2212885 r2216770 5 5 * Plugin URL: Addon for sagepay and WooCommerce 6 6 * Description: Addon for sagepay and WooCommerce allows you to accept payments on your Woocommerce store. It accpets credit card payments and processes them securely with your merchant account. 7 * Version: 1.0. 47 * Version: 1.0.5 8 8 * WC requires at least:2.3 9 9 * WC tested up to: 3.8.1 10 10 * Requires at least: 4.0+ 11 * Tested up to: 5.3 11 * Tested up to: 5.3.2 12 12 * Contributors: wp_estatic 13 13 * Author: Estatic Infotech Pvt Ltd … … 17 17 * @category Woocommerce Payment Gateway 18 18 */ 19 require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); 19 20 require_once ABSPATH . 'wp-admin/includes/plugin.php'; 20 21 $logs_message = ""; 21 22 … … 23 24 24 25 deactivate_plugins(plugin_basename(__FILE__)); 25 add_action('load-plugins.php', function () {26 add_filter('gettext', ' change_text', 99, 3);26 add_action('load-plugins.php', function () { 27 add_filter('gettext', 'wsap_change_text', 99, 3); 27 28 }); 28 29 29 function change_text($translated_text, $untranslated_text, $domain) { 30 function wsap_change_text($translated_text, $untranslated_text, $domain) 31 { 30 32 $old = array( 31 33 "Plugin <strong>activated</strong>.", 32 "Selected plugins <strong>activated</strong>." 34 "Selected plugins <strong>activated</strong>.", 33 35 ); 34 36 … … 39 41 remove_filter(current_filter(), __FUNCTION__, 99); 40 42 } 43 41 44 return $translated_text; 42 45 } 43 46 44 return FALSE;47 return false; 45 48 } 46 49 47 add_action('plugins_loaded', 'init_woocommerce_sagepay', 0); 48 49 function init_woocommerce_sagepay() { 50 add_action('plugins_loaded', 'wsap_init_woocommerce_sagepay', 0); 51 52 function wsap_init_woocommerce_sagepay() 53 { 50 54 51 55 if (!class_exists('WC_Payment_Gateway_CC')) { … … 55 59 load_plugin_textdomain('woocommerce', false, dirname(plugin_basename(__FILE__)) . '/lang'); 56 60 57 class woocommerce_sagepay extends WC_Payment_Gateway_CC { 58 59 public function __construct() { 61 function wsap_add_sagepay_gateway($methods) 62 { 63 64 $methods[] = 'woocommerce_sagepay'; 65 return $methods; 66 } 67 68 add_filter('woocommerce_payment_gateways', 'wsap_add_sagepay_gateway'); 69 70 class woocommerce_sagepay extends WC_Payment_Gateway_CC 71 { 72 73 public function __construct() 74 { 60 75 global $woocommerce; 61 76 … … 65 80 $this->has_fields = true; 66 81 $this->notify_url = add_query_arg('wc-api', 'woocommerce_sagepay', home_url('/')); 82 67 83 $this->init_form_fields(); 68 84 $this->init_settings(); 85 69 86 $this->title = $this->get_option('title'); 70 87 $this->method_description = sprintf(__('sagepay allows you to accept payments on your Woocommerce store. It accpets credit card payments and processes them securely with your merchant account.Please dont forget to test with sandbox account first. <li style="color: red;"><span id="message">Please Add Currency Which Is Provided By Your Sagepay Merchant Account</span></li> ', 'woocommerce')); … … 77 94 $this->sagepay_cardtypes = $this->get_option('sagepay_cardtypes'); 78 95 79 $this->sagepay_zerocurrency = array("BIF", "CLP", "DJF", "GNF", "JPY", "KMF", "KRW", "MGA", "PYG", "RWF", "VND", "VUV", "XAF", "XOF", "XPF"); 80 add_action('init', array($this, 'auth_success')); 96 $this->sagepay_zerocurrency = array("BIF", "CLP", "DJF", "GNF", "JPY", "KMF", "KRW", "MGA", "PYG", "RWF", "VND", "VUV", "XAF", "XOF", "XPF", "GBP"); 97 98 add_action('init', array($this, 'wsap_auth_success')); 99 add_action('woocommerce_api_woocommerce_sagepay', array($this, 'wsap_auth_success')); 100 add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); 101 add_action('woocommerce_order_status_processing_to_cancelled', array($this, 'wsap_restore_order_stock'), 10, 1); 102 add_action('woocommerce_order_status_completed_to_cancelled', array($this, 'wsap_restore_order_stock'), 10, 1); 103 add_action('woocommerce_order_status_on-hold_to_cancelled', array($this, 'wsap_restore_order_stock'), 10, 1); 104 add_action('woocommerce_order_status_processing_to_refunded', array($this, 'wsap_restore_order_stock'), 10, 1); 105 106 add_action('woocommerce_receipt_sagepay', array($this, 'receipt_page')); 107 add_action('woocommerce_order_status_completed_to_refunded', array($this, 'wsap_restore_order_stock'), 10, 1); 108 add_action('woocommerce_order_status_on-hold_to_refunded', array($this, 'wsap_restore_order_stock'), 10, 1); 81 109 add_filter('woocommerce_credit_card_form_fields', array($this, 'sagepay_card_type'), 10, 2); 82 83 add_action('woocommerce_api_woocommerce_sagepay', array($this, 'auth_success')); 84 add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); 85 add_action('woocommerce_order_status_processing_to_cancelled', array($this, 'restore_order_stock'), 10, 1); 86 add_action('woocommerce_order_status_completed_to_cancelled', array($this, 'restore_order_stock'), 10, 1); 87 add_action('woocommerce_order_status_on-hold_to_cancelled', array($this, 'restore_order_stock'), 10, 1); 88 add_action('woocommerce_order_status_processing_to_refunded', array($this, 'restore_order_stock'), 10, 1); 89 add_action('woocommerce_receipt_sagepay', array($this, 'receipt_page')); 90 add_action('woocommerce_order_status_completed_to_refunded', array($this, 'restore_order_stock'), 10, 1); 91 add_action('woocommerce_order_status_on-hold_to_refunded', array($this, 'restore_order_stock'), 10, 1); 92 } 93 94 function get_the_user_ip() { 110 } 111 112 function get_the_user_ip() 113 { 95 114 if (!empty($_SERVER['HTTP_CLIENT_IP'])) { 96 115 … … 105 124 } 106 125 107 function sagepay_card_type($args, $payment_id) { 126 function sagepay_card_type($args, $payment_id) 127 { 108 128 $new_cards_type = ""; 109 129 if ($payment_id == $this->id) { … … 130 150 } 131 151 132 public function get_icon() { 152 public function get_icon() 153 { 133 154 if ($this->get_option('show_accepted') == 'yes') { 134 155 $get_cardtypes = $this->get_option('sagepay_cardtypes'); … … 145 166 } 146 167 147 private function sagepay_ssl($url) { 168 private function sagepay_ssl($url) 169 { 148 170 if ('yes' == get_option('woocommerce_sagepay_ssl_checkout')) { 149 171 $url = str_replace('http:', 'https:', $url); … … 152 174 } 153 175 154 public function init_form_fields() { 176 public function init_form_fields() 177 { 155 178 $this->form_fields = array( 156 179 'enabled' => array( … … 158 181 'type' => 'checkbox', 159 182 'label' => __('Enable Sagepay', 'woocommerce'), 160 'default' => 'yes' 183 'default' => 'yes', 161 184 ), 162 185 'title' => array( … … 165 188 'description' => __('Display this title on checkout page.', 'woocommerce'), 166 189 'default' => __('Sagepay', 'woocommerce'), 167 'desc_tip' => true 190 'desc_tip' => true, 168 191 ), 169 192 'description' => array( … … 171 194 'type' => 'textarea', 172 195 'desc_tip' => __('user sees during checkout.', 'woocommerce'), 173 'default' => __("Payment via SagePay, Please enter your credit or debit card below.", 'woocommerce') 196 'default' => __("Payment via SagePay, Please enter your credit or debit card below.", 'woocommerce'), 174 197 ), 175 198 'vendorname' => array( … … 177 200 'type' => 'text', 178 201 'desc_tip' => __('Please enter your vendor name which is provided by your sagepay account.', 'woocommerce'), 179 'default' => '' 202 'default' => '', 180 203 ), 181 204 'mode' => array( … … 184 207 'options' => array( 185 208 'test' => 'Test', 186 'live' => 'Live' 209 'live' => 'Live', 187 210 ), 188 'desc_tip' => __('Select the mode to accept.', 'woocommerce') 211 'desc_tip' => __('Select the mode to accept.', 'woocommerce'), 189 212 ), 190 213 'send_shipping' => array( … … 193 216 'options' => array( 194 217 'auto' => 'Auto', 195 'yes' => 'Billing Address' 218 'yes' => 'Billing Address', 196 219 ), 197 220 'desc_tip' => __('Slect your send shipping address.', 'woocommerce'), 198 'default' => 'auto' 221 'default' => 'auto', 199 222 ), 200 223 'transtype' => array( … … 206 229 'AUTHENTICATE' => __('Authenticate', 'woocommerce'), 207 230 ), 208 'desc_tip' => __('Select Payment, Deferred or Authenticate.', 'woocommerce') 231 'desc_tip' => __('Select Payment, Deferred or Authenticate.', 'woocommerce'), 209 232 ), 210 233 'show_accepted' => array( … … 218 241 'no' => 'No', 219 242 ), 220 'default' => array('yes'),243 'default' => 'yes', 221 244 ), 222 245 'sagepay_cardtypes' => array( … … 233 256 'visa' => 'Visa', 234 257 ), 235 ) 258 ), 236 259 ); 237 260 } 238 261 239 function payment_fields() { 240 echo wpautop(wptexturize($this->description)); 241 $this->form(); 242 } 243 244 function validate_fields() { 262 function validate_fields() 263 { 245 264 global $woocommerce; 246 265 … … 249 268 } 250 269 251 if (!$this-> if_creadit_card_is_empty(sanitize_text_field($_POST['sagepay-card-number']))) {270 if (!$this->wsap_if_credit_card_is_empty(sanitize_text_field($_POST['sagepay-card-number']))) { 252 271 wc_add_notice('<strong>Credit Card Number</strong> ' . __('is required.', 'woocommerce'), 'error'); 253 } elseif (!$this-> is_valid_credit_card(sanitize_text_field($_POST['sagepay-card-number']))) {272 } elseif (!$this->wsap_is_valid_credit_card(sanitize_text_field($_POST['sagepay-card-number']))) { 254 273 wc_add_notice('<strong>Credit Card Number</strong> ' . __('is not a valid credit card number.', 'woocommerce'), 'error'); 255 274 } 256 275 257 if (!$this-> if_expire_date_is_empty(sanitize_text_field($_POST['sagepay-card-expiry']))) {276 if (!$this->wsap_if_expire_date_is_empty(sanitize_text_field($_POST['sagepay-card-expiry']))) { 258 277 wc_add_notice('<strong>Card Expiry Date</strong> ' . __('is required.', 'woocommerce'), 'error'); 259 } elseif (!$this-> is_valid_expire_date(sanitize_text_field($_POST['sagepay-card-expiry']))) {278 } elseif (!$this->wsap_is_valid_expire_date(sanitize_text_field($_POST['sagepay-card-expiry']))) { 260 279 wc_add_notice('<strong>Card Expiry Date</strong> ' . __('is not a valid expiry date.', 'woocommerce'), 'error'); 261 280 } 262 281 263 if (!$this->if_cvv_number_is_empty(sanitize_text_field($_POST['sagepay-card-cvc']))) { 264 wc_add_notice('<strong>CCV Number</strong> ' . __('is required.', 'woocommerce'), 'error'); 265 } 266 } 267 268 private function if_creadit_card_is_empty($credit_card) { 282 if (!$this->wsap_if_cvv_number_is_empty(sanitize_text_field($_POST['sagepay-card-cvc']))) { 283 wc_add_notice('<strong>CVV Number</strong> ' . __('is required.', 'woocommerce'), 'error'); 284 } 285 } 286 287 private function wsap_if_credit_card_is_empty($credit_card) 288 { 269 289 if (empty($credit_card)) { 270 290 return false; … … 273 293 } 274 294 275 public function field_name($name) { 295 public function field_name($name) 296 { 276 297 return $this->supports('tokenization') ? '' : ' name="' . esc_attr($this->id . '-' . $name) . '" '; 277 298 } 278 299 279 private function if_expire_date_is_empty($expiry_date) {280 300 private function wsap_if_expire_date_is_empty($expiry_date) 301 { 281 302 $expiry_date = str_replace(' / ', '', $expiry_date); 282 303 283 if (is_numeric($expiry_date) && ( strlen($expiry_date) == 4)) {304 if (is_numeric($expiry_date) && (strlen($expiry_date) == 4)) { 284 305 return true; 285 306 } … … 287 308 } 288 309 289 private function if_cvv_number_is_empty($ccv_number) { 310 private function wsap_if_cvv_number_is_empty($ccv_number) 311 { 290 312 $length = strlen($ccv_number); 291 return is_numeric($ccv_number) AND $length > 2 AND $length < 5; 292 } 293 294 function get_card_type($number) { 313 return is_numeric($ccv_number) and $length > 2 and $length < 5; 314 } 315 316 private function wsap_is_valid_expire_date($expiry_date) 317 { 318 319 $month = $year = ''; 320 $month = substr($expiry_date, 0, 2); 321 $year = substr($expiry_date, 5, 7); 322 $year = '20' . $year; 323 324 if ($month > 12) { 325 return false; 326 } 327 328 if (date("Y-m-d", strtotime($year . "-" . $month . "-01")) > date("Y-m-d")) { 329 return true; 330 } 331 332 return false; 333 } 334 335 private function wsap_is_valid_credit_card($credit_card) 336 { 337 $credit_card = preg_replace('/(?<=\d)\s+(?=\d)/', '', trim($credit_card)); 338 $number = preg_replace('/[^0-9]+/', '', $credit_card); 339 $strlen = strlen($number); 340 $sum = 0; 341 if ($strlen < 13) { 342 return false; 343 } 344 for ($i = 0; $i < $strlen; $i++) { 345 $digit = substr($number, $strlen - $i - 1, 1); 346 347 if ($i % 2 == 1) { 348 349 $sub_total = $digit * 2; 350 351 if ($sub_total > 9) { 352 $sub_total = 1 + ($sub_total - 10); 353 } 354 } else { 355 $sub_total = $digit; 356 } 357 $sum += $sub_total; 358 } 359 360 if ($sum > 0 and $sum % 10 == 0) { 361 return true; 362 } 363 364 return false; 365 } 366 367 function get_card_type($number) 368 { 295 369 $number = preg_replace('/[^\d]/', '', $number); 296 370 … … 314 388 } 315 389 316 function receipt_page($order) { 390 function receipt_page($order) 391 { 317 392 global $woocommerce; 318 393 … … 321 396 } 322 397 323 public function generate_sagepay_form($order_id) { 398 public function generate_sagepay_form($order_id) 399 { 324 400 global $woocommerce; 325 401 326 402 $order = new WC_Order($order_id); 327 403 328 $sagepay_args = array_merge(329 array(404 if (!empty(WC()->session->get('set_pareq'))) { 405 $sagepay_args = array( 330 406 'PaReq' => WC()->session->get('set_pareq'), 331 407 'MD' => WC()->session->get('set_md'), 332 'TermUrl' => $this->notify_url 333 ) 334 ); 335 408 'TermUrl' => $this->notify_url, 409 ); 410 } 336 411 $sagepay_args_array = array(); 337 412 … … 339 414 $sagepay_args_array[] = '<input type="hidden" name="' . esc_attr($key) . '" value="' . esc_attr($value) . '" />'; 340 415 } 341 416 342 417 wc_enqueue_js(' 343 418 jQuery("body").block({ 344 message: "<img src=\"' . esc_url($woocommerce->plugin_url()) . '/ images/ajax-loader.gif\" alt=\"Redirecting...\" style=\"float:left; margin-right: 10px;\" />' . __('Thank you for your order. We are now redirecting you to verify your card.', 'woocommerce') . '",419 message: "<img src=\"' . esc_url($woocommerce->plugin_url()) . '/assets/images/select2-spinner.gif\" alt=\"Redirecting...\" style=\"float:left; margin-right: 10px;\" />' . __('Thank you for your order. We are now redirecting you to verify your card.', 'woocommerce') . '", 345 420 overlayCSS: 346 421 { … … 348 423 opacity: 0.6 349 424 }, 350 425 351 426 }); 352 427 jQuery("#submit_sagepay_payment_form").click(); 353 428 '); 354 429 355 430 return '<form action="' . esc_url(WC()->session->get('set_acsurl')) . '" method="post" id="sagepay_payment_form"> 356 431 ' . implode('', $sagepay_args_array) . ' 357 432 <input type="submit" class="button-alt" id="submit_sagepay_payment_form" value="' . __('Submit', 'woocommerce') . '" /> <a class="button cancel" href="' . esc_url($order->get_cancel_order_url()) . '">' . __('Cancel order & restore cart', 'woocommerce') . '</a> 358 433 </form>'; 359 // var_dump($dd);exit; 360 } 361 362 function process_payment($order_id) { 434 435 } 436 437 function process_payment($order_id) 438 { 363 439 global $woocommerce; 364 440 365 441 $order = new WC_Order($order_id); 366 442 … … 376 452 WC()->session->set('sagepay_set', $orderid); 377 453 WC()->session->set('sagepay_oid', $order_id); 378 379 454 380 455 $product_item['BillingSurname'] = $order->billing_last_name; … … 392 467 $product_item['BillingPhone'] = $order->billing_phone; 393 468 394 395 if ($this->if_meta_product() == true || $this->send_shipping == 'yes') { 469 if ($this->wsap_if_meta_product() == true || $this->send_shipping == 'yes') { 396 470 $product_item['DeliverySurname'] = $order->billing_last_name; 397 471 $product_item['DeliveryFirstnames'] = $order->billing_first_name; … … 454 528 $product_item['product_categories'] = $this->get_categories; 455 529 $product_item['customer_email'] = $order->billing_email; 456 $product_item['VPSTxID'] = // $product_item['CreateToken'] = 1;457 530 458 531 $post_values = ""; … … 471 544 'body' => $post_values, 472 545 'method' => 'POST', 473 'sslverify' => FALSE546 'sslverify' => false, 474 547 )); 475 476 548 477 549 if (!is_wp_error($response) && $response['response']['code'] >= 200 && $response['response']['code'] < 300) { … … 486 558 } 487 559 488 if (isset($responce_update['Status'])) 560 if (isset($responce_update['Status'])) { 489 561 update_post_meta($order->id, 'Status', $responce_update['Status']); 490 491 if (isset($responce_update['AVSCV2'])) 562 } 563 564 if (isset($responce_update['AVSCV2'])) { 492 565 update_post_meta($order->id, 'AVSCV2', $responce_update['AVSCV2']); 493 494 if (isset($responce_update['TxAuthNo'])) 566 } 567 568 if (isset($responce_update['TxAuthNo'])) { 495 569 update_post_meta($order->id, 'TxAuthNo', $responce_update['TxAuthNo']); 496 497 if (isset($responce_update['PostCodeResult'])) 570 } 571 572 if (isset($responce_update['PostCodeResult'])) { 498 573 update_post_meta($order->id, 'PostCodeResult', $responce_update['PostCodeResult']); 499 500 if (isset($responce_update['VPSTxId'])) 574 } 575 576 if (isset($responce_update['VPSTxId'])) { 501 577 update_post_meta($order->id, 'VPSTxId', $responce_update['VPSTxId']); 502 503 if (isset($responce_update['StatusDetail'])) 578 WC()->session->set('set_vpstxid', $responce_update['VPSTxId']); 579 } 580 581 if (isset($responce_update['StatusDetail'])) { 504 582 update_post_meta($order->id, 'StatusDetail', $responce_update['StatusDetail']); 505 506 if (isset($responce_update['SecurityKey'])) 583 } 584 585 if (isset($responce_update['SecurityKey'])) { 507 586 update_post_meta($order->id, 'SecurityKey', $responce_update['SecurityKey']); 508 509 if (isset($responce_update['CV2Result'])) 587 } 588 589 if (isset($responce_update['CV2Result'])) { 510 590 update_post_meta($order->id, 'CV2Result', $responce_update['CV2Result']); 511 512 if (isset($responce_update['3DSecureStatus'])) 591 } 592 593 if (isset($responce_update['3DSecureStatus'])) { 513 594 update_post_meta($order->id, '3DSecureStatus', $responce_update['3DSecureStatus']); 514 515 if (WC()->session->get('sagepay_set') != '') 595 } 596 597 if (WC()->session->get('sagepay_set') != '') { 516 598 update_post_meta($order->id, 'VendorTxCode', WC()->session->get('sagepay_set')); 517 518 if (isset($responce_update['expiry_date'])) 599 } 600 601 if (isset($responce_update['expiry_date'])) { 519 602 update_post_meta($order->id, 'expiry_date', $responce_update['expiry_date']); 520 521 if (isset($responce_update['product_categories'])) 522 update_post_meta($order->id, 'product_categories', $responce_update['product_categories']); 523 603 } 524 604 525 605 if ($responce_update['Status'] == "OK" || $responce_update['Status'] == "REGISTERED" || $responce_update['Status'] == "AUTHENTICATED") { … … 529 609 $redirect_url = $this->get_return_url($order); 530 610 531 532 611 return array( 533 612 'result' => 'success', 534 'redirect' => $redirect_url 613 'redirect' => $redirect_url, 535 614 ); 536 615 } else if ($responce_update['Status'] == "3DAUTH") { 537 616 538 617 if ($responce_update['3DSecureStatus'] == 'OK') { 539 540 541 542 WC()->session->set('set_acsurl', $responce_update['ACSURL']); 543 WC()->session->set('set_pareq', $responce_update['PAReq']); 544 WC()->session->set('set_md', $responce_update['MD']); 545 546 $redirect_url = $order->get_checkout_payment_url(true); 547 548 return array( 549 'result' => 'success', 550 'redirect' => $redirect_url 551 ); 618 if (isset($responce_update['ACSURL']) && (isset($responce_update['PAReq']))) { 619 620 WC()->session->set('set_acsurl', $responce_update['ACSURL']); 621 622 if (isset($responce_update['PAReq']) && !empty($responce_update['PAReq'])) { 623 WC()->session->set('set_pareq', $responce_update['PAReq']); 624 } 625 626 WC()->session->set('set_md', $responce_update['MD']); 627 628 $redirect = $order->get_checkout_payment_url(true); 629 return array( 630 'result' => 'success', 631 'redirect' => $redirect, 632 ); 633 } 552 634 } 553 635 } … … 557 639 } 558 640 559 static public function setStore($key, $value) { 641 static public function setStore($key, $value) 642 { 643 560 644 if (gettype($value) == "object") { 561 645 $_SESSION[$key] = serialize($value); … … 565 649 } 566 650 567 public function getSharedUrl($method, $env = '') { 651 public function getSharedUrl($method, $env = '') 652 { 653 568 654 $env = $this->_validEnvironment($env); 569 655 if (isset($this->_sharedUrls[$env][$method])) { … … 573 659 } 574 660 575 function update_logs($script_name, $msg, $file_name = 'logs.txt') { 661 function wsap_update_logs($script_name, $msg, $file_name = 'logs.txt') 662 { 663 576 664 $file = fopen($file_name, 'r+'); 577 665 $message_old = fread($file, filesize($file_name)); … … 582 670 } 583 671 584 public function restore_order_stock($order_id) { 672 public function wsap_restore_order_stock($order_id) 673 { 674 585 675 $order = new WC_Order($order_id); 586 676 … … 588 678 $VPSTxId = substr($custom['VPSTxId'][0], 1, -1); 589 679 590 $rand_no = wp_generate_password(12, FALSE, FALSE);680 $rand_no = wp_generate_password(12, false, false); 591 681 $caracter = 'Estatic'; 592 682 … … 612 702 $params['TxType'] = urlencode('REFUND'); 613 703 $params['Vendor'] = urlencode('chestnutregistr'); 614 $params['VendorTxCode'] = urlencode($generat); //Sample value given by me704 $params['VendorTxCode'] = urlencode($generat); //Sample value given by me 615 705 $params['Amount'] = urlencode($custom['_order_total'][$i]); 616 706 $params['Currency'] = urlencode($custom['_order_currency'][$i]); 617 707 $params['Description'] = urlencode('Testing Refunds'); 618 $params['RelatedVPSTxId'] = urlencode($VPSTxId); //VPSTxId of main transaction /* '210C00C7-8B04-CF68-6BE0-7AE59C18F5A8' */619 $params['RelatedVendorTxCode'] = urlencode($custom['VendorTxCode'][$i]); //VendorTxCode of main transaction620 $params['RelatedSecurityKey'] = urlencode($custom['SecurityKey'][$i]); //securitykey of main transaction708 $params['RelatedVPSTxId'] = urlencode($VPSTxId); //VPSTxId of main transaction /* '210C00C7-8B04-CF68-6BE0-7AE59C18F5A8' */ 709 $params['RelatedVendorTxCode'] = urlencode($custom['VendorTxCode'][$i]); //VendorTxCode of main transaction 710 $params['RelatedSecurityKey'] = urlencode($custom['SecurityKey'][$i]); //securitykey of main transaction 621 711 $params['RelatedTxAuthNo'] = urlencode($custom['TxAuthNo'][$i]); 622 712 … … 624 714 'body' => $params, 625 715 'method' => 'POST', 626 'sslverify' => FALSE,716 'sslverify' => false, 627 717 'timeout' => '5', 628 'headers' => array() 718 'headers' => array(), 629 719 ); 630 720 … … 650 740 } 651 741 652 public function thankyou_page() {653 742 public function thankyou_page() 743 { 654 744 if ($this->instructions) { 655 745 echo wpautop(wptexturize($this->instructions)); … … 657 747 } 658 748 659 public function email_instructions($order, $sent_to_admin, $plain_text = false) { 660 661 if ($this->instructions && !$sent_to_admin && 'offline' === $order->payment_method && $order->has_status('on-hold')) { 662 echo wpautop(wptexturize($this->instructions)) . PHP_EOL; 663 } 664 } 665 666 private function is_valid_credit_card($credit_card) { 667 668 $credit_card = preg_replace('/(?<=\d)\s+(?=\d)/', '', trim($credit_card)); 669 $number = preg_replace('/[^0-9]+/', '', $credit_card); 670 $strlen = strlen($number); 671 $sum = 0; 672 if ($strlen < 13) { 673 return false; 674 } 675 for ($i = 0; $i < $strlen; $i++) { 676 $digit = substr($number, $strlen - $i - 1, 1); 677 678 if ($i % 2 == 1) { 679 680 $sub_total = $digit * 2; 681 682 if ($sub_total > 9) { 683 $sub_total = 1 + ( $sub_total - 10 ); 684 } 685 } else { 686 $sub_total = $digit; 687 } 688 $sum += $sub_total; 689 } 690 691 if ($sum > 0 AND $sum % 10 == 0) { 692 return true; 693 } 694 695 return false; 696 } 697 698 function auth_success() { 749 public function wsap_auth_success() 750 { 699 751 global $woocommerce; 700 752 … … 704 756 705 757 $request_array = array( 706 'MD' => $_REQUEST['MD'],707 'P ARes' => $_REQUEST['PaRes'],758 'MD' => sanitize_text_field($_REQUEST['MD']), 759 'PaRes' => sanitize_text_field($_REQUEST['PaRes']), 708 760 'VendorTxCode' => WC()->session->get('sagepay_set'), 761 'VPSTxId' => WC()->session->get('set_vpstxid'), 709 762 ); 710 763 711 764 $request = http_build_query($request_array); 712 713 $params = array(714 'body' => $request,715 'method' => 'POST',716 'sslverify' => false717 );718 765 719 766 if ($this->mode == 'test') { … … 723 770 } 724 771 725 $response = wp_remote_ get($redirect_for_pay__url, array(772 $response = wp_remote_post($redirect_for_pay__url, array( 726 773 'body' => $request, 727 774 'method' => 'POST', 728 'sslverify' => false 775 'sslverify' => false, 729 776 )); 730 731 777 732 778 if (!is_wp_error($response) && $response['response']['code'] >= 200 && $response['response']['code'] < 300) { … … 742 788 } 743 789 744 if (isset($responce_update['Status'])) 790 if (isset($responce_update['Status'])) { 745 791 update_post_meta($order->id, 'Status', $responce_update['Status']); 746 747 if (isset($responce_update['AVSCV2'])) 792 } 793 794 if (isset($responce_update['AVSCV2'])) { 748 795 update_post_meta($order->id, 'AVSCV2', $responce_update['AVSCV2']); 749 750 if (isset($responce_update['TxAuthNo'])) 796 } 797 798 if (isset($responce_update['TxAuthNo'])) { 751 799 update_post_meta($order->id, 'TxAuthNo', $responce_update['TxAuthNo']); 752 753 if (isset($responce_update['PostCodeResult'])) 800 } 801 802 if (isset($responce_update['PostCodeResult'])) { 754 803 update_post_meta($order->id, 'PostCodeResult', $responce_update['PostCodeResult']); 755 756 if (isset($responce_update['VPSTxId'])) 804 } 805 806 if (isset($responce_update['VPSTxId'])) { 757 807 update_post_meta($order->id, 'VPSTxId', $responce_update['VPSTxId']); 758 759 if (isset($responce_update['StatusDetail'])) 808 WC()->session->set('set_vpstxid', $responce_update['VPSTxId']); 809 } 810 811 if (isset($responce_update['StatusDetail'])) { 760 812 update_post_meta($order->id, 'StatusDetail', $responce_update['StatusDetail']); 761 762 if (isset($responce_update['SecurityKey'])) 813 } 814 815 if (isset($responce_update['SecurityKey'])) { 763 816 update_post_meta($order->id, 'SecurityKey', $responce_update['SecurityKey']); 764 765 if (isset($responce_update['CV2Result'])) 817 } 818 819 if (isset($responce_update['CV2Result'])) { 766 820 update_post_meta($order->id, 'CV2Result', $responce_update['CV2Result']); 767 768 if (isset($responce_update['3DSecureStatus'])) 821 } 822 823 if (isset($responce_update['3DSecureStatus'])) { 769 824 update_post_meta($order->id, '3DSecureStatus', $responce_update['3DSecureStatus']); 770 771 if (WC()->session->get('sagepay_set') != '') 825 } 826 827 if (WC()->session->get('sagepay_set') != '') { 772 828 update_post_meta($order->id, 'VendorTxCode', WC()->session->get('sagepay_set')); 773 774 if (isset($responce_update['expiry_date'])) 829 } 830 831 if (isset($responce_update['expiry_date'])) { 775 832 update_post_meta($order->id, 'expiry_date', $responce_update['expiry_date']); 776 777 if (isset($responce_update['product_categories'])) 778 update_post_meta($order->id, 'product_categories', $responce_update['product_categories']); 779 833 } 780 834 781 835 if ($responce_update['Status'] == "OK" || $responce_update['Status'] == "REGISTERED" || $responce_update['Status'] == "AUTHENTICATED") { … … 785 839 $order->payment_complete(); 786 840 $redirect_url = $this->get_return_url($order); 841 787 842 wp_redirect($redirect_url); 788 843 exit(); 844 789 845 } else if ($responce_update['Status'] == "3DAUTH") { 790 846 791 if ($responce_update['3DSecureStatus'] == 'OK') { 792 793 if (isset($responce_update['ACSURL']) && isset($responce_update['MD'])) { 794 795 WC()->session->set('set_acsurl', $responce_update['ACSURL']); 847 if (isset($responce_update['ACSURL']) && (isset($responce_update['PAReq']))) { 848 WC()->session->set('set_acsurl', $responce_update['ACSURL']); 849 850 if (isset($responce_update['PAReq']) && !empty($responce_update['PAReq'])) { 796 851 WC()->session->set('set_pareq', $responce_update['PAReq']); 797 WC()->session->set('set_md', $responce_update['MD']);798 $redirect = $order->get_checkout_payment_url(true);799 wp_redirect($redirect);800 852 } 853 854 WC()->session->set('set_md', $responce_update['MD']); 855 856 $redirect = $order->get_checkout_payment_url(true); 857 858 return array( 859 'result' => 'success', 860 'redirect' => $redirect, 861 ); 801 862 } 802 863 } … … 811 872 } 812 873 813 private function is_valid_expire_date($expiry_date) { 814 815 $month = $year = ''; 816 $month = substr($expiry_date, 0, 2); 817 $year = substr($expiry_date, 5, 7); 818 $year = '20' . $year; 819 820 if ($month > 12) { 821 return false; 822 } 823 824 if (date("Y-m-d", strtotime($year . "-" . $month . "-01")) > date("Y-m-d")) { 825 return true; 826 } 827 828 return false; 829 } 830 831 private function if_meta_product() { 874 private function wsap_if_meta_product() 875 { 832 876 global $woocommerce; 833 877 … … 854 898 } 855 899 856 function add_sagepay_gateway($methods) {857 $methods[] = 'woocommerce_sagepay';858 return $methods;859 }860 861 add_filter('woocommerce_payment_gateways', 'add_sagepay_gateway');862 900 }
Note: See TracChangeset
for help on using the changeset viewer.