コード例 #1
0
 public function purchase($tid)
 {
     global $lng;
     $this->getDebtor();
     $this->deb->createInvoice();
     $products = array();
     foreach ($this->sc as $i) {
         $pod = ilPaymentObject::_getObjectData($i['pobject_id']);
         $bo = new ilPaymentBookings($this->ilUser->getId());
         $ilias_tid = $this->ilUser->getId() . "_" . $tid;
         // psc_id, pobject_id, obj_id, typ, betrag_string
         $bo->setTransaction($ilias_tid);
         $bo->setPobjectId(isset($i['pobject_id']) ? $i['pobject_id'] : 0);
         $bo->setCustomerId($this->ilUser->getId());
         $bo->setVendorId($pod['vendor_id']);
         $bo->setPayMethod($this->paytype);
         $bo->setOrderDate(time());
         // $bo->setDuration($i['dauer']); // duration
         // $bo->setPrice(  $i['betrag'] ); // amount
         //$bo->setPrice( ilPaymentPrices::_getPriceString( $i['price_id'] ));
         $bo->setDuration($i['duration']);
         $bo->setPrice($i['price_string']);
         $bo->setDiscount(0);
         $bo->setVoucher('');
         $bo->setVatRate($i['vat_rate']);
         $bo->setVatUnit($i['vat_unit']);
         $bo->setTransactionExtern($tid);
         // $product_name = $i['buchungstext'];
         //$duration = $i['dauer'];
         //$amount = $i['betrag'];
         $product_name = $i['object_title'];
         $duration = $i['duration'];
         $amount = $i['price'];
         // -> ? $i['price_string']
         include_once './Services/Payment/classes/class.ilPayMethods.php';
         $save_adr = (int) ilPaymethods::_EnabledSaveUserAddress($this->paytype) ? 1 : 0;
         //if($save_adr == 1)
         //{
         $bo->setStreet($this->ilUser->getStreet(), '');
         $bo->setPoBox('');
         //$this->ilUser->);
         $bo->setZipcode($this->ilUser->getZipcode());
         $bo->setCity($this->ilUser->getCity());
         $bo->setCountry($this->ilUser->getCountry());
         //}
         $bo->setPayed(1);
         $bo->setAccess(1);
         $bo->setAccessExtension($this->sc['extension']);
         $boid = $bo->add();
         //$bo->update();
         if ($i['typ'] == 'crs') {
             include_once './Modules/Course/classes/class.ilCourseParticipants.php';
             $this->deb->createInvoiceLine(0, $product_name . " (" . $duration . ")", 1, $amount);
             $products[] = $product_name;
             $obj_id = ilObject::_lookupObjId($pod["ref_id"]);
             $cp = ilCourseParticipants::_getInstanceByObjId($obj_id);
             $cp->add($this->ilUser->getId(), IL_CRS_MEMBER);
             $cp->sendNotification($cp->NOTIFY_ACCEPT_SUBSCRIBER, $this->ilUser->getId());
         }
     }
     $inv = $this->deb->bookInvoice();
     $invoice_number = $this->deb->getInvoiceNumber();
     $attach = $this->deb->getInvoicePDF($inv);
     $this->deb->saveInvoice($attach, false);
     $lng->loadLanguageModule('payment');
     $this->deb->sendInvoice($lng->txt('pay_order_paid_subject'), $this->ilUser->getFullName() . ",\n" . str_replace('%products%', implode(", ", $products), $lng->txt('pay_order_paid_body')), $this->ilUser->getEmail(), $attach, $lng->txt('pays_invoice') . "-" . $invoice_number);
     $this->cart->emptyShoppingCart();
 }
コード例 #2
0
 private function addBookings($pay_method, $coupon_session)
 {
     global $ilUser, $ilObjDataCache;
     include_once './Services/Payment/classes/class.ilPaymentBookings.php';
     include_once './Services/Payment/classes/class.ilPaymentObject.php';
     include_once './Services/Payment/classes/class.ilPaymentPrices.php';
     $booking_obj = new ilPaymentBookings();
     $sc_obj = new ilPaymentShoppingCart($this->user_obj);
     $items = $sc_obj->getEntries($pay_method);
     $sc_obj->clearCouponItemsSession();
     foreach ($items as $entry) {
         $pobject = new ilPaymentObject($this->user_obj, $entry['pobject_id']);
         $price = ilPaymentPrices::_getPrice($entry['price_id']);
         if (!empty($_SESSION['coupons'][$coupon_session])) {
             $entry['math_price'] = $entry['price'];
             // (float) ilPaymentPrices::_getPriceFromArray($price);
             foreach ($_SESSION['coupons'][$coupon_session] as $key => $coupon) {
                 $this->coupon_obj->setId($coupon['pc_pk']);
                 $this->coupon_obj->setCurrentCoupon($coupon);
                 if ($this->coupon_obj->isObjectAssignedToCoupon($pobject->getRefId())) {
                     $_SESSION['coupons'][$coupon_session][$key]['total_objects_coupon_price'] += $entry['price'];
                     //(float) ilPaymentPrices::_getPriceFromArray($price);
                     $_SESSION['coupons'][$coupon_session][$key]['items'][] = $entry;
                 }
             }
         }
         unset($pobject);
     }
     $coupon_discount_items = $sc_obj->calcDiscountPrices($_SESSION['coupons'][$coupon_session]);
     foreach ($items as $entry) {
         $pobject = new ilPaymentObject($this->user_obj, $entry['pobject_id']);
         $price = ilPaymentPrices::_getPrice($entry['price_id']);
         if (array_key_exists($entry['pobject_id'], $coupon_discount_items)) {
             $bonus = $coupon_discount_items[$entry['pobject_id']]['math_price'] - $coupon_discount_items[$entry['pobject_id']]['discount_price'];
         }
         $booking_obj->setPobjectId($entry['pobject_id']);
         $booking_obj->setCustomerId($this->user_obj->getId());
         $booking_obj->setVendorId($pobject->getVendorId());
         $booking_obj->setPayMethod($pobject->getPayMethod());
         $booking_obj->setOrderDate(time());
         $booking_obj->setDuration($price['duration']);
         $booking_obj->setPrice(ilPaymentPrices::_getPriceString($entry['price_id']));
         $booking_obj->setDiscount($bonus > 0 ? -1 * $bonus : 0);
         $booking_obj->setPayed(1);
         $booking_obj->setAccess(1);
         switch ($price['price_type']) {
             case ilPaymentPrices::TYPE_UNLIMITED_DURATION:
                 $booking_obj->setDuration(0);
                 break;
             case ilPaymentPrices::TYPE_DURATION_MONTH:
                 $booking_obj->setDuration($price['duration']);
                 break;
             case ilPaymentPrices::TYPE_DURATION_DATE:
                 $booking_obj->setAccessStartdate($price['duration_from']);
                 $booking_obj->setAccessEnddate($price['duration_until']);
                 break;
         }
         $booking_obj->setAccessExtension($price['extension']);
         $obj_id = $ilObjDataCache->lookupObjId($pobject->getRefId());
         $obj_title = $ilObjDataCache->lookupTitle($obj_id);
         $oVAT = new ilShopVats((int) $pobject->getVatId());
         $obj_vat_rate = $oVAT->getRate();
         if ($bonus > 0) {
             $tmp_price = $booking_obj->getPrice() - $bonus;
             $obj_vat_unit = $pobject->getVat($tmp_price);
         } else {
             $obj_vat_unit = $pobject->getVat($booking_obj->getPrice());
         }
         $booking_obj->setObjectTitle($obj_title);
         $booking_obj->setVatRate($obj_vat_rate);
         $booking_obj->setVatUnit($obj_vat_unit);
         if (ilPaymethods::_EnabledSaveUserAddress($booking_obj->getPayMethod())) {
             $booking_obj->setStreet($this->user_obj->getStreet(), $this->user_obj->getHouseNumber);
             $booking_obj->setZipcode($this->user_obj->getZipcode());
             $booking_obj->setCity($this->user_obj->getCity());
             $booking_obj->setCountry($this->user_obj->getCountry());
         }
         $current_booking_id = $booking_obj->add();
         if ($current_booking_id) {
             $sc_obj->delete($entry['psc_id']);
             if (!empty($_SESSION['coupons'][$coupon_session])) {
                 foreach ($_SESSION['coupons'][$coupon_session] 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($current_booking_id);
                     }
                 }
             }
         }
         unset($current_booking_id);
         unset($pobject);
     }
     if (!empty($_SESSION['coupons'][$coupon_session])) {
         foreach ($_SESSION['coupons'][$coupon_session] as $coupon) {
             $this->coupon_obj->setId($coupon['pc_pk']);
             $this->coupon_obj->setCurrentCoupon($coupon);
             $this->coupon_obj->addTracking();
         }
     }
 }
コード例 #3
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);
 }