Plugin Directory

Changeset 2216770


Ignore:
Timestamp:
12/23/2019 08:11:28 AM (6 years ago)
Author:
wp_estatic
Message:

Made changes in funcations

Location:
woo-sagepay-addon/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • woo-sagepay-addon/trunk/README.txt

    r2212885 r2216770  
    33Tags: 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.
    44Requires at least: 4.0 & WooCommerce 2.3+
    5 Tested up to: 5.3 & Woocommerce 3.8.1
     5Tested up to: 5.3.2 & Woocommerce 3.8.1
    66Stable tag: trunk
    77License: GPLv3
     
    109109= 1.0.3 =
    110110* Fix - Payment method reduce issue
    111 = 1.0.4 =
    112 * Fix - Remove depricated funcations
     111= 1.0.5 =
     112* Fix - Made funcation changes.
    113113== Upgrade Notice ==
  • woo-sagepay-addon/trunk/woo-sagepay-addon.php

    r2212885 r2216770  
    55 * Plugin URL:          Addon for sagepay and WooCommerce
    66 * 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.4
     7 * Version:             1.0.5
    88 * WC requires at least:2.3
    99 * WC tested up to:     3.8.1
    1010 * Requires at least:   4.0+
    11  * Tested up to:        5.3
     11 * Tested up to:        5.3.2
    1212 * Contributors:        wp_estatic
    1313 * Author:              Estatic Infotech Pvt Ltd
     
    1717 * @category Woocommerce Payment Gateway
    1818 */
    19 require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
     19
     20require_once ABSPATH . 'wp-admin/includes/plugin.php';
    2021$logs_message = "";
    2122
     
    2324
    2425    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);
    2728    });
    2829
    29     function change_text($translated_text, $untranslated_text, $domain) {
     30    function wsap_change_text($translated_text, $untranslated_text, $domain)
     31    {
    3032        $old = array(
    3133            "Plugin <strong>activated</strong>.",
    32             "Selected plugins <strong>activated</strong>."
     34            "Selected plugins <strong>activated</strong>.",
    3335        );
    3436
     
    3941            remove_filter(current_filter(), __FUNCTION__, 99);
    4042        }
     43
    4144        return $translated_text;
    4245    }
    4346
    44     return FALSE;
     47    return false;
    4548}
    4649
    47 add_action('plugins_loaded', 'init_woocommerce_sagepay', 0);
    48 
    49 function init_woocommerce_sagepay() {
     50add_action('plugins_loaded', 'wsap_init_woocommerce_sagepay', 0);
     51
     52function wsap_init_woocommerce_sagepay()
     53{
    5054
    5155    if (!class_exists('WC_Payment_Gateway_CC')) {
     
    5559    load_plugin_textdomain('woocommerce', false, dirname(plugin_basename(__FILE__)) . '/lang');
    5660
    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        {
    6075            global $woocommerce;
    6176
     
    6580            $this->has_fields = true;
    6681            $this->notify_url = add_query_arg('wc-api', 'woocommerce_sagepay', home_url('/'));
     82
    6783            $this->init_form_fields();
    6884            $this->init_settings();
     85
    6986            $this->title = $this->get_option('title');
    7087            $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'));
     
    7794            $this->sagepay_cardtypes = $this->get_option('sagepay_cardtypes');
    7895
    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);
    81109            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        {
    95114            if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
    96115
     
    105124        }
    106125
    107         function sagepay_card_type($args, $payment_id) {
     126        function sagepay_card_type($args, $payment_id)
     127        {
    108128            $new_cards_type = "";
    109129            if ($payment_id == $this->id) {
     
    130150        }
    131151
    132         public function get_icon() {
     152        public function get_icon()
     153        {
    133154            if ($this->get_option('show_accepted') == 'yes') {
    134155                $get_cardtypes = $this->get_option('sagepay_cardtypes');
     
    145166        }
    146167
    147         private function sagepay_ssl($url) {
     168        private function sagepay_ssl($url)
     169        {
    148170            if ('yes' == get_option('woocommerce_sagepay_ssl_checkout')) {
    149171                $url = str_replace('http:', 'https:', $url);
     
    152174        }
    153175
    154         public function init_form_fields() {
     176        public function init_form_fields()
     177        {
    155178            $this->form_fields = array(
    156179                'enabled' => array(
     
    158181                    'type' => 'checkbox',
    159182                    'label' => __('Enable Sagepay', 'woocommerce'),
    160                     'default' => 'yes'
     183                    'default' => 'yes',
    161184                ),
    162185                'title' => array(
     
    165188                    'description' => __('Display this title on checkout page.', 'woocommerce'),
    166189                    'default' => __('Sagepay', 'woocommerce'),
    167                     'desc_tip' => true
     190                    'desc_tip' => true,
    168191                ),
    169192                'description' => array(
     
    171194                    'type' => 'textarea',
    172195                    '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'),
    174197                ),
    175198                'vendorname' => array(
     
    177200                    'type' => 'text',
    178201                    'desc_tip' => __('Please enter your vendor name which is provided by your sagepay account.', 'woocommerce'),
    179                     'default' => ''
     202                    'default' => '',
    180203                ),
    181204                'mode' => array(
     
    184207                    'options' => array(
    185208                        'test' => 'Test',
    186                         'live' => 'Live'
     209                        'live' => 'Live',
    187210                    ),
    188                     'desc_tip' => __('Select the mode to accept.', 'woocommerce')
     211                    'desc_tip' => __('Select the mode to accept.', 'woocommerce'),
    189212                ),
    190213                'send_shipping' => array(
     
    193216                    'options' => array(
    194217                        'auto' => 'Auto',
    195                         'yes' => 'Billing Address'
     218                        'yes' => 'Billing Address',
    196219                    ),
    197220                    'desc_tip' => __('Slect your send shipping address.', 'woocommerce'),
    198                     'default' => 'auto'
     221                    'default' => 'auto',
    199222                ),
    200223                'transtype' => array(
     
    206229                        'AUTHENTICATE' => __('Authenticate', 'woocommerce'),
    207230                    ),
    208                     'desc_tip' => __('Select Payment, Deferred or Authenticate.', 'woocommerce')
     231                    'desc_tip' => __('Select Payment, Deferred or Authenticate.', 'woocommerce'),
    209232                ),
    210233                'show_accepted' => array(
     
    218241                        'no' => 'No',
    219242                    ),
    220                     'default' => array('yes'),
     243                    'default' => 'yes',
    221244                ),
    222245                'sagepay_cardtypes' => array(
     
    233256                        'visa' => 'Visa',
    234257                    ),
    235                 )
     258                ),
    236259            );
    237260        }
    238261
    239         function payment_fields() {
    240             echo wpautop(wptexturize($this->description));
    241             $this->form();
    242         }
    243 
    244         function validate_fields() {
     262        function validate_fields()
     263        {
    245264            global $woocommerce;
    246265
     
    249268            }
    250269
    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']))) {
    252271                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']))) {
    254273                wc_add_notice('<strong>Credit Card Number</strong> ' . __('is not a valid credit card number.', 'woocommerce'), 'error');
    255274            }
    256275
    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']))) {
    258277                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']))) {
    260279                wc_add_notice('<strong>Card Expiry Date</strong> ' . __('is not a valid expiry date.', 'woocommerce'), 'error');
    261280            }
    262281
    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        {
    269289            if (empty($credit_card)) {
    270290                return false;
     
    273293        }
    274294
    275         public function field_name($name) {
     295        public function field_name($name)
     296        {
    276297            return $this->supports('tokenization') ? '' : ' name="' . esc_attr($this->id . '-' . $name) . '" ';
    277298        }
    278299
    279         private function if_expire_date_is_empty($expiry_date) {
    280 
     300        private function wsap_if_expire_date_is_empty($expiry_date)
     301        {
    281302            $expiry_date = str_replace(' / ', '', $expiry_date);
    282303
    283             if (is_numeric($expiry_date) && ( strlen($expiry_date) == 4 )) {
     304            if (is_numeric($expiry_date) && (strlen($expiry_date) == 4)) {
    284305                return true;
    285306            }
     
    287308        }
    288309
    289         private function if_cvv_number_is_empty($ccv_number) {
     310        private function wsap_if_cvv_number_is_empty($ccv_number)
     311        {
    290312            $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        {
    295369            $number = preg_replace('/[^\d]/', '', $number);
    296370
     
    314388        }
    315389
    316         function receipt_page($order) {
     390        function receipt_page($order)
     391        {
    317392            global $woocommerce;
    318393
     
    321396        }
    322397
    323         public function generate_sagepay_form($order_id) {
     398        public function generate_sagepay_form($order_id)
     399        {
    324400            global $woocommerce;
    325401
    326402            $order = new WC_Order($order_id);
    327403
    328             $sagepay_args = array_merge(
    329                 array(
     404            if (!empty(WC()->session->get('set_pareq'))) {
     405                $sagepay_args = array(
    330406                    'PaReq' => WC()->session->get('set_pareq'),
    331407                    'MD' => WC()->session->get('set_md'),
    332                     'TermUrl' => $this->notify_url
    333                 )
    334             );
    335 
     408                    'TermUrl' => $this->notify_url,
     409                );
     410            }
    336411            $sagepay_args_array = array();
    337412
     
    339414                $sagepay_args_array[] = '<input type="hidden" name="' . esc_attr($key) . '" value="' . esc_attr($value) . '" />';
    340415            }
    341 
     416           
    342417            wc_enqueue_js('
    343418                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') . '",
    345420                    overlayCSS:
    346421          {
     
    348423                        opacity: 0.6
    349424          },
    350          
     425
    351426        });
    352427        jQuery("#submit_sagepay_payment_form").click();
    353428      ');
    354 
     429       
    355430            return '<form action="' . esc_url(WC()->session->get('set_acsurl')) . '" method="post" id="sagepay_payment_form">
    356431      ' . implode('', $sagepay_args_array) . '
    357432      <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 &amp; restore cart', 'woocommerce') . '</a>
    358433      </form>';
    359             // var_dump($dd);exit;
    360         }
    361 
    362         function process_payment($order_id) {
     434
     435        }
     436
     437        function process_payment($order_id)
     438        {
    363439            global $woocommerce;
    364 
     440           
    365441            $order = new WC_Order($order_id);
    366442
     
    376452            WC()->session->set('sagepay_set', $orderid);
    377453            WC()->session->set('sagepay_oid', $order_id);
    378 
    379454
    380455            $product_item['BillingSurname'] = $order->billing_last_name;
     
    392467            $product_item['BillingPhone'] = $order->billing_phone;
    393468
    394 
    395             if ($this->if_meta_product() == true || $this->send_shipping == 'yes') {
     469            if ($this->wsap_if_meta_product() == true || $this->send_shipping == 'yes') {
    396470                $product_item['DeliverySurname'] = $order->billing_last_name;
    397471                $product_item['DeliveryFirstnames'] = $order->billing_first_name;
     
    454528            $product_item['product_categories'] = $this->get_categories;
    455529            $product_item['customer_email'] = $order->billing_email;
    456             $product_item['VPSTxID'] = //   $product_item['CreateToken'] = 1;
    457530
    458531            $post_values = "";
     
    471544                'body' => $post_values,
    472545                'method' => 'POST',
    473                 'sslverify' => FALSE
     546                'sslverify' => false,
    474547            ));
    475 
    476548
    477549            if (!is_wp_error($response) && $response['response']['code'] >= 200 && $response['response']['code'] < 300) {
     
    486558                }
    487559
    488                 if (isset($responce_update['Status']))
     560                if (isset($responce_update['Status'])) {
    489561                    update_post_meta($order->id, 'Status', $responce_update['Status']);
    490 
    491                 if (isset($responce_update['AVSCV2']))
     562                }
     563
     564                if (isset($responce_update['AVSCV2'])) {
    492565                    update_post_meta($order->id, 'AVSCV2', $responce_update['AVSCV2']);
    493 
    494                 if (isset($responce_update['TxAuthNo']))
     566                }
     567
     568                if (isset($responce_update['TxAuthNo'])) {
    495569                    update_post_meta($order->id, 'TxAuthNo', $responce_update['TxAuthNo']);
    496 
    497                 if (isset($responce_update['PostCodeResult']))
     570                }
     571
     572                if (isset($responce_update['PostCodeResult'])) {
    498573                    update_post_meta($order->id, 'PostCodeResult', $responce_update['PostCodeResult']);
    499 
    500                 if (isset($responce_update['VPSTxId']))
     574                }
     575
     576                if (isset($responce_update['VPSTxId'])) {
    501577                    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'])) {
    504582                    update_post_meta($order->id, 'StatusDetail', $responce_update['StatusDetail']);
    505 
    506                 if (isset($responce_update['SecurityKey']))
     583                }
     584
     585                if (isset($responce_update['SecurityKey'])) {
    507586                    update_post_meta($order->id, 'SecurityKey', $responce_update['SecurityKey']);
    508 
    509                 if (isset($responce_update['CV2Result']))
     587                }
     588
     589                if (isset($responce_update['CV2Result'])) {
    510590                    update_post_meta($order->id, 'CV2Result', $responce_update['CV2Result']);
    511 
    512                 if (isset($responce_update['3DSecureStatus']))
     591                }
     592
     593                if (isset($responce_update['3DSecureStatus'])) {
    513594                    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') != '') {
    516598                    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'])) {
    519602                    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                }
    524604
    525605                if ($responce_update['Status'] == "OK" || $responce_update['Status'] == "REGISTERED" || $responce_update['Status'] == "AUTHENTICATED") {
     
    529609                    $redirect_url = $this->get_return_url($order);
    530610
    531 
    532611                    return array(
    533612                        'result' => 'success',
    534                         'redirect' => $redirect_url
     613                        'redirect' => $redirect_url,
    535614                    );
    536615                } else if ($responce_update['Status'] == "3DAUTH") {
    537616
    538617                    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                        }
    552634                    }
    553635                }
     
    557639        }
    558640
    559         static public function setStore($key, $value) {
     641        static public function setStore($key, $value)
     642        {
     643
    560644            if (gettype($value) == "object") {
    561645                $_SESSION[$key] = serialize($value);
     
    565649        }
    566650
    567         public function getSharedUrl($method, $env = '') {
     651        public function getSharedUrl($method, $env = '')
     652        {
     653
    568654            $env = $this->_validEnvironment($env);
    569655            if (isset($this->_sharedUrls[$env][$method])) {
     
    573659        }
    574660
    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
    576664            $file = fopen($file_name, 'r+');
    577665            $message_old = fread($file, filesize($file_name));
     
    582670        }
    583671
    584         public function restore_order_stock($order_id) {
     672        public function wsap_restore_order_stock($order_id)
     673        {
     674
    585675            $order = new WC_Order($order_id);
    586676
     
    588678            $VPSTxId = substr($custom['VPSTxId'][0], 1, -1);
    589679
    590             $rand_no = wp_generate_password(12, FALSE, FALSE);
     680            $rand_no = wp_generate_password(12, false, false);
    591681            $caracter = 'Estatic';
    592682
     
    612702                    $params['TxType'] = urlencode('REFUND');
    613703                    $params['Vendor'] = urlencode('chestnutregistr');
    614                     $params['VendorTxCode'] = urlencode($generat);            //Sample value given by me
     704                    $params['VendorTxCode'] = urlencode($generat); //Sample value given by me
    615705                    $params['Amount'] = urlencode($custom['_order_total'][$i]);
    616706                    $params['Currency'] = urlencode($custom['_order_currency'][$i]);
    617707                    $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 transaction
    620                     $params['RelatedSecurityKey'] = urlencode($custom['SecurityKey'][$i]);       //securitykey of main transaction
     708                    $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
    621711                    $params['RelatedTxAuthNo'] = urlencode($custom['TxAuthNo'][$i]);
    622712
     
    624714                        'body' => $params,
    625715                        'method' => 'POST',
    626                         'sslverify' => FALSE,
     716                        'sslverify' => false,
    627717                        'timeout' => '5',
    628                         'headers' => array()
     718                        'headers' => array(),
    629719                    );
    630720
     
    650740        }
    651741
    652         public function thankyou_page() {
    653 
     742        public function thankyou_page()
     743        {
    654744            if ($this->instructions) {
    655745                echo wpautop(wptexturize($this->instructions));
     
    657747        }
    658748
    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        {
    699751            global $woocommerce;
    700752
     
    704756
    705757                $request_array = array(
    706                     'MD' => $_REQUEST['MD'],
    707                     'PARes' => $_REQUEST['PaRes'],
     758                    'MD' => sanitize_text_field($_REQUEST['MD']),
     759                    'PaRes' => sanitize_text_field($_REQUEST['PaRes']),
    708760                    'VendorTxCode' => WC()->session->get('sagepay_set'),
     761                    'VPSTxId' => WC()->session->get('set_vpstxid'),
    709762                );
    710763
    711764                $request = http_build_query($request_array);
    712 
    713                 $params = array(
    714                     'body' => $request,
    715                     'method' => 'POST',
    716                     'sslverify' => false
    717                 );
    718765
    719766                if ($this->mode == 'test') {
     
    723770                }
    724771
    725                 $response = wp_remote_get($redirect_for_pay__url, array(
     772                $response = wp_remote_post($redirect_for_pay__url, array(
    726773                    'body' => $request,
    727774                    'method' => 'POST',
    728                     'sslverify' => false
     775                    'sslverify' => false,
    729776                ));
    730 
    731777
    732778                if (!is_wp_error($response) && $response['response']['code'] >= 200 && $response['response']['code'] < 300) {
     
    742788                    }
    743789
    744                     if (isset($responce_update['Status']))
     790                    if (isset($responce_update['Status'])) {
    745791                        update_post_meta($order->id, 'Status', $responce_update['Status']);
    746 
    747                     if (isset($responce_update['AVSCV2']))
     792                    }
     793
     794                    if (isset($responce_update['AVSCV2'])) {
    748795                        update_post_meta($order->id, 'AVSCV2', $responce_update['AVSCV2']);
    749 
    750                     if (isset($responce_update['TxAuthNo']))
     796                    }
     797
     798                    if (isset($responce_update['TxAuthNo'])) {
    751799                        update_post_meta($order->id, 'TxAuthNo', $responce_update['TxAuthNo']);
    752 
    753                     if (isset($responce_update['PostCodeResult']))
     800                    }
     801
     802                    if (isset($responce_update['PostCodeResult'])) {
    754803                        update_post_meta($order->id, 'PostCodeResult', $responce_update['PostCodeResult']);
    755 
    756                     if (isset($responce_update['VPSTxId']))
     804                    }
     805
     806                    if (isset($responce_update['VPSTxId'])) {
    757807                        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'])) {
    760812                        update_post_meta($order->id, 'StatusDetail', $responce_update['StatusDetail']);
    761 
    762                     if (isset($responce_update['SecurityKey']))
     813                    }
     814
     815                    if (isset($responce_update['SecurityKey'])) {
    763816                        update_post_meta($order->id, 'SecurityKey', $responce_update['SecurityKey']);
    764 
    765                     if (isset($responce_update['CV2Result']))
     817                    }
     818
     819                    if (isset($responce_update['CV2Result'])) {
    766820                        update_post_meta($order->id, 'CV2Result', $responce_update['CV2Result']);
    767 
    768                     if (isset($responce_update['3DSecureStatus']))
     821                    }
     822
     823                    if (isset($responce_update['3DSecureStatus'])) {
    769824                        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') != '') {
    772828                        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'])) {
    775832                        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                    }
    780834
    781835                    if ($responce_update['Status'] == "OK" || $responce_update['Status'] == "REGISTERED" || $responce_update['Status'] == "AUTHENTICATED") {
     
    785839                        $order->payment_complete();
    786840                        $redirect_url = $this->get_return_url($order);
     841
    787842                        wp_redirect($redirect_url);
    788843                        exit();
     844
    789845                    } else if ($responce_update['Status'] == "3DAUTH") {
    790846
    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'])) {
    796851                                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);
    800852                            }
     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                            );
    801862                        }
    802863                    }
     
    811872        }
    812873
    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        {
    832876            global $woocommerce;
    833877
     
    854898    }
    855899
    856     function add_sagepay_gateway($methods) {
    857         $methods[] = 'woocommerce_sagepay';
    858         return $methods;
    859     }
    860 
    861     add_filter('woocommerce_payment_gateways', 'add_sagepay_gateway');
    862900}
Note: See TracChangeset for help on using the changeset viewer.