Skip to content

Commit

Permalink
Add licence and add sample usage in readme
Browse files Browse the repository at this point in the history
  • Loading branch information
mnabialek committed Oct 3, 2016
1 parent cfa3a3c commit b6c6791
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 12 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"Tests\\": "tests"
}
},
"license": "MIT",
"minimum-stability": "dev",
"prefer-stable": true,
"require-dev": {
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

80 changes: 69 additions & 11 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
## Laravel Paybox Gateway

**This module is currently under development, please check later.**

This module makes integration with **[Paybox](http://www1.paybox.com/?lang=en)** payment gateway much easier. It supports currently 2 ways of making payments using Paybox system.

1. **Full payment via Paybox System** - this is the most common way to receive payment - client has to pay for his order and after payment you can process the order
2. **Authorization via Paybox System followed by capture via Paybox Direct** - first client makes payment but in fact the real payment is not made, payment is only authorized so far. In maximum period of 7 days you have to confirm you want to/are able to process the order and you capture the payment. After successful payment capture you can process the order.

### Installation

Expand Down Expand Up @@ -30,9 +32,18 @@

in your console to publish default configuration files and sample views

4. Open `config/paybox.php` and configure it according to your needs. By default you should put `PAYBOX_TEST`, `PAYBOX_SITE`, `PAYBOX_RANK`, `PAYBOX_ID` and `PAYBOX_HMAC_KEY` into your `.env` file and fill them with valid values. For testing you should set `PAYBOX_TEST` to true, otherwise it should be set to false.
4. Open `config/paybox.php` and configure it according to your needs. By default you should put the following variables into your `.env` file and fill them with valid values:

* `PAYBOX_TEST` - whether Paybox test system should be used (it should be set to `true` only for tests) ,
* `PAYBOX_SITE` - Site number provided by Paybox
* `PAYBOX_RANK` - Rank number provided by Paybox
* `PAYBOX_ID` - Internal identifier provided by Paybox
* `PAYBOX_BACK_OFFICE_PASSWORD` - Paybox back-office password. It's required only if you are going to make `Capture` requests. Otherwise it's not recommended to fill it (it won't be used)
* `PAYBOX_HMAC_KEY` - This is key you should generate in your Paybox back-office

5. Download [Paybox public key](http://www1.paybox.com/espace-integrateur-documentation/manuels/?lang=en) and put it in directory and name you specified in `config/paybox.php` for `public_key` key

5. In your routes file register routes with names defined in `customer_return_routes_names` and `transaction_verify_route_name` groups of your `config/paybox.php`
6. In your routes file register routes with names defined in `customer_return_routes_names` and `transaction_verify_route_name` groups of your `config/paybox.php`

### Usage

Expand All @@ -44,11 +55,13 @@ In order to use the system, you need to do a few things:

3. You should handle transaction verify route. Here you should change status of payment after receiving request and make any additional actions.

4. In case you use want to capture previously authorized payments, you should also handle capturing previous payments.

#### Authorization request

This is main request you need to launch to init payment.

This module uses Paybox system in order to make payment so it means, customer is redirected to Paybox website in order to make payment. However you can do it using 2 strategies - you can either make customer to be charged as soon as possible (what should be used in most cases) or you might want to charge customer only in some cases (for example when shop's staff will accept client's order).

The most basic sample code for authorization request looks like this:
The most basic sample code for authorization request could look like this:

```php
$authorizationRequest = \App::make(\Devpark\PayboxGateway\Requests\AuthorizationWithCapture::class);
Expand All @@ -58,7 +71,7 @@ return $authorizationRequest->setAmount(100)->setCustomerEmail('[email protected]
```
This code should be run in controller as it's returning view which will by default automatically redirect customer to Paybox website.

Above sample if with capture (customer will be charged as soon as possible). If you want to charge customer later use `AuthorizationWithoutCapture` instead.
In above sample code the full payment is made. If you want to only authorize payment (which you will capture later) you should use `AuthorizationWithoutCapture` class instead of `AuthorizationWithCapture`

If you want more customization take a look at public methods of `\Devpark\PayboxGateway\Requests\Authorization` class.

Expand All @@ -68,10 +81,55 @@ Also for `setPaymentNumber` you should make sure the number you gave here is uni

You might want in this step adjust also view for sending request because in some cases it might be seen by a client. However you shouldn't change fields you send to Paybox in this step or it won't work.

In case you use `AuthorizationWithoutCapture` you should make sure, you have `\Devpark\PayboxGateway\ResponseField::SUBSCRIPTION_CARD_OR_PAYPAL_AUTHORIZATION` in your return fields because this value will be needed when capturing payment later. You should also always have `\Devpark\PayboxGateway\ResponseField::AUTHORIZATION_NUMBER` and `\Devpark\PayboxGateway\ResponseField::SIGNATURE` in your return fields and signature should be always last parameter.
In case you use `AuthorizationWithoutCapture` you should make sure, you have `\Devpark\PayboxGateway\ResponseField::PAYBOX_CALL_NUMBER` and `\Devpark\PayboxGateway\ResponseField::TRANSACTION_NUMBER` in your return fields because those values will be needed when capturing payment later. You should also always have `\Devpark\PayboxGateway\ResponseField::AUTHORIZATION_NUMBER` and `\Devpark\PayboxGateway\ResponseField::SIGNATURE` in your return fields and signature should be always last parameter.

#### Define customer returning routes

By default 4 sample views were created with sample English texts. You should create routes that will display those views (those routes will be launched using `GET` HTTP method), adjust those views and in most cases it will be enough because you should not rely on data you receive from Paybox here.
By default 4 sample views were created with sample English texts. You should create routes that will display those views (those routes will be launched using `GET` HTTP method), adjust those views and in most cases it will be enough because the real status of payment will be verified using transaction verify route.

#### Handling transaction verify route

#### Handling transaction verify route
To make sure the payment was really successful you should use `\Devpark\PayboxGateway\Responses\Verify` class. The simplest code could look like this:

```php
$payment = Payment::where('number', $request->input('order_number'))->firstOrFail();
$payboxVerify = \App::make(\Devpark\PayboxGateway\Responses\Verify::class);
try {
$success = $payboxVerify->isSuccess($payment->amount);
if ($success) {
// process order here after making sure it was real payment
}
echo "OK";
}
catch (InvalidSignature $e) {
Log::alert('Invalid payment signature detected');
}
```

This code should be run in controller, because you should return non-empty response when receiving valid Paybox request for transaction verify route. As you see, first you need to find order by number and then you need to make sure that it was successful. If yes, you should make sure it was real payment before you process the order (if you use full payment it will be always true but in case in your application you use also authorization only payments with later capture you should make sure you won't process the order for authorization only payment).

#### Capturing previously authorized request

In case you use **Authorization via Paybox System followed by capture via Paybox Direct** you are going to finally capture previously authorized payment (you have up-to 7 days to do that).

The simplest code could look like this:

```php
$payment = PaymentModel::find($idOfAuthorizedPayment);
$captureRequest = \App::make(\Devpark\PayboxGateway\Requests\Capture::class);
$response = $captureRequest->setAmount($payment->amount)
->setPayboxCallNumber($payment->call_number)
->setPayboxTransactionNumber($payment->transaction_number)
->setDayRequestNumber(2)
->send();

if ($response->isSuccess()) {
// process order here
}
```

In above code you should make sure value you give for `setDayRequestNumber` is unique number in current day from 1 to 2147483647. For `setPayboxCallNumber` and `setPayboxTransactionNumber` you should use values you received in handling `Handling transaction verify route` step so you should probably save them in this step to use them here.

### Licence

This package is licenced under the [MIT license](http://opensource.org/licenses/MIT)

0 comments on commit b6c6791

Please sign in to comment.