ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilPurchasePaypal.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
12 include_once './Services/Payment/classes/class.ilPayMethods.php';
13 include_once './Services/Payment/classes/class.ilPurchaseBaseGUI.php';
14 
15 define('SUCCESS', 0);
16 define('ERROR_OPENSOCKET', 1);
17 define('ERROR_WRONG_CUSTOMER', 2);
18 define('ERROR_NOT_COMPLETED', 3);
19 define('ERROR_PREV_TRANS_ID', 4);
20 define('ERROR_WRONG_VENDOR', 5);
21 define('ERROR_WRONG_ITEMS', 6);
22 define('ERROR_FAIL', 7);
23 
25 {
26  /*
27  * id of vendor, admin or trustee
28  */
29  public $psc_obj = null;
30  public $user_obj = null;
31  public $pay_method = null;
32  public $currency = null;
33  public $db = null;
34  public $paypalConfig;
35  private $totalVat = 0;
36 
37  public function ilPurchasePaypal($user_obj)
38  {
39  global $ilDB, $lng;
40 
41  $this->user_obj = $user_obj;
42  $this->pay_method = ilPayMethods::_getIdByTitle('paypal');
43 
45  $this->paypalConfig = $ppSet->getAll();
46 
47  parent::__construct($this->user_obj, $this->pay_method);
48  }
49 
50  public function openSocket()
51  {
52  // post back to PayPal system to validate
53  $fp = @fsockopen ($path = $this->paypalConfig["server_host"], 80, $errno, $errstr, 30);
54  return $fp;
55  }
56 
57  public function checkData($fp)
58  {
59  global $ilUser;
60 
61  //Token from paypal account
62  $auth_token = $this->paypalConfig["auth_token"];
63 
64  //add 'cmd' as required
65  $req = 'cmd=_notify-synch';
66 
67  //Get token
68  $tx_token = $_REQUEST['tx'];
69 
70  //append both tokens as required
71  $req .= "&tx=$tx_token&at=$auth_token";
72 
73  //send information back to paypal
74  // info: https required!!!
75  $submiturl = 'https://'.$this->paypalConfig["server_host"].$this->paypalConfig["server_path"];
76 
77  $ch = curl_init();
78  curl_setopt($ch, CURLOPT_URL,$submiturl);
79  curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);//return into variable
80  curl_setopt($ch, CURLOPT_POST, 1);//make it a post
81  curl_setopt($ch, CURLOPT_POSTFIELDS, $req);//post request
82  curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded", "Content-Length: " . strlen($req)));
83  curl_setopt($ch, CURLOPT_HEADER , 0); //dont return headers
84  curl_setopt($ch, CURLOPT_VERBOSE, 1);//more informaiton in error
85  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);//dont verify
86  curl_setopt($ch, CURLOPT_TIMEOUT, 30);//define timeout
87  $result= @curl_exec($ch);//get result
88  curl_close($ch);//close connection
89 
90 // only for TEST
91 // echo $result;//display response
92 
93  // parse the data
94  $lines = explode("\n", $result);
95 
96  $keyarray = array();
97  $keyarray[0] = $lines[0]; // save payment status!
98 
99  if (strcmp ($lines[0], "SUCCESS") == 0)
100  {
101  for ($i=1; $i<count($lines);$i++)
102  {
103  list($key,$val) = explode("=", $lines[$i]);
104  $keyarray[urldecode($key)] = urldecode($val);
105  }
106 // check customer
107  if ($ilUser->getId() != $keyarray["custom"])
108  {
109 #echo "Wrong customer";
110  return ERROR_WRONG_CUSTOMER;
111  }
112 
113 // check the payment_status is Completed
114  if (!in_array($keyarray["payment_status"], array("Completed", "In-Progress", "Pending", "Processed")))
115  {
116 #echo "Not completed";
117  return ERROR_NOT_COMPLETED;
118  }
119 
120 // check that txn_id has not been previously processed
121  if ($this->__checkTransactionId($keyarray["txn_id"]))
122  {
123  if($_SESSION['tmp_transaction']['result'] == 'success'
124  && $_SESSION['tmp_transaction']['tx_id'] == $keyarray["txn_id"])
125  {
126  // this is for catching the problem, if the user doubleklicks on the paypal
127  // site to return to the ilias shop and his purchasings already exists in db
128  return SUCCESS;
129  }
130  else
131 #echo "Prev. processed trans. id";
132  return ERROR_PREV_TRANS_ID;
133  }
134 
135 // check that receiver_email is your Primary PayPal email
136  if ($keyarray["receiver_email"] != $this->paypalConfig["vendor"])
137  {
138 #echo "Wrong vendor";
139  return ERROR_WRONG_VENDOR;
140  }
141 
142 // check that payment_amount/payment_currency are correct
143  if (!$this->__checkItems($keyarray))
144  {
145 #echo "Wrong items";
146  return ERROR_WRONG_ITEMS;
147  }
148 
149  if($ilUser->getId() == ANONYMOUS_USER_ID)
150  {
151  include_once './Services/Payment/classes/class.ilShopUtils.php';
152  // anonymous user needs an account to use crs
153  $ilUser = ilShopUtils::_createRandomUserAccount($keyarray);
154  $user_id = $ilUser->getId();
155 
156  $_SESSION['tmp_transaction']['tx_id'] = $keyarray["txn_id"];
157  $_SESSION['tmp_transaction']['usr_id'] = $user_id;
158 
159  if($_SESSION['is_crs_object'] && ($ilUser->getId() == ANONYMOUS_USER_ID))
160  {
161  include_once "./Modules/Course/classes/class.ilCourseParticipants.php";
162  foreach ($_SESSION['crs_obj_ids'] as $obj_id)
163  {
164  $members_obj = ilCourseParticipants::_getInstanceByObjId($obj_id);
165  $members_obj->add($user_id,IL_CRS_MEMBER);
166  }
167  }
168  }
169  //#else
170  //if(($_SESSION['is_lm_object'] || $_SESSION['is_file_object'] ) && ($ilUser->getId() == ANONYMOUS_USER_ID))
171 /* if($ilUser->getId() == ANONYMOUS_USER_ID)
172  {
173  include_once './Services/Payment/classes/class.ilShopUtils.php';
174  // anonymous user needs an account to use lm
175  $ilUser = ilShopUtils::_createRandomUserAccount($keyarray);
176  $user_id = $ilUser->getId();
177 
178  $_SESSION['tmp_transaction']['tx_id'] = $keyarray["txn_id"];
179  $_SESSION['tmp_transaction']['usr_id'] = $user_id;
180  }
181  */
182 // old one TODO: if possible use ilPurchaseBaseGUI
183  $bookings = $this->__saveTransaction($keyarray);
184 
185  $this->__sendBill($bookings, $keyarray);
186 /* new one
187  $external_data = array();
188  $external_data['transaction_extern'] = $keyarray["txn_id"];
189  $external_data['street'] = $keyarray["address_street"];
190  $external_data['zipcode'] = $keyarray["address_zip"];
191  $external_data['city'] = $keyarray["address_city"];
192  $external_data['country'] = $keyarray["address_country"];
193 
194  parent::__addBookings($external_data);
195 */
196 
197  $_SESSION["coupons"]["paypal"] = array();
198  $_SESSION['tmp_transaction']['result'] = 'success';
199 
200  return SUCCESS;
201  }
202  else if (strcmp ($lines[0], "FAIL") == 0)
203  {
204  return ERROR_FAIL;
205  }
206  else
207  return ERROR_FAIL;
208  }
209 
210  function __checkTransactionId($a_id)
211  {
212  global $ilDB;
213 
214  $res = $ilDB->queryF('SELECT * FROM payment_statistic WHERE transaction_extern = %s',
215  array('text'), array($a_id));
216 
217  return $res->numRows() ? true : false;
218  }
219 
220  function __checkItems($a_array)
221  {
222 
223 /*TODO : CURRENCY
224  #$genSet = new ilGeneralSettings();
225 
226  include_once './Services/Payment/classes/class.ilPayMethods.php';
227 
228  // pretty quick and dirty
229  include_once './Services/Payment/classes/class.ilPaymentCurrency.php';
230  $currency = ilPaymentCurrency::_getUnit(1);
231 // Wrong currency
232  if ($a_array["mc_currency"] != $currency)#$genSet->get("currency_unit"))
233  */
234  $genSet = new ilGeneralSettings();
235 
236  include_once './Services/Payment/classes/class.ilPayMethods.php';
237 
238 // Wrong currency
239  if ($a_array["mc_currency"] != $genSet->get("currency_unit"))
240  {
241  return false;
242  }
243 
244  $sc = $this->psc_obj->getShoppingCart($this->pay_method);
245  $this->psc_obj->clearCouponItemsSession();
246 
247  if (is_array($sc) && count($sc) > 0)
248  {
249  for ($i = 0; $i < count($sc); $i++)
250  {
251  $items[$i] = array(
252  "name" => $a_array["item_name".($i+1)],
253  "amount" => $a_array["mc_gross_".($i+1)]
254  );
255 
256  if (!empty($_SESSION["coupons"]["paypal"]))
257  {
258  $sc[$i]["math_price"] = (float) $sc[$i]["price"];
259 
260  $tmp_pobject = new ilPaymentObject($this->user_obj, $sc[$i]['pobject_id']);
261 
262  foreach ($_SESSION["coupons"]["paypal"] as $key => $coupon)
263  {
264  $this->coupon_obj->setId($coupon["pc_pk"]);
265  $this->coupon_obj->setCurrentCoupon($coupon);
266 
267  if ($this->coupon_obj->isObjectAssignedToCoupon($tmp_pobject->getRefId()))
268  {
269  $_SESSION["coupons"]["paypal"][$key]["total_objects_coupon_price"] += (float) $sc[$i]["price"];
270  $_SESSION["coupons"]["paypal"][$key]["items"][] = $sc[$i];
271  }
272  }
273 
274  unset($tmp_pobject);
275  }
276  }
277 
278  $coupon_discount_items = $this->psc_obj->calcDiscountPrices($_SESSION["coupons"]["paypal"]);
279 
280  $found = 0;
281  $total = 0;
282  for ($i = 0; $i < count($sc); $i++)
283  {
284  if (array_key_exists($sc[$i]["pobject_id"], $coupon_discount_items))
285  {
286  $sc[$i]["price"] = round($coupon_discount_items[$sc[$i]["pobject_id"]]["discount_price"], 2);
287  if ($sc[$i]["price"] < 0) $sc[$i]["price"] = 0.0;
288  }
289 
290  for ($j = 0; $j < count($items); $j++)
291  {
292  if (substr($items[$j]["name"], 0, strlen($sc[$i]["obj_id"])+2) == "[".$sc[$i]["obj_id"]."]" &&
293  $items[$j]["amount"] == $sc[$i]["price"])
294  {
295  $total += $items[$j]["amount"];
296  $found++;
297  }
298  }
299  }
300 
301 // The number of items, the items themselves and their amounts and the total amount correct
302  if (number_format($total, 2, ".", "") == $a_array["mc_gross"] &&
303  $found == count($sc))
304  {
305  return true;
306  }
307  }
308 
309  return false;
310  }
311 
312  function __saveTransaction($keyarray)
313  {
314  global $ilias, $ilUser, $ilObjDataCache;
315 
366  $sc = $this->psc_obj->getShoppingCart($this->pay_method);
367  $this->psc_obj->clearCouponItemsSession();
368 
369  if (is_array($sc) && count($sc) > 0)
370  {
371  include_once './Services/Payment/classes/class.ilPaymentBookings.php';
372  $book_obj =& new ilPaymentBookings($this->usr_obj);
373 
374  for ($i = 0; $i < count($sc); $i++)
375  {
376  if (!empty($_SESSION["coupons"]["paypal"]))
377  {
378  $sc[$i]["math_price"] = (float) $sc[$i]["price"];
379 
380  $tmp_pobject =& new ilPaymentObject($this->user_obj, $sc[$i]['pobject_id']);
381 
382  foreach ($_SESSION["coupons"]["paypal"] as $key => $coupon)
383  {
384  $this->coupon_obj->setId($coupon["pc_pk"]);
385  $this->coupon_obj->setCurrentCoupon($coupon);
386 
387  if ($this->coupon_obj->isObjectAssignedToCoupon($tmp_pobject->getRefId()))
388  {
389  $_SESSION["coupons"]["paypal"][$key]["total_objects_coupon_price"] += (float) $sc[$i]["price"];
390  $_SESSION["coupons"]["paypal"][$key]["items"][] = $sc[$i];
391  }
392  }
393  unset($tmp_pobject);
394  }
395  }
396 
397  $coupon_discount_items = $this->psc_obj->calcDiscountPrices($_SESSION["coupons"]["paypal"]);
398 
399  $inst_id_time = $ilias->getSetting('inst_id').'_'.$ilUser->getId().'_'.substr((string) time(),-3);
400  $transaction = $inst_id_time.substr(md5(uniqid(rand(), true)), 0, 4);
401 
402  for ($i = 0; $i < count($sc); $i++)
403  {
404  $pobjectData = ilPaymentObject::_getObjectData($sc[$i]["pobject_id"]);
405  $pobject = new ilPaymentObject($this->user_obj,$sc[$i]['pobject_id']);
406 
407  $price = $sc[$i]["price"];
408  $bonus = 0.0;
409 
410  if (array_key_exists($sc[$i]["pobject_id"], $coupon_discount_items))
411  {
412  $bonus = $coupon_discount_items[$sc[$i]["pobject_id"]]["math_price"] - $coupon_discount_items[$sc[$i]["pobject_id"]]["discount_price"];
413  }
414 
415  $book_obj->setTransaction($transaction);
416  $book_obj->setPobjectId($sc[$i]["pobject_id"]);
417  $book_obj->setCustomerId($ilUser->getId());
418  $book_obj->setVendorId($pobjectData["vendor_id"]);
419  $book_obj->setPayMethod($pobjectData["pay_method"]);
420  $book_obj->setOrderDate(time());
421  $book_obj->setDuration($sc[$i]["duration"]);
422  $book_obj->setPrice($sc[$i]["price_string"]);
423  // $book_obj->setDiscount($bonus > 0 ? ilPaymentPrices::_getPriceStringFromAmount($bonus * (-1)) : 0);
424  $book_obj->setDiscount($bonus > 0 ? ($bonus * (-1)) : 0);
425  $book_obj->setPayed(1);
426  $book_obj->setAccess(1);
427  $book_obj->setVoucher('');
428  $book_obj->setTransactionExtern($keyarray['txn_id']);
429 
430  $book_obj->setObjectTitle($sc[$i]['object_title']);
431  $book_obj->setVatRate($sc[$i]['vat_rate']);
432  $book_obj->setVatUnit($sc[$i]['vat_unit']);
433 
434  $book_obj->setEmailExtern($keyarray['payer_email']);
435  $book_obj->setNameExtern($keyarray['address_name']);
436  $_SESSION['transaction']=$book_obj->getTransaction();
437  include_once './Services/Payment/classes/class.ilPayMethods.php';
438  //$save_user_adr_bill = (int) ilPayMethods::_enabled('save_user_adr_paypal') ? 1 : 0;
439  $save_user_adr = (int) ilPayMethods::_EnabledSaveUserAddress($this->pay_method) ? 1 : 0;
440 
441 
442  if($save_user_adr == '1' || (ANONYMOUS_USER_ID == $ilUser->getId()))
443  {
444  $book_obj->setStreet($keyarray['address_street'],'');
445  $book_obj->setZipCode($keyarray['address_zip']);
446  $book_obj->setCity($keyarray['address_city']);
447  $book_obj->setCountry($keyarray['address_country_code']);
448 
449  $_SESSION['paypal']['personal_data']['name'] = $keyarray['address_name'];
450  $_SESSION['paypal']['personal_data']['email'] = $keyarray['payer_email'];
451 
452  }
453 
454  $booking_id = $book_obj->add();
455 
456  if (!empty($_SESSION["coupons"]["paypal"]) && $booking_id)
457  {
458  foreach ($_SESSION["coupons"]["paypal"] as $coupon)
459  {
460  $this->coupon_obj->setId($coupon["pc_pk"]);
461  $this->coupon_obj->setCurrentCoupon($coupon);
462 
463  if ($this->coupon_obj->isObjectAssignedToCoupon($pobject->getRefId()))
464  {
465  $this->coupon_obj->addCouponForBookingId($booking_id);
466  }
467  }
468  }
469 
470  unset($booking_id);
471  unset($pobject);
472 
473  $obj_id = $ilObjDataCache->lookupObjId($pobjectData["ref_id"]);
474  $obj_type = $ilObjDataCache->lookupType($obj_id);
475  $obj_title = $ilObjDataCache->lookupTitle($obj_id);
476 
477  include_once "./Services/Repository/classes/class.ilRepositoryExplorer.php";
478  $obj_link = ilRepositoryExplorer::buildLinkTarget($pobjectData["ref_id"],$obj_type);
479  $obj_target = ilRepositoryExplorer::buildFrameTarget($obj_type,$pobjectData["ref_id"],$obj_id);
480  $message_link = "" . ILIAS_HTTP_PATH."/".$obj_link."&transaction=".$book_obj->getTransaction();
481  if($obj_type == 'file')
482  $download_links[] = $message_link;
483 
484  $bookings["list"][] = array(
485  "type" => $obj_type,
486  "title" => "[".$obj_id."]: " . $obj_title,
487  "message_link" => $message_link,
488  "duration" => $sc[$i]["duration"],
489  "vat_rate" => $sc[$i]["vat_rate"],
490  "vat_unit" => $sc[$i]["vat_unit"],
491  'price_string' => $sc[$i]['price_string'],
492  'price' => $sc[$i]['price'],
493  'bonus'=> $bonus,
494  'currency_unit' =>$sc[$i]['currency_unit']
495  );
496 
497  $total += $sc[$i]["price"];
498  $total_vat += $sc[$i]['vat_unit'];
499 
500  if ($sc[$i]["psc_id"]) $this->psc_obj->delete($sc[$i]["psc_id"]);
501  }
502 
503  if (!empty($_SESSION["coupons"]["paypal"]))
504  {
505  foreach ($_SESSION["coupons"]["paypal"] as $coupon)
506  {
507  $this->coupon_obj->setId($coupon["pc_pk"]);
508  $this->coupon_obj->setCurrentCoupon($coupon);
509  $this->coupon_obj->addTracking();
510  }
511  }
512  }
513 
514  $bookings["total"] = $total;
515  $bookings['total_vat'] = $total_vat;
516 
517  $bookings['email_extern'] = $keyarray['payer_email'];
518  $bookings['name_extern'] = $keyarray['address_name'];
519 
520  $_SESSION['download_links'] = $download_links;
521 
522  return $bookings;
523  }
524 
525  function __sendBill($bookings, $a_array)
526  {
527  global $ilUser, $ilias;
528 
529  $transaction = $a_array["txn_id"];
530 
531  include_once './classes/class.ilTemplate.php';
532  include_once './Services/Utilities/classes/class.ilUtil.php';
533  include_once './Services/Payment/classes/class.ilGeneralSettings.php';
534  include_once './Services/Payment/classes/class.ilPaymentShoppingCart.php';
535  include_once 'Services/Mail/classes/class.ilMimeMail.php';
536 
537  $genSet = new ilGeneralSettings();
538 
539  $tpl = new ilTemplate('tpl.pay_bill.html', true, true, 'Services/Payment');
540 
541  $tpl->setVariable("VENDOR_ADDRESS", nl2br(utf8_decode($genSet->get("address"))));
542  $tpl->setVariable("VENDOR_ADD_INFO", nl2br(utf8_decode($genSet->get("add_info"))));
543  $tpl->setVariable("VENDOR_BANK_DATA", nl2br(utf8_decode($genSet->get("bank_data"))));
544  $tpl->setVariable("TXT_BANK_DATA", utf8_decode($this->lng->txt("pay_bank_data")));
545 
546  $tpl->setVariable("CUSTOMER_FIRSTNAME", $a_array["first_name"]);
547  $tpl->setVariable("CUSTOMER_LASTNAME", $a_array["last_name"]);
548  $tpl->setVariable("CUSTOMER_STREET", $a_array["address_street"]);
549  $tpl->setVariable("CUSTOMER_ZIPCODE", $a_array["address_zip"]);
550  $tpl->setVariable("CUSTOMER_CITY", $a_array["address_city"]);
551  $tpl->setVariable("CUSTOMER_COUNTRY", $a_array["address_country"]);
552 
553  $tpl->setVariable("BILL_NO", $transaction);
554  $tpl->setVariable("DATE", date("d.m.Y"));
555 
556  $tpl->setVariable("TXT_BILL", utf8_decode($this->lng->txt("pays_bill")));
557  $tpl->setVariable("TXT_BILL_NO", utf8_decode($this->lng->txt("pay_bill_no")));
558  $tpl->setVariable("TXT_DATE", utf8_decode($this->lng->txt("date")));
559 
560  $tpl->setVariable("TXT_ARTICLE", utf8_decode($this->lng->txt("pay_article")));
561  $tpl->setVariable('TXT_VAT_RATE', utf8_decode($this->lng->txt('vat_rate')));
562  $tpl->setVariable('TXT_VAT_UNIT', utf8_decode($this->lng->txt('vat_unit')));
563  $tpl->setVariable("TXT_PRICE", utf8_decode($this->lng->txt("price_a")));
564 
565  for ($i = 0; $i < count($bookings["list"]); $i++)
566  {
567  $tmp_pobject = new ilPaymentObject($this->user_obj, $bookings["list"][$i]['pobject_id']);
568 
569  $assigned_coupons = '';
570  if (!empty($_SESSION["coupons"]["paypal"]))
571  {
572  foreach ($_SESSION["coupons"]["paypal"] as $key => $coupon)
573  {
574  $this->coupon_obj->setId($coupon["pc_pk"]);
575  $this->coupon_obj->setCurrentCoupon($coupon);
576 
577  if ($this->coupon_obj->isObjectAssignedToCoupon($tmp_pobject->getRefId()))
578  {
579  $assigned_coupons .= '<br />' . $this->lng->txt('paya_coupons_coupon') . ': ' . $coupon["pcc_code"];
580  }
581  }
582  }
583  if($bookings["list"][$i]["type"] == 'file')
584  {
585  $message_link .= $bookings['list'][$i]['message_link'] . "\n\n";
586  }
587  $tpl->setCurrentBlock("loop");
588  $tpl->setVariable("LOOP_OBJ_TYPE", utf8_decode($this->lng->txt($bookings["list"][$i]["type"])));
589  $tpl->setVariable("LOOP_TITLE", utf8_decode($bookings["list"][$i]["title"]) . $assigned_coupons);
590  $tpl->setVariable("LOOP_TXT_ENTITLED_RETRIEVE", utf8_decode($this->lng->txt("pay_entitled_retrieve")));
591 
592  if( $bookings['list'][$i]['duration'] == 0)
593  {
594  $tpl->setVariable('LOOP_DURATION', utf8_decode($this->lng->txt('unlimited_duration')));
595  }
596  else
597  $tpl->setVariable('LOOP_DURATION', $bookings['list'][$i]['duration'] . ' ' . utf8_decode($this->lng->txt('paya_months')));
598 
599  $tpl->setVariable("LOOP_VAT_RATE", ilShopUtils::_formatVAT($bookings["list"][$i]["vat_rate"]));
600  $tpl->setVariable('LOOP_VAT_UNIT', ilShopUtils::_formatFloat($bookings['list'][$i]['vat_unit']).' '.$genSet->get('currency_unit'));
601  $tpl->setVariable("LOOP_PRICE", $bookings["list"][$i]["price"].' '.$bookings["list"][$i]['currency_unit']);
602  $tpl->parseCurrentBlock("loop");
603 
604  unset($tmp_pobject);
605  }
606 
607  if (!empty($_SESSION["coupons"]["paypal"]))
608  {
609  if (count($items = $bookings["list"]))
610  {
611  $sub_total_amount = $bookings["total"];
612 
613  foreach ($_SESSION["coupons"]["paypal"] as $coupon)
614  {
615  $this->coupon_obj->setId($coupon["pc_pk"]);
616  $this->coupon_obj->setCurrentCoupon($coupon);
617 
618  $total_object_price = 0.0;
619  $current_coupon_bonus = 0.0;
620 
621  foreach ($bookings["list"] as $item)
622  {
623  $tmp_pobject =& new ilPaymentObject($this->user_obj, $item['pobject_id']);
624 
625  if ($this->coupon_obj->isObjectAssignedToCoupon($tmp_pobject->getRefId()))
626  {
627  $total_object_price += $item["price"];
628  }
629 
630  unset($tmp_pobject);
631  }
632 
633  $current_coupon_bonus = $this->coupon_obj->getCouponBonus($total_object_price);
634 
635  $bookings["total"] += $current_coupon_bonus * (-1);
636 
637  $tpl->setCurrentBlock("cloop");
638  $tpl->setVariable("TXT_COUPON", utf8_decode($this->lng->txt("paya_coupons_coupon") . " " . $coupon["pcc_code"]));
639  $tpl->setVariable("BONUS", number_format($current_coupon_bonus * (-1), 2, ',', '.') . " " . $genSet->get("currency_unit"));
640  $tpl->parseCurrentBlock();
641  }
642 
643  $tpl->setVariable("TXT_SUBTOTAL_AMOUNT", utf8_decode($this->lng->txt("pay_bmf_subtotal_amount")));
644  $tpl->setVariable("SUBTOTAL_AMOUNT", number_format($sub_total_amount, 2, ",", ".") . " " . $genSet->get("currency_unit"));
645  }
646  }
647 
648  if ($bookings["total"] < 0)
649  {
650  $bookings["total"] = 0.0;
651  $bookings["total_vat"] = 0.0;
652  }
653 
654  $tpl->setVariable("TXT_TOTAL_AMOUNT", utf8_decode($this->lng->txt("pay_bmf_total_amount")));
655  $tpl->setVariable("TOTAL_AMOUNT", number_format($bookings["total"], 2, ",", ".") . " " . $genSet->get("currency_unit"));
656  if ($bookings["total_vat"] > 0)
657  {
658  $tpl->setVariable("TOTAL_VAT", ilShopUtils::_formatFloat($bookings["total_vat"]). " " . $genSet->get("currency_unit"));
659  $tpl->setVariable("TXT_TOTAL_VAT", utf8_decode($this->lng->txt("pay_bmf_vat_included")));
660  }
661 
662  $tpl->setVariable("TXT_PAYMENT_TYPE", utf8_decode($this->lng->txt("pay_payed_paypal")));
663 
664  if (!@file_exists($genSet->get("pdf_path")))
665  {
666  ilUtil::makeDir($genSet->get("pdf_path"));
667  }
668 
669  if (@file_exists($genSet->get("pdf_path")))
670  {
671  ilUtil::html2pdf($tpl->get(), $genSet->get("pdf_path") . "/" . $transaction . ".pdf");
672 
673  }
674 
675  if (@file_exists($genSet->get("pdf_path") . "/" . $transaction . ".pdf") &&
676  $ilUser->getEmail() != "" &&
677  $ilias->getSetting("admin_email") != "")
678  {
679  $m= new ilMimeMail; // create the mail
680  $m->Subject( $this->lng->txt("pay_message_subject") );
681  $m->From( $ilias->getSetting("admin_email") );
682 
683  if(ANONYMOUS_USER_ID == $ilUser->getId())
684  {
685  $m->To($bookings['payer_email']);
686 
687  $message = $this->lng->txt("pay_message_hello") . " " .$booking['address_name']. ",\n\n";
688 
689  }
690  else
691  {
692  $m->To( $ilUser->getEmail() );
693  $message = $this->lng->txt("pay_message_hello") . " " . $ilUser->getFirstname() . " " . $ilUser->getLastname() . ",\n\n";
694  }
695  $message .= $this->lng->txt("pay_message_thanks") . "\n\n";
696  $message .= $message_link."\n\n";
697  $message .= $this->lng->txt("pay_message_attachment") . "\n\n";
698  $message .= $this->lng->txt("pay_message_regards") . "\n\n";
699  $message .= strip_tags($genSet->get("address"));
700  $m->Body( $message ); // set the body
701  $m->Attach( $genSet->get("pdf_path") . "/" . $transaction . ".pdf", "application/pdf" ) ; // attach a file of type image/gif
702  $m->Send(); // send the mail
703  }
704 
705  @unlink($genSet->get("pdf_path") . "/" . $transaction . ".html");
706  @unlink($genSet->get("pdf_path") . "/" . $transaction . ".pdf");
707 
708  }
709 
711  {
712  $this->psc_obj = new ilPaymentShoppingCart($this->user_obj);
713  }
714 
715  function __getCountries()
716  {
717  global $lng;
718 
719  $lng->loadLanguageModule("meta");
720 
721  $cntcodes = array ("DE","ES","FR","GB","AT","CH","AF","AL","DZ","AS","AD","AO",
722  "AI","AQ","AG","AR","AM","AW","AU","AT","AZ","BS","BH","BD","BB","BY",
723  "BE","BZ","BJ","BM","BT","BO","BA","BW","BV","BR","IO","BN","BG","BF",
724  "BI","KH","CM","CA","CV","KY","CF","TD","CL","CN","CX","CC","CO","KM",
725  "CG","CK","CR","CI","HR","CU","CY","CZ","DK","DJ","DM","DO","TP","EC",
726  "EG","SV","GQ","ER","EE","ET","FK","FO","FJ","FI","FR","FX","GF","PF",
727  "TF","GA","GM","GE","DE","GH","GI","GR","GL","GD","GP","GU","GT","GN",
728  "GW","GY","HT","HM","HN","HU","IS","IN","ID","IR","IQ","IE","IL","IT",
729  "JM","JP","JO","KZ","KE","KI","KP","KR","KW","KG","LA","LV","LB","LS",
730  "LR","LY","LI","LT","LU","MO","MK","MG","MW","MY","MV","ML","MT","MH",
731  "MQ","MR","MU","YT","MX","FM","MD","MC","MN","MS","MA","MZ","MM","NA",
732  "NR","NP","NL","AN","NC","NZ","NI","NE","NG","NU","NF","MP","NO","OM",
733  "PK","PW","PA","PG","PY","PE","PH","PN","PL","PT","PR","QA","RE","RO",
734  "RU","RW","KN","LC","VC","WS","SM","ST","SA","CH","SN","SC","SL","SG",
735  "SK","SI","SB","SO","ZA","GS","ES","LK","SH","PM","SD","SR","SJ","SZ",
736  "SE","SY","TW","TJ","TZ","TH","TG","TK","TO","TT","TN","TR","TM","TC",
737  "TV","UG","UA","AE","GB","UY","US","UM","UZ","VU","VA","VE","VN","VG",
738  "VI","WF","EH","YE","ZR","ZM","ZW");
739  $cntrs = array();
740  foreach($cntcodes as $cntcode)
741  {
742  $cntrs[$cntcode] = $lng->txt("meta_c_".$cntcode);
743  }
744  asort($cntrs);
745  return $cntrs;
746  }
747 
748  function __getCountryCode($value = "")
749  {
750  $countries = $this->__getCountries();
751  foreach($countries as $code => $text)
752  {
753  if ($text == $value)
754  {
755  return $code;
756  }
757  }
758  return;
759  }
760 
761  function __getCountryName($value = "")
762  {
763  $countries = $this->__getCountries();
764  return $countries[$value];
765  }
766 
767 }
768 ?>