I'm currently working on integrating paypal with my MODx installation, and at this point in the code, I've just received the data from paypal which contains some variables, most notably being "$username" which is the MODx username of the user (which I sent to paypal at the very beginning, and am now receiving it back.)
Since the file I'm running this through is in a subdirectory of MODx, and stand-alone from MODx, I have to import the MODx system, and the result is as shown below:
Main Class
purchase.php
<?php
// This initialises all MODx Commands and Permissions! :D
require_once '../config.core.php';
require_once MODX_CORE_PATH.'model/modx/modx.class.php';
$modx = new modX();
$modx->initialize('mgr');
$modx->getService('error','error.modError', '', '');
function userPurchasedItem($item_id, $payment_amount, $payer_email, $username) {
// Setup the user, using the $username passed to the function
$myUser = $modx->getObject('modUser', array('username'=>$username));
if ($myUser instanceof modUser) {
$modx->user = $myUser;
echo 'user Success!';
} else {
die('No User');
}
}
?>
I then made a test.php class which included and called on the file & function, and I've run into an error which I'm not quite sure how to fix.
Fatal error: Call to a member function getObject() on a non-object in path/to/upgrade/purchase.php on line 10
Can someone please let me know what I am doing wrong?