|
There have been a few questions about how to install the SDK as well as a few errors that have been posted, I will try to explain how the SDK can be installed and how to run the samples as well list some of the common errors and possible fixes, so hopefully this will help. This is be for PHP 4.3.x +
If you are running PHP 5, then you don't have to use the SDK, you can try the examples here, which uses a wrapper class using PHP 5 Soap Extension.
If the PHP SDK seems like it is just to complex for what you want to do you can try to use an easier solution at this page, which is a non Pear based solution for Express Checkout and Direct Payment.
Before installing the SDK, make sure that you have the following:
- PHP (pcre) Perl Compatible Regular Expressions extension for PHP 4.3.0+ and higher
- PHP cURL extension for PHP 4.3.0+ and higher with SSL support
- PHP OpenSSL extension for PHP 4.3.0+ and higher (for digital certificate transcoding)
Also, make sure that you have short_open_tag turned on (php.ini) as it is used in the SDK.
If you are not sure if you have these installed you can contact your host or run phpinfo() and check for your self.
Create a file called phpinfo.php and put the following code in it. <?php phpinfo(); ?>
Upload the file to your hosts server and then navigate to the file using your web browser, this should give you information about the PHP version that is installed and the extensions that are installed as well. Please contact your host or install the extension that is missing before continuing.
(PEAR) PHP with PHP Extension and Application Repository is needed as well but most of the time this is already installed by the host.
Installing the SDK/Samples:
If you have access to the command prompt on your local machine or through SSH then you can use the install.php file to install the SDK samples, if you don't have access to the command prompt it is still possible to use the SDK you can follow the steps below.
Before you being please visit http://www.paypal.com/sdk and download a copy of the PHP SDK.
If you have access to the command prompt follow these steps:
1. Unpack and upload the files in the SDK to a folder that is above the web root directory, where it is not accessible through web browser.
2. Via SSH or the command line, execute the following command:
php install.php
3. Then enter the path to where you want to install the samples, this should be a folder that is accessable through the web browser. The files will actually stay where they are but the samples directory will be copied to a new folder at the server path specified.
4. Once the samples have been installed. The SDK will generate and move a configuration file into the new samples directory. The file is called ppsdk_include_path.inc, this file will set the include path, it will have the path to where you uploaded the SDK in step 1 as well as get the include path that is set in php.ini.
5. You should now test by opening a browser to the samples directory on your server. Try the default account first, a demo API account is used to run tests.
If you get an error message take a look at the common errors section at the bottom of this post.
If you are planning on using the 3-token method (signature method) then take a look at the section titled, 'If you are planning on using the 3-token method' below you will need to change the Soap endpoints because they are set incorrectly in the SDK for the 3-token method.
If you want to install the SDK/Samples manually or you don't have access to the command prompt follow these steps:
1. Unpack the SDK to your desktop
2. Open up an FTP connection to your server.
3. Create a directory above the web root to hold the libraries, this should be a directory that is not accessible by a web browser, name the directory php-sdk for example.
4. Upload the lib folder from the SDK package that is on your desktop into the new directory (php-sdk) on your server.
5. Next, you need to upload the samples folder from the SDK package that is on your desktop into a directory below your web root, basically a directory that is accessible through your web browser.
6. On your desktop, create a new file in your favorite text editor and name the file ppsdk_include_path.inc.
7. Copy the following code into the ppsdk_include_path.inc file save it.
Code: <?php
set_include_path('path_to_sdk_root'. DIRECTORY_SEPARATOR . 'lib' . PATH_SEPARATOR . get_include_path());
?>
Where 'path_to_sdk_root' is the path to your PHP SDK folder on your server. This is the folder that you created in step 3 above.
=========================
EXAMPLES:
FOR UNIX/LINUX
Code: <?php
set_include_path('/home/someuser/php-sdk' . DIRECTORY_SEPARATOR . 'lib' . PATH_SEPARATOR . get_include_path());
?>
FOR WINDOWS
Code: <?php
set_include_path('C:\Inetpub\wwwroot\php-sdk' . DIRECTORY_SEPARATOR . 'lib' . PATH_SEPARATOR . get_include_path());
?>
=================
8. Upload this file into the samples directory with the other sample files (the same folder as index.php file)
9. Open your web browser to the samples directory (index.php) and try the default account first, a demo API account is used to run tests.
If you get an error message take a look at the common errors section at the bottom of this post.
If you are planning on using the 3-token method (signature method) then please take a look at the section below you will need to change the Soap endpoints because they are set incorrectly in the SDK.
If you are planning on using the 3-token method (signature based authentication) then please do the following (Only if you are using PHP SDK 4.1.1, the latest version of the PHP SDK 4.2.0 doesn't have this issue)
Open this file in your favorite text editor: path_to_sdk_root\lib\PayPal\wsdl\paypal-endpoints.php
Change these two lines:
Code: 'PayPalAPI-threetoken' => 'https://api.paypal.com/2.0/',
'PayPalAPIAA-threetoken' => 'https://api-aa.paypal.com/2.0/',
To the following:
Code: 'PayPalAPI-threetoken' => 'https://api-3t.paypal.com/2.0/',
'PayPalAPIAA-threetoken' => 'https://api-aa-3t.paypal.com/2.0/',
This will set the 3-token endpoints correctly for live production server.
Common Errors
Warning: main(PayPal.php): failed to open stream: No such file or directory in /home/www/user/paypal_php_samples/index.php on line 12 Fatal error: main(): Failed opening required 'PayPal.php' (include_path='/home/www/php-sdk4.1.1/lib:.:/usr/local/lib/php') in /home/www/user/paypal_php_samples/index.php on line 12
It is obvious from the error that it is not able to find PayPal.php and the hint is in the include path, basically the path_to_sdk_root that you entered in the ppsdk_include_path.inc is not correct, so knowing this it should be pretty easy to fix this issue. If you are not sure what the path to sdk root is you will want to ask your host.
**********
Warning: main(PEAR.php): failed to open stream: No such file or directory in C:\php-sdk\lib\PayPal.php on line 11 Fatal error: main(): Failed opening required 'PEAR.php' (include_path='C:\php-sdk\lib;C:\peard;.;c:\php\includes') in C:\php-sdk\lib\PayPal.php on line 11
Once again it is quite obvious that it is not able to find PEAR.php, usually this is installed by the host so you can contact your host to see if they can install it or you can visit the following page to download it.
http://www.php.net/downloads.php
Once you have the file you can unpack it and upload it above the web root where it is not accessible through the web browser. Then you can add its path to the include path in the ppsdk_include_path.inc file, for example:
Code: <?php
set_include_path('path_to_sdk_root'. DIRECTORY_SEPARATOR . 'lib' . PATH_SEPARATOR . 'path_to_pear' . PATH_SEPARATOR . get_include_path());
?>
**********
Fatal error: Call to undefined function: dodirectpayment() in /home/www/user/paypal_php_samples/DoDirectPaymentReceipt.php on line 133
This can be caused by several things:
- Make sure that you have cURL with ssl support
- Make sure that you have created your profile object correctly.
(index.php)
$profile->setAPIUsername('sdk-seller_api1.sdk.com'); $profile->setAPIPassword('12345678'); $profile->setSignature(null); $profile->setCertificateFile($cert_file_path); $profile->setEnvironment(ENVIRONMENT);
- Not including the API username and/or password will generate that error.
- Also if the path to the certificate is not correct then it will generate that error, if you changed the file name of the certificate then make sure the file name of the certificate is correct in your code. For example ($cert_file_path = $doc_root . $path_info . '/sdk-seller_cert_key_pem.txt'
- Make sure that you set the environment to either 'sandbox' or 'live' setting it to nothing or something else will cause that error as well. (ENVIRONMENT is defined in the samplesfolder/php/lib/constants.inc.php file)
**********
Fatal error: Call to undefined function: getack() in /home/www/user/paypal_php_samples/DoDirectPaymentReceipt.php on line 135
curl_exec error 35 SSL: error:14094418:SSL routines:SSL3_READ_BYTES:tlsv1 alert unknown ca (this would be displayed in the PayPal log file)
- Make sure that you have cURL with ssl support
- This error message is usually generated when you set the environment to live and then use the sandbox API credentials (username, password, certificate) or vise versa. (if you are testing in the sandbox make sure to use the API username, password and certificate from the sandbox and if you are testing the live site then make sure to use the API username, password and certificate from your live PayPal account)
- If you are using the 3-token (signature) method on PayPal's live server and you are getting this message then it is because you haven't updated the paypal-endpoints.php file to the correct Soap endpoints for 3-token, take a look at the above section titled, 'If you are planning on using the 3-token method'.
**********
When testing the Direct Payment API sample and you get the message, A PayPal API has returned an error! but the Ack, Correlation ID, Version, Error Number, Short Message and Long Message are blank/not displayed in your browser then chances are that you don't have short_open_tag turned on, you can contact your hosting company so that they can do turn it on for you or if possible you can turn on it in your php.ini file.
**********
If the PHP SDK seems like it is too complicated or just to much code for what you are trying to do then you might want to try a Simple PHP ExpressCheckout/DirectPayment example which might be easier to use, you can get it here.
Message Edited by PayPal_Ahmad on 04-14-2008 12:39 PM Ahmad Merchant Tech Services, PayPal
|