there is a user community at http://paypal.lithium.com but it's not particularly helpful.
Can anyone explain why I cannot create certain class objects in a subroutine and have them be defined in the scope of my script? It's baffling. For example, my main script has some code like this:
// initialize vars before we call subroutine
$profile = NULL;
$caller = NULL;
include("paypal.php");
create_caller_and_profile($profile, $caller);
// check for errors
if (PayPal::isError($profile)) {
jta_error("Error creating profile in main.");
}
if (!is_object($profile)) {
jta_error('Paypal init error. Failed to create a valid profile object in main');
}
if (PayPal::isError($caller)) {
jta_error("Paypal init error. Caller creation failed in main.");
}
if (!is_object($caller)) {
jta_error('Paypal init error. Caller failed to create a valid object in main');
}
and paypal.php, in addition to requiring a variety of files from the paypal SDK, defined this routine:
function create_caller_and_profile(&$profile, &$caller) {
$handler = & ProfileHandler_Array::getInstance(array(
'username' => PAYPAL_USERNAME,
'certificateFile' => PAYPAL_CERT_LOCATION,
'subject' => null,
'environment' => PAYPAL_ENVIRONMENT ));
if (PayPal::isError($handler)) {
jta_error("Error creating hander in subroutine.");
}
$pid = ProfileHandler::generateID();
$profile = & new APIProfile($pid, $handler);
if (PayPal::isError($profile)) {
jta_error("Error creating profile in subroutine.");
}
if (!is_object($profile)) {
jta_error('Paypal init error. Failed to create a valid profile object in subroutine');
}
$profile->setAPIUsername(PAYPAL_USERNAME);
$profile->setAPIPassword(PAYPAL_PASSWORD);
$profile->setSignature(null);
$profile->setCertificateFile(PAYPAL_CERT_LOCATION);
$profile->setEnvironment(PAYPAL_ENVIRONMENT);
$caller = & PayPal::getCallerServices($profile);
if (PayPal::isError($caller)) {
jta_error("Paypal init error. Caller creation failed in subroutine.");
}
if (!is_object($caller)) {
jta_error('Paypal init error. Caller failed to create a valid object in subroutine');
}
}
When I run this code, i get
Failed to create a valid profile object in main.
I'm passing the vars by reference. Why are the objects not deifined outside the subroutine?? I have also tried this by adding global statements to the subroutine like this:
function create_caller_and_profile(&$profile, &$caller, &$handler) {
global $profile;
global $caller;
global $handler;
// etc.
}
I've also tried storing the created objects in session but that doesn't work either. I'm not sure that it makes any difference how i've defined the objects but if anyone wants to see them, you can read some slightly old ones here :
http://www.keystone-design.com/apidoc/