Skip to content
This repository has been archived by the owner on Sep 29, 2023. It is now read-only.

Samples

Jay edited this page Oct 24, 2017 · 14 revisions

This sample project is a simple web app that you can explore to understand what each PayPal APIs can do for you.

You must clone the GitHub repository to get a copy of the samples. The samples are not included with an installation via Composer or the GitHub release downloads to help prevent the samples from being included in a deployed application.

Viewing Sample Code

You can view sample source codes here. However, we recommend you run samples locally to get a better idea.

Instructions

If you are running PHP 5.4 or greater, PHP provides a built-in support for hosting PHP sites.

Note: The root directory for Composer based download would be vendor and for direct download it would be PayPal-PHP-SDK. Please update the commands accordingly.

  1. Run php -f PayPal-PHP-SDK/paypal/rest-api-sdk-php/sample/index.php from your project root directory.

  2. This would host a PHP server at localhost:5000. The output should look something like this:

    <!-- Welcome to PayPal REST SDK -- >
    PHP 5.5.14 Development Server started at Sat Jan 10 14:04:35 2015
    Listening on http://localhost:5000
    Document root is /Users/japatel/Desktop/project/PayPal-PHP-SDK/paypal/rest-api-sdk-php/sample
    Press Ctrl-C to quit.
    
  3. Open http://localhost:5000/ in your web browser.

Configuration (Optional)

The sample comes pre-configured with a test account but in case you need to try them against your account, you must

  • Obtain your client id and client secret from the developer portal

  • Update the bootstrap.php file come with the sample folder with your new client id and secret.

Alternative Options

There are two other ways you could run your samples, as shown below:

  • Alternatives: LAMP Stack (All supported PHP Versions)

    • You could host the entire project in your local web server, by using tools like MAMP or XAMPP.
    • Once done, you could easily open the samples by opening the matching URL. For e.g.: http://localhost/PayPal-PHP-SDK/paypal/rest-api-sdk-php/sample/index.php
  • Alternatives: Running on console

    Please note that there are few samples that requires you to have a working local server, to receive redirects when user accepts/denies PayPal Web flow

    • To run samples itself on console, you need to open command prompt, and direct to samples directory.
    • Execute the sample php script by using php -f command as shown below:
php -f invoice/GetInvoice.php
  • The result would be as shown below:
 php -f invoice/GetInvoice.php 

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
(1) CREATE INVOICE
-------------------------------------------------------------

Object with ID: INV2-VBPT-L6S7-N676-HQ4M 
-------------------------------------------------------------
	REQUEST:
{
    "merchant_info": {
        ...
    "logo_url": "https://www.paypalobjects.com/webstatic/i/logo/rebrand/ppcom.svg"
}

	RESPONSE:
{
    "merchant_info": {
        ...
    "allow_tip": false,
    "links": [
        {
            "rel": "self",
            "href": "https://api.sandbox.paypal.com/v1/invoicing/invoices/INV2-VBPT-L6S7-N676-HQ4M",
            "method": "GET"
        }...
    ]
}
-------------------------------------------------------------


+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
(2) GET INVOICE
-------------------------------------------------------------

Object with ID: INV2-VBPT-L6S7-N676-HQ4M 
-------------------------------------------------------------
	REQUEST:
INV2-VBPT-L6S7-N676-HQ4M

	RESPONSE:
{
    "id": "INV2-VBPT-L6S7-N676-HQ4M",
    ...
}
-------------------------------------------------------------

More Help

If you are looking for a full fledged application that uses the new RESTful APIs, check out the Pizza store sample app at https://github.com/paypal/PayPal-PHP-SDK/tree/master/sample

Next Step