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.

PayPal PHP SDK Class Library 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.
  • 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.

Looking for Live Help?

Schedule a live meeting with Drew Angell, PayPal Certified Developer, and get all of your questions or concerns answered.