public function unlockPAYPALObjectsInShoppingCart() { include_once './Services/Payment/classes/class.ilPurchaseBaseGUI.php'; $purchase = new ilPurchaseBaseGUI($this->user_obj, ilPayMethods::_getIdByTitle('paypal')); $purchase->__addBookings(); ilUtil::sendSuccess($this->lng->txt('pay_paypal_success'), true); $this->ctrl->redirectByClass('ilShopBoughtObjectsGUI', ''); return true; }
public function checkData($fp) { 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"]) { #echo "Wrong customer"; return ERROR_WRONG_CUSTOMER; } // check the payment_status is Completed if (!in_array($keyarray["payment_status"], array("Completed", "In-Progress", "Pending", "Processed"))) { #echo "Not completed"; return ERROR_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"; return ERROR_PREV_TRANS_ID; } } // check that receiver_email is your Primary PayPal email if ($keyarray["receiver_email"] != $this->paypalConfig["vendor"]) { //echo "Wrong vendor"; return ERROR_WRONG_VENDOR; } // check that payment_amount/payment_currency are correct if (!$this->__checkItems($keyarray)) { //echo "Wrong items"; return ERROR_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; } } }