ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilPurchase.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2009 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
30 require_once './include/inc.header.php';
31 require_once './payment/classes/class.ilPaymentObject.php';
32 require_once './payment/classes/class.ilPaymentBookings.php';
33 require_once './payment/classes/class.ilPaymentShoppingCart.php';
34 require_once './Services/User/classes/class.ilObjUser.php';
35 require_once './Services/Payment/classes/class.ilERP.php';
36 
37 
38 
40 {
41  private $deb;
42  private $ilUser;
43  private $active_erp;
44  private $cart;
45  private $sc;
46  private $pay_type;
47 
48  public function __construct( $usr_id, $pay_type )
49  {
50  $this->ilUser = new ilObjUser($usr_id);
51  $this->pay_type = $pay_type;
52  $this->active_erp = ilERP::getActive();
53  $this->erp_cls = "ilERPDebtor_" . $this->active_erp['erp_short'];
54  require_once './Services/Payment/classes/class.' . $this->erp_cls. '.php';
55 
56  $this->deb = new $this->erp_cls();
57  $this->cart = new ilPaymentShoppingCart( $this->ilUser );
58  $this->sc = $this->cart->getShoppingCart( $pay_type );
59 
60  if (! $this->sc) throw new ilERPException("EmptyCart");
61  }
62 
63 
64 
65  private function getDebtor()
66  {
67  if (!$this->deb->getDebtorByNumber($this->ilUser->getId()))
68  {
69  $this->deb->setAll( array(
70  'number' => $this->ilUser->getId(),
71  'name' => $this->ilUser->getFullName(),
72  'email' => $this->ilUser->email,
73  'address' => $this->ilUser->street,
74  'postalcode' => $this->ilUser->zipcode,
75  'city' => $this->ilUser->city,
76  'country' => $this->ilUser->country,
77  'phone' => $this->ilUser->phone_mobile)
78  );
79  $this->deb->createDebtor($this->ilUser->getId());
80  }
81  }
82 
83  public function purchase($tid)
84  {
85  global $lng;
86  $this->getDebtor();
87  $this->deb->createInvoice();
88  $products = array();
89  foreach ($this->sc as $i)
90  {
91  $pod = ilPaymentObject::_getObjectData($i['pobject_id']);
92  $bo =& new ilPaymentBookings( $this->ilUser->getId());
93 
94  $ilias_tid = $this->ilUser->getId() . "_" . $tid;
95 
96  // psc_id, pobject_id, obj_id, typ, betrag_string
97  $bo->setTransaction($ilias_tid);
98  $bo->setPobjectId( isset($i['pobject_id']) ? $i['pobject_id'] : 0 );
99  $bo->setCustomerId( $this->ilUser->getId() );
100  $bo->setVendorId( $pod['vendor_id'] );
101  $bo->setPayMethod($this->paytype);
102  $bo->setOrderDate(time());
103  $bo->setDuration($i['dauer']); // duration
104  $bo->setPrice( $i['betrag'] ); // amount
105  //$bo->setPrice( ilPaymentPrices::_getPriceString( $i['price_id'] ));
106  $bo->setDiscount(0);
107  $bo->setVoucher('');
108  $bo->setVatRate( $i['vat_rate'] );
109  $bo->setVatUnit( $i['vat_unit'] );
110 
111  $bo->setTransactionExtern($tid);
112  $product_name = $i['buchungstext'];
113  $duration = $i['dauer'];
114  $amount = $i['betrag'];
115 
116  include_once './payment/classes/class.ilPayMethods.php';
117  $save_adr = (int) ilPaymethods::_enabled('save_user_adr_epay') ? 1 : 0;
118  //if($save_adr == 1)
119  //{
120  $bo->setStreet($this->ilUser->getStreet(), '');
121  $bo->setPoBox('');//$this->ilUser->);
122  $bo->setZipcode($this->ilUser->getZipcode());
123  $bo->setCity($this->ilUser->getCity);
124  $bo->setCountry($this->ilUser->getCountry());
125  //}
126 
127  $bo->setPayed(1);
128  $bo->setAccess(1);
129  $boid = $bo->add();
130  //$bo->update();
131 
132  if ( $i['typ'] == 'crs')
133  {
134  include_once './Modules/Course/classes/class.ilCourseParticipants.php';
135  $this->deb->createInvoiceLine( 0, $product_name . " (" . $duration. ")", 1, $amount );
136  $products[] = $product_name;
137  $obj_id = ilObject::_lookupObjId($pod["ref_id"]);
139  $cp->add($this->ilUser->getId(), IL_CRS_MEMBER);
140  $cp->sendNotification($cp->NOTIFY_ACCEPT_SUBSCRIBER, $this->ilUser->getId());
141  }
142  }
143  $inv = $this->deb->bookInvoice();
144  $invoice_number = $this->deb->getInvoiceNumber();
145 
146  $attach = $this->deb->getInvoicePDF($inv);
147  $this->deb->saveInvoice($attach, false);
148  $lng->loadLanguageModule('payment');
149  $this->deb->sendInvoice($lng->txt('pay_order_paid_subject'),
150  $this->ilUser->getFullName() . ",\n" .
151  str_replace( '%products%', implode(", ", $products), $lng->txt('pay_order_paid_body')) ,
152  $this->ilUser->getEmail(),
153  $attach, $lng->txt('pays_invoice') ."-" . $invoice_number
154  );
155  $this->cart->emptyShoppingCart();
156  }
157 }
158 ?>