/**
  * Sends a notification message to all users responsible for vat assignment.
  * 
  * @access	public
  * @static
  * @param	ilPaymentObject $oPaymentObject
  */
 public static function _sendNotificationToVATAdministration($oPaymentObject)
 {
     global $ilSetting, $lng, $ilClientIniFile;
     $payment_vat_admins = $ilSetting->get('payment_vat_admins');
     $users = explode(',', $payment_vat_admins);
     $subject = $lng->txt('payment_vat_assignment_notification_subject');
     $tmp_obj = ilObjectFactory::getInstanceByRefId($oPaymentObject->getRefId());
     $message = sprintf($lng->txt('payment_vat_assignment_notification_body'), $tmp_obj->getTitle()) . "\n\n";
     $message .= "------------------------------------------------------------\n";
     $message .= sprintf($lng->txt('payment_vat_assignment_notification_intro'), $ilClientIniFile->readVariable('client', 'name'), ILIAS_HTTP_PATH . '/?client_id=' . CLIENT_ID);
     include_once 'Services/Mail/classes/class.ilMail.php';
     $mail_obj = new ilMail(ANONYMOUS_USER_ID);
     foreach ((array) $users as $login) {
         if (strlen(trim($login)) && (int) ilObjUser::_lookupId(trim($login))) {
             $success = $mail_obj->sendMail(trim($login), '', '', $subject, $message, array(), array("system"));
         }
     }
 }
 public function saveCustomerObject()
 {
     global $ilUser, $ilObjDataCache;
     if (!isset($_GET['sell_id'])) {
         ilUtil::sendInfo($this->lng->txt('paya_error_no_object_id_given'));
         $this->showObjectSelectorObject();
         return true;
     }
     if (!isset($_GET['user_id'])) {
         ilUtil::sendInfo($this->lng->txt('paya_error_no_user_id_given'));
         $this->searchUserSPObject();
         return true;
     }
     if ($_POST['pay_method'] == '' || $_POST['price_id'] == '') {
         ilUtil::sendInfo($this->lng->txt('paya_error_mandatory_fields'));
         $this->addCustomerObject();
         return true;
     }
     $pObjectId = ilPaymentObject::_lookupPobjectId($_GET['sell_id']);
     $obj = new ilPaymentObject($this->user_obj, $pObjectId);
     $this->__initBookingObject();
     $transaction = ilInvoiceNumberPlaceholdersPropertyGUI::_generateInvoiceNumber($ilUser->getId());
     $this->booking_obj->setTransaction($transaction);
     $this->booking_obj->setTransactionExtern($_POST['transaction']);
     $this->booking_obj->setPobjectId($pObjectId);
     $this->booking_obj->setCustomerId($_GET['user_id']);
     $this->booking_obj->setVendorId($obj->getVendorId());
     $this->booking_obj->setPayMethod($_POST['pay_method']);
     $this->booking_obj->setOrderDate(time());
     $price = ilPaymentPrices::_getPrice($_POST['price_id']);
     //		$currency = ilPaymentCurrency::_getUnit($price['currency']);
     #@todo check this.
     switch ($price['price_type']) {
         case ilPaymentPrices::TYPE_DURATION_MONTH:
             $this->booking_obj->setDuration($price['duration']);
             break;
         case ilPaymentPrices::TYPE_DURATION_DATE:
             $this->booking_obj->setDuration(0);
             $this->booking_obj->setAccessStartdate($price['duration_from']);
             $this->booking_obj->setAccessEnddate($price['duration_until']);
             break;
         case ilPaymentPrices::TYPE_UNLIMITED_DURATION:
             $this->booking_obj->setDuration(0);
             $this->booking_obj->setAccessEnddate(NULL);
             break;
     }
     $this->booking_obj->setPriceType($price['price_type']);
     $this->booking_obj->setPrice($price['price']);
     $this->booking_obj->setAccess((int) $_POST['access']);
     $this->booking_obj->setPayed((int) $_POST['payed']);
     $this->booking_obj->setVoucher('');
     $obj_id = $ilObjDataCache->lookupObjId($obj->getRefId());
     $obj_type = $ilObjDataCache->lookupType($obj_id);
     $obj_title = $ilObjDataCache->lookupTitle($obj_id);
     //	include_once 'Services/Payment/classes/class.ilShopVatsList.php';
     $oVAT = new ilShopVats((int) $obj->getVatId());
     $obj_vat_rate = $oVAT->getRate();
     $obj_vat_unit = $obj->getVat($this->booking_obj->getPrice());
     $this->booking_obj->setObjectTitle($obj_title);
     $this->booking_obj->setVatRate($obj_vat_rate);
     $this->booking_obj->setVatUnit($obj_vat_unit);
     $genSet = ilPaymentSettings::_getInstance();
     $this->booking_obj->setCurrencyUnit($genSet->get('currency_unit'));
     include_once './Services/Payment/classes/class.ilPayMethods.php';
     $save_user_address_enabled = ilPayMethods::_EnabledSaveUserAddress($this->booking_obj->getPayMethod());
     if ($save_user_address_enabled == 1) {
         global $ilObjUser;
         $user_id[] = $_GET["user_id"];
         $cust_obj = ilObjUser::_readUsersProfileData($user_id);
         $this->booking_obj->setStreet($cust_obj[$_GET["user_id"]]['street'], '');
         $this->booking_obj->setZipcode($cust_obj[$_GET["user_id"]]['zipcode']);
         $this->booking_obj->setCity($cust_obj[$_GET["user_id"]]['city']);
         $this->booking_obj->setCountry($cust_obj[$_GET["user_id"]]['country']);
     }
     if ($this->booking_obj->add()) {
         // add purchased item to desktop
         ilShopUtils::_addPurchasedObjToDesktop($obj, $this->booking_obj->getCustomerId());
         // autosubscribe user if purchased object is a course
         if ($obj_type == 'crs') {
             ilShopUtils::_assignPurchasedCourseMemberRole($obj, $this->booking_obj->getCustomerId());
         }
         ilUtil::sendInfo($this->lng->txt('paya_customer_added_successfully'));
         $this->statisticObject();
     } else {
         ilUtil::sendInfo($this->lng->txt('paya_error_adding_customer'));
         $this->addCustomerObject();
     }
     return true;
 }
 private function showItemsTable(&$a_tpl, $a_result_set, $a_pay_method = 0)
 {
     include_once './Services/Payment/classes/class.ilPaymentSettings.php';
     $genSet = ilPaymentSettings::_getInstance();
     include_once './Services/Payment/classes/class.ilShoppingCartTableGUI.php';
     $tbl = new ilShoppingCartTableGUI($this);
     $tbl->setId('tbl_id_' . $a_pay_method);
     $tbl->setTitle($this->lng->txt('paya_shopping_cart') . " (" . $this->lng->txt('payment_system') . ": " . ilPayMethods::getStringByPaymethod($a_pay_method['pm_title']) . ")");
     $coupon_session = $a_pay_method['pm_title'];
     $tbl->setRowTemplate("tpl.shop_shoppingcart_row.html", "Services/Payment");
     $tbl->addColumn('', 'item', '1%', true);
     $tbl->addColumn($this->lng->txt('title'), "table" . $a_pay_method['pm_title'] . "_title", '30%');
     $tbl->addColumn($this->lng->txt('duration'), "table" . $a_pay_method['pm_title'] . "_duration", '30%');
     $tbl->addColumn($this->lng->txt('vat_rate'), "table" . $a_pay_method['pm_title'] . "_vat_rate", '15%');
     $tbl->addColumn($this->lng->txt('vat_unit'), "table" . $a_pay_method['pm_title'] . "_vat_unit", '15%');
     $tbl->addColumn($this->lng->txt('price_a'), "table" . $a_pay_method['pm_title'] . "_price", '10%');
     $tbl->setPrefix("table" . $a_pay_method['pm_title'] . "_");
     $tbl->addMultiCommand('deleteItem', $this->lng->txt('delete'));
     // show total amount of costs
     $sc_obj = new ilPaymentShoppingCart($this->user_obj);
     $totalAmount = $sc_obj->getTotalAmount();
     if (!empty($_SESSION['coupons'][$coupon_session])) {
         if (count($items = $sc_obj->getEntries($a_pay_method['pm_id']))) {
             $tbl->setTotalData('TXT_SUB_TOTAL', $this->lng->txt('pay_bmf_subtotal_amount') . ": ");
             $tbl->setTotalData('VAL_SUB_TOTAL', number_format($totalAmount[$a_pay_method['pm_id']], 2, ',', '.') . " " . $genSet->get('currency_unit'));
             foreach ($_SESSION['coupons'][$coupon_session] as $coupon) {
                 $this->coupon_obj->setId($coupon['pc_pk']);
                 $this->coupon_obj->setCurrentCoupon($coupon);
                 $total_object_price = 0.0;
                 $current_coupon_bonus = 0.0;
                 foreach ($items as $item) {
                     $tmp_pobject = new ilPaymentObject($this->user_obj, $item['pobject_id']);
                     if ($this->coupon_obj->isObjectAssignedToCoupon($tmp_pobject->getRefId())) {
                         $price_data = ilPaymentPrices::_getPrice($item['price_id']);
                         $price = (double) $price_data['price'];
                         $total_object_price += $price;
                     }
                     unset($tmp_pobject);
                 }
                 $current_coupon_bonus = $this->coupon_obj->getCouponBonus($total_object_price);
                 $totalAmount[$current_coupon_bonus] += $current_coupon_bonus * -1;
             }
             $tbl->setTotalData('TXT_COUPON_BONUS', $this->lng->txt('paya_coupons_coupon') . ": ");
             # . $coupon['pcc_code'] . ": ");
             #$tbl->setTotalData('VAL_COUPON_BONUS', number_format($current_coupon_bonus * (-1), 2, ',', '.') . " " . $genSet->get('currency_unit'));
             $tbl->setTotalData('VAL_COUPON_BONUS', number_format($totalAmount[$current_coupon_bonus], 2, ',', '.') . " " . $genSet->get('currency_unit'));
             if ($totalAmount[$a_pay_method['pm_id']] < 0) {
                 $totalAmount[$a_pay_method['pm_id']] = 0;
                 $this->totalVat = 0;
             }
         }
     }
     $this->totalAmount[$a_pay_method['pm_id']] = $totalAmount[$a_pay_method['pm_id']] - $totalAmount[$current_coupon_bonus] * -1;
     $tbl->setTotalData('TXT_TOTAL_AMOUNT', $this->lng->txt('pay_bmf_total_amount') . ": ");
     $tbl->setTotalData('VAL_TOTAL_AMOUNT', number_format($this->totalAmount[$a_pay_method['pm_id']], 2, ',', '.') . " " . $genSet->get('currency_unit'));
     #.$item['currency']);
     if ($this->totalVat > 0) {
         $tbl->setTotalData('TXT_TOTAL_VAT', $this->lng->txt('pay_bmf_vat_included') . ": ");
         $tbl->setTotalData('VAL_TOTAL_VAT', number_format($this->totalVat, 2, ',', '.') . " " . $genSet->get('currency_unit'));
     }
     $tbl->setData($a_result_set);
     $a_tpl->setVariable('ITEMS_TABLE', $tbl->getCartHTML());
     return true;
 }
 private function __checkItems($a_array)
 {
     $genSet = ilPaymentSettings::_getInstance();
     // Wrong currency
     if ($a_array["mc_currency"] != $genSet->get("currency_unit")) {
         return false;
     }
     $sc = $this->psc_obj->getShoppingCart($this->pay_method);
     $this->psc_obj->clearCouponItemsSession();
     if (is_array($sc) && count($sc) > 0) {
         for ($i = 0; $i < count($sc); $i++) {
             $items[$i] = array("name" => $a_array["item_name" . ($i + 1)], "amount" => $a_array["mc_gross_" . ($i + 1)]);
             if (!empty($_SESSION["coupons"]["paypal"])) {
                 $sc[$i]["math_price"] = (double) $sc[$i]["price"];
                 $tmp_pobject = new ilPaymentObject($this->user_obj, $sc[$i]['pobject_id']);
                 foreach ($_SESSION["coupons"]["paypal"] as $key => $coupon) {
                     $this->coupon_obj->setId($coupon["pc_pk"]);
                     $this->coupon_obj->setCurrentCoupon($coupon);
                     if ($this->coupon_obj->isObjectAssignedToCoupon($tmp_pobject->getRefId())) {
                         $_SESSION["coupons"]["paypal"][$key]["total_objects_coupon_price"] += (double) $sc[$i]["price"];
                         $_SESSION["coupons"]["paypal"][$key]["items"][] = $sc[$i];
                     }
                 }
                 unset($tmp_pobject);
             }
         }
         $coupon_discount_items = $this->psc_obj->calcDiscountPrices($_SESSION["coupons"]["paypal"]);
         $found = 0;
         $total = 0;
         for ($i = 0; $i < count($sc); $i++) {
             if (array_key_exists($sc[$i]["pobject_id"], $coupon_discount_items)) {
                 $sc[$i]["price"] = round($coupon_discount_items[$sc[$i]["pobject_id"]]["discount_price"], 2);
                 if ($sc[$i]["price"] < 0) {
                     $sc[$i]["price"] = 0.0;
                 }
             }
             for ($j = 0; $j < count($items); $j++) {
                 if (substr($items[$j]["name"], 0, strlen($sc[$i]["obj_id"]) + 2) == "[" . $sc[$i]["obj_id"] . "]" && $items[$j]["amount"] == $sc[$i]["price"]) {
                     $total += $items[$j]["amount"];
                     $found++;
                 }
             }
         }
         // The number of items, the items themselves and their amounts and the total amount correct
         if (number_format($total, 2, ".", "") == $a_array["mc_gross"] && $found == count($sc)) {
             return true;
         }
     }
     return false;
 }
 function sendCreditCard()
 {
     $this->psc_obj = new ilPaymentShoppingCart($this->user_obj);
     $this->psc_obj->clearCouponItemsSession();
     if (!count($items = $this->psc_obj->getEntries($this->pm_id))) {
         $this->tpl->setVariable("HEADER", $this->lng->txt('pay_bmf_your_order'));
         $this->tpl->touchBlock("stop_floating");
         ilUtil::sendInfo($this->lng->txt('pay_shopping_cart_empty'));
     } else {
         $payment = new KreditkartenzahlungWS();
         $customer = new Kunde($this->user_obj->getId());
         $creditCard = new Kreditkarte();
         $sc_obj = new ilPaymentShoppingCart($this->user_obj);
         $tmp_bookEntries = $sc_obj->getShoppingCart();
         if (!is_array($tmp_bookEntries)) {
             ilUtil::sendInfo($this->lng->txt('pay_shopping_cart_empty'));
         } else {
             $totalAmount = 0;
             for ($i = 0; $i < count($tmp_bookEntries); $i++) {
                 $booking = true;
                 if (!empty($_SESSION["coupons"]["bmf"])) {
                     $price = $tmp_bookEntries[$i]["price"];
                     $tmp_bookEntries[$i]["math_price"] = $price;
                     foreach ($_SESSION["coupons"]["bmf"] as $key => $coupon) {
                         $this->coupon_obj->setId($coupon["pc_pk"]);
                         $this->coupon_obj->setCurrentCoupon($coupon);
                         $tmp_pobject = new ilPaymentObject($this->user_obj, $tmp_bookEntries[$i]['pobject_id']);
                         if ($this->coupon_obj->isObjectAssignedToCoupon($tmp_pobject->getRefId())) {
                             $_SESSION["coupons"]["bmf"][$key]["total_objects_coupon_price"] += $price;
                             $_SESSION["coupons"]["bmf"][$key]["items"][] = $tmp_bookEntries[$i];
                             $booking = false;
                         }
                         unset($tmp_pobject);
                     }
                 }
                 if ($booking) {
                     $tmp_bookEntries[$i]["price_string"] = number_format((double) $tmp_bookEntries[$i]["price"], 2, ",", ".");
                     $bookEntries[] = new Buchung($tmp_bookEntries[$i]);
                     $totalAmount += $tmp_bookEntries[$i]["price"];
                 } else {
                     $tmp_bookEntries[$i]["price_string"] = number_format((double) $tmp_bookEntries[$i]["price"], 2, ",", ".");
                 }
             }
             $coupon_discount_items = $this->psc_obj->calcDiscountPrices($_SESSION["coupons"]["bmf"]);
             if (is_array($coupon_discount_items) && !empty($coupon_discount_items)) {
                 foreach ($coupon_discount_items as $item) {
                     $item["price"] = number_format((double) $item["discount_price"], 2, ".", "");
                     $bookEntries[] = new Buchung($item);
                     $totalAmount += $item["discount_price"];
                 }
             }
             $totalAmount = number_format((double) $totalAmount, 2, ".", "");
             $values = array("betrag" => $totalAmount, "buchungen" => $bookEntries);
             $bookingList = new BuchungsListe($this->user_obj->getId(), $values);
         }
         $resultObj = $payment->zahlenUndAnlegenKunde($customer, $creditCard, $bookingList);
         $result = $resultObj->ergebnis;
         if (is_object($result)) {
             if ($result->code < 0) {
                 $this->tpl->setVariable("HEADER", $this->lng->txt('error'));
                 $this->tpl->touchBlock("stop_floating");
                 $error = $this->lng->txt('pay_bmf_server_error_code') . " " . $result->code . ": " . $result->kurzText . "<br>\n" . $result->langText;
                 if ($result->code == -103 || $result->code == -104 || $result->code == -107 || $result->code <= -202 && $result->code >= -208 || $result->code == -213) {
                     ilUtil::sendInfo($error);
                     $this->showPersonalData();
                 } else {
                     if ($result->code == -507 || $result->code == -510 || $result->code == -511) {
                         ilUtil::sendInfo($error);
                         $this->showPaymentType();
                     } else {
                         if ($result->code == -701 || $result->code == -1701 || $result->code == -1706 || $result->code == -1707 || $result->code == -1710 || $result->code == -1711) {
                             ilUtil::sendInfo($error);
                             $this->showCreditCard();
                         } else {
                             $error .= "<br>\n" . $this->lng->txt('pay_bmf_server_error_sysadmin');
                             ilUtil::sendInfo($error);
                             $this->showPersonalData();
                         }
                     }
                 }
             } else {
                 // everything ok => send confirmation, fill statistik, delete session, delete shopping cart.
                 $external_data = array();
                 $external_data['voucher'] = $resultObj->buchungsListe->buchungen[$b++]->belegNr;
                 $external_data['transaction_extern'] = $resultObj->buchungsListe->kassenzeichen;
                 $external_data['street'] = utf8_decode($resultCustomerObj->kunde->rechnungsAdresse->strasse) . ' ' . utf8_decode($resultCustomerObj->kunde->rechnungsAdresse->hausNr);
                 $external_data['po_box'] = utf8_decode($resultCustomerObj->kunde->rechnungsAdresse->postfach);
                 $external_data['zipcode'] = utf8_decode($resultCustomerObj->kunde->rechnungsAdresse->PLZ);
                 $external_data['city'] = utf8_decode($resultCustomerObj->kunde->rechnungsAdresse->ort);
                 $external_data['country'] = utf8_decode($resultCustomerObj->kunde->rechnungsAdresse->land);
                 parent::__addbookings($external_data);
                 $this->__emptyShoppingCart();
                 $this->__clearSession();
                 $this->tpl->setVariable("HEADER", $this->lng->txt('pay_bmf_your_order'));
                 $this->tpl->setVariable("DESCRIPTION", $this->lng->txt('pay_bmf_thanks'));
                 $this->tpl->touchBlock("stop_floating");
                 ilUtil::sendInfo($this->lng->txt('pay_bmf_thanks'));
                 $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.pay_bmf_credit_card.html', 'Services/Payment');
                 if ($this->ilias->getSetting("https") != 1) {
                     $this->tpl->setCurrentBlock("buyed_objects");
                     $link = $this->ctrl->getLinkTargetByClass('ilshopboughtobjectsgui');
                     $this->tpl->setVariable("LINK_GOTO_BUYED_OBJECTS", $link);
                     $this->tpl->setVariable("TXT_GOTO_BUYED_OBJECTS", $this->lng->txt('pay_goto_buyed_objects'));
                     $this->tpl->parseCurrentBlock("buyed_objects");
                 }
                 $this->tpl->setVariable("TXT_CLOSE_WINDOW", $this->lng->txt('close_window'));
             }
         } else {
             $this->tpl->setVariable("HEADER", $this->lng->txt('error'));
             $this->tpl->touchBlock("stop_floating");
             ilUtil::sendInfo($this->lng->txt('pay_bmf_server_error_communication'));
         }
         /**/
         #zum testen
     }
 }
 function getShoppingCart($a_pay_method = 0)
 {
     if (!count($items = $this->getEntries($a_pay_method))) {
         return 0;
     }
     $counter = 0;
     $f_result = array();
     foreach ($items as $item) {
         $tmp_pobject = new ilPaymentObject($this->user_obj, $item['pobject_id']);
         $tmp_obj = ilObjectFactory::getInstanceByRefId($tmp_pobject->getRefId(), false);
         $f_result[$counter]["psc_id"] = $item['psc_id'];
         $f_result[$counter]["pobject_id"] = $item['pobject_id'];
         if ($tmp_obj) {
             $f_result[$counter]["obj_id"] = $tmp_obj->getId();
             $f_result[$counter]["type"] = $tmp_obj->getType();
             $f_result[$counter]["object_title"] = $tmp_obj->getTitle();
         } else {
             global $lng;
             $f_result[$counter]["obj_id"] = '';
             $f_result[$counter]["type"] = '';
             $f_result[$counter]["object_title"] = $lng->txt('object_deleted');
         }
         $price_data = ilPaymentPrices::_getPrice($item['price_id']);
         $price_string = ilPaymentPrices::_getPriceString($item['price_id']);
         $price = number_format($price_data['price'], 2, '.', '');
         $f_result[$counter]["price"] = $price;
         $f_result[$counter]["price_string"] = $price_string;
         $f_result[$counter]['extension'] = $price_data['extension'];
         require_once './Services/Payment/classes/class.ilShopVats.php';
         $oVAT = new ilShopVats((int) $tmp_pobject->getVatId());
         $f_result[$counter]['vat_rate'] = $oVAT->getRate();
         $f_result[$counter]['vat_unit'] = $tmp_pobject->getVat($price);
         $f_result[$counter]["duration"] = $price_data["duration"];
         $f_result[$counter]['unlimited_duration'] = $price_data['unlimited_duration'];
         $f_result[$counter]["price_type"] = $price_data["price_type"];
         $f_result[$counter]["duration_from"] = $price_data["duration_from"];
         $f_result[$counter]["duration_until"] = $price_data["duration_until"];
         $f_result[$counter]["description"] = $price_data["description"];
         unset($tmp_obj);
         unset($tmp_pobject);
         ++$counter;
     }
     return $f_result;
 }