| 1 |
PHP library for the PayPlug API |
| 2 |
=============================== |
| 3 |
|
| 4 |
.. image:: https://travis-ci.org/payplug/payplug-php.svg?branch=master |
| 5 |
:target: https://travis-ci.org/payplug/payplug-php |
| 6 |
:alt: CI Status |
| 7 |
|
| 8 |
.. image:: https://img.shields.io/packagist/v/payplug/payplug-php.svg?maxAge=2592000 |
| 9 |
:target: https://packagist.org/packages/payplug/payplug-php |
| 10 |
:alt: Packagist |
| 11 |
|
| 12 |
This is the documentation of PayPlug's PHP library. It is designed to |
| 13 |
help developers to use PayPlug as payment solution in a simple, yet robust way. |
| 14 |
|
| 15 |
You can create a PayPlug account at http://payplug.com. |
| 16 |
|
| 17 |
Prerequisites |
| 18 |
------------- |
| 19 |
|
| 20 |
PayPlug's library relies on **cURL** to perform HTTP requests and requires **OpenSSL (1.0.1 or newer)** to secure transactions. You also need **PHP 5.3** or newer for the PayPlug PHP V2. |
| 21 |
|
| 22 |
For version **PHP 5.2** or older you must refer to PayPlug PHP V1. |
| 23 |
|
| 24 |
Documentation |
| 25 |
------------- |
| 26 |
Please see https://www.payplug.com/docs/api for latest documentation. |
| 27 |
|
| 28 |
Installation |
| 29 |
------------ |
| 30 |
**Option 1 - Strongly preferred)** via composer: |
| 31 |
|
| 32 |
- Get composer from `composer website`_. |
| 33 |
- Make sure you have initialized your *composer.json*. |
| 34 |
- Run *composer require payplug/payplug-php* from your project directory. |
| 35 |
|
| 36 |
.. _composer website: https://getcomposer.org/download/ |
| 37 |
|
| 38 |
**Option 2)** clone the repository : |
| 39 |
:: |
| 40 |
|
| 41 |
git clone https://github.com/payplug/payplug-php.git |
| 42 |
|
| 43 |
**Option 3)** download as a tarball : |
| 44 |
|
| 45 |
- Download the most recent tarball from the `download page V2`_ (V2 for **PHP 5.3** or newer) |
| 46 |
- Download the most recent tarball from the `download page V1`_ (V1 for **PHP 5.2** or older) |
| 47 |
- Unpack the tarball |
| 48 |
- Put the files somewhere in your project |
| 49 |
|
| 50 |
.. _download page V1: https://github.com/payplug/payplug-php/releases/tag/V1.1.2 |
| 51 |
.. _download page V2: https://github.com/payplug/payplug-php/releases |
| 52 |
|
| 53 |
__ https://bitbucket.org/payplug/payplug_php/downloads#tag-downloads |
| 54 |
|
| 55 |
To get started, add the following to your PHP script (if you are not running a framework): |
| 56 |
|
| 57 |
.. sourcecode :: php |
| 58 |
|
| 59 |
<?php |
| 60 |
require_once("PATH_TO_PAYPLUG/payplug_php/lib/init.php"); |
| 61 |
|
| 62 |
Usage |
| 63 |
----- |
| 64 |
|
| 65 |
Here's how simple it is to create a payment request: |
| 66 |
|
| 67 |
.. sourcecode :: php |
| 68 |
|
| 69 |
<?php |
| 70 |
require_once("PATH_TO_PAYPLUG/payplug_php/lib/init.php"); // If not using a framework |
| 71 |
|
| 72 |
// Loads your account's parameters that you've previously downloaded and saved |
| 73 |
Payplug\Payplug::setSecretKey('YOUR_TOKEN'); |
| 74 |
|
| 75 |
// Create a payment request of €9.99. The payment confirmation (IPN) will be sent to "http://www.example.com/callbackURL" |
| 76 |
$payment = Payplug\Payment::create(array( |
| 77 |
'amount' => 999, |
| 78 |
'currency' => 'EUR', |
| 79 |
'customer' => array( |
| 80 |
'email' => '[email protected]', |
| 81 |
'first_name' => 'John', |
| 82 |
'last_name' => 'Doe' |
| 83 |
), |
| 84 |
'hosted_payment' => array( |
| 85 |
'return_url' => 'https://www.example.com/thank_you_for_your_payment.html', |
| 86 |
'cancel_url' => 'https://www.example.com/so_bad_it_didnt_make_it.html' |
| 87 |
), |
| 88 |
'notification_url' => 'http://www.example.com/callbackURL' |
| 89 |
)); |
| 90 |
|
| 91 |
// You will be able to find how the payment object is built in the documentation. |
| 92 |
// For instance, if you want to get an URL to the payment page, you get do: |
| 93 |
$paymentUrl = $payment->hosted_payment->payment_url; |
| 94 |
|
| 95 |
// Then, you can redirect the user to the payment page |
| 96 |
header("Location: $paymentUrl"); |
| 97 |
exit(); |
| 98 |
|
| 99 |
Go further: |
| 100 |
----------- |
| 101 |
Tests: |
| 102 |
++++++ |
| 103 |
See tests/README.rst. |
| 104 |
|