From f20fc4a85d0b64b94893a23d3523cdf5ce452ef0 Mon Sep 17 00:00:00 2001 From: japatel Date: Wed, 19 Nov 2014 21:42:46 -0600 Subject: [PATCH] Samples now uses built-in web server --- README.md | 26 +- sample/README.md | 27 +- sample/common.php | 9 +- sample/index.html | 815 ------------------------------------------ sample/index.php | 884 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 928 insertions(+), 833 deletions(-) delete mode 100644 sample/index.html create mode 100644 sample/index.php diff --git a/README.md b/README.md index 1099f5da..21429452 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ You can download composer using instructions on [Composer Official Website.](htt #### Steps to Install : -Currently, Paypal PHP Rest API SDK is available at [https://packagist.org](https://packagist.org/packages/paypal/rest-api-sdk-php). To use it in your project, you need to include it as a dependency in your project composer.json file. It can be done in two ways : +Currently, Paypal PHP Rest API SDK is available at [https://packagist.org](https://packagist.org/packages/paypal/rest-api-sdk-php). To use it in your project, you need to include it as a dependency in your project composer.json file. It can be done either: * Running `composer require paypal/rest-api-sdk-php:*` command on your project root location (where project composer.json is located.) @@ -64,11 +64,21 @@ If you do not want to use composer, you can grab the SDK zip that contains Paypa * Using the [htmlpreview](https://github.com/htmlpreview/htmlpreview.github.com) tool you can now [view sample source codes here](http://htmlpreview.github.io/?https://github.com/paypal/PayPal-PHP-SDK/blob/master/sample/index.html) ### Running Locally - * Clone the repo and navigate to the samples folder. - * Samples have dependency on the sdk and you can use [`composer`](http://getcomposer.org) to get the dependencies. Ensure that you have composer installed on your machine, navigate to the root folder and run `composer update --no-dev` to fetch the SDK. - * Optionally, update the bootstrap.php file with your own client Id and client secret, that you could find from the [developer portal](https://developer.paypal.com) - * You need to host this project locally using any server, e.g. Apache. - * Open the `index.html` page under `/sample` directory and checkout the samples. + +* Clone the [PayPal-PHP-SDK repository](https://github.com/paypal/PayPal-PHP-SDK) +``` +git clone https://github.com/paypal/PayPal-PHP-SDK +``` +* Run Composer installer on PayPal-PHP-SDK directory +``` +composer install +``` +* Run PHP Built-in web server by running +``` +php -f sample/index.php +``` + + * If you are using PHP version older than 5.4, you can follow the instructions described [here](sample/). ## Usage @@ -129,8 +139,8 @@ You can intialize the API objects by passing JSON string or Array representation ``` $obj = new SimpleClass('{"name":"test","description":"description"}'); -$obj->getName(); -$obj->getDescription(); +$obj->getName(); // test +$obj->getDescription(); // description ``` ### Accessor Validation diff --git a/sample/README.md b/sample/README.md index a1938a6d..2997ce49 100644 --- a/sample/README.md +++ b/sample/README.md @@ -5,8 +5,29 @@ This sample project is a simple web app that you can explore to understand what To try out the sample, run `composer update --no-dev` from the PayPal-PHP-SDK folder and you are all set. -#### Running on a web -* If you plan to run these samples on the web, you will need to host this project under a local server. E.g. Apache. +#### Running Samples + +##### PHP 5.4 or higher +* If you are running PHP 5.4 or greater, PHP provides a built-in support for hosting PHP sites. +* The fastest way to get it running is +```bash +php -f sample/index.php +``` +* This would get the [built-in web server](http://php.net/manual/en/features.commandline.webserver.php) started, and hosted on `http://localhost:5000' + +```bash +LM-AUN-00876403:PayPal-PHP-SDK japatel$ php -f sample/index.php +PHP 5.5.14 Development Server started at Wed Nov 19 21:07:52 2014 +Listening on http://localhost:5000 +Document root is /Users/japatel/Documents/workspace/Server-SDK/PayPal-PHP-SDK/sample +Press Ctrl-C to quit. +[Wed Nov 19 21:07:56 2014] ::1:60826 [200]: /index.php +... +``` + +##### PHP 5.3 or less + +* You could host the entire project in your local web server, by using tools like [MAMP](http://www.mamp.info/en/) or [XAMPP](https://www.apachefriends.org/index.html). * Once done, you could easily open the samples by opening the matching URL. For e.g.: `http://localhost/PayPal-PHP-SDK/sample/index.html` @@ -16,7 +37,7 @@ You should see a sample dashboard page as shown below: #### 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 on console, you need to open command prompt, and direct to samples directory. +* 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: ```bat php -f payments/CreatePaymentUsingSavedCard.php diff --git a/sample/common.php b/sample/common.php index 44811c89..09ccb36c 100644 --- a/sample/common.php +++ b/sample/common.php @@ -53,7 +53,7 @@ public static function printOutput($title, $objectName, $objectId = null, $reque if (self::$printResultCounter == 0) { include "header.html"; echo ' -

+

'; echo '
'; } @@ -193,13 +193,8 @@ function getBaseUrl() $protocol = 'http'; if ($_SERVER['SERVER_PORT'] == 443 || (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on')) { $protocol .= 's'; - $protocol_port = $_SERVER['SERVER_PORT']; - } else { - $protocol_port = 80; } - $host = $_SERVER['HTTP_HOST']; - $port = $_SERVER['SERVER_PORT']; $request = $_SERVER['PHP_SELF']; - return dirname($protocol . '://' . $host . ($port == $protocol_port ? '' : ':' . $port) . $request); + return dirname($protocol . '://' . $host . $request); } diff --git a/sample/index.html b/sample/index.html deleted file mode 100644 index f35dbf7f..00000000 --- a/sample/index.html +++ /dev/null @@ -1,815 +0,0 @@ - - - - - - - - - - - PayPal REST API Samples - - - - - - - - - - -
-
-
-
- -
-
-

REST API Samples

- -

These examples are created to experiment with the PayPal-PHP-SDK capabilities. Each examples are - designed to demonstrate the default use-cases in each segment. - Many examples should be executable, and should allow you to experience the default behavior of our - sdk, to expedite your integration experience.

- -
-
-
-
-
-
-
 
-
-
-
-

Payments

-
- - -
- - -
- - - -
- -
-
-

Sale

-
- - -
- -
- - - -
- -
-
-

Vault

-
- - -
- -
- - - -
- -
-
-

Invoice

-
- - -
- -
- - - -
-
-
-
- - - - - - - - - - - diff --git a/sample/index.php b/sample/index.php new file mode 100644 index 00000000..671797b8 --- /dev/null +++ b/sample/index.php @@ -0,0 +1,884 @@ +=') === true) { + //exec('php -S -t ' . __DIR__ . '/'); + $cmd = "php -S localhost:5000 -t " . __DIR__ . '/'; + $descriptors = array( + 0 => array("pipe", "r"), + 1 => STDOUT, + 2 => STDERR, + ); + $proc = proc_open($cmd, $descriptors, $pipes); + if ($proc === false) { + fprintf(STDERR, + "Unable to launch PHP's built-in web server.\n"); + exit(2); + } + fclose($pipes[0]); // Close the process' stdin. + $exitCode = proc_close($proc); // Wait for process to exit. + exit($exitCode); + } +} else { + ?> + + + + + + + + + + + PayPal REST API Samples + + + + + + + + + + +
+
+
+
+ +
+
+

REST API Samples

+ +

These examples are created to experiment with the PayPal-PHP-SDK capabilities. Each examples + are + designed to demonstrate the default use-cases in each segment. + Many examples should be executable, and should allow you to experience the default behavior + of our + sdk, to expedite your integration experience.

+ + +
+
+
+
+
+
+
 
+
+
+
+

Payments

+
+ + +
+ + +
+ + + +
+ +
+
+

Sale

+
+ + +
+ +
+ + + +
+ +
+
+

Vault

+
+ + +
+ +
+ + + +
+ +
+
+

Invoice

+
+ + +
+ +
+ + + +
+
+
+
+ + + + + + + + + + + +