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';
37 define(
'ERROR_OPENSOCKET', 1);
38 define(
'ERROR_WRONG_CUSTOMER', 2);
39 define(
'ERROR_NOT_COMPLETED', 3);
40 define(
'ERROR_PREV_TRANS_ID', 4);
41 define(
'ERROR_WRONG_VENDOR', 5);
42 define(
'ERROR_WRONG_ITEMS', 6);
43 define(
'ERROR_FAIL', 7);
69 $this->paypalConfig = $ppSet->getAll();
71 $this->lng->loadLanguageModule(
"payment");
73 if (!is_array(
$_SESSION[
"coupons"][
"paypal"]))
82 $fp = @fsockopen ($this->paypalConfig[
"server_host"], 80, $errno, $errstr, 30);
91 $req =
'cmd=_notify-synch';
93 $tx_token = $_REQUEST[
'tx'];
97 $req .=
"&tx=$tx_token&at=$auth_token";
98 $header .=
"POST " . $this->paypalConfig[
"server_path"] .
" HTTP/1.0\r\n";
99 $header .=
"Content-Type: application/x-www-form-urlencoded\r\n";
100 $header .=
"Content-Length: " . strlen($req) .
"\r\n\r\n";
102 fputs ($fp, $header . $req);
108 $line = fgets ($fp, 1024);
109 if (strcmp($line,
"\r\n") == 0)
114 else if ($headerdone)
121 $lines = explode(
"\n",
$res);
123 if (strcmp ($lines[0],
"SUCCESS") == 0)
125 for ($i=1; $i<count($lines);$i++)
127 list($key,$val) = explode(
"=", $lines[$i]);
128 $keyarray[urldecode($key)] = urldecode($val);
131 if ($ilUser->getId() != $keyarray[
"custom"])
133 #echo "Wrong customer";
138 if (!in_array($keyarray[
"payment_status"], array(
"Completed",
"In-Progress",
"Pending",
"Processed")))
140 #echo "Not completed";
147 #echo "Prev. processed trans. id";
152 if ($keyarray[
"receiver_email"] != $this->paypalConfig[
"vendor"])
154 #echo "Wrong vendor";
167 $_SESSION[
"coupons"][
"paypal"] = array();
171 else if (strcmp ($lines[0],
"FAIL") == 0)
179 $query =
"SELECT * FROM payment_statistic ".
180 "WHERE transaction_extern = '".$a_id.
"'";
182 $res = $this->db->query($query);
184 return $res->numRows() ?
true :
false;
191 include_once
'./payment/classes/class.ilPayMethods.php';
194 if ($a_array[
"mc_currency"] != $genSet->get(
"currency_unit"))
200 $this->psc_obj->clearCouponItemsSession();
205 for ($i = 0; $i < count($sc); $i++)
208 "name" => $a_array[
"item_name".($i+1)],
209 "amount" => $a_array[
"mc_gross_".($i+1)]
212 if (!empty(
$_SESSION[
"coupons"][
"paypal"]))
214 $sc[$i][
"math_price"] = (float) $sc[$i][
"betrag"];
216 $tmp_pobject =&
new ilPaymentObject($this->user_obj, $sc[$i][
'pobject_id']);
218 foreach (
$_SESSION[
"coupons"][
"paypal"] as $key => $coupon)
220 $this->coupon_obj->setId($coupon[
"pc_pk"]);
221 $this->coupon_obj->setCurrentCoupon($coupon);
223 if ($this->coupon_obj->isObjectAssignedToCoupon($tmp_pobject->getRefId()))
225 $_SESSION[
"coupons"][
"paypal"][$key][
"total_objects_coupon_price"] += (float) $sc[$i][
"betrag"];
226 $_SESSION[
"coupons"][
"paypal"][$key][
"items"][] = $sc[$i];
234 $coupon_discount_items = $this->psc_obj->calcDiscountPrices(
$_SESSION[
"coupons"][
"paypal"]);
238 for ($i = 0; $i < count($sc); $i++)
240 if (array_key_exists($sc[$i][
"pobject_id"], $coupon_discount_items))
242 $sc[$i][
"betrag"] = round($coupon_discount_items[$sc[$i][
"pobject_id"]][
"discount_price"], 2);
243 if ($sc[$i][
"betrag"] < 0) $sc[$i][
"betrag"] = 0.0;
246 for ($j = 0; $j < count($items); $j++)
248 if (substr($items[$j][
"name"], 0, strlen($sc[$i][
"obj_id"])+2) ==
"[".$sc[$i][
"obj_id"].
"]" &&
249 $items[$j][
"amount"] == $sc[$i][
"betrag"])
251 $total += $items[$j][
"amount"];
258 if (number_format(
$total, 2,
".",
"") == $a_array[
"mc_gross"] &&
259 $found == count($sc))
270 global $ilias, $ilUser, $ilObjDataCache;
273 $this->psc_obj->clearCouponItemsSession();
278 include_once
'./payment/classes/class.ilPaymentBookings.php';
281 for ($i = 0; $i < count($sc); $i++)
283 if (!empty(
$_SESSION[
"coupons"][
"paypal"]))
285 $sc[$i][
"math_price"] = (float) $sc[$i][
"betrag"];
287 $tmp_pobject =&
new ilPaymentObject($this->user_obj, $sc[$i][
'pobject_id']);
289 foreach (
$_SESSION[
"coupons"][
"paypal"] as $key => $coupon)
291 $this->coupon_obj->setId($coupon[
"pc_pk"]);
292 $this->coupon_obj->setCurrentCoupon($coupon);
294 if ($this->coupon_obj->isObjectAssignedToCoupon($tmp_pobject->getRefId()))
296 $_SESSION[
"coupons"][
"paypal"][$key][
"total_objects_coupon_price"] += (float) $sc[$i][
"betrag"];
297 $_SESSION[
"coupons"][
"paypal"][$key][
"items"][] = $sc[$i];
305 $coupon_discount_items = $this->psc_obj->calcDiscountPrices(
$_SESSION[
"coupons"][
"paypal"]);
307 for ($i = 0; $i < count($sc); $i++)
310 $pobject =&
new ilPaymentObject($this->user_obj,$sc[$i][
'pobject_id']);
312 $inst_id_time = $ilias->getSetting(
'inst_id').
'_'.$ilUser->getId().
'_'.substr((
string) time(),-3);
314 $price = $sc[$i][
"betrag"];
317 if (array_key_exists($sc[$i][
"pobject_id"], $coupon_discount_items))
319 $bonus = $coupon_discount_items[$sc[$i][
"pobject_id"]][
"math_price"] - $coupon_discount_items[$sc[$i][
"pobject_id"]][
"discount_price"];
322 $book_obj->setTransaction($inst_id_time.substr(md5(uniqid(rand(),
true)), 0, 4));
323 $book_obj->setPobjectId($sc[$i][
"pobject_id"]);
324 $book_obj->setCustomerId($ilUser->getId());
325 $book_obj->setVendorId($pobjectData[
"vendor_id"]);
326 $book_obj->setPayMethod($pobjectData[
"pay_method"]);
327 $book_obj->setOrderDate(time());
328 $book_obj->setDuration($sc[$i][
"dauer"]);
329 $book_obj->setPrice($sc[$i][
"betrag_string"]);
331 $book_obj->setPayed(1);
332 $book_obj->setAccess(1);
333 $book_obj->setVoucher(
'');
334 $book_obj->setTransactionExtern($a_id);
336 $booking_id = $book_obj->add();
338 if (!empty(
$_SESSION[
"coupons"][
"paypal"]) && $booking_id)
340 foreach (
$_SESSION[
"coupons"][
"paypal"] as $coupon)
342 $this->coupon_obj->setId($coupon[
"pc_pk"]);
343 $this->coupon_obj->setCurrentCoupon($coupon);
345 if ($this->coupon_obj->isObjectAssignedToCoupon($pobject->getRefId()))
347 $this->coupon_obj->addCouponForBookingId($booking_id);
355 $obj_id = $ilObjDataCache->lookupObjId($pobjectData[
"ref_id"]);
356 $obj_type = $ilObjDataCache->lookupType($obj_id);
357 $obj_title = $ilObjDataCache->lookupTitle($obj_id);
359 $bookings[
"list"][] = array(
361 "title" =>
"[".$obj_id.
"]: " . $obj_title,
362 "duration" => $sc[$i][
"dauer"],
363 "price" => $sc[$i][
"betrag_string"],
364 "betrag" => $sc[$i][
"betrag"]
367 $total += $sc[$i][
"betrag"];
370 if ($sc[$i][
"psc_id"]) $this->psc_obj->delete($sc[$i][
"psc_id"]);
373 if (!empty(
$_SESSION[
"coupons"][
"paypal"]))
375 foreach (
$_SESSION[
"coupons"][
"paypal"] as $coupon)
377 $this->coupon_obj->setId($coupon[
"pc_pk"]);
378 $this->coupon_obj->setCurrentCoupon($coupon);
379 $this->coupon_obj->addTracking();
384 $bookings[
"total"] =
$total;
385 $bookings[
"vat"] = $this->psc_obj->getVat(
$total);
392 global $ilUser, $ilias;
394 $transaction = $a_array[
"txn_id"];
396 include_once
'./classes/class.ilTemplate.php';
397 include_once
"./Services/Utilities/classes/class.ilUtil.php";
398 include_once
'./payment/classes/class.ilGeneralSettings.php';
399 include_once
'./payment/classes/class.ilPaymentShoppingCart.php';
400 include_once
'Services/Mail/classes/class.ilMimeMail.php';
404 $tpl =
new ilTemplate(
"./payment/templates/default/tpl.pay_paypal_bill.html",
true,
true,
true);
406 $tpl->setVariable(
"VENDOR_ADDRESS", nl2br(utf8_decode($genSet->get(
"address"))));
407 $tpl->setVariable(
"VENDOR_ADD_INFO", nl2br(utf8_decode($genSet->get(
"add_info"))));
408 $tpl->setVariable(
"VENDOR_BANK_DATA", nl2br(utf8_decode($genSet->get(
"bank_data"))));
409 $tpl->setVariable(
"TXT_BANK_DATA", utf8_decode($this->lng->txt(
"pay_bank_data")));
411 # $tpl->setVariable("CUSTOMER_FIRSTNAME", utf8_decode($ilUser->getFirstname()));
412 # $tpl->setVariable("CUSTOMER_LASTNAME", utf8_decode($ilUser->getLastname()));
413 # $tpl->setVariable("CUSTOMER_STREET", utf8_decode($ilUser->getStreet()));
414 # $tpl->setVariable("CUSTOMER_ZIPCODE", utf8_decode($ilUser->getZipcode()));
415 # $tpl->setVariable("CUSTOMER_CITY", utf8_decode($ilUser->getCity()));
416 # $tpl->setVariable("CUSTOMER_COUNTRY", utf8_decode($ilUser->getCountry()));
417 $tpl->setVariable(
"CUSTOMER_FIRSTNAME", $a_array[
"first_name"]);
418 $tpl->setVariable(
"CUSTOMER_LASTNAME", $a_array[
"last_name"]);
419 $tpl->setVariable(
"CUSTOMER_STREET", $a_array[
"address_street"]);
420 $tpl->setVariable(
"CUSTOMER_ZIPCODE", $a_array[
"address_zip"]);
421 $tpl->setVariable(
"CUSTOMER_CITY", $a_array[
"address_city"]);
422 $tpl->setVariable(
"CUSTOMER_COUNTRY", $a_array[
"address_country"]);
424 $tpl->setVariable(
"BILL_NO", $transaction);
425 $tpl->setVariable(
"DATE", date(
"d.m.Y"));
427 $tpl->setVariable(
"TXT_BILL", utf8_decode($this->lng->txt(
"pays_bill")));
428 $tpl->setVariable(
"TXT_BILL_NO", utf8_decode($this->lng->txt(
"pay_bill_no")));
429 $tpl->setVariable(
"TXT_DATE", utf8_decode($this->lng->txt(
"date")));
431 $tpl->setVariable(
"TXT_ARTICLE", utf8_decode($this->lng->txt(
"pay_article")));
432 $tpl->setVariable(
"TXT_PRICE", utf8_decode($this->lng->txt(
"price_a")));
434 for ($i = 0; $i < count($bookings[
"list"]); $i++)
436 $tmp_pobject =&
new ilPaymentObject($this->user_obj, $bookings[
"list"][$i][
'pobject_id']);
438 $assigned_coupons =
'';
439 if (!empty(
$_SESSION[
"coupons"][
"paypal"]))
441 foreach (
$_SESSION[
"coupons"][
"paypal"] as $key => $coupon)
443 $this->coupon_obj->setId($coupon[
"pc_pk"]);
444 $this->coupon_obj->setCurrentCoupon($coupon);
446 if ($this->coupon_obj->isObjectAssignedToCoupon($tmp_pobject->getRefId()))
448 $assigned_coupons .=
'<br />' . $this->lng->txt(
'paya_coupons_coupon') .
': ' . $coupon[
"pcc_code"];
453 $tpl->setCurrentBlock(
"loop");
454 $tpl->setVariable(
"LOOP_OBJ_TYPE", utf8_decode($this->lng->txt($bookings[
"list"][$i][
"type"])));
455 $tpl->setVariable(
"LOOP_TITLE", utf8_decode($bookings[
"list"][$i][
"title"]) . $assigned_coupons);
456 $tpl->setVariable(
"LOOP_TXT_ENTITLED_RETRIEVE", utf8_decode($this->lng->txt(
"pay_entitled_retrieve")));
457 $tpl->setVariable(
"LOOP_DURATION", $bookings[
"list"][$i][
"duration"] .
" " . utf8_decode($this->lng->txt(
"paya_months")));
458 $tpl->setVariable(
"LOOP_PRICE", $bookings[
"list"][$i][
"price"]);
459 $tpl->parseCurrentBlock(
"loop");
464 if (!empty(
$_SESSION[
"coupons"][
"paypal"]))
466 if (count($items = $bookings[
"list"]))
468 $sub_total_amount = $bookings[
"total"];
470 foreach (
$_SESSION[
"coupons"][
"paypal"] as $coupon)
472 $this->coupon_obj->setId($coupon[
"pc_pk"]);
473 $this->coupon_obj->setCurrentCoupon($coupon);
475 $total_object_price = 0.0;
476 $current_coupon_bonus = 0.0;
478 foreach ($bookings[
"list"] as $item)
480 $tmp_pobject =&
new ilPaymentObject($this->user_obj, $item[
'pobject_id']);
482 if ($this->coupon_obj->isObjectAssignedToCoupon($tmp_pobject->getRefId()))
484 $total_object_price += $item[
"betrag"];
490 $current_coupon_bonus = $this->coupon_obj->getCouponBonus($total_object_price);
492 $bookings[
"total"] += $current_coupon_bonus * (-1);
494 $tpl->setCurrentBlock(
"cloop");
495 $tpl->setVariable(
"TXT_COUPON", utf8_decode($this->lng->txt(
"paya_coupons_coupon") .
" " . $coupon[
"pcc_code"]));
496 $tpl->setVariable(
"BONUS", number_format($current_coupon_bonus * (-1), 2,
',',
'.') .
" " . $genSet->get(
"currency_unit"));
497 $tpl->parseCurrentBlock();
500 $tpl->setVariable(
"TXT_SUBTOTAL_AMOUNT", utf8_decode($this->lng->txt(
"pay_bmf_subtotal_amount")));
501 $tpl->setVariable(
"SUBTOTAL_AMOUNT", number_format($sub_total_amount, 2,
",",
".") .
" " . $genSet->get(
"currency_unit"));
505 if ($bookings[
"total"] < 0)
507 $bookings[
"total"] = 0.0;
508 $bookings[
"vat"] = 0.0;
512 $bookings[
"vat"] = $this->psc_obj->getVat($bookings[
"total"]);
515 $tpl->setVariable(
"TXT_TOTAL_AMOUNT", utf8_decode($this->lng->txt(
"pay_bmf_total_amount")));
516 $tpl->setVariable(
"TOTAL_AMOUNT", number_format($bookings[
"total"], 2,
",",
".") .
" " . $genSet->get(
"currency_unit"));
517 if ($bookings[
"vat"] > 0)
519 $tpl->setVariable(
"VAT", number_format($bookings[
"vat"], 2,
",",
".") .
" " . $genSet->get(
"currency_unit"));
520 $tpl->setVariable(
"TXT_VAT", $genSet->get(
"vat_rate") .
"% " . utf8_decode($this->lng->txt(
"pay_bmf_vat_included")));
523 $tpl->setVariable(
"TXT_PAYMENT_TYPE", utf8_decode($this->lng->txt(
"pay_payed_paypal")));
525 if (!@file_exists($genSet->get(
"pdf_path")))
530 if (@file_exists($genSet->get(
"pdf_path")))
535 if (@file_exists($genSet->get(
"pdf_path") .
"/" . $transaction .
".pdf") &&
536 $ilUser->getEmail() !=
"" &&
537 $ilias->getSetting(
"admin_email") !=
"")
540 $m->
From( $ilias->getSetting(
"admin_email") );
541 $m->To( $ilUser->getEmail() );
542 $m->Subject( $this->lng->txt(
"pay_message_subject") );
543 $message = $this->lng->txt(
"pay_message_hello") .
" " . $ilUser->getFirstname() .
" " . $ilUser->getLastname() .
",\n\n";
544 $message .= $this->lng->txt(
"pay_message_thanks") .
"\n\n";
545 $message .= $this->lng->txt(
"pay_message_attachment") .
"\n\n";
546 $message .= $this->lng->txt(
"pay_message_regards") .
"\n\n";
547 $message .= strip_tags($genSet->get(
"address"));
548 $m->Body( $message );
549 $m->Attach( $genSet->get(
"pdf_path") .
"/" . $transaction .
".pdf",
"application/pdf" ) ;
553 @unlink($genSet->get(
"pdf_path") .
"/" . $transaction .
".html");
554 @unlink($genSet->get(
"pdf_path") .
"/" . $transaction .
".pdf");
567 $lng->loadLanguageModule(
"meta");
569 $cntcodes = array (
"DE",
"ES",
"FR",
"GB",
"AT",
"CH",
"AF",
"AL",
"DZ",
"AS",
"AD",
"AO",
570 "AI",
"AQ",
"AG",
"AR",
"AM",
"AW",
"AU",
"AT",
"AZ",
"BS",
"BH",
"BD",
"BB",
"BY",
571 "BE",
"BZ",
"BJ",
"BM",
"BT",
"BO",
"BA",
"BW",
"BV",
"BR",
"IO",
"BN",
"BG",
"BF",
572 "BI",
"KH",
"CM",
"CA",
"CV",
"KY",
"CF",
"TD",
"CL",
"CN",
"CX",
"CC",
"CO",
"KM",
573 "CG",
"CK",
"CR",
"CI",
"HR",
"CU",
"CY",
"CZ",
"DK",
"DJ",
"DM",
"DO",
"TP",
"EC",
574 "EG",
"SV",
"GQ",
"ER",
"EE",
"ET",
"FK",
"FO",
"FJ",
"FI",
"FR",
"FX",
"GF",
"PF",
575 "TF",
"GA",
"GM",
"GE",
"DE",
"GH",
"GI",
"GR",
"GL",
"GD",
"GP",
"GU",
"GT",
"GN",
576 "GW",
"GY",
"HT",
"HM",
"HN",
"HU",
"IS",
"IN",
"ID",
"IR",
"IQ",
"IE",
"IL",
"IT",
577 "JM",
"JP",
"JO",
"KZ",
"KE",
"KI",
"KP",
"KR",
"KW",
"KG",
"LA",
"LV",
"LB",
"LS",
578 "LR",
"LY",
"LI",
"LT",
"LU",
"MO",
"MK",
"MG",
"MW",
"MY",
"MV",
"ML",
"MT",
"MH",
579 "MQ",
"MR",
"MU",
"YT",
"MX",
"FM",
"MD",
"MC",
"MN",
"MS",
"MA",
"MZ",
"MM",
"NA",
580 "NR",
"NP",
"NL",
"AN",
"NC",
"NZ",
"NI",
"NE",
"NG",
"NU",
"NF",
"MP",
"NO",
"OM",
581 "PK",
"PW",
"PA",
"PG",
"PY",
"PE",
"PH",
"PN",
"PL",
"PT",
"PR",
"QA",
"RE",
"RO",
582 "RU",
"RW",
"KN",
"LC",
"VC",
"WS",
"SM",
"ST",
"SA",
"CH",
"SN",
"SC",
"SL",
"SG",
583 "SK",
"SI",
"SB",
"SO",
"ZA",
"GS",
"ES",
"LK",
"SH",
"PM",
"SD",
"SR",
"SJ",
"SZ",
584 "SE",
"SY",
"TW",
"TJ",
"TZ",
"TH",
"TG",
"TK",
"TO",
"TT",
"TN",
"TR",
"TM",
"TC",
585 "TV",
"UG",
"UA",
"AE",
"GB",
"UY",
"US",
"UM",
"UZ",
"VU",
"VA",
"VE",
"VN",
"VG",
586 "VI",
"WF",
"EH",
"YE",
"ZR",
"ZM",
"ZW");
588 foreach($cntcodes as $cntcode)
590 $cntrs[$cntcode] = $lng->txt(
"meta_c_".$cntcode);
599 foreach($countries as $code => $text)
612 return $countries[$value];