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;
 }
예제 #2
0
 public function __addBookings($external_data = null)
 {
     global $ilUser, $ilObjDataCache;
     $sc = $this->psc_obj->getShoppingCart($this->pm_id);
     $total = 0;
     $total_vat = 0;
     $total_discount = 0;
     #		$this->psc_obj->clearCouponItemsSession();
     if (is_array($sc) && count($sc) > 0) {
         include_once './Services/Payment/classes/class.ilPaymentBookings.php';
         //@todo check $this->usr_obj
         $book_obj = new ilPaymentBookings($this->usr_obj);
         for ($i = 0; $i < count($sc); $i++) {
             if (!empty($_SESSION['coupons'][$this->session_var])) {
                 $sc[$i]['math_price'] = (double) $sc[$i]['price'];
                 $tmp_pobject = new ilPaymentObject($this->user_obj, $sc[$i]['pobject_id']);
                 foreach ($_SESSION['coupons'][$this->session_var] 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'][$this->session_var][$key]['total_objects_coupon_price'] += (double) $sc[$i]['price'];
                         $_SESSION['coupons'][$this->session_var][$key]['items'][] = $sc[$i];
                     }
                 }
                 unset($tmp_pobject);
             }
         }
         $coupon_discount_items = $this->psc_obj->calcDiscountPrices($_SESSION['coupons'][$this->session_var]);
         $transaction = ilInvoiceNumberPlaceholdersPropertyGUI::_generateInvoiceNumber($ilUser->getId());
         for ($i = 0; $i < count($sc); $i++) {
             $pobjectData = ilPaymentObject::_getObjectData($sc[$i]['pobject_id']);
             $pobject = new ilPaymentObject($this->user_obj, $sc[$i]['pobject_id']);
             $price = $sc[$i]['price'];
             $bonus = 0.0;
             if (array_key_exists($sc[$i]['pobject_id'], $coupon_discount_items)) {
                 $bonus = $coupon_discount_items[$sc[$i]['pobject_id']]['math_price'] - $coupon_discount_items[$sc[$i]['pobject_id']]['discount_price'];
                 if ($bonus > 0) {
                     $discount = round($bonus, 2) * -1;
                 } else {
                     $discount = round($bonus, 2);
                 }
             }
             $book_obj->setTransaction($transaction);
             $book_obj->setPobjectId($sc[$i]['pobject_id']);
             $book_obj->setCustomerId($this->user_obj->getId());
             $book_obj->setVendorId($pobjectData['vendor_id']);
             $book_obj->setPayMethod($pobjectData['pay_method']);
             $book_obj->setOrderDate(time());
             $book_obj->setPrice($sc[$i]['price_string']);
             //$book_obj->setDiscount($bonus > 0 ? ilPaymentPrices::_getPriceStringFromAmount($bonus * (-1)) : '');
             $book_obj->setDiscount($discount);
             $book_obj->setPayed($this->getPayed());
             $book_obj->setAccess($this->getAccess());
             $book_obj->setVoucher('');
             // bmf
             $book_obj->setTransactionExtern('');
             // bmf , paypal
             $book_obj->setVatRate($sc[$i]['vat_rate']);
             $book_obj->setVatUnit($sc[$i]['vat_unit']);
             $book_obj->setObjectTitle(strip_tags($sc[$i]['object_title']));
             $book_obj->setAccessExtension($sc[$i]['extension']);
             switch ($sc[$i]["price_type"]) {
                 case ilPaymentPrices::TYPE_DURATION_MONTH:
                     $book_obj->setDuration($sc[$i]['duration']);
                     break;
                 case ilPaymentPrices::TYPE_DURATION_DATE:
                     $book_obj->setDuration(0);
                     $book_obj->setAccessStartdate($sc[$i]['duration_from']);
                     $book_obj->setAccessEnddate($sc[$i]['duration_until']);
                     break;
                 case ilPaymentPrices::TYPE_UNLIMITED_DURATION:
                     $book_obj->setDuration(0);
                     $book_obj->setAccessEnddate(NULL);
                     $book_obj->setUnlimitedDuration($sc[$i]['unlimited_duration']);
                     break;
             }
             $book_obj->setPriceType($sc[$i]["price_type"]);
             //
             if ($external_data) {
                 $book_obj->setVoucher($external_data['voucher']);
                 // bmf
                 $book_obj->setTransactionExtern($external_data['transaction_extern']);
                 // bmf, paypal
                 $book_obj->setStreet($external_data['street'], '');
                 $book_obj->setZipcode($external_data['zipcode']);
                 $book_obj->setCity($external_data['city']);
                 $book_obj->setCountry($external_data['country']);
             } else {
                 if (isset($_SESSION[$this->session_var]['personal_data'])) {
                     $book_obj->setStreet($_SESSION[$this->session_var]['personal_data']['street'], $_SESSION[$this->session_var]['personal_data']['house_number']);
                     $book_obj->setPoBox($_SESSION[$this->session_var]['personal_data']['po_box']);
                     $book_obj->setZipcode($_SESSION[$this->session_var]['personal_data']['zipcode']);
                     $book_obj->setCity($_SESSION[$this->session_var]['personal_data']['city']);
                     $book_obj->setCountry($_SESSION[$this->session_var]['personal_data']['country']);
                 } else {
                     $book_obj->setStreet($this->user_obj->getStreet(), '');
                     $book_obj->setPoBox($this->user_obj->getPoBox());
                     $book_obj->setZipcode($this->user_obj->getZipCode());
                     $book_obj->setCity($this->user_obj->getCity());
                     $book_obj->setCountry($this->user_obj->getCountry());
                 }
             }
             $booking_id = $book_obj->add();
             // add purchased item to desktop
             ilShopUtils::_addPurchasedObjToDesktop($pobject);
             // autosubscribe user if purchased object is a course
             $obj_type = ilObject::_lookupType((int) $pobject->getRefId(), true);
             if ($obj_type == 'crs') {
                 ilShopUtils::_assignPurchasedCourseMemberRole($pobject);
             }
             if (!empty($_SESSION['coupons'][$this->session_var]) && $booking_id) {
                 foreach ($_SESSION['coupons'][$this->session_var] as $coupon) {
                     $this->coupon_obj->setId($coupon['pc_pk']);
                     $this->coupon_obj->setCurrentCoupon($coupon);
                     if ($this->coupon_obj->isObjectAssignedToCoupon($pobject->getRefId())) {
                         $this->coupon_obj->addCouponForBookingId($booking_id);
                     }
                 }
             }
             $obj_id = $ilObjDataCache->lookupObjId($pobjectData['ref_id']);
             $obj_type = $ilObjDataCache->lookupType($obj_id);
             $obj_title = $ilObjDataCache->lookupTitle($obj_id);
             $bookings['list'][] = array('pobject_id' => $sc[$i]['pobject_id'], 'type' => $obj_type, 'title' => '[' . $obj_id . ']: ' . $obj_title, 'duration' => $sc[$i]['duration'], 'vat_rate' => $sc[$i]['vat_rate'], 'vat_unit' => $sc[$i]['vat_unit'], 'price_string' => $sc[$i]['price_string'], 'price' => $sc[$i]['price'], "price_type" => $sc[$i]["price_type"], "duration_from" => $sc[$i]["duration_from"], "duration_until" => $sc[$i]["duration_until"], "b_pay_method" => $pobjectData["pay_method"], 'discount' => $discount, 'access_startdate' => $book_obj->getAccessStartdate(), 'access_enddate' => $book_obj->getAccessEnddate());
             $total += $sc[$i]['price'];
             $total_vat += $sc[$i]['vat_unit'];
             $total_discount += $discount;
             if ($sc[$i]['psc_id']) {
                 $this->psc_obj->delete($sc[$i]['psc_id']);
             }
         }
         if (!empty($_SESSION['coupons'][$this->session_var])) {
             foreach ($_SESSION['coupons'][$this->session_var] as $coupon) {
                 $this->coupon_obj->setId($coupon['pc_pk']);
                 $this->coupon_obj->setCurrentCoupon($coupon);
                 $this->coupon_obj->addTracking();
             }
         }
     }
     $bookings['total'] = $total;
     $bookings['total_vat'] = $total_vat;
     $bookings['total_discount'] = $total_discount;
     $bookings['transaction'] = $transaction;
     $bookings['street'] = $book_obj->getStreet();
     $bookings['zipcode'] = $book_obj->getZipCode();
     $bookings['city'] = $book_obj->getCity();
     if (2 == strlen($book_obj->getCountry())) {
         $bookings['country'] = $this->__getCountryName(strtoupper($book_obj->getCountry()));
     } else {
         $bookings['country'] = $book_obj->getCountry();
     }
     $bookings['transaction_extern'] = $book_obj->getTransactionExtern();
     $this->user_obj->_toggleActiveStatusOfUsers(array($this->user_obj->getId()), 1);
     $_SESSION['forceRedirectToShoppingcart'] = 1;
     $this->__sendBill($bookings);
 }