ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilPurchasePaypal Class Reference
+ Inheritance diagram for ilPurchasePaypal:
+ Collaboration diagram for ilPurchasePaypal:

Public Member Functions

 __construct ($user_obj)
 openSocket ()
 checkData ($fp)
- Public Member Functions inherited from ilPurchaseBaseGUI
 __construct ($user_obj, $pay_method)
 cancel ()
 showPersonalData ()
 getPersonalData ()
 showBillConfirm ()
 executeCommand ()
 execute command
 __addBookings ($external_data=null)
 __sendBill ($bookings)
 __emptyShoppingCart ()
 __clearSession ()
 __loadTemplate ()
 __buildStatusline ()
 __buildLocator ()
 __buildStylesheet ()
 __getCountries ()
 shows select box f�r countries
 __getCountryCode ($value= '')
 __getCountryName ($value= '')
 __getTotalAmount ()
 depricated!?
 getBill ()
 __showShoppingCart ()
 getAccess ()
 setAccess ($access)
 getPayed ()
 setPayed ($payed)
- Public Member Functions inherited from ilShopBaseGUI
 __construct ()

Data Fields

 $psc_obj = null
 $user_obj = null
 $pay_method = null
 $currency = null
 $db = null
 $paypalConfig
- Data Fields inherited from ilPurchaseBaseGUI
 $ctrl
 $tpl
 $psc_obj = null
 $user_obj = null
 $coupon_obj = null
 $error
 $pmethod_obj = null

Private Member Functions

 __checkTransactionId ($a_id)
 __checkItems ($a_array)

Additional Inherited Members

- Protected Member Functions inherited from ilShopBaseGUI
 prepareOutput ()
 addPager ($result, $a_session_key)
 buildSubTabs ()
 setSection ($a_section)
 getSection ()
 setSubSection ($a_sub_section)
 getSubSection ()
 showButton ($a_cmd, $a_text, $a_target= '')
 initTableGUI ()
 setTableGUIBasicData ($tbl, $result_set, $a_default_order_column= '')
- Protected Attributes inherited from ilShopBaseGUI
 $ctrl = null
 $lng = null
 $tpl = null
 $oGeneralSettings = null
 $section = 0
 $sub_section = 0

Detailed Description

Definition at line 27 of file class.ilPurchasePaypal.php.

Constructor & Destructor Documentation

ilPurchasePaypal::__construct (   $user_obj)

Definition at line 39 of file class.ilPurchasePaypal.php.

References $user_obj, ilShopBaseGUI\__construct(), ilPayMethods\_getIdByTitle(), and ilPaypalSettings\getInstance().

{
$this->user_obj = $user_obj;
$this->pay_method = ilPayMethods::_getIdByTitle('paypal');
$this->paypalConfig = $ppSet->getAll();
parent::__construct($this->user_obj, $this->pay_method);
}

+ Here is the call graph for this function:

Member Function Documentation

ilPurchasePaypal::__checkItems (   $a_array)
private

Definition at line 206 of file class.ilPurchasePaypal.php.

References $_SESSION, $total, and ilPaymentSettings\_getInstance().

Referenced by checkData().

{
// Wrong currency
if ($a_array["mc_currency"] != $genSet->get("currency_unit"))
{
return false;
}
$sc = $this->psc_obj->getShoppingCart($this->pay_method);
$this->psc_obj->clearCouponItemsSession();
if (is_array($sc) && count($sc) > 0)
{
for ($i = 0; $i < count($sc); $i++)
{
$items[$i] = array(
"name" => $a_array["item_name".($i+1)],
"amount" => $a_array["mc_gross_".($i+1)]
);
if (!empty($_SESSION["coupons"]["paypal"]))
{
$sc[$i]["math_price"] = (float) $sc[$i]["price"];
$tmp_pobject = new ilPaymentObject($this->user_obj, $sc[$i]['pobject_id']);
foreach ($_SESSION["coupons"]["paypal"] as $key => $coupon)
{
$this->coupon_obj->setId($coupon["pc_pk"]);
$this->coupon_obj->setCurrentCoupon($coupon);
if ($this->coupon_obj->isObjectAssignedToCoupon($tmp_pobject->getRefId()))
{
$_SESSION["coupons"]["paypal"][$key]["total_objects_coupon_price"] += (float) $sc[$i]["price"];
$_SESSION["coupons"]["paypal"][$key]["items"][] = $sc[$i];
}
}
unset($tmp_pobject);
}
}
$coupon_discount_items = $this->psc_obj->calcDiscountPrices($_SESSION["coupons"]["paypal"]);
$found = 0;
$total = 0;
for ($i = 0; $i < count($sc); $i++)
{
if (array_key_exists($sc[$i]["pobject_id"], $coupon_discount_items))
{
$sc[$i]["price"] = round($coupon_discount_items[$sc[$i]["pobject_id"]]["discount_price"], 2);
if ($sc[$i]["price"] < 0) $sc[$i]["price"] = 0.0;
}
for ($j = 0; $j < count($items); $j++)
{
if (substr($items[$j]["name"], 0, strlen($sc[$i]["obj_id"])+2) == "[".$sc[$i]["obj_id"]."]" &&
$items[$j]["amount"] == $sc[$i]["price"])
{
$total += $items[$j]["amount"];
$found++;
}
}
}
// The number of items, the items themselves and their amounts and the total amount correct
if (number_format($total, 2, ".", "") == $a_array["mc_gross"] &&
$found == count($sc))
{
return true;
}
}
return false;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilPurchasePaypal::__checkTransactionId (   $a_id)
private

Definition at line 195 of file class.ilPurchasePaypal.php.

References $res.

Referenced by checkData().

{
global $ilDB;
$res = $ilDB->queryF('SELECT * FROM payment_statistic
WHERE transaction_extern = %s',
array('text'), array($a_id));
return $res->numRows() ? true : false;
}

+ Here is the caller graph for this function:

ilPurchasePaypal::checkData (   $fp)

Definition at line 57 of file class.ilPurchasePaypal.php.

References $_REQUEST, $_SESSION, $ilUser, $result, ilPurchaseBaseGUI\__addBookings(), __checkItems(), __checkTransactionId(), ERROR_FAIL, ERROR_NOT_COMPLETED, ERROR_PREV_TRANS_ID, ERROR_WRONG_CUSTOMER, ERROR_WRONG_ITEMS, ERROR_WRONG_VENDOR, and SUCCESS.

{
global $ilUser;
//Token from paypal account
$auth_token = $this->paypalConfig["auth_token"];
//add 'cmd' as required
$req = 'cmd=_notify-synch';
//Get token
$tx_token = $_REQUEST['tx'];
//append both tokens as required
$req .= "&tx=$tx_token&at=$auth_token";
//send information back to paypal
// info: https required!!!
$submiturl = 'https://'.$this->paypalConfig["server_host"].$this->paypalConfig["server_path"];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$submiturl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);//return into variable
curl_setopt($ch, CURLOPT_POST, 1);//make it a post
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);//post request
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded", "Content-Length: " . strlen($req)));
curl_setopt($ch, CURLOPT_HEADER , 0); //dont return headers
curl_setopt($ch, CURLOPT_VERBOSE, 1);//more informaiton in error
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);//dont verify
curl_setopt($ch, CURLOPT_TIMEOUT, 30);//define timeout
$result= @curl_exec($ch);//get result
curl_close($ch);//close connection
// only for TEST
// echo $result;//display response
// parse the data
$lines = explode("\n", $result);
$keyarray = array();
$keyarray[0] = $lines[0]; // save payment status!
if (strcmp ($lines[0], "SUCCESS") == 0)
{
for ($i=1; $i<count($lines);$i++)
{
list($key,$val) = explode("=", $lines[$i]);
$keyarray[urldecode($key)] = urldecode($val);
}
// check customer
if ($ilUser->getId() != $keyarray["custom"]
&& $_SESSION['shop_user_id'] != $keyarray['custom'])
{
#echo "Wrong customer";
}
// check the payment_status is Completed
if (!in_array($keyarray["payment_status"], array("Completed", "In-Progress", "Pending", "Processed")))
{
#echo "Not completed";
}
// check that txn_id has not been previously processed
if ($this->__checkTransactionId($keyarray["txn_id"]))
{
if($_SESSION['tmp_transaction']['result'] == 'success'
&& $_SESSION['tmp_transaction']['tx_id'] == $keyarray["txn_id"])
{
// this is for catching the problem, if the user doubleklicks on the paypal
// site to return to the ilias shop and his purchasings already exists in db
return SUCCESS;
}
else
#echo "Prev. processed trans. id";
}
// check that receiver_email is your Primary PayPal email
if ($keyarray["receiver_email"] != $this->paypalConfig["vendor"])
{
//echo "Wrong vendor";
}
// check that payment_amount/payment_currency are correct
if (!$this->__checkItems($keyarray))
{
//echo "Wrong items";
}
// if($ilUser->getId() == ANONYMOUS_USER_ID)
// {
// include_once './Services/Payment/classes/class.ilShopUtils.php';
// // anonymous user needs an account to use crs
// $ilUser = ilShopUtils::_createRandomUserAccount($keyarray);
// $user_id = $ilUser->getId();
//
// $_SESSION['tmp_transaction']['tx_id'] = $keyarray["txn_id"];
// $_SESSION['tmp_transaction']['usr_id'] = $user_id;
//
// if($_SESSION['is_crs_object'] && ($ilUser->getId() == ANONYMOUS_USER_ID))
// {
// include_once "./Modules/Course/classes/class.ilCourseParticipants.php";
// foreach ($_SESSION['crs_obj_ids'] as $obj_id)
// {
// $members_obj = ilCourseParticipants::_getInstanceByObjId($obj_id);
// $members_obj->add($user_id,IL_CRS_MEMBER);
// }
// }
// }
$external_data = array();
$external_data['transaction_extern'] = $keyarray["txn_id"];
$external_data['street'] = $keyarray["address_street"];
$external_data['zipcode'] = $keyarray["address_zip"];
$external_data['city'] = $keyarray["address_city"];
$external_data['country'] = $keyarray["address_country"];
parent::__addBookings($external_data);
$_SESSION["coupons"]["paypal"] = array();
$_SESSION['tmp_transaction']['result'] = 'success';
return SUCCESS;
}
else if (strcmp ($lines[0], "FAIL") == 0)
{
return ERROR_FAIL;
}
else
{
return ERROR_FAIL;
}
}

+ Here is the call graph for this function:

ilPurchasePaypal::openSocket ( )

Definition at line 50 of file class.ilPurchasePaypal.php.

References $path.

{
// post back to PayPal system to validate
$fp = @fsockopen ($path = $this->paypalConfig["server_host"], 80, $errno, $errstr, 30);
return $fp;
}

Field Documentation

ilPurchasePaypal::$currency = null

Definition at line 35 of file class.ilPurchasePaypal.php.

ilPurchasePaypal::$db = null

Definition at line 36 of file class.ilPurchasePaypal.php.

ilPurchasePaypal::$pay_method = null

Definition at line 34 of file class.ilPurchasePaypal.php.

ilPurchasePaypal::$paypalConfig

Definition at line 37 of file class.ilPurchasePaypal.php.

ilPurchasePaypal::$psc_obj = null

Definition at line 32 of file class.ilPurchasePaypal.php.

ilPurchasePaypal::$user_obj = null

Definition at line 33 of file class.ilPurchasePaypal.php.

Referenced by __construct().


The documentation for this class was generated from the following file: