Skip to content

Commit 186258e

Browse files
committed
convert bad response come from hyperpay to a validationException
1 parent 5d66e8d commit 186258e

File tree

3 files changed

+21
-16
lines changed

3 files changed

+21
-16
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ build
22
composer.lock
33
docs
44
vendor
5-
coverage
5+
coverage
6+
.vscode/*

.vscode/launch.json

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/Support/HttpResponse.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use GuzzleHttp\Psr7\Response;
88
use Illuminate\Database\Eloquent\Model;
99
use Illuminate\Support\Arr;
10+
use Illuminate\Validation\ValidationException;
1011

1112
final class HttpResponse
1213
{
@@ -66,6 +67,8 @@ public function __construct(Response $response, ?Model $transaction = null, ?arr
6667
$this->transaction = $transaction;
6768

6869
$this->optionsData = $optionsData;
70+
71+
$this->checkResultStatus();
6972
}
7073

7174
/**
@@ -233,4 +236,20 @@ protected function updateTransaction($status, array $optionData)
233236
)));
234237
}
235238
}
239+
240+
241+
/**
242+
* Check the response status get it from hyperpay
243+
* if bad convert it to the ValidationException
244+
*
245+
* @return mixed
246+
*/
247+
protected function checkResultStatus()
248+
{
249+
if ($this->status() == 400) {
250+
throw ValidationException::withMessages($this->response());
251+
}
252+
253+
return $this;
254+
}
236255
}

0 commit comments

Comments
 (0)