Plugin Directory

Changeset 1768689


Ignore:
Timestamp:
11/16/2017 07:47:42 PM (8 years ago)
Author:
Helcim
Message:

1.0.5

  • Added Test Field in Plugin Configuration
  • Added Transaction Logs
  • Fixed Order Notes not showing in Commerce
Location:
helcim-commerce-for-woocommerce/trunk
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • helcim-commerce-for-woocommerce/trunk/class-wc-commerce-helcim.php

    r1658774 r1768689  
    1111 * @class       WC_Commerce_Helcim_JS
    1212 * @extends     WC_Payment_Gateway
    13  * @version     1.0.4
     13 * @version     1.0.5
    1414 * @author      Helcim Inc.
    1515 */
    1616class WC_Commerce_Helcim_JS extends WC_Payment_Gateway {
     17
     18    /**
     19     * @var Reference to logging class.
     20     */
     21    private static $log;
    1722
    1823    /**
     
    2328     */
    2429    public function __construct() {
     30
    2531        global $woocommerce;
    2632
     
    2834        $this->method_title = __( 'HelcimCommerce', 'woocommerce' );
    2935        $this->validated    = 0;
    30         // Load settings       
     36        // Load settings
    3137        $this->init_settings();
    3238        $this->init_form_fields();
    3339
    3440        // Define user set variables
     41        $this->test         = $this->get_option( 'test' );
     42        $this->token        = $this->get_option( 'token' );
    3543        $this->title        = $this->get_option( 'title' );
     44        $this->description  = $this->get_option( 'description' );
    3645        $this->show_logo    = $this->get_option( 'show_logo' ) == 'yes' ? 1 : 0;
    37         $this->description  = $this->get_option( 'description' );
    38         $this->token        = $this->get_option( 'token' );
    3946
    4047        if ($this->show_logo)
    41             $this->icon         = apply_filters( 'woocommerce_helcim_checkout_icon', plugins_url('assets/images/helcim_checkout_logo.png', __FILE__));;
     48            $this->icon         = apply_filters( 'woocommerce_helcim_checkout_icon', plugins_url('assets/images/helcim_checkout_logo.png', __FILE__));
    4249       
    4350
    4451        add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
    45         add_action( 'woocommerce_api_wc_gateway_helcim', array( $this, 'check_response' ) );       
     52        add_action( 'woocommerce_api_wc_gateway_helcim', array( $this, 'check_response' ) );
     53
     54        wp_register_script( 'helcim_scripts', untrailingslashit( plugins_url( '/', __FILE__ ) ) . '/assets/js/helcim-scripts.js', array(), $this->version );
     55        wp_enqueue_script( 'helcim_scripts' );
     56
    4657    }
    4758
     
    8495                        )
    8596            );
     97
     98        $this->form_fields['test'] = array(
     99                            'title' => __('Test', 'woocommerce' ),
     100                            'type' => 'checkbox',
     101                            'label' => __( 'Test Mode', 'woocommerce' ),
     102                            'default' => 'no'
     103                            );
    86104
    87105        $this->form_fields['token'] = array(
     
    140158            }
    141159
     160            // LOG
     161            $this->log('ORDER '.$order_id.' APPROVED');
     162
    142163            // UPDATE
    143164            $woocommerce->cart->empty_cart();
     
    157178                wc_add_notice('<b>Payment error:</b> '.@$_REQUEST['responseMessage'].' - Please contact merchant and verify if payment was already completed.','error');
    158179
     180                // LOG
     181                $this->log('ORDER '.$order_id.' ERROR - '.$_REQUEST['responseMessage']);
     182
    159183            }else{
    160184
    161185                // SET NOTICE
    162186                wc_add_notice('<b>Payment error:</b> Please contact merchant and verify if payment was already completed.','error');
     187
     188                // LOG
     189                $this->log('ORDER '.$order_id.' ERROR - RESPONSE MESSAGE IS NOT SET');
    163190
    164191            }
     
    213240        }
    214241
    215         // JAVASCRIPT FUNCTIONS
    216         $this->hcmJS_functions();
    217 
    218242        ?>
     243
     244        <!-- HELCIM JS -->
     245        <script type="text/javascript" src="https://secure.myhelcim.com/js/version2.js"></script>
    219246
    220247        <!-- SCRIPT -->
     
    241268        <input type="hidden" id="token" value="<?php echo $this->token; ?>">
    242269        <input type="hidden" id="user_id" value="<?php echo get_current_user_id(); ?>">
     270        <input type="hidden" id="test" value="<?php echo $this->test; ?>">
    243271
    244272        <?php
     
    332360    }
    333361
    334     // CREATE HIDDEN INPUT FIELDS
     362    /**
     363    * Create Hidden Input Fields
     364    *
     365    * @access private
     366    * @param string $fieldName
     367    * @param string $fieldValue
     368    * @return void
     369    */
    335370    private function create_hidden_input_fields($fieldName,$fieldValue){
    336371
     
    347382    }
    348383   
    349     // GENERATE ORDER INPUT FIELDS
     384    /**
     385    * Create Order Input Fields
     386    *
     387    * @access private
     388    * @param int $order_id
     389    * @return void
     390    */
    350391    private function generate_order_input_fields($order_id){
    351392
     
    397438
    398439                // INCREASE
    399                 $orderItemCounter++;
     440                @$orderItemCounter++;
    400441
    401442                $product = $order->get_product_from_item( $item );
     
    426467
    427468                // INCREASE
    428                 $orderItemCounter++;
     469                @$orderItemCounter++;
    429470
    430471                // CREATE INPUT FIELDS
     
    456497
    457498                // INCREASE
    458                 $orderItemCounter++;
     499                @$orderItemCounter++;
    459500
    460501                // CREATE INPUT FIELDS
     
    471512
    472513    }
    473    
    474     // JAVASCRIPT FUNCTIONS
    475     private function hcmJS_functions(){
    476 
    477     ?>
    478 
    479     <!-- HELCIM JS -->
    480     <script type="text/javascript" src="https://secure.myhelcim.com/js/version2.js"></script>
    481 
    482     <script type="text/javascript">
    483 
    484         function update_submit(){
    485 
    486             // SET
    487             var submitButton = document.getElementById('place_order');
    488 
    489             // CHECK SUBMIT BUTTON
    490             if(submitButton != null){
    491 
    492                 // submitButton.type = "button";
    493                 submitButton.setAttribute("onclick","javascript: return hcmStartProcess();");
    494 
    495             }else{
    496 
    497                 // SUBMIT AGAIN AFTER 1 SECOND
    498                 setTimeout(function(){ update_submit(); },1);
    499 
    500             }
    501 
    502         }
    503 
    504         function get_value(input){
    505 
    506             // SET
    507             var value = '';
    508 
    509             // CHECK INPUT
    510             if(input != null && typeof input === 'object'){
    511 
    512                 // CHECK TAG NAME
    513                 if('INPUT' == input.tagName){
    514 
    515                     // INPUT
    516 
    517                     // CHECK TYPE
    518                     if('text' == input.type){
    519 
    520                         // TEXT INPUT
    521                         value = input.value;
    522 
    523                     }else if('hidden' == input.type){
    524 
    525                         // HIDDEN INPUT
    526                         value = input.value;
    527 
    528                     }
    529 
    530                 }else if('SELECT' == input.tagName){
    531 
    532                     // SELECT
    533                     value = input.options[input.selectedIndex].value;
    534 
    535                 }
    536 
    537             }
    538 
    539             // RETURN
    540             return value.trim();
    541         }
    542 
    543         function create_hidden_input_fields(form,inputName,inputValue){
    544 
    545             // CHECK INPUTS
    546             if(form == null){ console.log('Missing Form Name'); return; }
    547             if(inputName == null){ console.log('Missing Input Name'); return; }
    548             if(inputValue == null){ console.log('Missing Input Value'); return; }
    549 
    550             // TRIM
    551             inputValue = inputValue.trim();
    552 
    553             // CHECK
    554             if(document.getElementById(inputName) != null){
    555 
    556                 // UPDATE
    557                 // document.getElementById(inputName).type = 'hidden';
    558                 // document.getElementById(inputName).id = inputName;
    559                 // document.getElementById(inputName).name = inputName;
    560                 // document.getElementById(inputName).value = inputValue;
    561 
    562             }else{
    563 
    564                 // NEW
    565                 var input = document.createElement('input');
    566                 input.type = 'hidden';
    567                 input.id = inputName;
    568                 input.name = inputName;
    569                 input.value = inputValue;
    570                 form.appendChild(input);
    571 
    572             }
    573 
    574         }
    575 
    576         function check_required_fields(){
    577 
    578             // CHECK
    579             if(typeof required_fields === 'undefined'){
    580 
    581                 // NO REQUIRED FIELDS
    582                 return true;
    583 
    584             }else{
    585 
    586                 // SET
    587                 var required_fields_array = JSON.parse(required_fields);
    588 
    589                 // GO THROUGH EACH REQUIRED FIELDS
    590                 for(var counter = 0; counter < required_fields_array.length; counter++){
    591 
    592                     // SET
    593                     var input_field_id = required_fields_array[counter]['key'];
    594                     var input_field_label = required_fields_array[counter]['label'];
    595                     var input_field_object = document.getElementById(input_field_id);
    596 
    597                     // CHECK
    598                     if(input_field_object == null){
    599 
    600                         // ERRROR
    601                         alert('WooCommerce Required Field is Missing - ' + input_field_label);
    602                         return false;
    603 
    604                     }else if(input_field_object.value.trim() == ''){
    605 
    606                         // ERRROR
    607                         alert('WooCommerce Required Field is Missing - ' + input_field_label);
    608                         input_field_object.focus();
    609                         return false;
    610 
    611                     }
    612 
    613                 }
    614 
    615             }
    616 
    617             // NO ERROR
    618             return true;
    619 
    620         }
    621 
    622         //////////////////////////////////////////////////////////////////////////////////////
    623         // FUNCTION - HIDE
    624         //////////////////////////////////////////////////////////////////////////////////////
    625         function hcmHide(id){
    626 
    627             // CHECK FOR ELEMENT EXISTS
    628             if(document.getElementById(id) != null){
    629 
    630                 // HIDE
    631                 document.getElementById(id).style.display = 'none';
    632 
    633             }
    634 
    635         }
    636 
    637         //////////////////////////////////////////////////////////////////////////////////////
    638         // FUNCTION - DISPLAY
    639         //////////////////////////////////////////////////////////////////////////////////////
    640         function hcmDisplay(id){
    641 
    642             // CHECK FOR ELEMENT EXISTS
    643             if(document.getElementById(id) != null){
    644 
    645                 // SHOW
    646                 document.getElementById(id).style.display = '';
    647 
    648             }
    649 
    650         }
    651 
    652         function hcmStartProcess(){
    653 
    654             // SHOW BLACK SCREEN
    655             hcmDisplay('LoadingScreen1');
    656 
    657             // SET
    658             var sleepMS = 1 * 1000;
    659             var helcimResults = document.getElementById('helcimResults');
    660             var response = document.getElementById('response');
    661             var submitButton = document.getElementById('place_order');
    662             var woocommerceForm = null;
    663             var createaccount = document.getElementById('createaccount');
    664             var paymentMethod = document.getElementById('payment_method_helcimjs');
    665 
    666             // CHECK PAYMENT METHOD
    667             if(paymentMethod == null){ return true; }
    668             if(!paymentMethod.checked){ return true; }
    669 
    670             // CHECK AND SET FORM
    671             if(document.forms['checkout'] != null){ woocommerceForm = document.forms['checkout']; }
    672             else if(document.forms['order_review'] != null){ woocommerceForm = document.forms['order_review']; }
    673 
    674             //
    675             // CHECKING
    676             //
    677 
    678             // CHECK CREATE ACCOUNT
    679             if(createaccount != null && createaccount.checked == true){
    680 
    681                 // ERROR
    682                 alert('Not Supported at the Moment, Please Create an Account First.');
    683                 createaccount.checked = false;
    684                 hcmHide('LoadingScreen1');
    685                 return false;
    686 
    687             }
    688 
    689             // CHECK FORM
    690             if(woocommerceForm == null){
    691 
    692                 // ERROR
    693                 console.log('Missing Form');
    694                 hcmHide('LoadingScreen1');
    695                 return false;
    696 
    697             }
    698 
    699             // CHECK SUBMIT BUTTON
    700             if(submitButton == null){
    701 
    702                 // ERROR
    703                 console.log('Missing Submit Button');
    704                 hcmHide('LoadingScreen1');
    705                 return false;
    706 
    707             }
    708 
    709             // CHECK
    710             if(response != null){
    711 
    712                 //
    713                 // TRANSACTION COMPLETED
    714                 //
    715 
    716                 // LOOK FOR APPROVED
    717                 if(response.value == 1){
    718 
    719                     // APPROVED
    720                     console.log('Approved');
    721 
    722                 }else{
    723 
    724                     // FAILED
    725                     console.log('Failed');
    726 
    727                 }
    728 
    729                 hcmHide('LoadingScreen1');
    730 
    731                 // SUBMIT
    732                 return true;
    733 
    734             }else if(helcimResults != null){
    735 
    736                 //
    737                 // CHECK FOR HELCIM RESULTS
    738                 //
    739 
    740                 // LOOK FOR CONNECTING
    741                 if(helcimResults.innerHTML.indexOf('CONNECTING') > -1){
    742 
    743                     // ONGOING TRANSACTION
    744                     console.log('Ongoing Transaction');
    745 
    746                     // SUBMIT AGAIN AFTER 5 SECONDS
    747                     setTimeout(function(){
    748 
    749                         // SUBMIT
    750                         submitButton.click();
    751 
    752                     },sleepMS);
    753 
    754                     // RETURN
    755                     return false;
    756 
    757                 }
    758 
    759                 // LOOK FOR ERROR
    760                 if(helcimResults.innerHTML.indexOf('ERROR') > -1){
    761 
    762                     // TRANSACTION FAILED
    763                     console.log(helcimResults.innerHTML);
    764                     alert(helcimResults.innerHTML);
    765 
    766                     // CLEAR
    767                     helcimResults.innerHTML = '';
    768 
    769                     hcmHide('LoadingScreen1');
    770                     return false;
    771 
    772                 }
    773 
    774             }else{
    775 
    776                 //
    777                 // HELCIM RESULTS DOES NOT EXIST
    778                 //
    779 
    780                 console.log('Missing Helcim Results');
    781                 hcmHide('LoadingScreen1');
    782                 return false;
    783 
    784             }
    785 
    786             //
    787             // CREATE FIELDS
    788             //
    789 
    790             // SET
    791             var billing_first_name = document.getElementById('billing_first_name');
    792             var billing_last_name = document.getElementById('billing_last_name');
    793             var billing_company = document.getElementById('billing_company');
    794             var billing_country = document.getElementById('billing_country');
    795             var billing_address_1 = document.getElementById('billing_address_1');
    796             var billing_address_2 = document.getElementById('billing_address_2');
    797             // var billing_city = document.getElementById('billing_city');
    798             var billing_state = document.getElementById('billing_state');
    799             var billing_postcode = document.getElementById('billing_postcode');
    800             // var billing_phone = document.getElementById('billing_phone');
    801             // var billing_email = document.getElementById('billing_email');
    802             var order_comments = document.getElementById('order_comments');
    803             var user_id = document.getElementById('user_id');
    804 
    805             // BUSINESS NAME
    806             if(user_id != null && user_id.value > 0){
    807 
    808                 // CREATE INPUT FIELD
    809                 create_hidden_input_fields(woocommerceForm,'customerCode',get_value(user_id));
    810 
    811             }
    812 
    813             // CONTACT NAME
    814             if(billing_first_name != null || billing_last_name != null){
    815 
    816                 // SET
    817                 var billing_contactName = '';
    818 
    819                 // SET FIRST NAME
    820                 if(billing_first_name != null){ billing_contactName += get_value(billing_first_name); }
    821 
    822                 // LAST NAME
    823                 if(billing_last_name != null){ billing_contactName += ' '+get_value(billing_last_name); }
    824 
    825                 // CREATE INPUT FIELD
    826                 create_hidden_input_fields(woocommerceForm,'billing_contactName',billing_contactName.trim());
    827 
    828             }
    829 
    830             // BUSINESS NAME
    831             if(billing_company != null){
    832 
    833                 // CREATE INPUT FIELD
    834                 create_hidden_input_fields(woocommerceForm,'billing_businessName',get_value(billing_company));
    835 
    836             }
    837 
    838             // STREET 1
    839             if(billing_address_1 != null){
    840 
    841                 // CREATE INPUT FIELD
    842                 create_hidden_input_fields(woocommerceForm,'billing_street1',get_value(billing_address_1));
    843 
    844             }
    845 
    846             // STREET 2
    847             if(billing_address_2 != null){
    848 
    849                 // CREATE INPUT FIELD
    850                 create_hidden_input_fields(woocommerceForm,'billing_street2',get_value(billing_address_2));
    851 
    852             }
    853 
    854             // // CITY
    855             // if(billing_city != null){
    856 
    857             //  // SET
    858             //  var billing_city = billing_city.value;
    859 
    860             //  // CREATE INPUT FIELD
    861             //  create_hidden_input_fields(woocommerceForm,'billing_city',billing_city);
    862 
    863             // }
    864 
    865             // PROVINCE
    866             if(billing_state != null){
    867 
    868                 // CREATE INPUT FIELD
    869                 create_hidden_input_fields(woocommerceForm,'billing_province',get_value(billing_state));
    870 
    871             }
    872 
    873             // POSTAL CODE
    874             if(billing_postcode != null){
    875 
    876                 // CREATE INPUT FIELD
    877                 create_hidden_input_fields(woocommerceForm,'billing_postalCode',get_value(billing_postcode));
    878 
    879             }
    880 
    881             // COUNTRY
    882             if(billing_country != null){
    883 
    884                 // CREATE INPUT FIELD
    885                 create_hidden_input_fields(woocommerceForm,'billing_country',get_value(billing_country));
    886 
    887             }
    888 
    889             // // PHONE
    890             // if(billing_phone != null){
    891 
    892             //  // SET
    893             //  var billing_phone = billing_phone.value;
    894 
    895             //  // CREATE INPUT FIELD
    896             //  create_hidden_input_fields(woocommerceForm,'billing_phone',billing_phone);
    897 
    898             // }
    899 
    900             // // EMAIL
    901             // if(billing_email != null){
    902 
    903             //  // SET
    904             //  var billing_email = billing_email.value;
    905 
    906             //  // CREATE INPUT FIELD
    907             //  create_hidden_input_fields(woocommerceForm,'billing_email',billing_email);
    908 
    909             // }
    910 
    911             // COMMENTS
    912             if(order_comments != null){
    913 
    914                 // CREATE INPUT FIELD
    915                 create_hidden_input_fields(woocommerceForm,'comments',get_value(order_comments));
    916 
    917             }
    918 
    919             // CHECK FOR REQUIRED FIELDS
    920             if(!check_required_fields()){
    921 
    922                 console.log('Missing Required Fields');
    923                 hcmHide('LoadingScreen1');
    924                 return false;
    925 
    926             }
    927 
    928             // PROCESS
    929             console.log('Helcim Process');
    930             helcimProcess();
    931 
    932             // SUBMIT AGAIN AFTER 5 SECONDS
    933             setTimeout(function(){
    934 
    935                 // SUBMIT
    936                 submitButton.click();
    937 
    938             },sleepMS);
    939 
    940             // DEFAULTS
    941             console.log('Reached end of function. return false');
    942             return false;
    943 
    944         }
    945     </script>
    946 
    947     <?php
    948 
    949     }
    950 
    951     // GET WOOCOMMERCE ORDER ID
     514
     515    /**
     516    * Get WooCommerce ID from Commerce Order Number
     517    *
     518    * @access private
     519    * @param string $commerce_order_number
     520    * @return int
     521    */
    952522    private function get_order_id($commerce_order_number){
    953523
     
    957527    }
    958528
    959     // SET COMMERCE ORDER NUMBER
     529    /**
     530    * Create Commerce Order Number from WooCommerce order id
     531    *
     532    * @access private
     533    * @param int $order_id
     534    * @return string
     535    */
    960536    private function set_order_number($order_id){
    961537
     
    965541    }
    966542
    967     // GENERATE REQUIRED INPUT FIELDS
     543    /**
     544    * Generate Required Input Fields
     545    *
     546    * @access private
     547    * @return void
     548    */
    968549    private function generate_required_input_fields(){
    969550
     
    1005586    }
    1006587
     588    /**
     589    * Logs
     590    *
     591    * @access public
     592    * @param string $message
     593    * @return void
     594    *
     595    */
     596    public static function log($message){
     597        if ( empty( self::$log ) ) {
     598            self::$log = new WC_Logger();
     599        }
     600
     601        self::$log->add( 'helcim-commerce', $message );
     602
     603    }
     604
    1007605}
  • helcim-commerce-for-woocommerce/trunk/index.php

    r1658774 r1768689  
    44Plugin URI: https://www.helcim.com/
    55Description: Helcim Commerce for WooCommerce
    6 Version: 1.0.4
     6Version: 1.0.5
    77Author: Helcim Inc.
    88Author URI: https://www.helcim.com/
  • helcim-commerce-for-woocommerce/trunk/readme.txt

    r1658774 r1768689  
    33Tags: helcim, helcim commerce, woocommerce, woocommerce payments, woocommerce payment gateway, payment gateway, shopping cart, wordpress payment gateway, woocommerce shopping cart, wordpress shopping cart, payment gateway for woocommerce, payments, credit cards, accept credit cards, recurring billing, woocommerce gateway, woocommerce payment plugin, woocommerce credit cards, accept credit cards woocommerce, credit card gateway woocommerce, accept credit cards on woocommerce, process payments, process credit cards, accept visa, accept mastercard,checkout, accept payments, merchant account, merchant services
    44Requires at least: 4.7.3
    5 Tested up to: 4.7.4
     5Tested up to: 4.8.3
    66
    77== Description ==
     
    1919
    2020**REQUIREMENTS:**       
    21        - WooCommerce 2.6.14 to 3.0.4
     21       - WooCommerce 2.6.14 to 3.2.3
    2222       - [US Merchant Account Sign Up](https://www.helcim.com/us/apply/ "Unlock Payment Gateway for US Business")     
    2323       - [Canadian Merchant Account Sign Up](https://www.helcim.com/ca/apply/ "Unlock Payment Gateway for Canadian Business") 
     
    5353
    5454
    55 ==  Changelog ==
     55== Changelog ==
     56
     57= 1.0.5 =
     58* Added Test Field in Plugin Configuration
     59* Added Transaction Logs
     60* Fixed Order Notes not showing in Commerce
    5661
    5762= 1.0.4 =
Note: See TracChangeset for help on using the changeset viewer.