Skip to content

Commit

Permalink
Merge pull request #5 from rawahamid/change-fib-classname
Browse files Browse the repository at this point in the history
Rename FIB class
  • Loading branch information
rawahamid authored Sep 12, 2023
2 parents 846a185 + 4bece36 commit 4255718
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ yarn-error.log
/.fleet
/.idea
/.vscode
composer.lock
7 changes: 5 additions & 2 deletions src/FIB.php → src/Fib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Rawahamid\FibIntegration;

use Illuminate\Http\JsonResponse;
use Symfony\Component\CssSelector\Exception\InternalErrorException;
use Symfony\Component\HttpFoundation\Response;

class Fib
{
Expand All @@ -15,10 +15,13 @@ protected static function baseUrl(): string
};
}

/**
* @throws InternalErrorException
*/
protected static function checkResponse($response, $message = 'Internal Server Error')
{
if ($response->failed()) {
throw new InternalErrorException($message, JsonResponse::HTTP_INTERNAL_SERVER_ERROR);
throw new InternalErrorException($message, Response::HTTP_INTERNAL_SERVER_ERROR);
}

return $response->json();
Expand Down
13 changes: 13 additions & 0 deletions src/Payments/FibPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
use Illuminate\Support\Facades\Http;
use Rawahamid\FibIntegration\Fib;
use Rawahamid\FibIntegration\Interfaces\PaymentInterface;
use Symfony\Component\CssSelector\Exception\InternalErrorException;

class FibPayment extends Fib implements PaymentInterface
{
/**
* @throws InternalErrorException
*/
public static function authenticate()
{
$response = Http::asForm()->post(self::baseUrl() . '/auth/realms/fib-online-shop/protocol/openid-connect/token', [
Expand All @@ -19,6 +23,9 @@ public static function authenticate()
return self::checkResponse($response, 'Payment Creation Failed');
}

/**
* @throws InternalErrorException
*/
public static function create($amount, $description = '')
{
$description = self::trimDescription($description);
Expand All @@ -36,6 +43,9 @@ public static function create($amount, $description = '')
return self::checkResponse($response, 'Payment Creation Failed');
}

/**
* @throws InternalErrorException
*/
public static function cancel($paymentId)
{
$response = Http::withToken(self::authenticate()['access_token'])
Expand All @@ -44,6 +54,9 @@ public static function cancel($paymentId)
return self::checkResponse($response, 'Cancel Payment Failed');
}

/**
* @throws InternalErrorException
*/
public static function status($paymentId)
{
$response = Http::withToken(self::authenticate()['access_token'])
Expand Down

0 comments on commit 4255718

Please sign in to comment.