Example #1
0
    function confirmation()
    {
        global $Shopp;
        $Shopping =& $Shopp->Shopping;
        $Order =& $Shopp->Order;
        require_once SHOPP_ADDONS . '/BillmateCore/BillMate.php';
        include_once SHOPP_ADDONS . "/BillmateCore/lib/xmlrpc.inc";
        include_once SHOPP_ADDONS . "/BillmateCore/lib/xmlrpcs.inc";
        $pno = $this->Order->pno;
        $phone = $this->Order->billmatephone;
        $eid = (int) $this->settings['eid'];
        $key = $this->settings['secretkey'];
        $ssl = true;
        $debug = false;
        $k = new BillMate($eid, $key, $ssl, $debug, $this->settings['testmode'] == 'on');
        $Customer = $this->Order->Customer;
        $Billing = $this->Order->Billing;
        $Shipping = $this->Order->Shipping;
        $country = $zone = $locale = $global = false;
        $country = $Billing->country;
        if (!in_array($country, $this->settings['avail_country'])) {
            new ShoppError(__('Billmate Invoice not available in selected country country code', 'shopp-billmate-invoice') . '(' . $country . ')', 2);
            echo '<script type="text/javascript">window.location.href="' . shoppurl(false, 'checkout') . '";</script>';
            die;
        }
        $country_to_currency = array('NO' => 'NOK', 'SE' => 'SEK', 'FI' => 'EUR', 'DK' => 'DKK', 'DE' => 'EUR', 'NL' => 'EUR');
        try {
            $addr = $k->GetAddress($pno);
            if (empty($addr[0])) {
                new ShoppError(__('Invalid personal number', 'shopp-billmate-invoice'), 2);
                echo '<script type="text/javascript">window.location.href="' . shoppurl(false, 'checkout') . '";</script>';
                die;
            }
            foreach ($addr[0] as $key => $col) {
                $addr[0][$key] = utf8_encode($col);
            }
            if (isset($addr['error'])) {
                new ShoppError(__('Invalid personal number', 'shopp-billmate-invoice'), 2);
                echo '<script type="text/javascript">window.location.href="' . shoppurl(false, 'checkout') . '";</script>';
                die;
            }
        } catch (Exception $e) {
            new ShoppError(__('Invalid personal number', 'shopp-billmate-invoice'), 2);
            echo '<script type="text/javascript">window.location.href="' . shoppurl(false, 'checkout') . '";</script>';
            die;
        }
        $bo = new StdClass();
        $bo->name = "Billmate Invoice Feee";
        $bo->unitprice = 122;
        if (!empty($this->settings['invoice_fee'])) {
            $Product = new Product($this->settings['invoice_fee']);
            $price = new Price($this->settings['invoice_fee'], 'product');
            $NewItem = new Item($Product, $Price, array(), array(), false);
            if (empty($this->Order->feeadded) || !$this->Order->feeadded) {
                $Shopp->Order->Cart->add(1, $Product, $price->id);
                $Shopp->Order->Cart->totals();
                $this->Order->feeadded = true;
            }
        }
        $Customer = $this->Order->Customer;
        $Billing = $Shopp->Order->Billing;
        $Shipping = $Shopp->Order->Shipping;
        foreach ($addr[0] as $key => $col) {
            $addr[0][$key] = Encoding::fixUTF8($col);
        }
        $fullname = $Customer->firstname . ' ' . $Customer->lastname . ' ' . $Customer->company;
        $firstArr = explode(' ', $Customer->firstname);
        $lastArr = explode(' ', $Customer->lastname);
        $apiName = $addr[0][0] . ' ' . $addr[0][1];
        if (empty($addr[0][0])) {
            $apifirst = $firstArr;
            $apilast = $lastArr;
        } else {
            $apifirst = explode(' ', $addr[0][0]);
            $apilast = explode(' ', $addr[0][1]);
        }
        $matchedFirst = array_intersect($apifirst, $firstArr);
        $matchedLast = array_intersect($apilast, $lastArr);
        $apiMatchedName = !empty($matchedFirst) && !empty($matchedLast);
        $addressNotMatched = !isEqual($addr[0][2], $Billing->address) || !isEqual($addr[0][3], $Billing->postcode) || !isEqual($addr[0][4], $Billing->city) || !isEqual($addr[0][5], BillmateCountry::fromCode(strtoupper($Billing->country)));
        $shippingAndBilling = !$apiMatchedName || !isEqual($Shipping->address, $Billing->address) || !isEqual($Shipping->postcode, $Billing->postcode) || !isEqual($Shipping->city, $Billing->city) || !isEqual($Shipping->country, $Billing->country);
        if ($addressNotMatched || $shippingAndBilling) {
            if (empty($this->Order->overritedefaultaddress) || !$this->Order->overritedefaultaddress) {
                $html = '<p style="margin:0px!important;"><b>' . __('Correct Address is :', 'shopp-billmate-invoice') . ': </b></p>' . $addr[0][0] . ' ' . $addr[0][1] . '<br>' . $addr[0][2] . '<br>' . $addr[0][3] . ' ' . $addr[0][4] . '<div style="padding: 17px 0px;"> <i>' . __('Click Yes to continue with new address, No to choose other payment method', 'shopp-billmate-invoice') . '</i></div> <input style="background:#1DA9E7" type="button" value="' . __('Yes', 'shopp-billmate-invoice') . '" onclick="updateAddress();" class="button"/> <input style="background:#1DA9E7" type="button" value="' . __('No', 'shopp-billmate-invoice') . '" onclick="closefunc(this);window.location.reload();" class="button" style="float:right" />';
                $code = '<style type="text/css">
.checkout-heading {
    background: none repeat scroll 0 0 #F8F8F8!important;
    border: 1px solid #DBDEE1!important;
    color: #555555!important;
    font-size: 13px!important;
    font-weight: bold!important;
    margin-bottom: 15px!important;
    padding: 8px!important;
}
#cboxClose{
 display:none!important;
 visibility:hidden!important;
}
.button:hover{
    background:#444444!important;
}
#divOverlay *{
	text-shadow:none!important;
}
#divOverlay table td, #divOverlay table th{
	padding:0px!important;
}
#divOverlay table td, #divOverlay table th, #divOverlay table{
	border:0px!important;
}

.button {
    border: 0 none!important;
    border-radius: 8px!important;
    box-shadow: 2px 2px 2px 1px #EAEAEA!important;
    color: #FFFFFF!important;
    cursor: pointer!important;
    font-family: arial!important;
    font-size: 14px!important;
    font-weight: bold!important;
    padding: 3px 17px!important;
}
#cboxContent{
    margin:0px!important;
}
	            </style><script type="text/javascript">
	            jQuery(document).ready(function(){
    	            jQuery("#billmatephone").attr("checked","checked");
                    jQuery("select[name=paymethod]").removeAttr("selected");
                    jQuery("select[name=paymethod] option[value^=billmate-invoice]").attr("selected","selected");
                    jQuery("select[name=paymethod] option[value^=billmate-faktura]").attr("selected","selected");
                    jQuery("select[name=paymethod]").trigger("change");
	            });
	            function updateAddress(){
    	            jQuery("select[name=paymethod]").after("<input type=\'hidden\' name=\'geturl\' value=\'true\'/>");
    	            jQuery("#checkout").submit();
	            }
	  jQuery(document).ready(function(){
		modalWin.ShowMessage(\'' . $html . '\',300,500,\'' . __('Your Billing address is wrong.', 'shopp-billmate-invoice') . '\');
	  });
	  </script>';
                new ShoppError($code, 2);
                echo '<script type="text/javascript">window.location.href="' . shoppurl(false, 'checkout') . '";</script>';
                die;
            } else {
                if (empty($addr[0][0])) {
                    $Shopp->Order->Customer->company = $addr[0][1];
                } else {
                    $Shopp->Order->Customer->firstname = $addr[0][0];
                    $Shopp->Order->Customer->lastname = $addr[0][1];
                    $Shopp->Order->Customer->company = '';
                }
                $Shipping->address = $addr[0][2];
                $Shipping->postcode = $addr[0][3];
                $Shipping->city = $addr[0][4];
                $Shipping->country = BillmateCountry::getCode($addr[0][5]);
                $Billing->address = $addr[0][2];
                $Billing->postcode = $addr[0][3];
                $Billing->city = $addr[0][4];
                $Billing->country = BillmateCountry::getCode($addr[0][5]);
                $Shopp->Order->Billing = $Billing;
                $Shopp->Order->Shipping = $Shipping;
            }
        }
        return false;
    }
 function fetchpclasses()
 {
     $eid = (int) $this->settings['eid'];
     $secret = $this->settings['secretkey'];
     $ssl = true;
     $debug = false;
     require_once SHOPP_ADDONS . '/BillmateCore/BillMate.php';
     include_once SHOPP_ADDONS . "/BillmateCore/lib/xmlrpc.inc";
     include_once SHOPP_ADDONS . "/BillmateCore/lib/xmlrpcs.inc";
     $k = new BillMate($eid, $secret, $ssl, $debug, $this->settings['testmode'] == 'on');
     $result = array();
     foreach ($this->countries as $countryid => $countryname) {
         $data = $k->FetchCampaigns(BillmateCountry::getCountryData($countryid));
         array_walk($data, array(&$this, 'correct_lang_billmate'));
         $countryCode = strtoupper(BillmateCountry::getCode($countryid));
         $result[$countryCode] = $data;
     }
     if (!sizeof($result)) {
         echo '<div class="wrap shopp"><div class="error"><p>', _e('Unable to fetch Billmate Pclasses', 'shopp-billmate-partpayment'), '</p></div></div>';
     } else {
         $pclases = json_encode($result, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE);
         $fp = fopen(SHOPP_ADDONS . '/BillmateCore/billmatepclasses.json', 'w+');
         if (!$fp) {
             echo '<div class="wrap shopp"><div class="error"><p>', _e('Unable to open file to write.' . SHOPP_ADDONS . '/BillmateCore/billmatepclasses.json', 'shopp-billmate-partpayment'), '</p></div></div>';
             return true;
         }
         fwrite($fp, $pclases);
         fclose($fp);
         echo '<div class="wrap shopp"><div class="updated"><p>', _e('Billmate Plcasses are saved', 'shopp-billmate-partpayment'), '</p></div></div>';
     }
 }