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