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

Commit

Permalink
Samples now uses built-in web server
Browse files Browse the repository at this point in the history
  • Loading branch information
japatel committed Nov 20, 2014
1 parent 0268024 commit f20fc4a
Show file tree
Hide file tree
Showing 5 changed files with 928 additions and 833 deletions.
26 changes: 18 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.)

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
27 changes: 24 additions & 3 deletions sample/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand All @@ -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
Expand Down
9 changes: 2 additions & 7 deletions sample/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static function printOutput($title, $objectName, $objectId = null, $reque
if (self::$printResultCounter == 0) {
include "header.html";
echo '
<div class="row header"><div class="col-md-3 pull-left"><br /><a href="../index.html"><h3>&#10094;&#10094; Back to Samples</h3></a><br /><br /></div> <br />
<div class="row header"><div class="col-md-3 pull-left"><br /><a href="../index.php"><h3>&#10094;&#10094; Back to Samples</h3></a><br /><br /></div> <br />
<div class="col-md-2 pull-right"><img src="../images/pp_v_rgb.png" height="70" /></div> </div><div class="clearfix visible-xs-block"></div><br />';
echo '<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">';
}
Expand Down Expand Up @@ -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);
}
Loading

0 comments on commit f20fc4a

Please sign in to comment.