Jump to Page:   1 · 2 · 3 · 4  |  Next Page
PHP SDK install tips/common errors/fixes   [ Edited ]
Options    Options  
PP_MTS_Ahmad Moderator
Moderator
Posts: 2377
Registered: 06-07-2006



Message 1 of 37

Viewed 47,604 times


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':smileywink:
  • 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

4
Kudos!
07-18-2006 03:04 PM  
Re: PHP SDK install tips/common errors/fixes
Options    Options  
damon Administrator
Administrator
Posts: 1144
Registered: 06-07-2006


damon

Message 2 of 37

Viewed 47,540 times


Awesome info, thanks for posting!!
 


-------------------------------------------------
Damon Williams

Author,
Pro PayPal E-Commerce

3
Kudos!
07-18-2006 04:24 PM  
Re: PHP SDK install tips/common errors/fixes
Options    Options  
laczar
Visitor
Posts: 3
Registered: 10-09-2006


laczar

Message 3 of 37

Viewed 45,270 times


Fatal error: Call to undefined function: getack() in /home/www/user/paypal_php_samples/DoDirectPaymentReceipt.php on line 135

This maybe quite a gray on me...
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)

when im using the test account everything seems to work just fine :smileysad:
Kudos!
10-09-2006 08:54 AM  
Re: PHP SDK install tips/common errors/fixes
Options    Options  
mebshe
Newbie
Posts: 3
Registered: 10-09-2006


mebshe

Message 4 of 37

Viewed 45,258 times


Hey -- this is great info for the PHP SDK -- you wouldn't have the same type of post for the Classic ASP SDK, would you????
 
There are alot of problems that i had to figure out, and it would have been real great to have a break-down like you did here with PHP.
 
Thanks
Kudos!
10-09-2006 12:23 PM  
Re: PHP SDK install tips/common errors/fixes
Options    Options  
PP_MTS_Ahmad Moderator
Moderator
Posts: 2377
Registered: 06-07-2006



Message 5 of 37

Viewed 45,203 times


laczar,

If you are getting that error when switching to the live server then can you include info on what you have done so far, are you using your API username/API password and Certificate/Signature from your live PayPal account and have you changed the ENVIRONMENt to live, it is defined in the samplesfolder/bin/constants.inc.php file.  Also is your PayPal account setup for the Signature method or certificate?


 

Ahmad
Merchant Tech Services, PayPal

Kudos!
10-10-2006 01:47 PM  
Re: PHP SDK install tips/common errors/fixes
Options    Options  
ekitel
Newbie
Posts: 3
Registered: 10-02-2006


ekitel

Message 6 of 37

Viewed 45,200 times


where do I go to hard code my 3 tokens? this information seems to be very esoteric since I've been searching and searching and still can't find it any where
2
Kudos!
10-10-2006 03:12 PM  
Re: PHP SDK install tips/common errors/fixes
Options    Options  
PP_MTS_Ahmad Moderator
Moderator
Posts: 2377
Registered: 06-07-2006



Message 7 of 37

Viewed 45,194 times


ekitel,

When using the SDK you have to create a profile object first - the profile object will include your API credentials as well as the environment you are using and the optional subject element, in the SDK samples (4.2.1) the profile object is created in the samples\php\WebPaymentsPro.php.  You can also use the samples\php\request_base.php file to create your profile object and caller object if you want for your solution.  If this seems like it is just too much for what you are trying to do then try a Simple PHP ExpressCheckout/DirectPayment example, you can get it here.  If you are using PHP 5 try the examples at this page


 

Ahmad
Merchant Tech Services, PayPal

Kudos!
10-10-2006 06:23 PM  
Re: PHP SDK install tips/common errors/fixes
Options    Options  
acalderon
Regular Visitor
Posts: 7
Registered: 10-14-2006


acalderon

Message 8 of 37

Viewed 45,067 times


Excellent,

Now I installed the SDK. But do you have any idea of why would the page will hang and never get a response?

Help is appreciated.
Kudos!
10-14-2006 07:28 PM  
Re: PHP SDK install tips/common errors/fixes
Options    Options  
damon Administrator
Administrator
Posts: 1144
Registered: 06-07-2006


damon

Message 9 of 37

Viewed 45,067 times


Fellas,

Please open a new thread for specific questions. Let's try to leave this message as a 'sticky' and not some long, multi-reponse thread with several different discussions going on.

Thanks for the consideration

-DW
 


-------------------------------------------------
Damon Williams

Author,
Pro PayPal E-Commerce

3
Kudos!
10-14-2006 08:04 PM  
Re: PHP SDK install tips/common errors/fixes
Options    Options  
dannoRBfy
Regular Visitor
Posts: 4
Registered: 01-11-2007


dannoRBfy

Message 10 of 37

Viewed 42,161 times


I'm getting this error after trying to install:

Fatal error: main() [function.require]: Failed opening required 'PayPal.php' (include_path='.:/usr/local/lib/php') in /homepages/43/d174272988/htdocs/samples/WebPaymentPro.php on line 12
Kudos!
01-11-2007 03:02 PM  
Jump to Page:   1 · 2 · 3 · 4  |  Next Page
Copyright © PayPal. All Rights Reserved. By using this site, you agree to be bound by PayPal's Legal Disclaimer, User Agreement, and Privacy Policy. This site is subject to change without notice. All other products and company names are trademarks of their respective corporations.