Setup PayPal PHP SDK
If you are using Composer you can get going quickly through our Packagist repo.
If you are not using Composer you can simply download the class library and add it to your project.
If you would like more details on either of these methods take a look at our install guide.
How to Make PayPal API Calls
- Open the template file that corresponds to the API call you’d like to make.
- Example: If we want to make a call to the RefundTransaction API we open /templates/RefundTransaction.php
- You may leave the file here or save this file to the location on your web server where you’d like this call to be made.
- I like to save the files to a separate location and keep the ones included with the library as empty templates.
- When working within an MVC framework, it’s a good idea to copy/paste the template functionality into a Model method.
- Each template file includes PHP arrays for every parameter available to that particular API. Simply fill in the array parameters with your own dynamic (or static) data. This data may come from…
- Session Variables
- PHP Variables
- Database Recordsets
- Static Values
- Etc.
- When you run the file you will get a
$PayPalResult
array that consists of all the response parameters from PayPal, original request parameters sent to PayPal, and raw request/response info for troubleshooting.- You may refer to the PayPal API Reference Guide for details about what response parameters you can expect to get back from any successful API request.
- Example: When working with RefundTransaction, I can see that PayPal will return a REFUNDTRANSACTIONID, FEEREFUNDAMT, etc. As such, I know that those values will be included in
$PayPalResult['REFUNDTRANSACTIONID']
and$PayPalResult['FEEREFUNDAMT']
respectively.
- Example: When working with RefundTransaction, I can see that PayPal will return a REFUNDTRANSACTIONID, FEEREFUNDAMT, etc. As such, I know that those values will be included in
- You may refer to the PayPal API Reference Guide for details about what response parameters you can expect to get back from any successful API request.
- If errors occur they will be available in
$PayPalResult['ERRORS']
.
Video Demo
General PayPal PHP Integration Tips
- The result of the API call will come back in
$PayPalResult['ACK']
.- Remember when checking the value that it could be Success, Failure, SuccessWithWarning, or FailureWithWarning. Simply checking for Success isn’t enough.
- You may use
$PayPal->APICallSuccessful($Ack)
to do this for you.
Tips for Testing in the PayPal Sandbox
- Create an account at http://developer.paypal.com
- Create at least one sandbox Seller account and one sandbox Buyer account from within your developer account.
- These accounts can be used to go through the entire process of buying items within your application, and reviewing what each party involved will see in their PayPal account when the transaction is completed.
Tips for Going Live
- Review PayPal’s Going Live Information
- Move /includes/config.php to a directory outside your web root.
- When you do this you’ll need to make sure any scripts where the config is included are updated to use the system path instead of the site path.
PayPal Developer Resources
- PayPal Developer Site
- This is where you can setup your own PayPal developer account.
- Within your developer account you can then create PayPal sandbox accounts. Â These can be used to send and receive money within the PayPal sandbox so that you can fully test your applications.
- PayPal REST API Documentation
- Here you can review all of the details about PayPal’s REST API web services.
- This will give you the raw details, but our library will simplify much of this for you.
- PayPal REST API Explorer
- This tool allows you to run API calls in a demo format to help see how JSON strings are constructed for various calls.
- Our library simplifies all of this for you, so that you don’t need to study this, but it’s still a good tool for general review.
- PayPal Classic API Payment Products
- Here you can review all of the products that PayPal offers with their Classic APIs.
- PayPal Classic API Integration Guides
- These guides can point you in the right direction if you have questions about which particular API calls you should be using to accomplish your goal.
- Within the integration guides you will find details about the API calls you will be working with.  You can then refer to the API reference for details about those individual API calls.
- PayPal Classic API Reference
- The Classic API is PayPal’s original platform which works with a variety of NVP or SOAP web services.
- This reference is a great resource for reviewing all of the APIs available.
- This PayPal PHP SDK supports all of the APIs you will find listed in the API reference.
Need Additional Help?
Schedule a live meeting with Drew Angell, PayPal Certified Developer, and get all of your questions or concerns answered.
Featured PayPal Products and Services
-
PayPal Support
$100.00 -
PayPal for WooCommerce
FREE! -
WooCommerce Multiple PayPal Accounts Plugin
$119.99 -
PayPal Shipment Tracking for WooCommerce
$49.99 -
Sale!
PayPal for WooCommerce – Credit Card Split Payment
$49.99 -
Offers for WooCommerce
$59.99 -
Sale!
Offers for WooCommerce – WC Vendors
$99.99 -
Sale!
Offers for WooCommerce – Dokan
$99.99
Hi Andrew-
Not sure if this is correct place to post this, but….
I have a few older apps using your class to integrate PayPal processing for some minor payments.
I recently had a new project which required this, and recycled much of the older code.. while testing this I noticed I was getting illegal off-set errors in PHP when trying to access the $PayPalResult object??
Specifically the ACCT value in the array… has something changed?
$PayPalResult[‘RAWREQUEST’][‘ACCT’] = substr($PayPalResult[‘RAWREQUEST’][‘ACCT’], -4);
// which is used to truncate the card# before logging… and has been in use for a long time. (until recently throwing an illegal offset error)
ie: Warning: Illegal string offset ‘ACCT’
but doesnt seem to exist anymore..
Updating to this:
$PayPalResult[‘ACCT’] = substr($PayPalResult[‘ACCT’], -4);
Seems to have worked..
but I’m more concerned about the change, when it happened and what caused it?
I’m not sure if there was a change with the formatting of the returned object/array?
The only other thing I can think of was a few weeks ago, I had this error:
Strict Standards: Declaration of PayPal_PayFlow::CURLRequest() should be compatible with PayPal::CURLRequest($Request = ”, $APIName = ”, $APIOperation = ”) in /usr/home/xxx/lib/php/xxx/paypal_angelleye/includes/paypal.payflow.class.php on line 165
which I had some out of sync files, and updated them all to be compliant/in sync with each other.
Was this update responsible for the array change?
That actually doesn’t look something that would have ever worked. RAWREQUEST is the entire NVP string, so it wouldn’t have ACCT separated within it. Sounds like maybe you didn’t have PHP error reporting enabled previously, so you probably just weren’t seeing the warning. $PayPalResult[‘ACCT’] isn’t going to work either, though. You would need to use $PayPalResult[‘REQUESTDATA’][‘ACCT’].
Is this SDK compliant with all the things Paypal will be requiring in June 2018? This is at: https://www.paypal-notice.com/en/
Looks like most of these are up to the web site itself (such as HTTPS only for IPN).
Yes, the library is good for all of that. As you mentioned, most of it needs to be handled at the server level.
Hello, how would you integrate this library with Laravel 5.8? I have successfully added the package to my project via composer, now I want toss-up the config file and the autoload? Many thanks.
Yes. We’ll be publishing some step by step tutorials for integrating the library into Laravel and other frameworks, but they’re not quite ready yet. For now you can take a look at this old project of mine where I tied these libraries into Laravel. It should all be very similar now.
You will see I have a paypal.php config file and then my controller and model work together.
Take a look at that and let me know if you have any specific questions.