Skip to content

Commit b6c6791

Browse files
committed
Add licence and add sample usage in readme
1 parent cfa3a3c commit b6c6791

File tree

3 files changed

+71
-12
lines changed

3 files changed

+71
-12
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"Tests\\": "tests"
1818
}
1919
},
20+
"license": "MIT",
2021
"minimum-stability": "dev",
2122
"prefer-stable": true,
2223
"require-dev": {

composer.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

readme.md

Lines changed: 69 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
## Laravel Paybox Gateway
22

3-
**This module is currently under development, please check later.**
4-
3+
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.
4+
5+
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
6+
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.
57

68
### Installation
79

@@ -30,9 +32,18 @@
3032

3133
in your console to publish default configuration files and sample views
3234

33-
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.
35+
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:
36+
37+
* `PAYBOX_TEST` - whether Paybox test system should be used (it should be set to `true` only for tests) ,
38+
* `PAYBOX_SITE` - Site number provided by Paybox
39+
* `PAYBOX_RANK` - Rank number provided by Paybox
40+
* `PAYBOX_ID` - Internal identifier provided by Paybox
41+
* `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)
42+
* `PAYBOX_HMAC_KEY` - This is key you should generate in your Paybox back-office
43+
44+
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
3445

35-
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`
46+
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`
3647

3748
### Usage
3849

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

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

58+
4. In case you use want to capture previously authorized payments, you should also handle capturing previous payments.
59+
4760
#### Authorization request
61+
62+
This is main request you need to launch to init payment.
4863

49-
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).
50-
51-
The most basic sample code for authorization request looks like this:
64+
The most basic sample code for authorization request could look like this:
5265

5366
```php
5467
$authorizationRequest = \App::make(\Devpark\PayboxGateway\Requests\AuthorizationWithCapture::class);
@@ -58,7 +71,7 @@ return $authorizationRequest->setAmount(100)->setCustomerEmail('test@example.com
5871
```
5972
This code should be run in controller as it's returning view which will by default automatically redirect customer to Paybox website.
6073

61-
Above sample if with capture (customer will be charged as soon as possible). If you want to charge customer later use `AuthorizationWithoutCapture` instead.
74+
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`
6275

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

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

6982
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.
7083

71-
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.
84+
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.
7285

7386
#### Define customer returning routes
7487

75-
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.
88+
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.
89+
90+
#### Handling transaction verify route
7691

77-
#### Handling transaction verify route
92+
To make sure the payment was really successful you should use `\Devpark\PayboxGateway\Responses\Verify` class. The simplest code could look like this:
93+
94+
```php
95+
$payment = Payment::where('number', $request->input('order_number'))->firstOrFail();
96+
$payboxVerify = \App::make(\Devpark\PayboxGateway\Responses\Verify::class);
97+
try {
98+
$success = $payboxVerify->isSuccess($payment->amount);
99+
if ($success) {
100+
// process order here after making sure it was real payment
101+
}
102+
echo "OK";
103+
}
104+
catch (InvalidSignature $e) {
105+
Log::alert('Invalid payment signature detected');
106+
}
107+
```
108+
109+
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).
110+
111+
#### Capturing previously authorized request
112+
113+
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).
114+
115+
The simplest code could look like this:
116+
117+
```php
118+
$payment = PaymentModel::find($idOfAuthorizedPayment);
119+
$captureRequest = \App::make(\Devpark\PayboxGateway\Requests\Capture::class);
120+
$response = $captureRequest->setAmount($payment->amount)
121+
->setPayboxCallNumber($payment->call_number)
122+
->setPayboxTransactionNumber($payment->transaction_number)
123+
->setDayRequestNumber(2)
124+
->send();
125+
126+
if ($response->isSuccess()) {
127+
// process order here
128+
}
129+
```
130+
131+
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.
132+
133+
### Licence
134+
135+
This package is licenced under the [MIT license](http://opensource.org/licenses/MIT)

0 commit comments

Comments
 (0)