Skip to content

Commit

Permalink
Update middleware update routes update readme file
Browse files Browse the repository at this point in the history
  • Loading branch information
zoranbogoevski committed Nov 16, 2023
1 parent 4c4fe28 commit 762c3c0
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ Follow these steps to install the package:
```
php artisan vendor:publish --provider="Kalimeromk\HalkbankPayment\HalkBankPaymentServiceProvider"
```

## Middleware
Pls register CsrfExemptMiddleware in the Kernel of laravel app
## Configure the Package
Edit the published config/payment.php with your Halkbank credentials and settings.
Usage
Expand Down
8 changes: 6 additions & 2 deletions src/Config/payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@
'store_type' => env('PAYMENT_STORE_TYPE', '3D_PAY_HOSTING'),
'currency' => env('PAYMENT_CURRENCY', '807'),
'transaction_type' => env('PAYMENT_TRANSACTION_TYPE', 'Auth'),
'ok_url' => env('PAYMENT_OK_URL', 'http://localhost:87/payment/success'),
'fail_url' => env('PAYMENT_FAIL_URL', 'http://localhost:87/payment/fail'),
'ok_url' => env('PAYMENT_OK_URL', 'http://localhost:8080/payment/success'),
'fail_url' => env('PAYMENT_FAIL_URL', 'http://localhost:8080/payment/fail'),
'lang' => env('PAYMENT_LANG', 'en'),
'layout' => env('PAYMENT_LAYOUT', 'layouts.app'),
'exempt_uris' => [
'payment/success',
'payment/fail',
]
];
24 changes: 16 additions & 8 deletions src/Middleware/CsrfExemptMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,17 @@ class CsrfExemptMiddleware extends BaseVerifier
*
* @var array
*/
protected $except = [
'payment-success',
'payment-fail',
];
protected $except;

/**
* Create a new middleware instance.
*
* @return void
*/
public function __construct()
{
$this->except = config('csrf_exempt.exempt_uris', []);
}

/**
* Handle an incoming request.
Expand All @@ -27,16 +34,17 @@ class CsrfExemptMiddleware extends BaseVerifier
* @return mixed
* @throws TokenMismatchException
*/
public function handle($request, Closure $next): mixed
public function handle($request, Closure $next)
{
// Iterate through the $except array to see if the request URI matches any patterns
// Check if the request URI matches any patterns in the $except array
foreach ($this->except as $route) {
if ($request->is($route)) {
// If a match is found, bypass CSRF verification
return $next($request);
}
}

// If none match, perform the regular CSRF check
// If no match is found, perform the regular CSRF check
return parent::handle($request, $next);
}
}
}
2 changes: 1 addition & 1 deletion src/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
Route::get('/{amount}', [PaymentController::class, 'showPaymentForm'])->name('payment.form');
Route::post('/', [PaymentController::class, 'showPaymentForm'])->name('payment.post');
Route::post('success', [PaymentController::class, 'paymentSuccess'])->name('payment.success')->middleware('csrf_exempt');
Route::post('fail', [PaymentController::class, 'paymentFail'])->name('payment.fail')->middleware('csrf_exempt');
Route::post('fail', [PaymentController::class, 'paymentFail'])->name('payment.fail')->middleware(['csrf_exempt']);
});

0 comments on commit 762c3c0

Please sign in to comment.