19 include_once
'./Services/Payment/classes/class.ilPayMethods.php';
20 include_once
'./Services/Payment/classes/class.ilPurchaseBaseGUI.php';
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);
52 $this->paypalConfig = $ppSet->getAll();
54 parent::__construct($this->user_obj, $this->pay_method);
60 $fp = @fsockopen (
$path = $this->paypalConfig[
"server_host"], 80, $errno, $errstr, 30);
69 $req =
'cmd=_notify-synch';
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";
81 fputs ($fp, $header . $req);
87 $line = fgets ($fp, 1024);
88 if (strcmp($line,
"\r\n") == 0)
101 $lines = explode(
"\n",
$res);
103 if (strcmp ($lines[0],
"SUCCESS") == 0)
105 for ($i=1; $i<count($lines);$i++)
107 list($key,$val) = explode(
"=", $lines[$i]);
108 $keyarray[urldecode($key)] = urldecode($val);
111 if ($ilUser->getId() != $keyarray[
"custom"])
113 #echo "Wrong customer";
118 if (!in_array($keyarray[
"payment_status"], array(
"Completed",
"In-Progress",
"Pending",
"Processed")))
120 #echo "Not completed";
127 if(
$_SESSION[
'tmp_transaction'][
'result'] ==
'success'
128 &&
$_SESSION[
'tmp_transaction'][
'tx_id'] == $keyarray[
"txn_id"])
135 #echo "Prev. processed trans. id";
140 if ($keyarray[
"receiver_email"] != $this->paypalConfig[
"vendor"])
142 #echo "Wrong vendor";
153 if($ilUser->getId() == ANONYMOUS_USER_ID)
155 include_once
'./Services/Payment/classes/class.ilShopUtils.php';
158 $user_id = $ilUser->getId();
160 $_SESSION[
'tmp_transaction'][
'tx_id'] = $keyarray[
"txn_id"];
161 $_SESSION[
'tmp_transaction'][
'usr_id'] = $user_id;
163 if(
$_SESSION[
'is_crs_object'] && ($ilUser->getId() == ANONYMOUS_USER_ID))
165 include_once
"./Modules/Course/classes/class.ilCourseParticipants.php";
166 foreach (
$_SESSION[
'crs_obj_ids'] as $obj_id)
201 $_SESSION[
"coupons"][
"paypal"] = array();
202 $_SESSION[
'tmp_transaction'][
'result'] =
'success';
206 else if (strcmp ($lines[0],
"FAIL") == 0)
218 $res = $ilDB->queryF(
'SELECT * FROM payment_statistic WHERE transaction_extern = %s',
219 array(
'text'), array($a_id));
221 return $res->numRows() ?
true :
false;
240 include_once
'./Services/Payment/classes/class.ilPayMethods.php';
243 if ($a_array[
"mc_currency"] != $genSet->get(
"currency_unit"))
248 $sc = $this->psc_obj->getShoppingCart($this->pay_method);
249 $this->psc_obj->clearCouponItemsSession();
251 if (is_array($sc) && count($sc) > 0)
253 for ($i = 0; $i < count($sc); $i++)
256 "name" => $a_array[
"item_name".($i+1)],
257 "amount" => $a_array[
"mc_gross_".($i+1)]
260 if (!empty(
$_SESSION[
"coupons"][
"paypal"]))
262 $sc[$i][
"math_price"] = (float) $sc[$i][
"price"];
264 $tmp_pobject =
new ilPaymentObject($this->user_obj, $sc[$i][
'pobject_id']);
266 foreach (
$_SESSION[
"coupons"][
"paypal"] as $key => $coupon)
268 $this->coupon_obj->setId($coupon[
"pc_pk"]);
269 $this->coupon_obj->setCurrentCoupon($coupon);
271 if ($this->coupon_obj->isObjectAssignedToCoupon($tmp_pobject->getRefId()))
273 $_SESSION[
"coupons"][
"paypal"][$key][
"total_objects_coupon_price"] += (float) $sc[$i][
"price"];
274 $_SESSION[
"coupons"][
"paypal"][$key][
"items"][] = $sc[$i];
282 $coupon_discount_items = $this->psc_obj->calcDiscountPrices(
$_SESSION[
"coupons"][
"paypal"]);
286 for ($i = 0; $i < count($sc); $i++)
288 if (array_key_exists($sc[$i][
"pobject_id"], $coupon_discount_items))
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;
294 for ($j = 0; $j < count($items); $j++)
296 if (substr($items[$j][
"name"], 0, strlen($sc[$i][
"obj_id"])+2) ==
"[".$sc[$i][
"obj_id"].
"]" &&
297 $items[$j][
"amount"] == $sc[$i][
"price"])
299 $total += $items[$j][
"amount"];
306 if (number_format(
$total, 2,
".",
"") == $a_array[
"mc_gross"] &&
307 $found == count($sc))
318 global $ilias, $ilUser, $ilObjDataCache;
370 $sc = $this->psc_obj->getShoppingCart($this->pay_method);
371 $this->psc_obj->clearCouponItemsSession();
373 if (is_array($sc) && count($sc) > 0)
375 include_once
'./Services/Payment/classes/class.ilPaymentBookings.php';
378 for ($i = 0; $i < count($sc); $i++)
380 if (!empty(
$_SESSION[
"coupons"][
"paypal"]))
382 $sc[$i][
"math_price"] = (float) $sc[$i][
"price"];
384 $tmp_pobject =&
new ilPaymentObject($this->user_obj, $sc[$i][
'pobject_id']);
386 foreach (
$_SESSION[
"coupons"][
"paypal"] as $key => $coupon)
388 $this->coupon_obj->setId($coupon[
"pc_pk"]);
389 $this->coupon_obj->setCurrentCoupon($coupon);
391 if ($this->coupon_obj->isObjectAssignedToCoupon($tmp_pobject->getRefId()))
393 $_SESSION[
"coupons"][
"paypal"][$key][
"total_objects_coupon_price"] += (float) $sc[$i][
"price"];
394 $_SESSION[
"coupons"][
"paypal"][$key][
"items"][] = $sc[$i];
401 $coupon_discount_items = $this->psc_obj->calcDiscountPrices(
$_SESSION[
"coupons"][
"paypal"]);
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);
406 for ($i = 0; $i < count($sc); $i++)
411 $price = $sc[$i][
"price"];
414 if (array_key_exists($sc[$i][
"pobject_id"], $coupon_discount_items))
416 $bonus = $coupon_discount_items[$sc[$i][
"pobject_id"]][
"math_price"] - $coupon_discount_items[$sc[$i][
"pobject_id"]][
"discount_price"];
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"]);
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']);
434 $book_obj->setObjectTitle($sc[$i][
'object_title']);
435 $book_obj->setVatRate($sc[$i][
'vat_rate']);
436 $book_obj->setVatUnit($sc[$i][
'vat_unit']);
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';
446 if($save_user_adr ==
'1' || (ANONYMOUS_USER_ID == $ilUser->getId()))
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']);
453 $_SESSION[
'paypal'][
'personal_data'][
'name'] = $keyarray[
'address_name'];
454 $_SESSION[
'paypal'][
'personal_data'][
'email'] = $keyarray[
'payer_email'];
458 $booking_id = $book_obj->add();
460 if (!empty(
$_SESSION[
"coupons"][
"paypal"]) && $booking_id)
462 foreach (
$_SESSION[
"coupons"][
"paypal"] as $coupon)
464 $this->coupon_obj->setId($coupon[
"pc_pk"]);
465 $this->coupon_obj->setCurrentCoupon($coupon);
467 if ($this->coupon_obj->isObjectAssignedToCoupon($pobject->getRefId()))
469 $this->coupon_obj->addCouponForBookingId($booking_id);
477 $obj_id = $ilObjDataCache->lookupObjId($pobjectData[
"ref_id"]);
478 $obj_type = $ilObjDataCache->lookupType($obj_id);
479 $obj_title = $ilObjDataCache->lookupTitle($obj_id);
481 include_once
"./Services/Repository/classes/class.ilRepositoryExplorer.php";
484 $message_link =
"" . ILIAS_HTTP_PATH.
"/".$obj_link.
"&transaction=".$book_obj->getTransaction();
485 if($obj_type ==
'file')
486 $download_links[] = $message_link;
488 $bookings[
"list"][] = array(
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'],
498 'currency_unit' =>$sc[$i][
'currency_unit']
501 $total += $sc[$i][
"price"];
502 $total_vat += $sc[$i][
'vat_unit'];
504 if ($sc[$i][
"psc_id"]) $this->psc_obj->delete($sc[$i][
"psc_id"]);
507 if (!empty(
$_SESSION[
"coupons"][
"paypal"]))
509 foreach (
$_SESSION[
"coupons"][
"paypal"] as $coupon)
511 $this->coupon_obj->setId($coupon[
"pc_pk"]);
512 $this->coupon_obj->setCurrentCoupon($coupon);
513 $this->coupon_obj->addTracking();
518 $bookings[
"total"] =
$total;
519 $bookings[
'total_vat'] = $total_vat;
521 $bookings[
'email_extern'] = $keyarray[
'payer_email'];
522 $bookings[
'name_extern'] = $keyarray[
'address_name'];
524 $_SESSION[
'download_links'] = $download_links;
531 global $ilUser, $ilias;
533 $transaction = $a_array[
"txn_id"];
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';
543 $tpl =
new ilTemplate(
'tpl.pay_bill.html',
true,
true,
'Services/Payment');
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")));
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"]);
557 $tpl->setVariable(
"BILL_NO", $transaction);
558 $tpl->setVariable(
"DATE", date(
"d.m.Y"));
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")));
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")));
569 for ($i = 0; $i < count($bookings[
"list"]); $i++)
571 $tmp_pobject =
new ilPaymentObject($this->user_obj, $bookings[
"list"][$i][
'pobject_id']);
573 $assigned_coupons =
'';
574 if (!empty(
$_SESSION[
"coupons"][
"paypal"]))
576 foreach (
$_SESSION[
"coupons"][
"paypal"] as $key => $coupon)
578 $this->coupon_obj->setId($coupon[
"pc_pk"]);
579 $this->coupon_obj->setCurrentCoupon($coupon);
581 if ($this->coupon_obj->isObjectAssignedToCoupon($tmp_pobject->getRefId()))
583 $assigned_coupons .=
'<br />' . $this->lng->txt(
'paya_coupons_coupon') .
': ' . $coupon[
"pcc_code"];
587 if($bookings[
"list"][$i][
"type"] ==
'file')
589 $message_link .= $bookings[
'list'][$i][
'message_link'] .
"\n\n";
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")));
596 if( $bookings[
'list'][$i][
'duration'] == 0)
598 $tpl->setVariable(
'LOOP_DURATION', utf8_decode($this->lng->txt(
'unlimited_duration')));
601 $tpl->setVariable(
'LOOP_DURATION', $bookings[
'list'][$i][
'duration'] .
' ' . utf8_decode($this->lng->txt(
'paya_months')));
605 $tpl->setVariable(
"LOOP_PRICE", $bookings[
"list"][$i][
"price"].
' '.$bookings[
"list"][$i][
'currency_unit']);
606 $tpl->parseCurrentBlock(
"loop");
611 if (!empty(
$_SESSION[
"coupons"][
"paypal"]))
613 if (count($items = $bookings[
"list"]))
615 $sub_total_amount = $bookings[
"total"];
617 foreach (
$_SESSION[
"coupons"][
"paypal"] as $coupon)
619 $this->coupon_obj->setId($coupon[
"pc_pk"]);
620 $this->coupon_obj->setCurrentCoupon($coupon);
622 $total_object_price = 0.0;
623 $current_coupon_bonus = 0.0;
625 foreach ($bookings[
"list"] as $item)
627 $tmp_pobject =&
new ilPaymentObject($this->user_obj, $item[
'pobject_id']);
629 if ($this->coupon_obj->isObjectAssignedToCoupon($tmp_pobject->getRefId()))
631 $total_object_price += $item[
"price"];
637 $current_coupon_bonus = $this->coupon_obj->getCouponBonus($total_object_price);
639 $bookings[
"total"] += $current_coupon_bonus * (-1);
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();
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"));
652 if ($bookings[
"total"] < 0)
654 $bookings[
"total"] = 0.0;
655 $bookings[
"total_vat"] = 0.0;
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)
663 $tpl->setVariable(
"TXT_TOTAL_VAT", utf8_decode($this->lng->txt(
"pay_bmf_vat_included")));
666 $tpl->setVariable(
"TXT_PAYMENT_TYPE", utf8_decode($this->lng->txt(
"pay_payed_paypal")));
668 if (!@file_exists($genSet->get(
"pdf_path")))
673 if (@file_exists($genSet->get(
"pdf_path")))
679 if (@file_exists($genSet->get(
"pdf_path") .
"/" . $transaction .
".pdf") &&
680 $ilUser->getEmail() !=
"" &&
681 $ilias->getSetting(
"admin_email") !=
"")
684 $m->
Subject( $this->lng->txt(
"pay_message_subject") );
685 $m->From( $ilias->getSetting(
"admin_email") );
687 if(ANONYMOUS_USER_ID == $ilUser->getId())
689 $m->To($bookings[
'payer_email']);
691 $message = $this->lng->txt(
"pay_message_hello") .
" " .$booking[
'address_name'].
",\n\n";
696 $m->To( $ilUser->getEmail() );
697 $message = $this->lng->txt(
"pay_message_hello") .
" " . $ilUser->getFirstname() .
" " . $ilUser->getLastname() .
",\n\n";
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 );
705 $m->Attach( $genSet->get(
"pdf_path") .
"/" . $transaction .
".pdf",
"application/pdf" ) ;
709 @unlink($genSet->get(
"pdf_path") .
"/" . $transaction .
".html");
710 @unlink($genSet->get(
"pdf_path") .
"/" . $transaction .
".pdf");
723 $lng->loadLanguageModule(
"meta");
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");
744 foreach($cntcodes as $cntcode)
746 $cntrs[$cntcode] = $lng->txt(
"meta_c_".$cntcode);
755 foreach($countries as $code => $text)
768 return $countries[$value];