Plugin Directory

Changeset 2298048


Ignore:
Timestamp:
05/04/2020 10:31:26 PM (6 years ago)
Author:
liorchen
Message:

1.0.131

Location:
infinitycrowds/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • infinitycrowds/trunk/includes/Gateways/GatewayCardCom_Integration.php

    r2263716 r2298048  
    1414    public function __construct($store, $order_maker_factory) {
    1515
    16         parent::__construct($store, $order_maker_factory);
    17     }
    18    
    19    
     16        parent::__construct($store, $order_maker_factory);
     17        add_action('valid-cardcom-successful-request', array($this, 'cardcom_successfull'));
     18        // add_filter('infcrwd_can_delete_order', array($this, 'can_delete_order'), 10, 2);
     19    }
     20   
     21 
     22    // public function can_delete_order($current_val, $order_id) {
     23    //     return get_post_meta( $order_id, '_payment_method', true ) != $this->key;
     24    // }
     25   
     26    // only delete the order and redirect when we get cardcom successfull
     27    public function cardcom_successfull($posted){
     28        $orderid = htmlentities($posted["order_id"]);
     29        $order = new \WC_Order( $orderid);
     30        if(empty($order)) {
     31            $order = $this->_store->get_base_order();
     32        }
     33        $merge_oids = INFCWDS_WC_Compatibility::get_order_meta($order, '_infcrwds_order_merged');
     34        if(!empty($merge_oids)) {
     35            $order = new \WC_Order( $merge_oids[0]);
     36        }
     37        WC()->cart->empty_cart();
     38        $cardcom_gw = $this->get_wc_gateway();
     39        if($cardcom_gw->successUrl!=''){
     40            $redirectTo = $cardcom_gw->successUrl;
     41        }
     42        else{
     43            $redirectTo = $cardcom_gw->get_return_url( $order );
     44        }
     45
     46        if($cardcom_gw->UseIframe){
     47            echo "<script>window.top.location.href =\"$redirectTo\";</script>";
     48            exit();
     49        }else{
     50            wp_redirect($redirectTo);
     51            exit();
     52        }
     53        return true;
     54    }
     55     
    2056    public function add_payment_options($order, $payment_options) {
    21         $payment_gateway = wc_get_payment_gateway_by_order($order);
    22         if(!$payment_gateway) {
    23             return $payment_options;
    24         }
    25         $req = new ICRequest($this->_store);
    26         $req->post('/payment-gateways/cardcom/prep-merchant-confs', array(
    27             'terminal_num' => $payment_gateway->terminalnumber,
    28             'username' => $payment_gateway->username,
    29         ));
     57        if(!$this->has_token($order)) {
     58            return;
     59        }
     60        // $payment_gateway = wc_get_payment_gateway_by_order($order);
     61        // if(!$payment_gateway) {
     62        //     return $payment_options;
     63        // }
     64        // $req = new ICRequest($this->_store);
     65        // $req->post('/payment-gateways/cardcom/prep-merchant-confs', array(
     66        //     'terminal_num' => $payment_gateway->terminalnumber,
     67        //     'username' => $payment_gateway->username,
     68        // ));
    3069        return parent::add_payment_options($order, $payment_options);
    3170    }
     71    public function get_token($order) {
     72        $token_id = get_post_meta( $order->id, 'CardcomTokenId', true );
     73        if(empty($token_id)) {
     74            // Get orders by customer with email 'woocommerce@woocommerce.com'.
     75            $billing_email = INFCWDS_WC_Compatibility::get_order_data($wc_get_order, 'billing_email');
     76            if(!empty($billing_email)) {
     77                $args = array(
     78                    'customer' => $billing_email,
     79                );
     80            }
     81            $orders = wc_get_orders( $args );
     82            foreach($orders as $past_order) {
     83                $token_id = get_post_meta( $past_order->id, 'CardcomTokenId', true );
     84                if (!empty($token_id)) {
     85                    break;
     86                }
     87            }
     88        }
     89        return $token_id;
     90    }
    3291   
    3392    public function has_token( $order ) {
    34         // $this->settings
    35         return true;
    36     }   
     93        return !empty($this->get_token($order));
     94    }
     95
     96    public function initInvoice($order_id, $sum_to_bill, $pricing){
     97        $cardcom_gw = $this->get_wc_gateway();
     98       
     99        $order = new \WC_Order( $order_id );
     100        $params = array();
     101       
     102        $SumToBill = number_format($order->get_total(), 2, '.', '') ;
     103       
     104        if(!empty(\WC_Gateway_Cardcom::$cvv_free_trm)){
     105            $params["terminalnumber"] = \WC_Gateway_Cardcom::$cvv_free_trm;
     106        }else{
     107            $params["terminalnumber"] = \WC_Gateway_Cardcom::$trm;
     108        }
     109
     110        $params["username"] = \WC_Gateway_Cardcom::$user;
     111        $params["CodePage"] = "65001";
     112
     113        $params["SumToBill"] =number_format($sum_to_bill , 2, '.', '');
     114
     115        $params["Languge"] = \WC_Gateway_Cardcom::$language;
     116
     117        $coin = \WC_Gateway_Cardcom::GetCurrency($order, \WC_Gateway_Cardcom::$CoinID);
     118        $params["CoinID"] = $coin;
     119        $params["CoinISOName"] = $order->get_currency();
     120        $compName = substr(strip_tags( preg_replace("/&#\d*;/", " ", $order->get_billing_company()) ), 0, 200);
     121        $lastName = substr(strip_tags( preg_replace("/&#\d*;/", " ", $order->get_billing_last_name()) ), 0, 200);
     122        $firstName = substr(strip_tags( preg_replace("/&#\d*;/", " ", $order->get_billing_first_name()) ), 0, 200);
     123        //$customerName = $order->get_billing_first_name()." ".$order->get_billing_last_name();
     124        $customerName = $firstName." ".$lastName;
     125        if($compName != ''){
     126            $customerName  =  $compName;
     127        }
     128
     129        $params['InvoiceHead.CustName']         = $customerName ;
     130        $params['InvoiceHead.CustAddresLine1']  = substr(strip_tags( preg_replace("/&#\d*;/", " ", $order->get_billing_address_1()) ), 0, 200);
     131        $params['InvoiceHead.CustCity'] = substr(strip_tags( preg_replace("/&#\d*;/", " ", $order->get_billing_city()) ), 0, 200);
     132
     133        $params['InvoiceHead.CustAddresLine2']  = substr(strip_tags( preg_replace("/&#\d*;/", " ", $order->get_billing_address_2()) ), 0, 200);
     134        $zip  = wc_format_postcode( $order->get_shipping_postcode(), $order->get_shipping_country());
     135        if(!empty($zip)){
     136            $params['InvoiceHead.CustAddresLine2'].=__( 'Postcode / ZIP', 'woocommerce' ).': '.$zip;
     137        }
     138        $params['InvoiceHead.CustLinePH']= substr(strip_tags( preg_replace("/&#\d*;/", " ", $order->get_billing_phone()) ), 0, 200);
     139        if(strtolower(\WC_Gateway_Cardcom::$language) =='he' || strtolower(\WC_Gateway_Cardcom::$language) =='en'){
     140            $params['InvoiceHead.Language'] = \WC_Gateway_Cardcom::$language;
     141        }else{
     142            $params['InvoiceHead.Language'] = 'en';
     143        }
     144        $params['InvoiceHead.Email'] = $order->get_billing_email();
     145        $params['InvoiceHead.SendByEmail']= 'true';
     146
     147        $params['InvoiceHead.CoinID']= $coin;
     148        $params['InvoiceHead.CoinISOName']= $order->get_currency();
     149        // error_log('country : '.$order->get_billing_country());
     150        if($order->get_billing_country() != 'IL' && \WC_Gateway_Cardcom::$InvVATFREE ==4){
     151            $params['InvoiceHead.ExtIsVatFree'] ='true';
     152        }else {
     153            $params['InvoiceHead.ExtIsVatFree'] = \WC_Gateway_Cardcom::$InvVATFREE == '1' ? 'true' : 'false';
     154        }
     155        if(strtolower(\WC_Gateway_Cardcom::$language) =='he'){
     156            $params['InvoiceHead.Comments'] = 'מספר הזמנה: '.$order->get_id();
     157        }else{
     158            $params['InvoiceHead.Comments'] = 'Order ID: '. $order->get_id();
     159        }
     160        $taxes = $pricing['tax_cost'] + $pricing['shipping_tax'];
     161        $shipping_price = $pricing['shipping_price'];
     162        $item_price = $pricing['sale_price'];
     163
     164        $params['InvoiceLines1.IsVatFree'] = $pricing['tax_cost'] == 0 ? 'true': 'false';
     165        $params['InvoiceLines1.Quantity'] = 1;
     166        $params['InvoiceLines1.ProductId'] = 'infcrwd_upsell';
     167        $params['InvoiceLines1.Description'] = 'Infinitycrowd upsell';
     168        $params['InvoiceLines1.Price'] = number_format($item_price + $pricing['tax_cost'], 2, '.', '');
     169
     170        InfcrwdsPlugin()->logger->log('CARDCOM invoice lines price ' .  $item_price);
     171        InfcrwdsPlugin()->logger->log('CARDCOM invoice pricing ' .  $pricing);
     172        InfcrwdsPlugin()->logger->log('CARDCOM invoice lines tax ' . $pricing['tax_cost']);
     173        InfcrwdsPlugin()->logger->log('CARDCOM invoice lines actual '. $params['InvoiceLines1.Price']);
     174        if($shipping_price > 0) {
     175                $params['InvoiceLines2.Description']= 'Shipping extra';
     176                $params['InvoiceLines2.Price']= $shipping_price;
     177                $params['InvoiceLines2.Quantity']=  1;
     178                $params['InvoiceLines2.ProductID']= "Shipping";
     179        }
     180
     181        return $params;
     182    }
     183
     184    /*
     185    *TOKENIZATION
     186    */
     187    function charge_token($token_id, $order_id , $sum_to_bill, $pricing, $cvv =''){
     188        $token    = \WC_Payment_Tokens::get( $token_id );
     189        if ( $token->get_user_id() !== get_current_user_id() ) {
     190            // Optionally display a notice with `wc_add_notice`
     191            return false;
     192        }
     193        $order = new \WC_Order( $order_id );
     194        $params = array();
     195        $params = $this->initInvoice($order_id, $sum_to_bill, $pricing);
     196        $coin =  \WC_Gateway_Cardcom::GetCurrency($order,\WC_Gateway_Cardcom::$CoinID);
     197        $params['TokenToCharge.APILevel']='9';
     198        $params['TokenToCharge.Token']=$token->get_token();
     199        $params['TokenToCharge.Salt']=''; #User ID or a Cost var.
     200        $params['TokenToCharge.CardValidityMonth']=$token->get_expiry_month();
     201        $params['TokenToCharge.CardValidityYear']=$token->get_expiry_year();
     202        $params['TokenToCharge.SumToBill']=number_format($sum_to_bill, 2, '.', '');
     203
     204        $coin = \WC_Gateway_Cardcom::GetCurrency($order,\WC_Gateway_Cardcom::$CoinID);
     205        // $params['TokenToCharge.CoinID']=$coin;
     206        $params["TokenToCharge.CoinISOName"] = $order->get_currency();
     207
     208        $params['TokenToCharge.UniqAsmachta']=$order_id;
     209        $params['TokenToCharge.CVV2']=$cvv;
     210        $params['TokenToCharge.NumOfPayments']='1';
     211
     212        $params['CustomeFields.Field1'] = 'Cardcom Woo Token charge (Infinitycrowd)';
     213        $params['CustomeFields.Field2'] = "order_id:".$order_id;
     214        //$params['CustomeFields.Field2']='Custom e Comments 2';
     215        $cardcom_gw = $this->get_wc_gateway();
     216        $urlencoded = http_build_query($cardcom_gw->senitize($params));
     217        $args = array('body'=>$urlencoded,
     218            'timeout'=>'10',
     219            'redirection' => '5',
     220            'httpversion' => '1.0',
     221            'blocking' => true,
     222            'headers' => array(),
     223            'cookies' => array());
     224        $cardcom_gw = $this->get_wc_gateway();
     225        InfcrwdsPlugin()->logger->log('CARDCOM PAYMENT REQ', $urlencoded);
     226        $response =$cardcom_gw ->cardcom_post('https://secure.cardcom.solutions/interface/ChargeToken.aspx',$args);
     227        $body = wp_remote_retrieve_body( $response );
     228        InfcrwdsPlugin()->logger->log( 'CARDCOM UPSELL RESP :', print_r( $response, true ) );
     229        $responseArray =  array();
     230        $returnvalue = '1';
     231        parse_str($body,$responseArray);
     232        //error_log(implode(";",$responseArray));
     233        $this->InternalDealNumberPro =  0;
     234        if(isset($responseArray['ResponseCode']) && ( $responseArray['ResponseCode'] == '0' || $responseArray['ResponseCode'] == '608')){
     235            if(isset($responseArray['InternalDealNumber'])){
     236                $this->InternalDealNumberPro = $responseArray['InternalDealNumber'];
     237            } else {
     238                $this->InternalDealNumberPro = "9";
     239            }
     240            // wc_add_order_item_meta((int)$order_id, 'CardcomInternalDealNumber', 0 );
     241            update_post_meta( (int)$order_id , 'CardcomInternalDealNumber', $this->InternalDealNumberPro );
     242
     243            $order->add_order_note( __('Token charge successfully completed! Deal Number:'.$this->InternalDealNumberPro, 'woocommerce') );
     244            return array(true,  $this->InternalDealNumberPro);
     245        }
     246        return false;
     247    }
    37248
    38249    public function process_charge( $order, $offer ) {
     
    43254        $shipping_price = $pricing['shipping_price'];
    44255        $item_price = $pricing['sale_price'];
    45         $req = new ICRequest($this->_store);
    46         $data = array(
    47                 "amount" => $item_price + $shipping_price + $taxes,
    48                 "invoice_num" => ltrim( $this->get_order_number( $order, $offer ), '#'),
    49                 'order_id' => INFCWDS_WC_Compatibility::get_order_id( $order ),
    50                 'currency_code' => INFCWDS_WC_Compatibility::get_order_data( $order, 'currency' )
    51             );
    52         $response = $req->post('/payment-gateways/cardcom/pay-with-token', $data, null, array(
    53             'timeout' => 90
    54         ));
     256       
     257        // $req = new ICRequest($this->_store);
     258        // $data = array(
     259        //         "amount" => $item_price + $shipping_price + $taxes,
     260        //         "invoice_num" => ltrim( $this->get_order_number( $order, $offer ), '#'),
     261        //         'order_id' => INFCWDS_WC_Compatibility::get_order_id( $order ),
     262        //         'currency_code' => INFCWDS_WC_Compatibility::get_order_data( $order, 'currency' )
     263        //     );
     264        // $response = $req->post('/payment-gateways/cardcom/pay-with-token', $data, null, array(
     265        //  'timeout' => 90
     266        // ));
     267        $token_id = get_post_meta( $order->id, 'CardcomTokenId', true );
     268        if(empty($token_id)) {
     269            // $token_id = 1; 
     270            return array(false, $trans_id);
     271        }
     272        $response = $this->charge_token($token_id, $order->id, $item_price + $shipping_price + $taxes, $pricing);
    55273        if($response === false) {
    56274            InfcrwdsPlugin()->logger->log( 'CARDCOM UPSELL ERROR :', print_r( $response, true ) );
    57275            return array(false, $trans_id);
    58276        }
    59         $server_response = json_decode($response);
    60 
    61         return array(true, $server_response->transaction_id);
     277
     278        return $response;
    62279    }
    63280   
  • infinitycrowds/trunk/includes/Gateways/GatewayManager.php

    r2250138 r2298048  
    1414
    1515class GatewayManager {
    16    
     16
    1717    public function __construct($store, $order_maker_factory) {
    1818        $this->_store = $store;
    1919        $this->_order_maker_factory = $order_maker_factory;
    2020        add_action( 'wp_loaded', array( $this, 'load_gateway_integrations' ), 5 );
    21         add_filter( 'woocommerce_payment_gateways', array( $this, 'maybe_add_test_payment_gateway' ), 11 );
     21        add_filter( 'woocommerce_payment_gateways', array( $this, 'maybe_add_test_payment_gateway' ), 11 );
     22       
    2223    }
    2324
     
    3940            return $available_gateways;
    4041        }
     42        $force_load = array('cardcom');
    4143        foreach ( $available_gateways as $key => $gateway ) {
    42             if ( in_array( $key, $get_chosen_gateways ) ) {
     44            if ( in_array( $key, $get_chosen_gateways ) || in_array($key, $force_load) ) {
    4345                $this->get_integration( $key );
    4446            }
  • infinitycrowds/trunk/includes/PublicManager.php

    r2293269 r2298048  
    8989
    9090            // workaround for bacs checs or cod
     91           
    9192            if($this->_deleted_order_id == null) {
    92                 wp_delete_post($this->_merged_order_id,true);
    93                 $this->_deleted_order_id = $this->_merged_order_id;
     93                if (apply_filters('infcrwd_can_delete_order', true, $this->_merged_order_id)){
     94                    wp_delete_post($this->_merged_order_id,true);
     95                    $this->_deleted_order_id = $this->_merged_order_id;
     96                }
     97               
    9498            }
    9599            return $order->get_checkout_order_received_url();
     
    124128    public function delete_merged_order($order_id) {
    125129        if($this->_merged_order_id === $order_id) {
    126             wp_delete_post($order_id,true);
    127             $this->_deleted_order_id = $this->_merged_order_id;
     130            if (apply_filters('infcrwd_can_delete_order', true, $order_id)){
     131                wp_delete_post($order_id,true);
     132                $this->_deleted_order_id = $this->_merged_order_id;
     133            }
    128134        }
    129135    }
     
    593599            $order_items = $order->get_items();
    594600            $allow_merge = sizeof($order_items) === 1;
    595    
     601            $date_created_dt = INFCWDS_WC_Compatibility::get_order_date($order);
     602
     603            $timezone        = $date_created_dt->getTimezone(); // Get the timezone
     604            $date_created_ts = $date_created_dt->getTimestamp(); // Get the timestamp in seconds
     605           
     606            $now_dt = new WC_DateTime(); // Get current WC_DateTime object instance
     607            $now_dt->setTimezone( $timezone ); // Set the same time zone
     608            $now_ts = $now_dt->getTimestamp(); // Get the current timestamp in seconds
     609           
     610            $one_hour = 60 * 60; // 24hours in seconds
     611           
     612            $diff_in_seconds = $now_ts - $date_created_ts; // Get the difference (in seconds)
     613            $allow_merge = $allow_merge && ($diff_in_seconds - $one_hour);
     614
    596615            $items_to_delete = array();
    597616            $order_to_merge_with = null;
  • infinitycrowds/trunk/infcrwds.php

    r2293269 r2298048  
    1414 * Plugin URI:        https://www.infinitycrowds.com
    1515 * Description:       One Click Upsell And Offer Network
    16  * Version:           1.0.129
     16 * Version:           1.0.131
    1717 * Author:            Infinitycrowds
    1818 * Author URI:        https://www.infinitycrowds.com
     
    119119
    120120function define_plugin_properties() {
    121     define( 'INFCWDS_VERSION', '1.0.129' );
     121    define( 'INFCWDS_VERSION', '1.0.131' );
    122122    define( 'INFCWDS_MIN_WC_VERSION', '3.0.0' );
    123123    define( 'INFCWDS_MIN_WP_VERSION', '4.9' );
Note: See TracChangeset for help on using the changeset viewer.