Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 39 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Cubes Nestpay

Nestpay E-commerce integration, shipped with Laravel Package

[![Latest Stable Version](https://poser.pugx.org/cubes-doo/nestpay/v/stable)](https://packagist.org/packages/cubes-doo/nestpay) [![Total Downloads](https://poser.pugx.org/cubes-doo/nestpay/downloads)](https://packagist.org/packages/cubes-doo/nestpay) [![License](https://poser.pugx.org/cubes-doo/nestpay/license)](https://packagist.org/packages/cubes-doo/nestpay)
Expand All @@ -22,8 +23,7 @@ You could create table by importing example SQL script:
mysql -u root -p your_db_name < vendor/cubes-doo/nestpay/resources/nestpay_payments.sql
```

*If you are using Laravel there is a ready to use migration (see documentation below)

\*If you are using Laravel there is a ready to use migration (see documentation below)

### Bootstrap & Configuration

Expand Down Expand Up @@ -52,14 +52,12 @@ $nestpayMerchantService = new MerchantService([

```


Setup the connection to the database by using existing PDO instance

```php
$nestpayMerchantService->setPDO($pdo); //$pdo is instanceof \PDO
```


If you want to have some other name for the **nestpay_payments** table, something you should pass another parameter

```php
Expand Down Expand Up @@ -98,14 +96,15 @@ For that reason it is important to write your logic, like sending email or chang
### Usage

#### The confirmation page

You should have confirmation page from which customers are redirected to the bank card processor page.

That page should have form with lots of hidden paramters.

Use **\Cubes\Nestpay\MerchantService::paymentMakeRequestParameters** method to generate necessary parameters (the HASH parameter and other necessary parameters)

```php
<?php
<?php

$requestParameters = $nestpayMerchantService->paymentMakeRequestParameters([
'amount' => 123.45,
Expand All @@ -115,7 +114,7 @@ $requestParameters = $nestpayMerchantService->paymentMakeRequestParameters([
\Cubes\Nestpay\Payment::PROP_TRANTYPE => \Cubes\Nestpay\Payment::TRAN_TYPE_PREAUTH,
//this is email of the customer
\Cubes\Nestpay\Payment::PROP_EMAIL => '[email protected]',

//below are optional parameters
\Cubes\Nestpay\Payment::PROP_INVOICENUMBER => '123456789', //must be numeric!!
\Cubes\Nestpay\Payment::PROP_BILLTONAME => 'John Doe',\Cubes\Nestpay\Payment::PROP_BILLTOSTREET1 => 'BillToStreet1',
Expand Down Expand Up @@ -168,7 +167,7 @@ After submitting this form customer is redirected to 3D gate bank card processin

After entering Card details, customer is redirected back to your website on success or fail url.

You should call **\Cubes\Nestpay\MerchantService::paymentProcess3DGateResponse** method to process $_POST parameters.
You should call **\Cubes\Nestpay\MerchantService::paymentProcess3DGateResponse** method to process $\_POST parameters.

On success page:

Expand All @@ -189,7 +188,7 @@ On fail page:
```php
<?php
//second parameter (true) indicates that this processing is on fail url
$payment = $nestpayMerchantService->paymentProcess3DGateResponse($_POST, true);
$payment = $nestpayMerchantService->paymentProcess3DGateResponse($_POST, true);

//display resultsu of the payment:
?>
Expand All @@ -206,7 +205,7 @@ You should use **\Cubes\Nestpay\MerchantService::paymentProcessOverNestpayApi**

```php
//$oid is the OID of some unprocessed payment (WHERE `processed` != 1)
$payment = $nestpayMerchantService->paymentProcessOverNestpayApi($oid);
$payment = $nestpayMerchantService->paymentProcessOverNestpayApi($oid);

//DO NOT SEND EMAIL HERE OR DO SOME ACTION ON SUCCESSFUL PAYMENT!
//USE $nestpayMerchantService->onSuccessfulPayment INSTEAD!!!
Expand All @@ -221,23 +220,24 @@ Use **\Cubes\Nestpay\MerchantService::postAuthorizationOverNestpayApi**

```php
//$oid is the OID of the payment
$result = $nestpayMerchantService->postAuthorizationOverNestpayApi($oid);
$result = $nestpayMerchantService->postAuthorizationOverNestpayApi($oid);
```

If you DO NOT want to capture entire amount, pass second parameter.

```php
//$oid is the OID of the payment
//$amount should not be greated than the orginal amount reserved in PreAuth
$result = $nestpayMerchantService->postAuthorizationOverNestpayApi($oid, $amount);
$result = $nestpayMerchantService->postAuthorizationOverNestpayApi($oid, $amount);
```

#### Void payment over API
#### Void payment over API

To void payment use **\Cubes\Nestpay\MerchantService::voidOverNestpayApi**

```php
//$oid is the OID of the payment
$result = $nestpayMerchantService->voidOverNestpayApi($oid);
$result = $nestpayMerchantService->voidOverNestpayApi($oid);
```

### Get working payment
Expand All @@ -246,7 +246,7 @@ If you want to get the last processed payment use **\Cubes\Nestpay\MerchantServi

```php

//$payment is instance of \Cubes\Nestpay\Payment
//$payment is instance of \Cubes\Nestpay\Payment
$payment = $nestpayMerchantService->getWorkingPayment();

//get some of the payment properties
Expand All @@ -257,7 +257,6 @@ $email = $payment->getEmail();

```


### Customize saving payment information

If you prefer some other method to store payments, you should create "Data Access Object" class of your own.
Expand All @@ -271,18 +270,18 @@ class MyPaymentDao implements PaymentDao
{
/**
* Fetch payment by $oid
*
*
* @return \Cubes\Nestpay\Payment
* @param scalar $oid
*/
public function getPayment($oid)
{
//return payment by oid
}

/**
* Saves the payment
*
*
* @param \Cubes\Nestpay\Payment $payment
* @return \Cubes\Nestpay\Payment
*/
Expand Down Expand Up @@ -315,14 +314,15 @@ $nestpayMerchantService->setPaymentDao(new MyPaymentDao());
Package `cubes-doo/nestpay` comes with built Laravel package.

Service provider class is **\Cubes\Nestpay\Laravel\NestpayServiceProvider**.

###### If you are using Laravel version < 5.5 you must include service provider manually

```php
<?php
//THIS IS config/app.php

return [

//got to providers key
// ...

Expand All @@ -341,14 +341,17 @@ return [
```

Before using the \Cubes\Nestpay\MerchantService class you should **edit your .env file**:

```shell
#add this to your .env file and set you clientID storeKey etc
NESTPAY_MERCHANT_CLIENT_ID=********
NESTPAY_MERCHANT_STORE_KEY=********
NESTPAY_MERCHANT_3DGATE_URL=https://testsecurepay.eway2pay.com/fim/est3Dgate
NESTPAY_MERCHANT_3D_GATE_URL=https://testsecurepay.eway2pay.com/fim/est3Dgate
NESTPAY_MERCHANT_STORE_TYPE=3D_PAY_HOSTING
NESTPAY_MERCHANT_API_NAME=*******
NESTPAY_MERCHANT_API_PASSWORD=*******
NESTPAY_MERCHANT_API_ENDPOINT_URL=https://testsecurepay.eway2pay.com/fim/api

```

The package provides **\Cubes\Nestpay\MerchantService** class which could be injected in controllers and other points in Laravel application:
Expand Down Expand Up @@ -402,14 +405,16 @@ php artisan vendor:publish --provider="Cubes\\Nestpay\\Laravel\\NestpayServicePr
//file: config/nestpay.php
return [
'merchant' => [/* the mercant configuration*/],

//change this if you want to use some other class for payment model
//Object of paymentModel class is going to be returned when calling MerchantService::getWorkingPayment
'paymentModel' => \App\Models\NestpayPayment::class
'paymentModel' => \App\Models\NestpayPayment::class
//...
];
```

3. Add Nestpay routes among others

```php
//file: routes/web.php

Expand All @@ -421,13 +426,14 @@ return [

```php
//file: app/Providers/EventServiceProvider.php

use App\Listeners\NestpayEventsSubscriber;
protected $subscribe = [
'App\Listeners\NestpayEventsSubscriber',
NestpayEventsSubscriber::class,
];
```

5. Customize published migration for `nestpay_payment` table

```php
//file: database/migrations/2020_03_27_144802_create_nestpay_payments_table.php

Expand Down Expand Up @@ -461,9 +467,10 @@ class NestpayPayment extends Model
//DO NOT REMOVE ANY FILLABLES JUST ADD NEW ONE FOOUR APPLICATION
'processed',
'oid',
'trantype',
'trantype',
//...
```

7. Customize controller **\App\Http\Controllers\NestpayController**

```php
Expand Down Expand Up @@ -508,12 +515,12 @@ class VerifyCsrfToken extends Middleware
8. Customize view scripts

```
resources
resources
└───views
│ │
│ └───vendor
│ │
│ │
│ │───nestpay
│ | │
│ | │ confirm.blade.php
Expand All @@ -531,7 +538,7 @@ class Kernel extends ConsoleKernel
{
//...


protected function schedule(Schedule $schedule)
{
//...
Expand All @@ -540,9 +547,10 @@ class Kernel extends ConsoleKernel

//...
```
10. Customize listener **\App\Listeners\NestpayEventsSubscriber**

**IMPORTANT NOTICE!!!**
10. Customize listener **\App\Listeners\NestpayEventsSubscriber**

**IMPORTANT NOTICE!!!**

THIS IS THE MOST IMPORTANT CUSTOMIZATION!!!

Expand All @@ -551,7 +559,7 @@ When payment is processed (eather over NestpayController or nestpay::handle-unpr
- \Cubes\Nestpay\Laravel\NestpayPaymentProcessedSuccessfullyEvent - for successful payments
- \Cubes\Nestpay\Laravel\NestpayPaymentProcessedFailedEvent - for failed events

At this point you should have the published event subscriber **\App\Listeners\NestpayEventsSubscriber** which is configured to listen to those events.
At this point you should have the published event subscriber **\App\Listeners\NestpayEventsSubscriber** which is configured to listen to those events.

The class has logic for sending necessary mail to the customer, all you have to do is add logic when payment has been successfull (when custmer HAS PAID)

Expand Down Expand Up @@ -579,4 +587,3 @@ class NestpayEventsSubscriber

//...
```

9 changes: 5 additions & 4 deletions src/Laravel/Facade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Cubes\Nestpay\Laravel;

use App\Http\Controllers\NestpayController;
use Illuminate\Support\Facades\Facade as BaseFacade;

class Facade extends BaseFacade
Expand All @@ -14,10 +15,10 @@ protected static function getFacadeAccessor()
public static function routes()
{
\Route::prefix('/nestpay')->group(function () {
\Route::get('/confirm', 'NestpayController@confirment')->name('nestpay.confirment');
\Route::post('/confirm', 'NestpayController@confirm')->name('nestpay.confirm');
\Route::post('/success', 'NestpayController@success')->name('nestpay.success');
\Route::post('/fail', 'NestpayController@fail')->name('nestpay.fail');
\Route::get('/confirm', NestpayController::class, 'confirment')->name('nestpay.confirment');
\Route::post('/confirm', NestpayController::class, 'confirm')->name('nestpay.confirm');
\Route::post('/success', NestpayController::class, 'success')->name('nestpay.success');
\Route::post('/fail', NestpayController::class, 'fail')->name('nestpay.fail');
});
}
}
Loading