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; }
public function add() { include_once './Services/Payment/classes/class.ilPaymentPrices.php'; switch ($this->getPriceType()) { case ilPaymentPrices::TYPE_DURATION_DATE: // do nothing. access_startdate, access_enddate is already set break; case ilPaymentPrices::TYPE_DURATION_MONTH: case ilPaymentPrices::TYPE_UNLIMITED_DURATION: if ($this->getAccessExtension() == 1) { $this->__checkExtensionDependencies(); } else { $this->setAccessStartdate(date('Y-m-d H:i:s', $this->getOrderDate())); if ($this->getDuration() > 0) { $this->__calculateAccessEnddate(); } } break; default: return false; // price_type_not_set!!! break; } $next_id = $this->db->nextId('payment_statistic'); if (ilPayMethods::_EnabledSaveUserAddress((int) $this->getPayMethod()) == 1) { $statement = $this->db->insert('payment_statistic', array('booking_id' => array('integer', $next_id), 'transaction' => array('text', $this->getTransaction()), 'pobject_id' => array('integer', $this->getPobjectId()), 'customer_id' => array('integer', $this->getCustomerId()), 'b_vendor_id' => array('integer', $this->getVendorId()), 'b_pay_method' => array('integer', $this->getPayMethod()), 'order_date' => array('integer', $this->getOrderDate()), 'duration' => array('text', $this->getDuration()), 'price' => array('float', $this->getPrice()), 'discount' => array('float', $this->getDiscount()), 'payed' => array('integer', $this->getPayedStatus()), 'access_granted' => array('integer', $this->getAccessStatus()), 'voucher' => array('text', $this->getVoucher()), 'transaction_extern' => array('text', $this->getTransactionExtern()), 'street' => array('text', $this->getStreet()), 'po_box' => array('text', $this->getPoBox()), 'zipcode' => array('text', $this->getZipcode()), 'city' => array('text', $this->getCity()), 'country' => array('text', $this->getCountry()), 'vat_rate' => array('float', $this->getVatRate()), 'vat_unit' => array('float', $this->getVatUnit()), 'object_title' => array('text', $this->getObjectTitle()), 'email_extern' => array('text', $this->getEmailExtern()), 'name_extern' => array('text', $this->getNameExtern()), 'currency_unit' => array('text', $this->getCurrencyUnit()), 'access_startdate' => array('timestamp', $this->getAccessStartdate()), 'access_enddate' => array('timestamp', $this->getAccessEnddate()))); } else { $statement = $this->db->insert('payment_statistic', array('booking_id' => array('integer', $next_id), 'transaction' => array('text', $this->getTransaction()), 'pobject_id' => array('integer', $this->getPobjectId()), 'customer_id' => array('integer', $this->getCustomerId()), 'b_vendor_id' => array('integer', $this->getVendorId()), 'b_pay_method' => array('integer', $this->getPayMethod()), 'order_date' => array('integer', $this->getOrderDate()), 'duration' => array('text', $this->getDuration()), 'price' => array('float', $this->getPrice()), 'discount' => array('float', $this->getDiscount()), 'payed' => array('integer', $this->getPayedStatus()), 'access_granted' => array('integer', $this->getAccessStatus()), 'voucher' => array('text', $this->getVoucher()), 'transaction_extern' => array('text', $this->getTransactionExtern()), 'vat_rate' => array('float', $this->getVatRate()), 'vat_unit' => array('float', $this->getVatUnit()), 'object_title' => array('text', $this->getObjectTitle()), 'email_extern' => array('text', $this->getEmailExtern()), 'name_extern' => array('text', $this->getNameExtern()), 'currency_unit' => array('text', $this->getCurrencyUnit()), 'access_startdate' => array('timestamp', $this->getAccessStartdate()), 'access_enddate' => array('timestamp', $this->getAccessEnddate()))); } return $next_id; }