12 include_once
'./Services/Payment/classes/class.ilPayMethods.php';
13 include_once
'./Services/Payment/classes/class.ilPurchaseBaseGUI.php';
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);
45 $this->paypalConfig = $ppSet->getAll();
47 parent::__construct($this->user_obj, $this->pay_method);
53 $fp = @fsockopen (
$path = $this->paypalConfig[
"server_host"], 80, $errno, $errstr, 30);
65 $req =
'cmd=_notify-synch';
71 $req .=
"&tx=$tx_token&at=$auth_token";
75 $submiturl =
'https://'.$this->paypalConfig[
"server_host"].$this->paypalConfig[
"server_path"];
78 curl_setopt($ch, CURLOPT_URL,$submiturl);
79 curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
80 curl_setopt($ch, CURLOPT_POST, 1);
81 curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
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);
84 curl_setopt($ch, CURLOPT_VERBOSE, 1);
85 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
86 curl_setopt($ch, CURLOPT_TIMEOUT, 30);
94 $lines = explode(
"\n",
$result);
97 $keyarray[0] = $lines[0];
99 if (strcmp ($lines[0],
"SUCCESS") == 0)
101 for ($i=1; $i<count($lines);$i++)
103 list($key,$val) = explode(
"=", $lines[$i]);
104 $keyarray[urldecode($key)] = urldecode($val);
107 if ($ilUser->getId() != $keyarray[
"custom"])
109 #echo "Wrong customer";
114 if (!in_array($keyarray[
"payment_status"], array(
"Completed",
"In-Progress",
"Pending",
"Processed")))
116 #echo "Not completed";
123 if(
$_SESSION[
'tmp_transaction'][
'result'] ==
'success'
124 &&
$_SESSION[
'tmp_transaction'][
'tx_id'] == $keyarray[
"txn_id"])
131 #echo "Prev. processed trans. id";
136 if ($keyarray[
"receiver_email"] != $this->paypalConfig[
"vendor"])
138 #echo "Wrong vendor";
149 if($ilUser->getId() == ANONYMOUS_USER_ID)
151 include_once
'./Services/Payment/classes/class.ilShopUtils.php';
154 $user_id = $ilUser->getId();
156 $_SESSION[
'tmp_transaction'][
'tx_id'] = $keyarray[
"txn_id"];
157 $_SESSION[
'tmp_transaction'][
'usr_id'] = $user_id;
159 if(
$_SESSION[
'is_crs_object'] && ($ilUser->getId() == ANONYMOUS_USER_ID))
161 include_once
"./Modules/Course/classes/class.ilCourseParticipants.php";
162 foreach (
$_SESSION[
'crs_obj_ids'] as $obj_id)
197 $_SESSION[
"coupons"][
"paypal"] = array();
198 $_SESSION[
'tmp_transaction'][
'result'] =
'success';
202 else if (strcmp ($lines[0],
"FAIL") == 0)
214 $res = $ilDB->queryF(
'SELECT * FROM payment_statistic WHERE transaction_extern = %s',
215 array(
'text'), array($a_id));
217 return $res->numRows() ?
true :
false;
236 include_once
'./Services/Payment/classes/class.ilPayMethods.php';
239 if ($a_array[
"mc_currency"] != $genSet->get(
"currency_unit"))
244 $sc = $this->psc_obj->getShoppingCart($this->pay_method);
245 $this->psc_obj->clearCouponItemsSession();
247 if (is_array($sc) && count($sc) > 0)
249 for ($i = 0; $i < count($sc); $i++)
252 "name" => $a_array[
"item_name".($i+1)],
253 "amount" => $a_array[
"mc_gross_".($i+1)]
256 if (!empty(
$_SESSION[
"coupons"][
"paypal"]))
258 $sc[$i][
"math_price"] = (float) $sc[$i][
"price"];
260 $tmp_pobject =
new ilPaymentObject($this->user_obj, $sc[$i][
'pobject_id']);
262 foreach (
$_SESSION[
"coupons"][
"paypal"] as $key => $coupon)
264 $this->coupon_obj->setId($coupon[
"pc_pk"]);
265 $this->coupon_obj->setCurrentCoupon($coupon);
267 if ($this->coupon_obj->isObjectAssignedToCoupon($tmp_pobject->getRefId()))
269 $_SESSION[
"coupons"][
"paypal"][$key][
"total_objects_coupon_price"] += (float) $sc[$i][
"price"];
270 $_SESSION[
"coupons"][
"paypal"][$key][
"items"][] = $sc[$i];
278 $coupon_discount_items = $this->psc_obj->calcDiscountPrices(
$_SESSION[
"coupons"][
"paypal"]);
282 for ($i = 0; $i < count($sc); $i++)
284 if (array_key_exists($sc[$i][
"pobject_id"], $coupon_discount_items))
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;
290 for ($j = 0; $j < count($items); $j++)
292 if (substr($items[$j][
"name"], 0, strlen($sc[$i][
"obj_id"])+2) ==
"[".$sc[$i][
"obj_id"].
"]" &&
293 $items[$j][
"amount"] == $sc[$i][
"price"])
295 $total += $items[$j][
"amount"];
302 if (number_format(
$total, 2,
".",
"") == $a_array[
"mc_gross"] &&
303 $found == count($sc))
314 global $ilias, $ilUser, $ilObjDataCache;
366 $sc = $this->psc_obj->getShoppingCart($this->pay_method);
367 $this->psc_obj->clearCouponItemsSession();
369 if (is_array($sc) && count($sc) > 0)
371 include_once
'./Services/Payment/classes/class.ilPaymentBookings.php';
374 for ($i = 0; $i < count($sc); $i++)
376 if (!empty(
$_SESSION[
"coupons"][
"paypal"]))
378 $sc[$i][
"math_price"] = (float) $sc[$i][
"price"];
380 $tmp_pobject =&
new ilPaymentObject($this->user_obj, $sc[$i][
'pobject_id']);
382 foreach (
$_SESSION[
"coupons"][
"paypal"] as $key => $coupon)
384 $this->coupon_obj->setId($coupon[
"pc_pk"]);
385 $this->coupon_obj->setCurrentCoupon($coupon);
387 if ($this->coupon_obj->isObjectAssignedToCoupon($tmp_pobject->getRefId()))
389 $_SESSION[
"coupons"][
"paypal"][$key][
"total_objects_coupon_price"] += (float) $sc[$i][
"price"];
390 $_SESSION[
"coupons"][
"paypal"][$key][
"items"][] = $sc[$i];
397 $coupon_discount_items = $this->psc_obj->calcDiscountPrices(
$_SESSION[
"coupons"][
"paypal"]);
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);
402 for ($i = 0; $i < count($sc); $i++)
407 $price = $sc[$i][
"price"];
410 if (array_key_exists($sc[$i][
"pobject_id"], $coupon_discount_items))
412 $bonus = $coupon_discount_items[$sc[$i][
"pobject_id"]][
"math_price"] - $coupon_discount_items[$sc[$i][
"pobject_id"]][
"discount_price"];
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"]);
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']);
430 $book_obj->setObjectTitle($sc[$i][
'object_title']);
431 $book_obj->setVatRate($sc[$i][
'vat_rate']);
432 $book_obj->setVatUnit($sc[$i][
'vat_unit']);
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';
442 if($save_user_adr ==
'1' || (ANONYMOUS_USER_ID == $ilUser->getId()))
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']);
449 $_SESSION[
'paypal'][
'personal_data'][
'name'] = $keyarray[
'address_name'];
450 $_SESSION[
'paypal'][
'personal_data'][
'email'] = $keyarray[
'payer_email'];
454 $booking_id = $book_obj->add();
456 if (!empty(
$_SESSION[
"coupons"][
"paypal"]) && $booking_id)
458 foreach (
$_SESSION[
"coupons"][
"paypal"] as $coupon)
460 $this->coupon_obj->setId($coupon[
"pc_pk"]);
461 $this->coupon_obj->setCurrentCoupon($coupon);
463 if ($this->coupon_obj->isObjectAssignedToCoupon($pobject->getRefId()))
465 $this->coupon_obj->addCouponForBookingId($booking_id);
473 $obj_id = $ilObjDataCache->lookupObjId($pobjectData[
"ref_id"]);
474 $obj_type = $ilObjDataCache->lookupType($obj_id);
475 $obj_title = $ilObjDataCache->lookupTitle($obj_id);
477 include_once
"./Services/Repository/classes/class.ilRepositoryExplorer.php";
480 $message_link =
"" . ILIAS_HTTP_PATH.
"/".$obj_link.
"&transaction=".$book_obj->getTransaction();
481 if($obj_type ==
'file')
482 $download_links[] = $message_link;
484 $bookings[
"list"][] = array(
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'],
494 'currency_unit' =>$sc[$i][
'currency_unit']
497 $total += $sc[$i][
"price"];
498 $total_vat += $sc[$i][
'vat_unit'];
500 if ($sc[$i][
"psc_id"]) $this->psc_obj->delete($sc[$i][
"psc_id"]);
503 if (!empty(
$_SESSION[
"coupons"][
"paypal"]))
505 foreach (
$_SESSION[
"coupons"][
"paypal"] as $coupon)
507 $this->coupon_obj->setId($coupon[
"pc_pk"]);
508 $this->coupon_obj->setCurrentCoupon($coupon);
509 $this->coupon_obj->addTracking();
514 $bookings[
"total"] =
$total;
515 $bookings[
'total_vat'] = $total_vat;
517 $bookings[
'email_extern'] = $keyarray[
'payer_email'];
518 $bookings[
'name_extern'] = $keyarray[
'address_name'];
520 $_SESSION[
'download_links'] = $download_links;
527 global $ilUser, $ilias;
529 $transaction = $a_array[
"txn_id"];
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';
539 $tpl =
new ilTemplate(
'tpl.pay_bill.html',
true,
true,
'Services/Payment');
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")));
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"]);
553 $tpl->setVariable(
"BILL_NO", $transaction);
554 $tpl->setVariable(
"DATE", date(
"d.m.Y"));
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")));
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")));
565 for ($i = 0; $i < count($bookings[
"list"]); $i++)
567 $tmp_pobject =
new ilPaymentObject($this->user_obj, $bookings[
"list"][$i][
'pobject_id']);
569 $assigned_coupons =
'';
570 if (!empty(
$_SESSION[
"coupons"][
"paypal"]))
572 foreach (
$_SESSION[
"coupons"][
"paypal"] as $key => $coupon)
574 $this->coupon_obj->setId($coupon[
"pc_pk"]);
575 $this->coupon_obj->setCurrentCoupon($coupon);
577 if ($this->coupon_obj->isObjectAssignedToCoupon($tmp_pobject->getRefId()))
579 $assigned_coupons .=
'<br />' . $this->lng->txt(
'paya_coupons_coupon') .
': ' . $coupon[
"pcc_code"];
583 if($bookings[
"list"][$i][
"type"] ==
'file')
585 $message_link .= $bookings[
'list'][$i][
'message_link'] .
"\n\n";
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")));
592 if( $bookings[
'list'][$i][
'duration'] == 0)
594 $tpl->setVariable(
'LOOP_DURATION', utf8_decode($this->lng->txt(
'unlimited_duration')));
597 $tpl->setVariable(
'LOOP_DURATION', $bookings[
'list'][$i][
'duration'] .
' ' . utf8_decode($this->lng->txt(
'paya_months')));
601 $tpl->setVariable(
"LOOP_PRICE", $bookings[
"list"][$i][
"price"].
' '.$bookings[
"list"][$i][
'currency_unit']);
602 $tpl->parseCurrentBlock(
"loop");
607 if (!empty(
$_SESSION[
"coupons"][
"paypal"]))
609 if (count($items = $bookings[
"list"]))
611 $sub_total_amount = $bookings[
"total"];
613 foreach (
$_SESSION[
"coupons"][
"paypal"] as $coupon)
615 $this->coupon_obj->setId($coupon[
"pc_pk"]);
616 $this->coupon_obj->setCurrentCoupon($coupon);
618 $total_object_price = 0.0;
619 $current_coupon_bonus = 0.0;
621 foreach ($bookings[
"list"] as $item)
623 $tmp_pobject =&
new ilPaymentObject($this->user_obj, $item[
'pobject_id']);
625 if ($this->coupon_obj->isObjectAssignedToCoupon($tmp_pobject->getRefId()))
627 $total_object_price += $item[
"price"];
633 $current_coupon_bonus = $this->coupon_obj->getCouponBonus($total_object_price);
635 $bookings[
"total"] += $current_coupon_bonus * (-1);
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();
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"));
648 if ($bookings[
"total"] < 0)
650 $bookings[
"total"] = 0.0;
651 $bookings[
"total_vat"] = 0.0;
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)
659 $tpl->setVariable(
"TXT_TOTAL_VAT", utf8_decode($this->lng->txt(
"pay_bmf_vat_included")));
662 $tpl->setVariable(
"TXT_PAYMENT_TYPE", utf8_decode($this->lng->txt(
"pay_payed_paypal")));
664 if (!@file_exists($genSet->get(
"pdf_path")))
669 if (@file_exists($genSet->get(
"pdf_path")))
675 if (@file_exists($genSet->get(
"pdf_path") .
"/" . $transaction .
".pdf") &&
676 $ilUser->getEmail() !=
"" &&
677 $ilias->getSetting(
"admin_email") !=
"")
680 $m->
Subject( $this->lng->txt(
"pay_message_subject") );
681 $m->From( $ilias->getSetting(
"admin_email") );
683 if(ANONYMOUS_USER_ID == $ilUser->getId())
685 $m->To($bookings[
'payer_email']);
687 $message = $this->lng->txt(
"pay_message_hello") .
" " .$booking[
'address_name'].
",\n\n";
692 $m->To( $ilUser->getEmail() );
693 $message = $this->lng->txt(
"pay_message_hello") .
" " . $ilUser->getFirstname() .
" " . $ilUser->getLastname() .
",\n\n";
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 );
701 $m->Attach( $genSet->get(
"pdf_path") .
"/" . $transaction .
".pdf",
"application/pdf" ) ;
705 @unlink($genSet->get(
"pdf_path") .
"/" . $transaction .
".html");
706 @unlink($genSet->get(
"pdf_path") .
"/" . $transaction .
".pdf");
719 $lng->loadLanguageModule(
"meta");
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");
740 foreach($cntcodes as $cntcode)
742 $cntrs[$cntcode] = $lng->txt(
"meta_c_".$cntcode);
751 foreach($countries as $code => $text)
764 return $countries[$value];