简体   繁体   中英

How to include or bootstrap the paypal-core-sdk php

I've downloaded the paypal-core-sdk for php from GitHub manually, my server does not have 'composer' and I've just manually copied the files to an include directory outside the document root. Problem is when I go call on some of the classes the server borks and doesn't know what I'm talking about ... ie

Fatal error: Class 'PPApiContext' not found in /home/rctoronto/public_html/start.php on line 143

if I include once on the file providing PPApiContext, it moves along to another error and so on eventually proceeds when I've included all the ones it complains about. But then the sdk has internal dependency issues.

How do I formally declare the sdk library so my app can use it - I've scoured the web and haven't managed to find a good answer to this question. I've tried manually altering my include_path using my php.ini and still it can't use the classes of the sdk. I don't have access to /usr/lib/php or /usr/local/lib/php as I am on a shared server.

this is the 'getAuthorize' url for paypal (which I've gotten to work with manually include_once on the files...

$apicontext = new PPApiContext(array('mode' => 'live'));
$clientId = PP_CLIENTID;
$clientSecret = PP_SECRET;
$scope = array('openid', 'email'); 
$redirectUri = 'https://maskedurl.ca/login?ltype=pp&loginSubmit=true';
$pp_authUrl = PPOpenIdSession::getAuthorizationUrl($redirectUri, $scope , $clientId,       $apicontext); 

But how do we properly declare the sdk library in whole?

From: http://paypal.github.io/sdk/

If you do not want to use composer, you can grab the SDK zip, unzip the file to your application folder and require the 'vendor/autoload.php' file. This file registers a custom autoloader that can autload the PayPal SDK files.

Download SDK zip

Here's how I solved it. Update composer.json as follows:

{
    "name": "PayPal Test",
    "require": {
        "paypal/sdk-core-php": "dev-stable"
    },
    "autoload": {
        "psr-0": {"PayPal\\": "vendor/paypal/sdk-core-php/lib/"}
    }    
}

This will do the job:

include('paypal-sdk-core/lib/common/PPApiContext.php');
include('paypal-sdk-core/lib/PPConstants.php');
include('paypal-sdk-core/lib/PPConfigManager.php');
include('paypal-sdk-core/lib/auth/openid/PPOpenIdSession.php');

If you need the full stack to make the example on https://devtools-paypal.com/guide/openid/php?interactive=ON&env=sandbox work, use this:

include('paypal-sdk-core/lib/common/PPApiContext.php');
include('paypal-sdk-core/lib/PPHttpConfig.php');
include('paypal-sdk-core/lib/common/PPUserAgent.php');
include('paypal-sdk-core/lib/PPHttpConnection.php');
include('paypal-sdk-core/lib/PPLoggingLevel.php');
include('paypal-sdk-core/lib/exceptions/PPConnectionException.php');
include('paypal-sdk-core/lib/common/PPModel.php');
include('paypal-sdk-core/lib/auth/IPPThirdPartyAuthorization.php');
include('paypal-sdk-core/lib/handlers/IPPHandler.php');
include('paypal-sdk-core/lib/PPConstants.php');
include('paypal-sdk-core/lib/PPConfigManager.php');
include('paypal-sdk-core/lib/auth/openid/PPOpenIdSession.php');
include('paypal-sdk-core/lib/auth/PPTokenAuthorization.php');
include('paypal-sdk-core/lib/auth/openid/PPOpenIdTokeninfo.php');
include('paypal-sdk-core/lib/transport/PPRestCall.php');
include('paypal-sdk-core/lib/PPLoggingManager.php');
include('paypal-sdk-core/lib/handlers/PPOpenIdHandler.php');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM