$extendArticleClass = "hidden"; // Look up PayPal user info for this user $payPalMsgHandler = new PayPalMsgHandler(); $payPalUser = $payPalMsgHandler->LookUpPayPalUserByUserId($dataAccess, $logger, $objUser->UserID); // If transaction details message is available, need to update related session variables $sessionDataAccess = new DataAccess(); $sessionHandler = new DBSessionHandler($sessionDataAccess); session_set_save_handler($sessionHandler, true); session_start(); // Remove transaction details from session storage, so that they are only shown immediately after user is returned to this page from PayPal unset($_SESSION['PayPalTxnDetails']); session_write_close(); } else { if ($objUser->IsPremiumMember) { // If this page not being accessed right after completed PayPal txn, look up this user's current subscription type $payPalMsgHandler = new PayPalMsgHandler(); $payPalUser = $payPalMsgHandler->LookUpPayPalUserByUserId($dataAccess, $logger, $objUser->UserID); $replyMsg->SelectedSubscriptionOption = $payPalUser->SubscriptionType; $replyMsg->SubscriptionIsRecurring = $payPalUser->IsRecurring; if ($replyMsg->SubscriptionIsRecurring) { $extendArticleClass = "hidden"; } else { $isRecurringArticleClass = "hidden"; } } } ?> <!DOCTYPE HTML> <!-- Project OGS by => Stephen Giles and Paul Morrell
<?php include_once 'classes/DataAccess.class.php'; include_once 'classes/PayPalMsgHandler.class.php'; include_once 'classes/Logger.class.php'; include_once 'classes/Constants.class.php'; $dataAccess = new DataAccess(); $loggerDataAccess = new DataAccess(); $logger = new Logger($loggerDataAccess); $payPalMsgHandler = new PayPalMsgHandler(); $ipnData = $_POST; $status = 500; $url = Constants::$payPalProdButtonFormUrl; if ($payPalMsgHandler->GetResponseValByKey($ipnData, 'test_ipn') == "1") { $url = Constants::$payPalTestButtonFormUrl; } // Debugging: log what we received //$logger->LogInfo("IPN Received. Post Data: " . $payPalMsgHandler->ConvertIPNPostDataToRawString($ipnData)); // For all instant notifications, must acknowledge as per PayPal requirement by sending a POST request containing the same data back to PayPal, // but only need to take further action for subscription creation, subscription renewal, and subscription cancellation. $response = $payPalMsgHandler->SendIPNPostRequest($ipnData, $url, $status); if ($status == 200 && $response == "VERIFIED") { // If this notification really came from PayPal, proceed to handle it and execute any necessary actions $rawIpnMessage = $payPalMsgHandler->ConvertIPNPostDataToRawString($ipnData); $notificationType = "IPN"; $payPalMsgHandler->HandlePayPalTxnResponse($ipnData, $rawIpnMessage, $dataAccess, $logger, $notificationType); } else { $txnId = ""; if (isset($ipnData["txn_id"])) { $txnId = $ipnData["txn_id"]; }
<?php include_once 'classes/DataAccess.class.php'; include_once 'classes/DBSessionHandler.class.php'; include_once 'classes/PayPalMsgHandler.class.php'; include_once 'classes/Logger.class.php'; include_once 'classes/Constants.class.php'; include_once 'classes/User.class.php'; include_once 'classes/PayPalTxnMsg.class.php'; $dataAccess = new DataAccess(); $loggerDataAccess = new DataAccess(); $logger = new Logger($loggerDataAccess); $payPalMsgHandler = new PayPalMsgHandler(); // Get txn ID from this notification and send to PayPal to retrieve full txn details try { if (isset($_GET['tx'])) { $tx = filter_var($_GET['tx'], FILTER_SANITIZE_STRING); if (strlen($tx) > 0) { $replyMsg = PayPalTxnMsg::ConstructDefaultMsg(); $url = Constants::$isPayPalTest ? Constants::$payPalTestButtonFormUrl : Constants::$payPalProdButtonFormUrl; $identityToken = Constants::$isPayPalTest ? Constants::$payPalTestPostIdentityToken : Constants::$payPalProdPostIdentityToken; $status = 500; $response = $payPalMsgHandler->SendPDTPostRequest($tx, $url, $status, $identityToken); if ($status != 200 || strpos($response, 'SUCCESS') !== 0) { $logger->LogError(sprintf("Received bad PayPal PDT message (status %d): %s", $status, $response)); throw new Exception("Unable to retrieve PDT transaction details."); } else { $txnDetailsAssociativeArray = $payPalMsgHandler->FormatPDTResponseInAssociativeArray($response); $rawPdtMessage = urldecode($response); $notificationType = "PDT"; $replyMsg = $payPalMsgHandler->HandlePayPalTxnResponse($txnDetailsAssociativeArray, $rawPdtMessage, $dataAccess, $logger, $notificationType);