14 include_once
'./Services/Payment/classes/class.ilInvoiceNumberPlaceholdersPropertyGUI.php';
15 include_once
'./Services/Payment/classes/class.ilPayMethods.php';
16 include_once
'./Services/Payment/classes/class.ilPurchaseBaseGUI.php';
19 define(
'ERROR_OPENSOCKET', 1);
20 define(
'ERROR_WRONG_CUSTOMER', 2);
21 define(
'ERROR_NOT_COMPLETED', 3);
22 define(
'ERROR_PREV_TRANS_ID', 4);
23 define(
'ERROR_WRONG_VENDOR', 5);
24 define(
'ERROR_WRONG_ITEMS', 6);
25 define(
'ERROR_FAIL', 7);
45 $this->paypalConfig = $ppSet->getAll();
53 $fp = @fsockopen (
$path = $this->paypalConfig[
"server_host"], 80, $errno, $errstr, 30);
62 $auth_token = $this->paypalConfig[
"auth_token"];
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"])
170 $external_data = array();
171 $external_data[
'transaction_extern'] = $keyarray[
"txn_id"];
172 $external_data[
'street'] = $keyarray[
"address_street"];
173 $external_data[
'zipcode'] = $keyarray[
"address_zip"];
174 $external_data[
'city'] = $keyarray[
"address_city"];
175 $external_data[
'country'] = $keyarray[
"address_country"];
179 $_SESSION[
"coupons"][
"paypal"] = array();
180 $_SESSION[
'tmp_transaction'][
'result'] =
'success';
184 else if (strcmp ($lines[0],
"FAIL") == 0)
198 $res = $ilDB->queryF(
'SELECT * FROM payment_statistic
199 WHERE transaction_extern = %s',
200 array(
'text'), array($a_id));
202 return $res->numRows() ?
true :
false;
210 if ($a_array[
"mc_currency"] != $genSet->get(
"currency_unit"))
215 $sc = $this->psc_obj->getShoppingCart($this->pay_method);
216 $this->psc_obj->clearCouponItemsSession();
218 if (is_array($sc) && count($sc) > 0)
220 for ($i = 0; $i < count($sc); $i++)
223 "name" => $a_array[
"item_name".($i+1)],
224 "amount" => $a_array[
"mc_gross_".($i+1)]
227 if (!empty(
$_SESSION[
"coupons"][
"paypal"]))
229 $sc[$i][
"math_price"] = (float) $sc[$i][
"price"];
231 $tmp_pobject =
new ilPaymentObject($this->user_obj, $sc[$i][
'pobject_id']);
233 foreach (
$_SESSION[
"coupons"][
"paypal"] as $key => $coupon)
235 $this->coupon_obj->setId($coupon[
"pc_pk"]);
236 $this->coupon_obj->setCurrentCoupon($coupon);
238 if ($this->coupon_obj->isObjectAssignedToCoupon($tmp_pobject->getRefId()))
240 $_SESSION[
"coupons"][
"paypal"][$key][
"total_objects_coupon_price"] += (float) $sc[$i][
"price"];
241 $_SESSION[
"coupons"][
"paypal"][$key][
"items"][] = $sc[$i];
248 $coupon_discount_items = $this->psc_obj->calcDiscountPrices(
$_SESSION[
"coupons"][
"paypal"]);
252 for ($i = 0; $i < count($sc); $i++)
254 if (array_key_exists($sc[$i][
"pobject_id"], $coupon_discount_items))
256 $sc[$i][
"price"] = round($coupon_discount_items[$sc[$i][
"pobject_id"]][
"discount_price"], 2);
257 if ($sc[$i][
"price"] < 0) $sc[$i][
"price"] = 0.0;
260 for ($j = 0; $j < count($items); $j++)
262 if (substr($items[$j][
"name"], 0, strlen($sc[$i][
"obj_id"])+2) ==
"[".$sc[$i][
"obj_id"].
"]" &&
263 $items[$j][
"amount"] == $sc[$i][
"price"])
265 $total += $items[$j][
"amount"];
272 if (number_format(
$total, 2,
".",
"") == $a_array[
"mc_gross"] &&
273 $found == count($sc))