31 include_once
'./payment/classes/class.ilPaymentObject.php';
32 include_once
'./payment/classes/class.ilPaymentShoppingCart.php';
33 include_once
'./payment/classes/class.ilPaypalSettings.php';
34 include_once
'./payment/classes/class.ilPaymentCoupons.php';
35 include_once
'Services/Payment/classes/class.ilShopVatsList.php';
38 define(
'ERROR_OPENSOCKET', 1);
39 define(
'ERROR_WRONG_CUSTOMER', 2);
40 define(
'ERROR_NOT_COMPLETED', 3);
41 define(
'ERROR_PREV_TRANS_ID', 4);
42 define(
'ERROR_WRONG_VENDOR', 5);
43 define(
'ERROR_WRONG_ITEMS', 6);
44 define(
'ERROR_FAIL', 7);
72 $this->paypalConfig = $ppSet->getAll();
74 $this->lng->loadLanguageModule(
"payment");
76 if (!is_array(
$_SESSION[
"coupons"][
"paypal"]))
85 $fp = @fsockopen ($path = $this->paypalConfig[
"server_host"], 80, $errno, $errstr, 30);
94 $req =
'cmd=_notify-synch';
96 $tx_token = $_REQUEST[
'tx'];
100 $req .=
"&tx=$tx_token&at=$auth_token";
101 $header .=
"POST " . $this->paypalConfig[
"server_path"] .
" HTTP/1.0\r\n";
102 $header .=
"Host:".$this->paypalConfig[
"server_host"].
"\r\n";
103 $header .=
"Content-Type: application/x-www-form-urlencoded\r\n";
104 $header .=
"Content-Length: " . strlen($req) .
"\r\n\r\n";
106 fputs ($fp, $header . $req);
112 $line = fgets ($fp, 1024);
113 if (strcmp($line,
"\r\n") == 0)
118 else if ($headerdone)
126 $lines = explode(
"\n",
$res);
128 if (strcmp ($lines[0],
"SUCCESS") == 0)
130 for ($i=1; $i<count($lines);$i++)
132 list(
$key,$val) = explode(
"=", $lines[$i]);
133 $keyarray[urldecode(
$key)] = urldecode($val);
136 if ($ilUser->getId() != $keyarray[
"custom"])
138 #echo "Wrong customer";
143 if (!in_array($keyarray[
"payment_status"], array(
"Completed",
"In-Progress",
"Pending",
"Processed")))
145 #echo "Not completed";
152 #echo "Prev. processed trans. id";
157 if ($keyarray[
"receiver_email"] != $this->paypalConfig[
"vendor"])
159 #echo "Wrong vendor";
172 $_SESSION[
"coupons"][
"paypal"] = array();
176 else if (strcmp ($lines[0],
"FAIL") == 0)
188 $res = $this->db->query(
'SELECT * FROM payment_statistic WHERE transaction_extern = '.$ilDB->quote($a_id,
'integer'));
190 return $res->numRows() ?
true :
false;
197 include_once
'./payment/classes/class.ilPayMethods.php';
200 if ($a_array[
"mc_currency"] != $genSet->get(
"currency_unit"))
206 $this->psc_obj->clearCouponItemsSession();
211 for ($i = 0; $i < count($sc); $i++)
214 "name" => $a_array[
"item_name".($i+1)],
215 "amount" => $a_array[
"mc_gross_".($i+1)]
218 if (!empty(
$_SESSION[
"coupons"][
"paypal"]))
220 $sc[$i][
"math_price"] = (float) $sc[$i][
"betrag"];
222 $tmp_pobject =&
new ilPaymentObject($this->user_obj, $sc[$i][
'pobject_id']);
226 $this->coupon_obj->setId($coupon[
"pc_pk"]);
227 $this->coupon_obj->setCurrentCoupon($coupon);
229 if ($this->coupon_obj->isObjectAssignedToCoupon($tmp_pobject->getRefId()))
231 $_SESSION[
"coupons"][
"paypal"][
$key][
"total_objects_coupon_price"] += (float) $sc[$i][
"betrag"];
240 $coupon_discount_items = $this->psc_obj->calcDiscountPrices(
$_SESSION[
"coupons"][
"paypal"]);
244 for ($i = 0; $i < count($sc); $i++)
246 if (array_key_exists($sc[$i][
"pobject_id"], $coupon_discount_items))
248 $sc[$i][
"betrag"] = round($coupon_discount_items[$sc[$i][
"pobject_id"]][
"discount_price"], 2);
249 if ($sc[$i][
"betrag"] < 0) $sc[$i][
"betrag"] = 0.0;
252 for ($j = 0; $j < count($items); $j++)
254 if (substr($items[$j][
"name"], 0, strlen($sc[$i][
"obj_id"])+2) ==
"[".$sc[$i][
"obj_id"].
"]" &&
255 $items[$j][
"amount"] == $sc[$i][
"betrag"])
257 $total += $items[$j][
"amount"];
264 if (number_format(
$total, 2,
".",
"") == $a_array[
"mc_gross"] &&
265 $found == count($sc))
276 global $ilias, $ilUser, $ilObjDataCache;
279 $this->psc_obj->clearCouponItemsSession();
284 include_once
'./payment/classes/class.ilPaymentBookings.php';
287 for ($i = 0; $i < count($sc); $i++)
289 if (!empty(
$_SESSION[
"coupons"][
"paypal"]))
291 $sc[$i][
"math_price"] = (float) $sc[$i][
"betrag"];
293 $tmp_pobject =&
new ilPaymentObject($this->user_obj, $sc[$i][
'pobject_id']);
297 $this->coupon_obj->setId($coupon[
"pc_pk"]);
298 $this->coupon_obj->setCurrentCoupon($coupon);
300 if ($this->coupon_obj->isObjectAssignedToCoupon($tmp_pobject->getRefId()))
302 $_SESSION[
"coupons"][
"paypal"][
$key][
"total_objects_coupon_price"] += (float) $sc[$i][
"betrag"];
311 $coupon_discount_items = $this->psc_obj->calcDiscountPrices(
$_SESSION[
"coupons"][
"paypal"]);
313 for ($i = 0; $i < count($sc); $i++)
316 $pobject =&
new ilPaymentObject($this->user_obj,$sc[$i][
'pobject_id']);
318 $inst_id_time = $ilias->getSetting(
'inst_id').
'_'.$ilUser->getId().
'_'.substr((
string) time(),-3);
320 $price = $sc[$i][
"betrag"];
323 if (array_key_exists($sc[$i][
"pobject_id"], $coupon_discount_items))
325 $bonus = $coupon_discount_items[$sc[$i][
"pobject_id"]][
"math_price"] - $coupon_discount_items[$sc[$i][
"pobject_id"]][
"discount_price"];
327 $inst_id_time = $ilias->getSetting(
'inst_id').
'_'.$ilUser->getId().
'_'.substr((
string) time(),-3);
328 $transaction = $inst_id_time.substr(md5(uniqid(rand(),
true)), 0, 4);
330 $book_obj->setTransaction($inst_id_time.substr(md5(uniqid(rand(),
true)), 0, 4));
331 $book_obj->setPobjectId($sc[$i][
"pobject_id"]);
332 $book_obj->setCustomerId($ilUser->getId());
333 $book_obj->setVendorId($pobjectData[
"vendor_id"]);
334 $book_obj->setPayMethod($pobjectData[
"pay_method"]);
335 $book_obj->setOrderDate(time());
336 $book_obj->setDuration($sc[$i][
"dauer"]);
337 $book_obj->setPrice($sc[$i][
"betrag_string"]);
339 $book_obj->setPayed(1);
340 $book_obj->setAccess(1);
341 $book_obj->setVoucher(
'');
342 $book_obj->setTransactionExtern($a_id);
344 $book_obj->setObjectTitle($sc[$i][
'buchungstext']);
345 $book_obj->setVatRate($sc[$i][
'vat_rate']);
346 $book_obj->setVatUnit($sc[$i][
'vat_unit']);
348 include_once
'./payment/classes/class.ilPayMethods.php';
351 if($save_user_adr_bill ==
'1')
353 $book_obj->setStreet(
$_SESSION[
'paypal'][
'personal_data'][
'street'],
$_SESSION[
'bill'][
'personal_data'][
'house_number']);
354 $book_obj->setPoBox(
$_SESSION[
'paypal'][
'personal_data'][
'po_box']);
355 $book_obj->setZipcode(
$_SESSION[
'paypal'][
'personal_data'][
'zipcode']);
356 $book_obj->setCity(
$_SESSION[
'paypal'][
'personal_data'][
'city']);
357 $book_obj->setCountry(
$_SESSION[
'paypal'][
'personal_data'][
'country']);
360 $booking_id = $book_obj->add();
362 if (!empty(
$_SESSION[
"coupons"][
"paypal"]) && $booking_id)
364 foreach (
$_SESSION[
"coupons"][
"paypal"] as $coupon)
366 $this->coupon_obj->setId($coupon[
"pc_pk"]);
367 $this->coupon_obj->setCurrentCoupon($coupon);
369 if ($this->coupon_obj->isObjectAssignedToCoupon($pobject->getRefId()))
371 $this->coupon_obj->addCouponForBookingId($booking_id);
379 $obj_id = $ilObjDataCache->lookupObjId($pobjectData[
"ref_id"]);
380 $obj_type = $ilObjDataCache->lookupType($obj_id);
381 $obj_title = $ilObjDataCache->lookupTitle($obj_id);
383 $bookings[
"list"][] = array(
385 "title" =>
"[".$obj_id.
"]: " . $obj_title,
386 "duration" => $sc[$i][
"dauer"],
387 "vat_rate" => $sc[$i][
"vat_rate"],
388 "vat_unit" => $sc[$i][
"vat_unit"],
389 "price" => $sc[$i][
"betrag_string"],
390 "betrag" => $sc[$i][
"betrag"]
393 $total += $sc[$i][
"betrag"];
394 $total_vat += $sc[$i][
'vat_unit'];
396 if ($sc[$i][
"psc_id"]) $this->psc_obj->delete($sc[$i][
"psc_id"]);
399 if (!empty(
$_SESSION[
"coupons"][
"paypal"]))
401 foreach (
$_SESSION[
"coupons"][
"paypal"] as $coupon)
403 $this->coupon_obj->setId($coupon[
"pc_pk"]);
404 $this->coupon_obj->setCurrentCoupon($coupon);
405 $this->coupon_obj->addTracking();
410 $bookings[
"total"] =
$total;
411 $bookings[
'total_vat'] = $total_vat;
418 global $ilUser, $ilias;
420 $transaction = $a_array[
"txn_id"];
422 include_once
'./classes/class.ilTemplate.php';
423 include_once
'./Services/Utilities/classes/class.ilUtil.php';
424 include_once
'./payment/classes/class.ilGeneralSettings.php';
425 include_once
'./payment/classes/class.ilPaymentShoppingCart.php';
426 include_once
'Services/Mail/classes/class.ilMimeMail.php';
430 $tpl =
new ilTemplate(
"./payment/templates/default/tpl.pay_paypal_bill.html",
true,
true,
true);
432 $tpl->setVariable(
"VENDOR_ADDRESS", nl2br(utf8_decode($genSet->get(
"address"))));
433 $tpl->setVariable(
"VENDOR_ADD_INFO", nl2br(utf8_decode($genSet->get(
"add_info"))));
434 $tpl->setVariable(
"VENDOR_BANK_DATA", nl2br(utf8_decode($genSet->get(
"bank_data"))));
435 $tpl->setVariable(
"TXT_BANK_DATA", utf8_decode($this->lng->txt(
"pay_bank_data")));
437 $tpl->setVariable(
"CUSTOMER_FIRSTNAME", $a_array[
"first_name"]);
438 $tpl->setVariable(
"CUSTOMER_LASTNAME", $a_array[
"last_name"]);
439 $tpl->setVariable(
"CUSTOMER_STREET", $a_array[
"address_street"]);
440 $tpl->setVariable(
"CUSTOMER_ZIPCODE", $a_array[
"address_zip"]);
441 $tpl->setVariable(
"CUSTOMER_CITY", $a_array[
"address_city"]);
442 $tpl->setVariable(
"CUSTOMER_COUNTRY", $a_array[
"address_country"]);
444 $tpl->setVariable(
"BILL_NO", $transaction);
445 $tpl->setVariable(
"DATE", date(
"d.m.Y"));
447 $tpl->setVariable(
"TXT_BILL", utf8_decode($this->lng->txt(
"pays_bill")));
448 $tpl->setVariable(
"TXT_BILL_NO", utf8_decode($this->lng->txt(
"pay_bill_no")));
449 $tpl->setVariable(
"TXT_DATE", utf8_decode($this->lng->txt(
"date")));
451 $tpl->setVariable(
"TXT_ARTICLE", utf8_decode($this->lng->txt(
"pay_article")));
452 $tpl->setVariable(
'TXT_VAT_RATE', utf8_decode($this->lng->txt(
'vat_rate')));
453 $tpl->setVariable(
'TXT_VAT_UNIT', utf8_decode($this->lng->txt(
'vat_unit')));
454 $tpl->setVariable(
"TXT_PRICE", utf8_decode($this->lng->txt(
"price_a")));
456 for ($i = 0; $i < count($bookings[
"list"]); $i++)
458 $tmp_pobject =&
new ilPaymentObject($this->user_obj, $bookings[
"list"][$i][
'pobject_id']);
460 $assigned_coupons =
'';
461 if (!empty(
$_SESSION[
"coupons"][
"paypal"]))
465 $this->coupon_obj->setId($coupon[
"pc_pk"]);
466 $this->coupon_obj->setCurrentCoupon($coupon);
468 if ($this->coupon_obj->isObjectAssignedToCoupon($tmp_pobject->getRefId()))
470 $assigned_coupons .=
'<br />' . $this->lng->txt(
'paya_coupons_coupon') .
': ' . $coupon[
"pcc_code"];
475 $tpl->setCurrentBlock(
"loop");
476 $tpl->setVariable(
"LOOP_OBJ_TYPE", utf8_decode($this->lng->txt($bookings[
"list"][$i][
"type"])));
477 $tpl->setVariable(
"LOOP_TITLE", utf8_decode($bookings[
"list"][$i][
"title"]) . $assigned_coupons);
478 $tpl->setVariable(
"LOOP_TXT_ENTITLED_RETRIEVE", utf8_decode($this->lng->txt(
"pay_entitled_retrieve")));
479 $tpl->setVariable(
"LOOP_DURATION", $bookings[
"list"][$i][
"duration"] .
" " . utf8_decode($this->lng->txt(
"paya_months")));
482 $tpl->setVariable(
"LOOP_PRICE", $bookings[
"list"][$i][
"price"]);
483 $tpl->parseCurrentBlock(
"loop");
488 if (!empty(
$_SESSION[
"coupons"][
"paypal"]))
490 if (count($items = $bookings[
"list"]))
492 $sub_total_amount = $bookings[
"total"];
494 foreach (
$_SESSION[
"coupons"][
"paypal"] as $coupon)
496 $this->coupon_obj->setId($coupon[
"pc_pk"]);
497 $this->coupon_obj->setCurrentCoupon($coupon);
499 $total_object_price = 0.0;
500 $current_coupon_bonus = 0.0;
502 foreach ($bookings[
"list"] as $item)
504 $tmp_pobject =&
new ilPaymentObject($this->user_obj, $item[
'pobject_id']);
506 if ($this->coupon_obj->isObjectAssignedToCoupon($tmp_pobject->getRefId()))
508 $total_object_price += $item[
"betrag"];
514 $current_coupon_bonus = $this->coupon_obj->getCouponBonus($total_object_price);
516 $bookings[
"total"] += $current_coupon_bonus * (-1);
518 $tpl->setCurrentBlock(
"cloop");
519 $tpl->setVariable(
"TXT_COUPON", utf8_decode($this->lng->txt(
"paya_coupons_coupon") .
" " . $coupon[
"pcc_code"]));
520 $tpl->setVariable(
"BONUS", number_format($current_coupon_bonus * (-1), 2,
',',
'.') .
" " . $genSet->get(
"currency_unit"));
521 $tpl->parseCurrentBlock();
524 $tpl->setVariable(
"TXT_SUBTOTAL_AMOUNT", utf8_decode($this->lng->txt(
"pay_bmf_subtotal_amount")));
525 $tpl->setVariable(
"SUBTOTAL_AMOUNT", number_format($sub_total_amount, 2,
",",
".") .
" " . $genSet->get(
"currency_unit"));
529 if ($bookings[
"total"] < 0)
531 $bookings[
"total"] = 0.0;
532 $bookings[
"total_vat"] = 0.0;
535 $tpl->setVariable(
"TXT_TOTAL_AMOUNT", utf8_decode($this->lng->txt(
"pay_bmf_total_amount")));
536 $tpl->setVariable(
"TOTAL_AMOUNT", number_format($bookings[
"total"], 2,
",",
".") .
" " . $genSet->get(
"currency_unit"));
537 if ($bookings[
"total_vat"] > 0)
540 $tpl->setVariable(
"TXT_TOTAL_VAT", utf8_decode($this->lng->txt(
"pay_bmf_vat_included")));
543 $tpl->setVariable(
"TXT_PAYMENT_TYPE", utf8_decode($this->lng->txt(
"pay_payed_paypal")));
545 if (!@file_exists($genSet->get(
"pdf_path")))
550 if (@file_exists($genSet->get(
"pdf_path")))
555 if (@file_exists($genSet->get(
"pdf_path") .
"/" . $transaction .
".pdf") &&
556 $ilUser->getEmail() !=
"" &&
557 $ilias->getSetting(
"admin_email") !=
"")
560 $m->
From( $ilias->getSetting(
"admin_email") );
561 $m->To( $ilUser->getEmail() );
562 $m->Subject( $this->lng->txt(
"pay_message_subject") );
563 $message = $this->lng->txt(
"pay_message_hello") .
" " . $ilUser->getFirstname() .
" " . $ilUser->getLastname() .
",\n\n";
564 $message .= $this->lng->txt(
"pay_message_thanks") .
"\n\n";
565 $message .= $this->lng->txt(
"pay_message_attachment") .
"\n\n";
566 $message .= $this->lng->txt(
"pay_message_regards") .
"\n\n";
567 $message .= strip_tags($genSet->get(
"address"));
568 $m->Body( $message );
569 $m->Attach( $genSet->get(
"pdf_path") .
"/" . $transaction .
".pdf",
"application/pdf" ) ;
573 @unlink($genSet->get(
"pdf_path") .
"/" . $transaction .
".html");
574 @unlink($genSet->get(
"pdf_path") .
"/" . $transaction .
".pdf");
587 $lng->loadLanguageModule(
"meta");
589 $cntcodes = array (
"DE",
"ES",
"FR",
"GB",
"AT",
"CH",
"AF",
"AL",
"DZ",
"AS",
"AD",
"AO",
590 "AI",
"AQ",
"AG",
"AR",
"AM",
"AW",
"AU",
"AT",
"AZ",
"BS",
"BH",
"BD",
"BB",
"BY",
591 "BE",
"BZ",
"BJ",
"BM",
"BT",
"BO",
"BA",
"BW",
"BV",
"BR",
"IO",
"BN",
"BG",
"BF",
592 "BI",
"KH",
"CM",
"CA",
"CV",
"KY",
"CF",
"TD",
"CL",
"CN",
"CX",
"CC",
"CO",
"KM",
593 "CG",
"CK",
"CR",
"CI",
"HR",
"CU",
"CY",
"CZ",
"DK",
"DJ",
"DM",
"DO",
"TP",
"EC",
594 "EG",
"SV",
"GQ",
"ER",
"EE",
"ET",
"FK",
"FO",
"FJ",
"FI",
"FR",
"FX",
"GF",
"PF",
595 "TF",
"GA",
"GM",
"GE",
"DE",
"GH",
"GI",
"GR",
"GL",
"GD",
"GP",
"GU",
"GT",
"GN",
596 "GW",
"GY",
"HT",
"HM",
"HN",
"HU",
"IS",
"IN",
"ID",
"IR",
"IQ",
"IE",
"IL",
"IT",
597 "JM",
"JP",
"JO",
"KZ",
"KE",
"KI",
"KP",
"KR",
"KW",
"KG",
"LA",
"LV",
"LB",
"LS",
598 "LR",
"LY",
"LI",
"LT",
"LU",
"MO",
"MK",
"MG",
"MW",
"MY",
"MV",
"ML",
"MT",
"MH",
599 "MQ",
"MR",
"MU",
"YT",
"MX",
"FM",
"MD",
"MC",
"MN",
"MS",
"MA",
"MZ",
"MM",
"NA",
600 "NR",
"NP",
"NL",
"AN",
"NC",
"NZ",
"NI",
"NE",
"NG",
"NU",
"NF",
"MP",
"NO",
"OM",
601 "PK",
"PW",
"PA",
"PG",
"PY",
"PE",
"PH",
"PN",
"PL",
"PT",
"PR",
"QA",
"RE",
"RO",
602 "RU",
"RW",
"KN",
"LC",
"VC",
"WS",
"SM",
"ST",
"SA",
"CH",
"SN",
"SC",
"SL",
"SG",
603 "SK",
"SI",
"SB",
"SO",
"ZA",
"GS",
"ES",
"LK",
"SH",
"PM",
"SD",
"SR",
"SJ",
"SZ",
604 "SE",
"SY",
"TW",
"TJ",
"TZ",
"TH",
"TG",
"TK",
"TO",
"TT",
"TN",
"TR",
"TM",
"TC",
605 "TV",
"UG",
"UA",
"AE",
"GB",
"UY",
"US",
"UM",
"UZ",
"VU",
"VA",
"VE",
"VN",
"VG",
606 "VI",
"WF",
"EH",
"YE",
"ZR",
"ZM",
"ZW");
608 foreach($cntcodes as $cntcode)
610 $cntrs[$cntcode] = $lng->txt(
"meta_c_".$cntcode);
619 foreach($countries as $code => $text)
632 return $countries[$value];