Setup
- Download the PHP class library for PayPal and upload to a directory on your web server.
- Open /includes/config-sample.php and adjust the values with your own Sandbox and Production API credentials. then Save-As config.php
- There are detailed comments inside the config file to help you fill it out correctly.
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 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.
- 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'].
General 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 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.