Beispiel #1
0
    public static function getPayment(&$ref, &$OPCloader, &$num, $ajax = false, $isexpress = false)
    {
        if ($isexpress) {
            $reta = array();
            $reta['html'] = '<input type="hidden" name="virtuemart_paymentmethod_id" value="' . $ref->cart->virtuemart_paymentmethod_id . '" />';
            $reta['extra'] = '';
            return $reta;
        }
        include JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'config' . DS . 'onepage.cfg.php';
        $payment_not_found_text = '';
        $payments_payment_rates = array();
        if (!class_exists('OPCrenderer')) {
            require JPATH_SITE . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'renderer.php';
        }
        $renderer = OPCrenderer::getInstance();
        if (!$renderer->checkPaymentMethodsConfigured()) {
            if (method_exists($renderer, 'assignRef')) {
                $renderer->assignRef('paymentplugins_payments', $payments_payment_rates);
                $renderer->assignRef('found_payment_method', $found_payment_method);
            }
        }
        $p = JRequest::getVar('payment_method_id', $payment_default);
        if (empty($p)) {
            $selectedPayment = empty($ref->cart->virtuemart_paymentmethod_id) ? 0 : $ref->cart->virtuemart_paymentmethod_id;
        } else {
            $selectedPayment = $p;
        }
        // set missing fields for klarna
        OPCloader::prepareBT($ref->cart);
        $dpps = array();
        $shipping = JRequest::getVar('shipping_rate_id', '');
        //if ($ajax)
        if (!empty($shipping)) {
            if (!empty($disable_payment_per_shipping)) {
                $session = JFactory::getSession();
                $dpps = $session->get('dpps', null);
                if (empty($dpps)) {
                    $OPCloader->getShipping($ref, $ref->cart, true);
                }
                $dpps = $session->get('dpps', null);
                if (!empty($dpps)) {
                }
            }
        }
        //
        if (!empty($shipping)) {
            if (!empty($shipping)) {
                $ref->cart->virtuemart_shipmentmethod_id = $shipping;
            }
            $vm2015 = false;
            $ref->cart->prices = $ref->cart->pricesUnformatted = OPCloader::getCheckoutPrices($ref->cart, false, $vm2015, 'opc');
        }
        $paymentplugins_payments = array();
        if ($p === 'none') {
            $p = 0;
        }
        if ($payment_default === 'none') {
            $paymentplugins = array();
            $psel = '<input onclick="javascript: Onepage.runPay(\'\',\'\',op_textinclship, op_currency, 0)" type="radio" name="virtuemart_paymentmethod_id" id="payment_id_0"   value="0" not_a_valid_payment="not_a_valid_payment" ';
            if (empty($p) || $p === 'none') {
                $psel .= ' selected="selected" ';
                $payment_default = 0;
            }
            $psel .= ' />
<label for="payment_id_0"><span class="vmpayment"><span class="vmpayment_name">-' . OPCLang::_('COM_VIRTUEMART_CART_EDIT_PAYMENT') . '- </span></span></label>';
            $paymentplugins[] = $psel;
        }
        if (!class_exists('vmPSPlugin')) {
            require JPATH_VM_PLUGINS . DS . 'vmpsplugin.php';
        }
        JPluginHelper::importPlugin('vmpayment');
        $dispatcher = JDispatcher::getInstance();
        require_once JPATH_SITE . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'ajaxhelper.php';
        $bhelper = new basketHelper();
        //$bhelper->createDefaultAddress($ref, $ref->cart);
        //old: 2.0.208 and prior: $returnValues = $dispatcher->trigger('plgVmDisplayListFEPayment', array($ref->cart, $selectedPayment, &$paymentplugins_payments));
        //plgVmDisplayListFEPaymentOPCNocache
        $returnValues = $dispatcher->trigger('plgVmDisplayListFEPaymentOPCNocache', array(&$ref->cart, $selectedPayment, &$paymentplugins_payments));
        if (empty($returnValues)) {
            $returnValues = $dispatcher->trigger('plgVmDisplayListFEPayment', array($ref->cart, $selectedPayment, &$paymentplugins_payments));
        }
        // if no payment defined
        $found_payment_method = false;
        $n = 0;
        $debug = '';
        foreach ($paymentplugins_payments as $p1) {
            if (is_array($p1)) {
                $n += count($p1);
            }
        }
        if ($n > 0) {
            $found_payment_method = true;
        }
        $num = $n;
        if (!$found_payment_method) {
            $link = '';
            // todo
            $payment_not_found_text = OPCLang::sprintf('COM_VIRTUEMART_CART_NO_PAYMENT_METHOD_PUBLIC', '<a href="' . $link . '">' . $link . '</a>');
        }
        require_once JPATH_SITE . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'ajaxhelper.php';
        $bhelper = new basketHelper();
        require_once JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'transform.php';
        $ret = array();
        if ($found_payment_method) {
            if (!empty($payment_inside)) {
                $ret2 = OPCTransform::paymentToSelect($paymentplugins_payments, $shipping, $dpps);
                if (!empty($ret2)) {
                    $ret = array($ret2['select']);
                    $extra = $ret2['extra'];
                    /*
                    		  foreach ($ret['extra'] as $key=>$val)
                    {
                      $extra[$key] = $val; 
                    }
                    */
                }
            }
            if (empty($payment_inside) || empty($ret)) {
                $sorted = array();
                $unknown = array();
                foreach ($paymentplugins_payments as $paymentplugin_payments) {
                    if (is_array($paymentplugin_payments)) {
                        foreach ($paymentplugin_payments as $paymentplugin_payment) {
                            $id = OPCTransform::getFT($paymentplugin_payment, 'input', 'virtuemart_paymentmethod_id', 'name', 'virtuemart_paymentmethod_id', '>', 'value');
                            if (is_array($id)) {
                                $id = reset($id);
                            }
                            $paymentplugin_payment = str_replace('class="vmpayment_description"', 'class="vmpayment_description vmpayment_description_' . $id . '"', $paymentplugin_payment);
                            //vmpayment_cardinfo
                            $paymentplugin_payment = str_replace('class="vmpayment_cardinfo"', 'class="vmpayment_cardinfo vmpayment_cardinfo_' . $id . '"', $paymentplugin_payment);
                            //ccDetails
                            $paymentplugin_payment = str_replace('class="ccDetails"', 'class="ccDetails ccDetails_' . $id . '"', $paymentplugin_payment);
                            OPCloader::opcDebug('checking shipping ' . $shipping);
                            OPCloader::opcDebug('dpps:');
                            OPCloader::opcDebug($dpps);
                            OPCloader::opcDebug('dpps_disable:');
                            OPCloader::opcDebug($dpps_disable);
                            if (!empty($shipping)) {
                                if (!empty($dpps)) {
                                    if (!empty($disable_payment_per_shipping)) {
                                        foreach ($dpps_disable as $k => $v) {
                                            if (!empty($dpps[$k])) {
                                                foreach ($dpps[$k] as $y => $try) {
                                                    if ((int) $dpps[$k][$y] == (int) $shipping) {
                                                        if ($dpps_disable[$k] == $id) {
                                                            OPCloader::opcDebug('disabling payment id ' . $id . ' for shipping id ' . $shipping);
                                                            $paymentplugin_payment = '';
                                                            continue 3;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            // PPL Pro fix
                            $paymentplugin_payment = str_replace('<br/><a href="' . JRoute::_('index.php?option=com_virtuemart&view=cart&task=editpayment&Itemid=' . JRequest::getInt('Itemid'), false) . '">' . JText::_('VMPAYMENT_PAYPAL_CC_ENTER_INFO') . '</a>', '', $paymentplugin_payment);
                            $paymentplugin_payment = str_replace('name="virtuemart_paymentmethod_id"', 'name="virtuemart_paymentmethod_id" onclick="javascript: Onepage.runPay(\'\',\'\',op_textinclship, op_currency, 0)" ', $paymentplugin_payment);
                            $ret[] = $paymentplugin_payment;
                            if ($n === 1 && !empty($hide_payment_if_one)) {
                                $paymentplugin_payment = str_replace('type="radio"', 'type="hidden"', $paymentplugin_payment);
                            }
                            if (is_numeric($id)) {
                                $ind = (int) $id;
                                if (empty($sorted[$ind])) {
                                    $sorted[$ind] = $paymentplugin_payment;
                                } else {
                                    $unknown[] = $paymentplugin_payment;
                                }
                            } else {
                                if (is_numeric($id[0])) {
                                    $ind = (int) $id[0];
                                    if (empty($sorted[$ind])) {
                                        $sorted[$ind] = $paymentplugin_payment;
                                    } else {
                                        $unknown[] = $paymentplugin_payment;
                                    }
                                } else {
                                    $unknown[] = $paymentplugin_payment;
                                }
                            }
                        }
                    }
                }
                if (!empty($sorted)) {
                    $dbj = JFactory::getDBO();
                    $dbj->setQuery("select * from #__virtuemart_paymentmethods where published = '1' order by ordering asc limit 999");
                    $list = $dbj->loadAssocList();
                    $msg = $dbj->getErrorMsg();
                    if (!empty($msg)) {
                        echo $msg;
                    }
                    $sortedfinal = array();
                    if (!empty($list)) {
                        foreach ($list as $pme) {
                            if (!empty($sorted[$pme['virtuemart_paymentmethod_id']])) {
                                $sortedfinal[] = $sorted[$pme['virtuemart_paymentmethod_id']];
                            }
                        }
                        if (empty($unknown)) {
                            $unknown = array();
                        }
                        if (!empty($sortedfinal)) {
                            $ret = array_merge($sortedfinal, $unknown);
                        }
                    }
                }
            }
        } else {
            $ret[] = $payment_not_found_text . '<input type="hidden" name="virtuemart_paymentmethod_id" id="opc_missing_payment" value="0" />';
        }
        if (empty($payment_inside)) {
            if (!empty($ret)) {
                if (!empty($paymentplugins)) {
                    $ret = array_merge($paymentplugins, $ret);
                }
            }
        }
        $vars = array('payments' => $ret, 'cart' => $ref->cart);
        $html = $OPCloader->fetch($OPCloader, 'list_payment_methods.tpl', $vars);
        $pid = JRequest::getVar('payment_method_id', '');
        if (!empty($pid) && is_numeric($pid)) {
            if (strpos($html, 'value="' . $pid . '"') !== false) {
                $html = str_replace('checked="checked"', '', $html);
                $html = str_replace(' checked', ' ', $html);
                $html = str_replace('value="' . $pid . '"', 'value="' . $pid . '" checked="checked" ', $html);
            }
        } else {
            if (strpos($html, 'value="' . $payment_default . '"') !== false) {
                $html = str_replace('checked="checked"', '', $html);
                $html = str_replace(' checked', ' ', $html);
                $html = str_replace('value="' . $payment_default . '"', 'value="' . $payment_default . '" checked="checked" ', $html);
            }
        }
        $html = str_replace('"radio"', '"radio" autocomplete="off" ', $html);
        if (!$payment_inside) {
            if (strpos($html, 'checked') === false) {
                $x1 = strpos($html, 'name="virtuemart_paymentmethod_id"');
                if ($x1 !== false) {
                    $html = substr($html, 0, $x1) . ' checked="checked" ' . substr($html, $x1);
                } else {
                    // we've got no method here !
                }
            }
        }
        // klarna compatibility
        $count = 0;
        $html = str_replace('name="klarna_paymentmethod"', 'name="klarna_paymentmethod_opc"', $html, $count);
        $html .= '<input type="hidden" name="opc_payment_method_id" id="opc_payment_method_id" value="" />';
        if ($count > 0) {
            if (!defined('klarna_opc_id')) {
                $html .= '<input type="hidden" name="klarna_opc_method" id="klarna_opc_method" value="" />';
                define('klarna_opc_id', 1);
            }
        }
        $reta = array();
        $reta['html'] = $html;
        if (!empty($extra)) {
            $reta['extra'] = $extra;
        } else {
            $reta['extra'] = '';
        }
        return $reta;
    }
Beispiel #2
0
 function setExtAddress(&$cart, $ajax = false, $force_only_st = false)
 {
     $session = JFactory::getSession();
     // parkbeach fedex:
     // this will reset address once per ajax
     if (isset($_SESSION['cart']['fedex_ship_dest_zip'])) {
         unset($_SESSION['cart']['fedex_ship_dest_zip']);
     }
     $kIndex = 'klarna_';
     $klarna_method = JRequest::getVar('klarna_opc_method', '');
     if (!empty($klarna_method)) {
         JRequest::setVar('klarna_paymentmethod', $klarna_method);
     }
     $klarna['klarna_paymentmethod'] = JRequest::getVar($kIndex . 'paymentmethod');
     if ($klarna['klarna_paymentmethod'] == 'klarna_invoice') {
         $klarna_option = 'invoice';
     } elseif ($klarna['klarna_paymentmethod'] == 'klarna_partPayment') {
         $klarna_option = 'part';
     } elseif ($klarna['klarna_paymentmethod'] == 'klarna_speccamp') {
         $klarna_option = 'spec';
     } else {
         return NULL;
     }
     $prefix = $klarna_option . '_' . $kIndex;
     $x = JRequest::getVar('klarna_paymentPlan', '');
     $y = JRequest::getVar($prefix . 'paymentPlan', $x);
     if (empty($y)) {
         JRequest::setVar($prefix . 'paymentPlan', $x);
     }
     $sn = JRequest::getVar($prefix . 'socialNumber');
     if (empty($sn)) {
         if (!isset($cart->BT['socialNumber'])) {
             $sn = JRequest::getVar('socialNumber', '');
             if (!empty($sn)) {
                 JRequest::setVar($prefix . 'socialNumber', $sn);
             }
         } else {
             JRequest::setVar($prefix . 'socialNumber', $cart->BT['socialNumber']);
         }
     }
     if (!isset($cart->BT['first_name'])) {
         JRequest::setVar($prefix . 'firstName', JRequest::getVar('first_name', ''));
     } else {
         JRequest::setVar($prefix . 'firstName', $cart->BT['first_name']);
     }
     if (!isset($cart->BT['last_name'])) {
         JRequest::setVar($prefix . 'lastName', JRequest::getVar('last_name', ''));
     } else {
         JRequest::setVar($prefix . 'lastName', $cart->BT['last_name']);
     }
     $bd = JRequest::getVar($prefix . 'birth_day');
     if (empty($bd)) {
         JRequest::setVar($prefix . 'birth_day', JRequest::getVar('klarna_birth_day', ''));
         JRequest::setVar($prefix . 'birth_month', JRequest::getVar('klarna_birth_month', ''));
         JRequest::setVar($prefix . 'birth_year', JRequest::getVar('klarna_birth_year', ''));
     }
     if (empty($cart->BT['fax'])) {
         $cart->BT['fax'] = '';
     }
     if (empty($cart->BT['phone_2'])) {
         $cart->BT['phone_2'] = '';
     }
     if (empty($cart->ST['fax'])) {
         $cart->BT['fax'] = '';
     }
     if (empty($cart->ST['phone_2'])) {
         $cart->BT['phone_2'] = '';
     }
     JRequest::setVar($prefix . 'fax', JRequest::getVar('fax', ''));
     JRequest::setVar($prefix . 'phone_2', JRequest::getVar('phone_2', ''));
     if (!isset($cart->BT['phone_1'])) {
         JRequest::setVar($prefix . 'phone', JRequest::getVar('phone_1', ''));
     } else {
         JRequest::setVar($prefix . 'phone', $cart->BT['phone_1']);
     }
     //klarna_birth_day
     //klarna_birth_month
     //klarna_birth_year
     if (isset($cart->BT['birthday'])) {
         $bday = $cart->BT['birthday'];
         $arr = explode('-', $bday);
         if (count($arr) == 3) {
             JRequest::setVar($prefix . 'birth_day', $arr[2]);
             JRequest::setVar($prefix . 'birth_month', $arr[1]);
             JRequest::setVar($prefix . 'birth_year', $arr[0]);
         }
     }
     if (!isset($cart->BT['address_1'])) {
         JRequest::setVar($prefix . 'street', JRequest::getVar('address_1', ''));
     } else {
         JRequest::setVar($prefix . 'street', $cart->BT['address_1']);
     }
     if (!isset($cart->BT['address_2'])) {
         JRequest::setVar($prefix . 'homenumber', JRequest::getVar('address_2', ''));
     } else {
         JRequest::setVar($prefix . 'homenumber', $cart->BT['address_2']);
     }
     //klarna_city
     if (!isset($cart->BT['city'])) {
         JRequest::setVar($prefix . 'city', JRequest::getVar('city', ''));
     } else {
         JRequest::setVar($prefix . 'city', $cart->BT['city']);
     }
     if (!isset($cart->BT['zip'])) {
         JRequest::setVar($prefix . 'zipcode', JRequest::getVar('zip', ''));
     } else {
         JRequest::setVar($prefix . 'zipcode', $cart->BT['zip']);
     }
     $country_id = JRequest::getVar('virtuemart_country_id', '');
     if (isset($cart->BT['virtuemart_country_id'])) {
         $country_id = $cart->BT['virtuemart_country_id'];
     }
     $klarna_country = JRequest::getVar('klarna_country_2_code', null);
     if (isset($klarna_country) && empty($klarna_country)) {
         if (is_numeric($country_id)) {
             $q = 'select country_2_code from #__virtuemart_countries where virtuemart_country_id = ' . $country_id . ' limit 0,1';
             $db = JFactory::getDBO();
             $db->setQuery($q);
             $country_2_code = $db->loadResult();
             JRequest::setVar($prefix . 'country_2_code', strtoupper($country_2_code));
         }
     }
     $emailPost = JRequest::getVar('email', '');
     if (!empty($emailPost)) {
         $cart->BT['email'] = $emailPost;
         if (is_array($cart->ST)) {
             $cart->ST['email'] = $emailPost;
         }
     }
     if (!isset($cart->BT['email'])) {
         JRequest::setVar($prefix . 'emailAddress', JRequest::getVar('email'));
     } else {
         JRequest::setVar($prefix . 'emailAddress', $cart->BT['email']);
     }
     $em = JRequest::getVar($prefix . 'emailAddress', '');
     if (empty($em)) {
         $em = $this->getEmail();
         JRequest::setVar($prefix . 'emailAddress', $em);
     }
     if (!empty($cart->BT['title'])) {
         switch ($cart->BT['title']) {
             case OPCLang::_('COM_VIRTUEMART_SHOPPER_TITLE_MR'):
                 JRequest::setVar('part_klarna_gender', 1);
                 JRequest::setVar('spec_klarna_gender', 1);
                 JRequest::setVar('invoice_klarna_gender', 1);
                 JRequest::setVar($prefix . 'gender', 1);
                 break;
             case 'Mr':
                 JRequest::setVar('part_klarna_gender', 1);
                 JRequest::setVar('spec_klarna_gender', 1);
                 JRequest::setVar('invoice_klarna_gender', 1);
                 JRequest::setVar($prefix . 'gender', 1);
                 break;
             case 'Ms':
             case 'Mrs':
             case OPCLang::_('COM_VIRTUEMART_SHOPPER_TITLE_MISS'):
             case OPCLang::_('COM_VIRTUEMART_SHOPPER_TITLE_MRS'):
                 JRequest::setVar('klarna_gender', 0);
                 JRequest::setVar('spec_klarna_gender', 0);
                 JRequest::setVar('invoice_klarna_gender', 0);
                 JRequest::setVar($prefix . 'gender', 0);
                 break;
             default:
                 JRequest::setVar('klarna_gender', NULL);
                 JRequest::setVar($prefix . 'gender', NULL);
                 break;
         }
     }
     if (isset($cart->BT['house_no'])) {
         JRequest::setVar($prefix . 'homenumber', $cart->BT['house_no']);
     }
     //if (isset($cart->BT['klarna_house_extension
     $company = JRequest::getVar('company', @$cart->BT['company']);
     if (empty($company)) {
         JRequest::setVar('klarna_invoice_type', 'private');
     } else {
         JRequest::setVar('klarna_invoice_type', 'company');
         JRequest::setVar('klarna_company', $company);
         JRequest::setVar('klarna_invoice_type', 'company');
         JRequest::setVar('klarna_company_name', $company);
     }
     //JRequest::setVar('klarna_country_2_code', JRequest::getVar('virtuemart_country_id', ''));
     //klarna_birth_day, klarna_birth_month, klarna_birth_year
     /*
      */
     //if (empty($cart->BT['birthday'])) $cart->BT['birthday'] = '';
     OPCloader::prepareBT($cart);
 }