diff --git a/.gitignore b/.gitignore index 2f7896d1d..321a5d586 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ target/ +vendor/ +composer.phar +composer.lock diff --git a/connect-examples/v2/README.md b/connect-examples/v2/README.md index 4109ff34e..03da150fe 100644 --- a/connect-examples/v2/README.md +++ b/connect-examples/v2/README.md @@ -1,12 +1,15 @@ -The project is structured under two folders: +This folder includes the following samples: -* rails_payment: rails server implementation, within here it also includes frontend implementations for: - * plain JS +* __rails_payment__: a rails server implementation. This example includes front-end +implementations for: + * Standard Javascript * JQuery * Angular 1 * React * Ember * JS + Bootstrap -* node_payment: node server implementation, within here there is a frontend implementation: - * plain JS +* __node_payment__: a node server implementation. This example includes a single, +standard Javascript front-end implementation. +* __php_payment__: a simple PHP server implementation with an accompanying payment +form. diff --git a/connect-examples/v2/php_payment/README.md b/connect-examples/v2/php_payment/README.md new file mode 100644 index 000000000..b8e81996e --- /dev/null +++ b/connect-examples/v2/php_payment/README.md @@ -0,0 +1,49 @@ +# Payment processing example: PHP + +This sample demonstrates processing card payments with Square Connect API, using the +Square Connect PHP client library. + +## Setup + +### Install the PHP client library + +This sample already includes the `square/connect` dependency in its `composer.json` +file. To install the client library: + +1. Make sure you've downloaded Composer, following the instructions +[here](https://getcomposer.org/download/). + +2. Run the following command from the directory containing `composer.json`: + + php composer.phar install + +### Provide required credentials + +Both `process-card.php` and `index.html` have values near the top of the file +that you need to replace with various credentials associated with your application. +If you're just testing things out, it's recommended that you use your _sandbox_ +credentials for now. See +[this article](https://docs.connect.squareup.com/articles/using-sandbox/) +for more information on the API sandbox. + +You can `grep` for `REPLACE_ME` to find all of the fields to replace. + + +## Running the sample + +From the sample's root directory, run: + + php -S localhost:8000 + +You can then visit `localhost:8000` in your browser to see the card form. + +If you're using your sandbox credentials, you can test out an valid credit card +transaction by providing the following card information in the form: + +* Card Number 4532 7597 3454 5858 +* Card CVV 111 +* Card Expiration (Any time in the future) +* Card Postal Code (Any valid US postal code) + +**Note that if you are _not_ using your sandbox credentials and you enter _real_ +credit card information, YOU WILL CHARGE THE CARD.** diff --git a/connect-examples/v2/php_payment/composer.json b/connect-examples/v2/php_payment/composer.json new file mode 100644 index 000000000..584f63705 --- /dev/null +++ b/connect-examples/v2/php_payment/composer.json @@ -0,0 +1,5 @@ +{ + "require": { + "square/connect": "*" + } +} diff --git a/connect-examples/v2/php_payment/index.html b/connect-examples/v2/php_payment/index.html new file mode 100644 index 000000000..1b4ba8862 --- /dev/null +++ b/connect-examples/v2/php_payment/index.html @@ -0,0 +1,118 @@ + +
+"; + print_r($result); + echo ""; +} catch (\SquareConnect\ApiException $e) { + echo "Caught exception!
"; var_dump($e->getResponseBody()); echo ""; + echo "
"; var_dump($e->getResponseHeaders()); echo ""; +}