Skip to content

Commit

Permalink
handle errors from get request
Browse files Browse the repository at this point in the history
  • Loading branch information
aemaddin committed Dec 3, 2019
1 parent 072fded commit 8628318
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 21 deletions.
2 changes: 1 addition & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
use Illuminate\Support\Facades\Route;

Route::post('/response', 'KnetController@handleKnet')->name('response');
Route::post('/error', 'KnetController@error')->name('error');
Route::get('/error', 'KnetController@error')->name('error');
15 changes: 15 additions & 0 deletions src/Http/Controllers/KnetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,19 @@ protected function missingMethod($parameters = [])
{
return new Response;
}

public function error(Request $request)
{
KnetResponseReceived::dispatch($request->all());

$knetResponseHandler = new KnetResponseHandler();

// update transaction
KnetTransaction::findByTrackId($request->input('trackid'))
->update($knetResponseHandler->toArray());

if ($knetResponseHandler->hasErrors()) {
throw new KnetException($knetResponseHandler->error());
}
}
}
6 changes: 6 additions & 0 deletions src/KnetResponseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ public function __construct()
}
}
} else {
$this->result['error_text'] = request('ErrorText');
$this->result['error'] = request('Error');
$this->result['paymentid'] = request('paymentid');
$this->result['avr'] = request('avr');
$this->result['result'] = 'FAILED';

$this->error = request('ErrorText');
$this->error_code = request('Error');
}
Expand Down
20 changes: 0 additions & 20 deletions src/KnetResponseSignature.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,8 @@

abstract class KnetResponseSignature
{
const EXPECTED_REFERER = 'https://kpaytest.com.kw/kpg/paymentrouter.htm';

public static function verifyHeader($payload, $header, $trackid)
{
$referer = $header['referer'][0];

if (empty($referer)) {
throw SignatureVerificationException::factory(
"No referer found with expected scheme",
$payload,
$header
);
}

if ($referer != self::EXPECTED_REFERER) {
throw SignatureVerificationException::factory(
"No referer found matching the expected referer for payload",
$payload,
$header
);
}

if (KnetTransaction::findByTrackId($trackid) == null) {
throw SignatureVerificationException::factory(
"No trackid found matching the expected",
Expand Down

0 comments on commit 8628318

Please sign in to comment.