function process()
 {
     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;
     $country_to_currency = array('NO' => 'NOK', 'SE' => 'SEK', 'FI' => 'EUR', 'DK' => 'DKK', 'DE' => 'EUR', 'NL' => 'EUR');
     $ship_address = $bill_address = array();
     $countryData = BillmateCountry::getCountryData($Shipping->country);
     $ship_address = array('email' => $Customer->email, 'telno' => $Customer->phone, 'cellno' => '', 'fname' => $Customer->firstname, 'lname' => $Customer->lastname, 'company' => $Customer->company, 'careof' => '', 'street' => $Shipping->address, 'house_number' => isset($house_no) ? $house_no : '', 'house_extension' => isset($house_ext) ? $house_ext : '', 'zip' => $Shipping->postcode, 'city' => $Shipping->city, 'country' => $countryData['country']);
     $bill_address = array('email' => $Customer->email, 'telno' => $Customer->phone, 'cellno' => '', 'fname' => $Customer->firstname, 'lname' => $Customer->lastname, 'company' => $Customer->company, 'careof' => '', 'street' => $Billing->address, 'house_number' => '', 'house_extension' => '', 'zip' => $Billing->postcode, 'city' => $Billing->city, 'country' => $countryData['country']);
     foreach ($ship_address as $key => $col) {
         $ship_address[$key] = utf8_decode(Encoding::fixUTF8($col));
     }
     foreach ($bill_address as $key => $col) {
         $bill_address[$key] = utf8_decode(Encoding::fixUTF8($col));
     }
     extract($countryData);
     $goods_list = array();
     $taxrate = 0;
     if (sizeof($this->Order->Cart) <= 1 && !empty($this->settings['invoice_fee'])) {
         $Shopp->Order->Cart = array();
         new ShoppError(__('Cart is empty', 'shopp-billmate-invoice'), 2);
         $this->Order->feeadded = false;
         echo '<script type="text/javascript">window.location.href="' . shoppurl(false, 'cart') . '";</script>';
         die;
     }
     foreach ($this->Order->Cart as $item) {
         // echo links for the items
         $flag = stripos($item->name, 'billmate fee') === false ? stripos($item->name, 'billmate invoice fee') === false ? 0 : 16 : 0;
         $flag = stripos($item->name, 'billmate fee') === false ? stripos($item->name, 'billmate invoice fee') === false ? 0 : 16 : 0;
         $taxrate = $taxrate == 0 ? $item->taxrate : $taxrate;
         $goods_list[] = array('qty' => (int) $item->quantity, 'goods' => array('artno' => $item->product, 'title' => $item->name, 'price' => round($item->unitprice * 100, 0), 'vat' => round($item->taxrate * 100, 0), 'discount' => 0.0, 'flags' => $flag));
     }
     if ($this->Order->Cart->Totals->discount > 0) {
         $rate = (100 + $taxrate * 100) / 100;
         $totalAmt = $this->Order->Cart->Totals->discount;
         $price = $totalAmt - $totalAmt / $rate;
         $discount = $totalAmt - $price;
         $goods_list[] = array('qty' => (int) 1, 'goods' => array('artno' => __('discount', 'shopp-billmate-invoice'), 'title' => __('Discount', 'shopp-billmate-invoice'), 'price' => -1 * abs(round($this->Order->Cart->Totals->discount * 100, 0)), 'vat' => $taxrate * 100, 'discount' => 0, 'flags' => $flag));
     }
     if (!empty($this->Order->Cart->Totals->shipping)) {
         $totalAmt = $this->Order->Cart->Totals->shipping;
         $goods_list[] = array('qty' => (int) 1, 'goods' => array('artno' => __('Shipping', 'shopp-billmate-invoice'), 'title' => __('Shipping', 'shopp-billmate-invoice'), 'price' => round($totalAmt * 100, 0), 'vat' => $taxrate * 100, 'discount' => 0, 'flags' => 8));
     }
     $pclass = -1;
     $transaction = array("order1" => (string) $this->txnid(), "comment" => (string) "", "flags" => 0, "reference" => "", "reference_code" => "", "currency" => $currency, "country" => $country, "language" => $language, "pclass" => $pclass, "shipInfo" => array("delay_adjust" => "1"), "travelInfo" => array(), "incomeInfo" => array(), "bankInfo" => array(), "sid" => array("time" => microtime(true)), "extraInfo" => array(array("cust_no" => (string) $order_info['customer_id'])));
     $result1 = $k->AddInvoice($pno, $bill_address, $ship_address, $goods_list, $transaction);
     //shopp_rmv_cart_item($this->settings['invoice_fee']);
     if (!is_array($result1)) {
         $this->remove_fee();
         /*
         if( !empty($this->settings['invoice_fee'])){
         	$Shopp->Order->Cart->remove(sizeof( $this->Order->Cart )-1);
         	$Shopp->Order->Cart->totals();
         	$this->Order->feeadded = false;
         	unset($this->Order->feeadded);
         }
         */
         new ShoppError(__('Unable to process billmate try again <br/>Error:', 'shopp-billmate-invoice') . utf8_encode($result1), 2);
         echo '<script type="text/javascript">window.location.href="' . shoppurl(false, 'checkout') . '";</script>';
         die;
     } else {
         $this->Order->billmateId = $result1[0];
     }
     $this->Order->pno = '';
     $this->Order->billmatephone = '';
     $this->Order->feeadded = false;
     $this->Order->transaction($this->txnid());
     return true;
 }
 function process()
 {
     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->partpaymentpno;
     $phone = $this->Order->partpaymentphone;
     $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;
     $country_to_currency = array('NO' => 'NOK', 'SE' => 'SEK', 'FI' => 'EUR', 'DK' => 'DKK', 'DE' => 'EUR', 'NL' => 'EUR');
     $ship_address = $bill_address = array();
     $countryData = BillmateCountry::getCountryData($Shipping->country);
     $ship_address = array('email' => $Customer->email, 'telno' => $Customer->phone, 'cellno' => '', 'fname' => $Customer->firstname, 'lname' => $Customer->lastname, 'company' => $Customer->company, 'careof' => '', 'street' => $Shipping->address, 'house_number' => isset($house_no) ? $house_no : '', 'house_extension' => isset($house_ext) ? $house_ext : '', 'zip' => $Shipping->postcode, 'city' => $Shipping->city, 'country' => $countryData['country']);
     $bill_address = array('email' => $Customer->email, 'telno' => $Customer->phone, 'cellno' => '', 'fname' => $Customer->firstname, 'lname' => $Customer->lastname, 'company' => $Customer->company, 'careof' => '', 'street' => $Billing->address, 'house_number' => '', 'house_extension' => '', 'zip' => $Billing->postcode, 'city' => $Billing->city, 'country' => $countryData['country']);
     foreach ($ship_address as $key => $col) {
         $ship_address[$key] = utf8_decode(Encoding::fixUTF8($col));
     }
     foreach ($bill_address as $key => $col) {
         $bill_address[$key] = utf8_decode(Encoding::fixUTF8($col));
     }
     extract($countryData);
     //new ShoppError(var_export($Shipping->country,1), 'invalid_personal_number');
     //shopp_safe_redirect(shoppurl(false,'checkout'));
     $goods_list = array();
     foreach ($this->Order->Cart->contents as $item) {
         // echo links for the items
         $flag = stripos($item->name, 'billmate fee') === false ? stripos($item->name, 'billmate invoice fee') === false ? 0 : 16 : 0;
         $goods_list[] = array('qty' => (int) $item->quantity, 'goods' => array('artno' => $item->product, 'title' => $item->name, 'price' => round($item->unitprice * 100, 0), 'vat' => round($item->taxrate * 100, 0), 'discount' => 0.0, 'flags' => $flag));
         $taxrate = $item->taxrate;
     }
     if ($this->Order->Cart->Totals->discount > 0) {
         $rate = (100 + $taxrate * 100) / 100;
         $totalAmt = $this->Order->Cart->Totals->discount;
         $price = $totalAmt - $totalAmt / $rate;
         $discount = $totalAmt - $price;
         $goods_list[] = array('qty' => 1, 'goods' => array('artno' => __('discount', 'shopp-billmate-partpayment'), 'title' => __('Discount', 'shopp-billmate-partpayment'), 'price' => -1 * abs(round($this->Order->Cart->Totals->discount * 100, 0)), 'vat' => $taxrate * 100, 'discount' => 0, 'flags' => $flag));
     }
     if (!empty($this->Order->Cart->Totals->shipping)) {
         $taxrate = $taxrate * 100;
         //$rate = (100+$taxrate)/100;
         $totalAmt = $this->Order->Cart->Totals->shipping;
         //$price = $totalAmt-($totalAmt/$rate);
         // $shipping = $totalAmt - $price;
         $goods_list[] = array('qty' => (int) 1, 'goods' => array('artno' => __('Shipping', 'shopp-billmate-partpayment'), 'title' => __('Shipping', 'shopp-billmate-partpayment'), 'price' => round($totalAmt * 100, 0), 'vat' => $taxrate, 'discount' => 0, 'flags' => 8));
     }
     $pclass = (int) $this->Order->pclass;
     $transaction = array("order1" => (string) $this->txnid(), "comment" => (string) "", "flags" => 0, "reference" => "", "reference_code" => "", "currency" => $currency, "country" => $country, "language" => $language, "pclass" => $pclass, "shipInfo" => array("delay_adjust" => "1"), "travelInfo" => array(), "incomeInfo" => array(), "bankInfo" => array(), "sid" => array("time" => microtime(true)), "extraInfo" => array(array("cust_no" => (string) $order_info['customer_id'])));
     try {
         $result1 = $k->AddInvoice($pno, $bill_address, $ship_address, $goods_list, $transaction);
     } catch (Exception $ex) {
     }
     $this->Order->partpaymentpno = '';
     $this->Order->partpaymentphone = '';
     $this->Order->pclass = false;
     if (!is_array($result1)) {
         new ShoppError(__('It is not possible to pay with that method and to choose a different payment method or use a different personal number', 'shopp-billmate-partpayment'), 'billmate_error', SHOPP_TRXN_ERR);
         shopp_redirect(shoppurl(false, 'checkout'));
         die;
     } else {
         $this->Order->billmateId = $result1[0];
     }
     $this->Order->transaction($this->txnid());
     return true;
 }
 function billmate_transaction($add_order = false)
 {
     global $Shopp;
     $Shopping =& $Shopp->Shopping;
     $Order =& $Shopp->Order;
     if (empty($_POST)) {
         $_POST = $_GET;
     }
     $pno = '';
     $eid = (int) $this->settings['merchantid'];
     $key = $this->settings['cardpaysecret'];
     $ssl = true;
     $debug = false;
     $k = new BillMate($eid, $key, $ssl, $debug);
     $Customer = $this->Order->Customer;
     $Billing = $this->Order->Billing;
     $Shipping = $this->Order->Shipping;
     $country = $zone = $locale = $global = false;
     $country = $Billing->country;
     $country_to_currency = array('NO' => 'NOK', 'SE' => 'SEK', 'FI' => 'EUR', 'DK' => 'DKK', 'DE' => 'EUR', 'NL' => 'EUR');
     $ship_address = $bill_address = array();
     $countries = Lookup::countries();
     //$countryData = BillmateCountry::getCountryData($Shipping->country);
     $countryData = BillmateCountry::getSwedenData();
     $ship_address = array('email' => $Customer->email, 'telno' => $Customer->phone, 'cellno' => '', 'fname' => $Customer->firstname, 'lname' => $Customer->lastname, 'company' => $Customer->company, 'careof' => '', 'street' => $Shipping->address, 'house_number' => isset($house_no) ? $house_no : '', 'house_extension' => isset($house_ext) ? $house_ext : '', 'zip' => $Shipping->postcode, 'city' => $Shipping->city, 'country' => $countries[$Shipping->country]['name']);
     $bill_address = array('email' => $Customer->email, 'telno' => $Customer->phone, 'cellno' => '', 'fname' => $Customer->firstname, 'lname' => $Customer->lastname, 'company' => $Customer->company, 'careof' => '', 'street' => $Billing->address, 'house_number' => '', 'house_extension' => '', 'zip' => $Billing->postcode, 'city' => $Billing->city, 'country' => $countries[$Billing->country]['name']);
     foreach ($ship_address as $key => $col) {
         $ship_address[$key] = utf8_decode(Encoding::fixUTF8($col));
     }
     foreach ($bill_address as $key => $col) {
         $bill_address[$key] = utf8_decode(Encoding::fixUTF8($col));
     }
     extract($countryData);
     $goods_list = array();
     $taxrate = 0;
     foreach ($this->Order->Cart as $item) {
         // echo links for the items
         $flag = stripos($item->name, 'billmate fee') === false ? stripos($item->name, 'billmate invoice fee') === false ? 0 : 16 : 0;
         $taxrate = $taxrate == 0 ? $item->taxrate : $taxrate;
         $goods_list[] = array('qty' => (int) $item->quantity, 'goods' => array('artno' => $item->product, 'title' => $item->name, 'price' => round($item->unitprice * 100, 0), 'vat' => (double) round($item->taxrate * 100, 0), 'discount' => 0.0, 'flags' => $flag));
     }
     if ($this->Order->Cart->Totals->discount > 0) {
         $rate = (100 + $taxrate * 100) / 100;
         $totalAmt = $this->Order->Cart->Totals->discount;
         $price = $totalAmt - $totalAmt / $rate;
         $discount = $totalAmt - $price;
         $goods_list[] = array('qty' => (int) 1, 'goods' => array('artno' => __('discount', 'shopp-billmate-cardpay'), 'title' => __('Discount', 'shopp-billmate-cardpay'), 'price' => -1 * abs(round($this->Order->Cart->Totals->discount * 100, 0)), 'vat' => (double) $taxrate * 100, 'discount' => (double) 0, 'flags' => $flag));
     }
     if (!empty($this->Order->Cart->Totals->shipping)) {
         /* $taxrate = $taxrate * 100;
            $rate = (100+$taxrate)/100;
            $totalAmt = $this->Order->Cart->Totals->shipping;
            $price = $totalAmt-($totalAmt/$rate);
            $shipping = $totalAmt - $price;*/
         $goods_list[] = array('qty' => (int) 1, 'goods' => array('artno' => __('Shipping', 'shopp-billmate-cardpay'), 'title' => __('Shipping', 'shopp-billmate-cardpay'), 'price' => round($this->Order->Cart->Totals->shipping * 100, 0), 'vat' => (double) $taxrate * 100, 'discount' => 0, 'flags' => 8));
     }
     $pclass = -1;
     $lang = explode("_", strtoupper(WPLANG));
     $base = $Shopp->Settings->get('base_operations');
     $_ = array();
     $transaction = array("order1" => (string) $this->txnid(), "comment" => (string) "", "flags" => 0, "reference" => "", "reference_code" => "", "currency" => $base['currency']['code'], "country" => 209, "language" => $lang[0], "pclass" => $pclass, "shipInfo" => array("delay_adjust" => "1"), "travelInfo" => array(), "incomeInfo" => array(), "bankInfo" => array(), "sid" => array("time" => microtime(true)), "extraInfo" => array(array("cust_no" => (string) $Customer->id, "creditcard_data" => $_POST)));
     if (!empty($this->Order->capture) && $this->Order->capture == 'YES') {
         $transaction["extraInfo"][0]["status"] = 'Paid';
     }
     if ($add_order) {
         return $k->AddOrder($pno, $bill_address, $ship_address, $goods_list, $transaction);
     }
     if (!isset($_SESSION['card_invoice_called']) || $_SESSION['card_invoice_called'] == false) {
         $result1 = $k->AddInvoice($pno, $bill_address, $ship_address, $goods_list, $transaction);
     } else {
         $result1[0] = $_SESSION['card_invoice_called_inv'];
     }
     if (!is_array($result1)) {
         new ShoppError(__('Unable to process billmate try again <br/>Error:', 'shopp-billmate-cardpay') . utf8_encode($result1), 2);
         echo '<script type="text/javascript">window.location.href="' . shoppurl(false, 'checkout') . '";</script>';
         die;
     } else {
         $this->Order->billmateId = $result1[0];
     }
 }
Beispiel #4
0
 function makePayment()
 {
     $quote = Mage::getSingleton('checkout/session')->getQuote();
     $_customer = Mage::getSingleton('customer/session')->isLoggedIn() ? Mage::getSingleton('customer/session')->getCustomer()->getData() : null;
     $Customer = (object) $_customer;
     if (empty($_POST)) {
         $_POST = $_GET;
     }
     $country_to_currency = array('NO' => 'NOK', 'SE' => 'SEK', 'FI' => 'EUR', 'DK' => 'DKK', 'DE' => 'EUR', 'NL' => 'EUR');
     $k = Mage::helper('billmatecardpay')->getBillmate(true, false);
     $customerId = Mage::getSingleton('customer/session')->getCustomer()->getId();
     //  $quote = Mage::getSingleton('checkout/session')->getQuote();
     $Billing = $quote->getBillingAddress();
     $Shipping = $quote->getShippingAddress();
     $billingiso3 = Mage::getModel('directory/country')->load($Billing->getCountryId())->getIso3Code();
     $billing_country = Mage::getModel('directory/country')->load($Billing->getCountryId())->getName();
     $shippingiso3 = Mage::getModel('directory/country')->load($Shipping->getCountryId())->getIso3Code();
     $shipping_country = Mage::getModel('directory/country')->load($Shipping->getCountryId())->getName();
     $shipping_country = $shipping_country == 'SWE' ? 209 : $shipping_country;
     // Get Store Country
     $countryCode = Mage::getStoreConfig('general/country/default', Mage::app()->getStore());
     $storeCountryIso2 = Mage::getModel('directory/country')->loadByCode($countryCode)->getIso2Code();
     // Get Store language
     $storeLanguage = Mage::app()->getLocale()->getLocaleCode();
     $language = 138;
     $encoding = 2;
     $currency = 0;
     switch ($billingiso3) {
         // Sweden
         case 'SWE':
             $country = 209;
             $language = 138;
             $encoding = 2;
             $currency = 0;
             $billing_country = 209;
             break;
     }
     $baseCurrencyCode = Mage::app()->getStore()->getBaseCurrencyCode();
     $currentCurrencyCode = Mage::app()->getStore()->getCurrentCurrencyCode();
     $ship_address = $bill_address = array();
     $shipp = $Shipping->getStreet();
     $bill = $Billing->getStreet();
     $orderValues['PaymentData'] = array('method' => 8, 'currency' => $currentCurrencyCode, 'country' => $storeCountryIso2, 'orderid' => $quote->getId(), 'autoactivate' => Mage::getStoreConfig('payment/billmatecardpay/payment_action') == 'sale' ? 1 : 0, 'language' => BillmateCountry::fromLocale($storeLanguage));
     $orderValues['PaymentInfo'] = array('paymentdate' => (string) date('Y-m-d'), 'paymentterms' => 14, 'yourreference' => $Billing->getFirstname() . ' ' . $Billing->getLastname(), 'delivery' => $Shipping->getShippingDescription());
     $prompt_name = Mage::getStoreConfig('payment/billmatecardpay/prompt_name') == 1 ? '1' : '0';
     $do3dsecure = Mage::getStoreConfig('payment/billmatecardpay/do_3d_secure') == 0 ? '0' : '1';
     $orderValues['Card'] = array('3dsecure' => $do3dsecure, 'promptname' => $prompt_name, 'accepturl' => Mage::getUrl('cardpay/cardpay/success', array('_secure' => true)), 'cancelurl' => Mage::getUrl('cardpay/cardpay/cancel', array('_secure' => true)), 'callbackurl' => Mage::getUrl('cardpay/cardpay/notify', array('_secure' => true)), 'returnmethod' => Mage::app()->getStore()->isCurrentlySecure() ? 'POST' : 'GET');
     $orderValues['Customer'] = array('nr' => $customerId);
     $orderValues['Customer']['Billing'] = array('firstname' => $Billing->getFirstname(), 'lastname' => $Billing->getLastname(), 'company' => $Billing->getCompany(), 'street' => $bill[0], 'street2' => isset($bill[1]) ? $bill[1] : '', 'zip' => $Billing->getPostcode(), 'city' => $Billing->getCity(), 'country' => $Billing->getCountryId(), 'phone' => $Billing->getTelephone(), 'email' => $Billing->email);
     $orderValues['Customer']['Shipping'] = array('firstname' => $Shipping->getFirstname(), 'lastname' => $Shipping->getLastname(), 'company' => $Shipping->getCompany(), 'street' => $shipp[0], 'street2' => isset($shipp[1]) ? $shipp[1] : '', 'zip' => $Shipping->getPostcode(), 'city' => $Shipping->getCity(), 'country' => $Shipping->getCountryId(), 'phone' => $Shipping->getTelephone());
     foreach ($bill_address as $key => $col) {
         $bill_address[$key] = utf8_decode($col);
     }
     foreach ($ship_address as $key => $col) {
         $ship_address[$key] = utf8_decode($col);
     }
     $goods_list = array();
     $_directory = Mage::helper('directory');
     $_taxHelper = Mage::helper('tax');
     $_weeeHelper = Mage::helper('weee');
     $percent = 0;
     $store = Mage::app()->getStore();
     $discountAmount = 0;
     $_simplePricesTax = $_taxHelper->displayPriceIncludingTax() || $_taxHelper->displayBothPrices();
     // Create Array to save ParentId when bundle is fixed prised
     $bundleArr = array();
     $totalValue = 0;
     $totalTax = 0;
     $discountAdded = false;
     $discountValue = 0;
     $discountTax = 0;
     $discounts = array();
     $configSku = false;
     foreach ($quote->getAllItems() as $_item) {
         /**
          * @var $_item Mage_Sales_Model_Quote_Item
          */
         // Continue if bundleArr contains item parent id, no need for get price then.
         if (in_array($_item->getParentItemId(), $bundleArr)) {
             continue;
         }
         $request = Mage::getSingleton('tax/calculation')->getRateRequest(null, null, null, $store);
         $taxclassid = $_item->getProduct()->getData('tax_class_id');
         // If Product type == bunde and if bundle price type == fixed
         if ($_item->getProductType() == 'bundle' && $_item->getProduct()->getPriceType() == 1) {
             // Set bundle id to $bundleArr
             $bundleArr[] = $_item->getId();
         }
         if ($_item->getProductType() == 'configurable') {
             $configSku = $_item->getSku();
             $cp = $_item->getProduct();
             $sp = Mage::getModel('catalog/product')->loadByAttribute('sku', $_item->getSku());
             $price = $_directory->currencyConvert($_item->getCalculationPrice(), $baseCurrencyCode, $currentCurrencyCode);
             $percent = Mage::getSingleton('tax/calculation')->getRate($request->setProductClassId($taxclassid));
             $discount = 0.0;
             $discountAmount = 0;
             if ($_item->getDiscountPercent() != 0) {
                 $discountAdded = true;
                 $marginal = $percent / 100 / (1 + $percent / 100);
                 $discount = $_item->getDiscountPercent();
                 $discountAmount = $_item->getBaseDiscountAmount();
                 // $discountPerArticle without VAT
                 $discountAmount = $discountAmount - $discountAmount * $marginal;
             }
             $total = $discountAdded ? (int) round(($price * $_item->getQty() - $discountAmount) * 100) : (int) round($price * 100) * $_item->getQty();
             $orderValues['Articles'][] = array('quantity' => (int) $_item->getQty(), 'artnr' => $_item->getProduct()->getSKU(), 'title' => $cp->getName() . ' - ' . $sp->getName(), 'aprice' => (int) round($price * 100, 0), 'taxrate' => (double) $percent, 'discount' => $discount, 'withouttax' => $total);
             $temp = $total;
             $totalValue += $temp;
             $totalTax += $temp * ($percent / 100);
             if (isset($discounts[$percent])) {
                 $discounts[$percent] += $temp;
             } else {
                 $discounts[$percent] = $temp;
             }
         }
         if ($_item->getSku() == $configSku) {
             continue;
         }
         // If Product type == bunde and if bundle price type == dynamic
         if ($_item->getProductType() == 'bundle' && $_item->getProduct()->getPriceType() == 0) {
             $percent = Mage::getSingleton('tax/calculation')->getRate($request->setProductClassId($taxclassid));
             $orderValues['Articles'][] = array('quantity' => (int) $_item->getQty(), 'artnr' => $_item->getProduct()->getSKU(), 'title' => $_item->getName(), 'aprice' => (int) 0, 'taxrate' => (double) $percent, 'discount' => 0.0, 'withouttax' => (int) 0);
             // Else the item is not bundle and dynamic priced
         } else {
             $temp = 0;
             $percent = Mage::getSingleton('tax/calculation')->getRate($request->setProductClassId($taxclassid));
             // For tierPrices to work, we need to get calculation price not the price on the product.
             // If a customer buys many of a kind and get a discounted price, the price will bee on the quote item.
             $price = $_directory->currencyConvert($_item->getCalculationPrice(), $baseCurrencyCode, $currentCurrencyCode);
             //Mage::throwException( 'error '.$_regularPrice.'1-'. $_finalPrice .'2-'.$_finalPriceInclTax.'3-'.$_price);
             $discount = 0.0;
             $discountAmount = 0;
             if ($_item->getDiscountPercent() != 0) {
                 $discountAdded = true;
                 //$discount = 100 *($_item->getBaseDiscountAmount() / $price);
                 $marginal = $percent / 100 / (1 + $percent / 100);
                 $discount = $_item->getDiscountPercent();
                 $discountAmount = $_item->getBaseDiscountAmount();
                 // $discountPerArticle without VAT
                 $discountAmount = $discountAmount - $discountAmount * $marginal;
             }
             $total = $discountAdded ? (int) round(($price * $_item->getQty() - $discountAmount) * 100) : (int) round($price * 100) * $_item->getQty();
             $orderValues['Articles'][] = array('quantity' => (int) $_item->getQty(), 'artnr' => $_item->getProduct()->getSKU(), 'title' => $_item->getName(), 'aprice' => (int) round($price * 100, 0), 'taxrate' => (double) $percent, 'discount' => $discount, 'withouttax' => $total);
             $temp = $total;
             $totalValue += $temp;
             $totalTax += $temp * ($percent / 100);
             if (isset($discounts[$percent])) {
                 $discounts[$percent] += $temp;
             } else {
                 $discounts[$percent] = $temp;
             }
         }
     }
     $totals = Mage::getSingleton('checkout/session')->getQuote()->getTotals();
     //print_r($quote1['subtotal']->getData());
     if (isset($totals['discount']) && !$discountAdded) {
         $totalDiscountInclTax = $totals['discount']->getValue();
         $subtotal = $totalValue;
         foreach ($discounts as $percent => $amount) {
             $discountPercent = $amount / $subtotal;
             $floor = 1 + $percent / 100;
             $marginal = 1 / $floor;
             $discountAmount = $discountPercent * $totalDiscountInclTax;
             $orderValues['Articles'][] = array('quantity' => (int) 1, 'artnr' => 'discount', 'title' => Mage::helper('payment')->__('Discount') . ' ' . Mage::helper('billmatecardpay')->__('%s Vat', $percent), 'aprice' => round($discountAmount * $marginal * 100), 'taxrate' => (double) $percent, 'discount' => 0.0, 'withouttax' => round($discountAmount * $marginal * 100));
             $totalValue += 1 * round($discountAmount * $marginal * 100);
             $totalTax += 1 * round($discountAmount * $marginal * 100) * ($percent / 100);
         }
     }
     $rates = $quote->getShippingAddress()->getShippingRatesCollection();
     if (!empty($rates)) {
         if ($Shipping->getBaseShippingTaxAmount() > 0) {
             $rate = round($Shipping->getBaseShippingTaxAmount() / $Shipping->getBaseShippingAmount() * 100);
         } else {
             $rate = 0;
         }
         $orderValues['Cart']['Shipping'] = array('withouttax' => $Shipping->getShippingAmount() * 100, 'taxrate' => (int) $rate);
         $totalValue += $Shipping->getShippingAmount() * 100;
         $totalTax += $Shipping->getShippingAmount() * 100 * ($rate / 100);
     }
     $round = round($quote->getGrandTotal() * 100 - ((int) $totalValue + (int) $totalTax));
     $orderValues['Cart']['Total'] = array('withouttax' => $totalValue, 'tax' => (int) $totalTax, 'rounding' => $round, 'withtax' => (int) $totalValue + (int) $totalTax + (int) $round);
     $result = $k->addPayment($orderValues);
     if (isset($result['code'])) {
         Mage::throwException(utf8_encode($result['message']));
     } else {
         $session = Mage::getSingleton('core/session', array('name' => 'frontend'));
         $session->setData('billmateinvoice_id', $result['number']);
         $session->setData('billmateorder_id', $result['orderid']);
     }
     return $result;
 }
Beispiel #5
0
 function makePayment()
 {
     // Init $orderValues Array
     $orderValues = array();
     $quote = Mage::getSingleton('checkout/session')->getQuote();
     $Billing = $quote->getBillingAddress();
     $Shipping = $quote->getShippingAddress();
     $payment = Mage::app()->getRequest()->getPost('payment');
     $methodname = $payment['method'] == 'billmateinvoice' ? 'billmateinvoice' : 'partpayment';
     $k = Mage::helper('billmateinvoice')->getBillmate(true, false);
     $customerId = Mage::getSingleton('customer/session')->getCustomer()->getId();
     $countryCode = Mage::getStoreConfig('general/country/default', Mage::app()->getStore());
     $storeCountryIso2 = Mage::getModel('directory/country')->loadByCode($countryCode)->getIso2Code();
     $storeLanguage = Mage::app()->getLocale()->getLocaleCode();
     $ship_address = $bill_address = array();
     $shipp = $Shipping->getStreet();
     $bill = $Billing->getStreet();
     foreach ($bill_address as $key => $col) {
         $bill_address[$key] = mb_convert_encoding($col, 'UTF-8', 'auto');
     }
     foreach ($ship_address as $key => $col) {
         $ship_address[$key] = mb_convert_encoding($col, 'UTF-8', 'auto');
     }
     $baseCurrencyCode = Mage::app()->getStore()->getBaseCurrencyCode();
     $currentCurrencyCode = Mage::app()->getStore()->getCurrentCurrencyCode();
     $_directory = Mage::helper('directory');
     $store = Mage::app()->getStore();
     $orderValues['PaymentData'] = array('method' => 1, 'currency' => $currentCurrencyCode, 'country' => $storeCountryIso2, 'orderid' => (string) time(), 'autoactivate' => 0, 'language' => BillmateCountry::fromLocale($storeLanguage));
     $orderValues['PaymentInfo'] = array('paymentdate' => (string) date('Y-m-d'), 'paymentterms' => 14, 'yourreference' => $Billing->getFirstname() . ' ' . $Billing->getLastname(), 'delivery' => $Shipping->getShippingDescription());
     $orderValues['Customer'] = array('nr' => $customerId, 'pno' => empty($payment[$methodname . '_pno']) ? $payment['person_number'] : $payment[$methodname . '_pno']);
     $orderValues['Customer']['Billing'] = array('firstname' => $Billing->getFirstname(), 'lastname' => $Billing->getLastname(), 'company' => $Billing->getCompany(), 'street' => $bill[0], 'street2' => isset($bill[1]) ? $bill[1] : '', 'zip' => $Billing->getPostcode(), 'city' => $Billing->getCity(), 'country' => $Billing->getCountryId(), 'phone' => $Billing->getTelephone(), 'email' => $Billing->email);
     $orderValues['Customer']['Shipping'] = array('firstname' => $Shipping->getFirstname(), 'lastname' => $Shipping->getLastname(), 'company' => $Shipping->getCompany(), 'street' => $shipp[0], 'street2' => isset($shipp[1]) ? $shipp[1] : '', 'zip' => $Shipping->getPostcode(), 'city' => $Shipping->getCity(), 'country' => $Shipping->getCountryId(), 'phone' => $Shipping->getTelephone());
     // Create Array to save ParentId when bundle is fixed prised
     $bundleArr = array();
     $totalValue = 0;
     $totalTax = 0;
     $discountAdded = false;
     $discountValue = 0;
     $configSku = false;
     $discounts = array();
     foreach ($quote->getAllItems() as $_item) {
         // Continue if bundleArr contains item parent id, no need for get price then.
         if (in_array($_item->getParentItemId(), $bundleArr)) {
             continue;
         }
         $request = Mage::getSingleton('tax/calculation')->getRateRequest(null, null, null, $store);
         $taxclassid = $_item->getProduct()->getData('tax_class_id');
         // If Product type == bunde and if bundle price type == fixed
         if ($_item->getProductType() == 'bundle' && $_item->getProduct()->getPriceType() == 1) {
             // Set bundle id to $bundleArr
             $bundleArr[] = $_item->getId();
         }
         if ($_item->getProductType() == 'configurable') {
             $configSku = $_item->getSku();
             $cp = $_item->getProduct();
             $sp = Mage::getModel('catalog/product')->loadByAttribute('sku', $_item->getSku());
             $price = $_directory->currencyConvert($_item->getCalculationPrice(), $baseCurrencyCode, $currentCurrencyCode);
             $percent = Mage::getSingleton('tax/calculation')->getRate($request->setProductClassId($taxclassid));
             $discount = 0.0;
             $discountAmount = 0;
             if ($_item->getDiscountPercent() != 0) {
                 $discountAdded = true;
                 $discount = $_item->getDiscountPercent();
                 $marginal = $percent / 100 / (1 + $percent / 100);
                 $discountAmount = $_item->getBaseDiscountAmount();
                 // $discountPerArticle without VAT
                 $discountAmount = $discountAmount - $discountAmount * $marginal;
             }
             $total = $discountAdded ? (int) round(($price * $_item->getQty() - $discountAmount) * 100) : (int) round($price * 100) * $_item->getQty();
             $orderValues['Articles'][] = array('quantity' => (int) $_item->getQty(), 'artnr' => $_item->getProduct()->getSKU(), 'title' => $cp->getName() . ' - ' . $sp->getName(), 'aprice' => (int) round($price * 100, 0), 'taxrate' => (double) $percent, 'discount' => $discount, 'withouttax' => $total);
             $temp = $total;
             $totalValue += $temp;
             $totalTax += $temp * ($percent / 100);
             if (isset($discounts[$percent])) {
                 $discounts[$percent] += $temp;
             } else {
                 $discounts[$percent] = $temp;
             }
         }
         if ($_item->getSku() == $configSku) {
             continue;
         }
         // If Product type == bunde and if bundle price type == dynamic
         if ($_item->getProductType() == 'bundle' && $_item->getProduct()->getPriceType() == 0) {
             $percent = Mage::getSingleton('tax/calculation')->getRate($request->setProductClassId($taxclassid));
             $orderValues['Articles'][] = array('quantity' => (int) $_item->getQty(), 'artnr' => $_item->getProduct()->getSKU(), 'title' => $_item->getName(), 'aprice' => (int) 0, 'taxrate' => (double) $percent, 'discount' => 0.0, 'withouttax' => (int) 0);
             // Else the item is not bundle and dynamic priced
         } else {
             $temp = 0;
             $percent = Mage::getSingleton('tax/calculation')->getRate($request->setProductClassId($taxclassid));
             // For tierPrices to work, we need to get calculation price not the price on the product.
             // If a customer buys many of a kind and get a discounted price, the price will bee on the quote item.
             $price = $_directory->currencyConvert($_item->getCalculationPrice(), $baseCurrencyCode, $currentCurrencyCode);
             //Mage::throwException( 'error '.$_regularPrice.'1-'. $_finalPrice .'2-'.$_finalPriceInclTax.'3-'.$_price);
             $discount = 0.0;
             $discountAmount = 0;
             if ($_item->getDiscountPercent() != 0) {
                 $discountAdded = true;
                 $discount = $_item->getDiscountPercent();
                 $marginal = $percent / 100 / (1 + $percent / 100);
                 $discountAmount = $_item->getBaseDiscountAmount();
                 // $discountPerArticle without VAT
                 $discountAmount = $discountAmount - $discountAmount * $marginal;
             }
             $total = $discountAdded ? (int) round(($price * $_item->getQty() - $discountAmount) * 100) : (int) round($price * 100) * $_item->getQty();
             $orderValues['Articles'][] = array('quantity' => (int) $_item->getQty(), 'artnr' => $_item->getProduct()->getSKU(), 'title' => $_item->getName(), 'aprice' => (int) round($price * 100, 0), 'taxrate' => (double) $percent, 'discount' => $discount, 'withouttax' => $total);
             $temp = $total;
             $totalValue += $temp;
             $totalTax += $temp * ($percent / 100);
             if (isset($discounts[$percent])) {
                 $discounts[$percent] += $temp;
             } else {
                 $discounts[$percent] = $temp;
             }
         }
     }
     $totals = Mage::getSingleton('checkout/session')->getQuote()->getTotals();
     if (isset($totals['discount']) && !$discountAdded) {
         $totalDiscountInclTax = $totals['discount']->getValue();
         $subtotal = $totalValue;
         foreach ($discounts as $percent => $amount) {
             $discountPercent = $amount / $subtotal;
             $floor = 1 + $percent / 100;
             $marginal = 1 / $floor;
             $discountAmount = $discountPercent * $totalDiscountInclTax;
             $orderValues['Articles'][] = array('quantity' => (int) 1, 'artnr' => 'discount', 'title' => Mage::helper('payment')->__('Discount') . ' ' . Mage::helper('billmateinvoice')->__('%s Vat', $percent), 'aprice' => round($discountAmount * $marginal * 100), 'taxrate' => (double) $percent, 'discount' => 0.0, 'withouttax' => round($discountAmount * $marginal * 100));
             $totalValue += 1 * round($discountAmount * $marginal * 100);
             $totalTax += 1 * round($discountAmount * $marginal * 100) * ($percent / 100);
         }
     }
     $rates = $quote->getShippingAddress()->getShippingRatesCollection();
     if (!empty($rates)) {
         if ($Shipping->getBaseShippingTaxAmount() > 0) {
             $rate = round($Shipping->getBaseShippingTaxAmount() / $Shipping->getBaseShippingAmount() * 100);
         } else {
             $rate = 0;
         }
         $orderValues['Cart']['Shipping'] = array('withouttax' => $Shipping->getShippingAmount() * 100, 'taxrate' => (int) $rate);
         $totalValue += $Shipping->getShippingAmount() * 100;
         $totalTax += $Shipping->getShippingAmount() * 100 * ($rate / 100);
     }
     if ($methodname == 'billmateinvoice') {
         $invoiceFee = Mage::getStoreConfig('payment/billmateinvoice/billmate_fee');
         $invoiceFee = Mage::helper('billmateinvoice')->replaceSeparator($invoiceFee);
         //if(Mage::getStoreConfig('payment/billmateinvoice/tax_class')){
         $feeinfo = Mage::helper('billmateinvoice')->getInvoiceFeeArray($invoiceFee, $Shipping, $quote->getCustomerTaxClassId());
         //}
         if (!empty($invoiceFee) && $invoiceFee > 0) {
             // $invoiceFee = $_directory->currencyConvert($invoiceFee,$baseCurrencyCode,$currentCurrencyCode);
             $orderValues['Cart']['Handling'] = array('withouttax' => $Shipping->getBaseFeeAmount() * 100, 'taxrate' => $feeinfo['rate']);
             $totalValue += $Shipping->getBaseFeeAmount() * 100;
             $totalTax += $Shipping->getBaseFeeAmount() * 100 * ($feeinfo['rate'] / 100);
         }
     }
     $round = round($quote->getGrandTotal() * 100 - ((int) $totalValue + (int) $totalTax));
     $orderValues['Cart']['Total'] = array('withouttax' => $totalValue, 'tax' => (int) $totalTax, 'rounding' => $round, 'withtax' => (int) $totalValue + (int) $totalTax + (int) $round);
     $result = $k->addPayment($orderValues);
     if (isset($result['code'])) {
         Mage::throwException(utf8_encode($result['message']));
     } else {
         $session = Mage::getSingleton('core/session', array('name' => 'frontend'));
         $session->setData('billmateinvoice_id', $result['number']);
         $session->setData('billmateorder_id', $result['orderid']);
         return $result['number'];
     }
 }