Skip to content

Commit

Permalink
style: code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
aarongerig committed Mar 7, 2024
1 parent e2303ad commit 02ae4e6
Show file tree
Hide file tree
Showing 13 changed files with 105 additions and 109 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"require": {
"php": ">=7.4",
"payum/core": "^1.7",
"php-http/guzzle6-adapter": "^2.0",
"payrexx/payrexx": "^1.8"
},
"autoload": {
Expand Down
21 changes: 11 additions & 10 deletions src/Action/Api/CaptureOffsiteAction.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

declare(strict_types=1);

/**
* @author Miguel Gomes
*
* instride AG
*
* LICENSE
Expand All @@ -13,18 +13,16 @@
* @copyright 2024 instride AG (https://instride.ch)
*/

declare(strict_types=1);

namespace Instride\Payum\Payrexx\Action\Api;

use Instride\Payum\Payrexx\Api;
use Instride\Payum\Payrexx\Request\Api\CaptureOffsite;
use Payum\Core\Action\ActionInterface;
use Payum\Core\ApiAwareInterface;
use Payum\Core\ApiAwareTrait;
use Payum\Core\Bridge\Spl\ArrayObject;
use Payum\Core\Exception\RequestNotSupportedException;
use Payum\Core\Reply\HttpRedirect;
use Instride\Payum\Payrexx\Api;
use Instride\Payum\Payrexx\Request\Api\CaptureOffsite;

class CaptureOffsiteAction implements ActionInterface, ApiAwareInterface
{
Expand All @@ -41,9 +39,8 @@ public function __construct()
public function execute($request)
{
RequestNotSupportedException::assertSupports($this, $request);
throw new HttpRedirect(
$this->api->getAfterLink()
);

throw new HttpRedirect($this->api->getAfterLink());
}

public function supports($request): bool
Expand All @@ -55,6 +52,10 @@ public function supports($request): bool
if (!$request->getModel() instanceof \ArrayAccess) {
return false;
}
return array_key_exists('gateway_id', ArrayObject::ensureArrayObject($request->getModel())->toUnsafeArray());

return \array_key_exists(
'gateway_id',
ArrayObject::ensureArrayObject($request->getModel())->toUnsafeArray()
);
}
}
17 changes: 7 additions & 10 deletions src/Action/Api/CreateTransactionAction.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

declare(strict_types=1);

/**
* @author Miguel Gomes
*
* instride AG
*
* LICENSE
Expand All @@ -13,19 +13,16 @@
* @copyright 2024 instride AG (https://instride.ch)
*/


declare(strict_types=1);

namespace Instride\Payum\Payrexx\Action\Api;

use Instride\Payum\Payrexx\Api;
use Instride\Payum\Payrexx\Request\Api\CreateTransaction;
use Payrexx\Models\Request\Transaction;
use Payum\Core\Action\ActionInterface;
use Payum\Core\ApiAwareInterface;
use Payum\Core\ApiAwareTrait;
use Payum\Core\Bridge\Spl\ArrayObject;
use Payum\Core\Exception\RequestNotSupportedException;
use Instride\Payum\Payrexx\Api;
use Instride\Payum\Payrexx\Request\Api\CreateTransaction;

class CreateTransactionAction implements ActionInterface, ApiAwareInterface
{
Expand All @@ -43,6 +40,7 @@ public function execute($request)
{
RequestNotSupportedException::assertSupports($this, $request);
$model = ArrayObject::ensureArrayObject($request->getModel());

try {
$returnUrl = $request->getToken()->getAfterUrl();
$tokenHash = $request->getToken()->getHash();
Expand All @@ -57,8 +55,7 @@ public function execute($request)

public function supports($request): bool
{
return
$request instanceof CreateTransaction &&
$request->getModel() instanceof \ArrayAccess;
return $request instanceof CreateTransaction
&& $request->getModel() instanceof \ArrayAccess;
}
}
13 changes: 6 additions & 7 deletions src/Action/CaptureAction.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

declare(strict_types=1);

/**
* @author Miguel Gomes
*
* instride AG
*
* LICENSE
Expand All @@ -13,19 +13,17 @@
* @copyright 2024 instride AG (https://instride.ch)
*/

declare(strict_types=1);

namespace Instride\Payum\Payrexx\Action;

use Instride\Payum\Payrexx\Request\Api\CaptureOffsite;
use Instride\Payum\Payrexx\Request\Api\CreateTransaction;
use Payum\Core\Action\ActionInterface;
use Payum\Core\Bridge\Spl\ArrayObject;
use Payum\Core\Exception\RequestNotSupportedException;
use Payum\Core\GatewayAwareInterface;
use Payum\Core\GatewayAwareTrait;
use Payum\Core\Request\Capture;
use Payum\Core\Request\GetHttpRequest;
use Instride\Payum\Payrexx\Request\Api\CaptureOffsite;
use Instride\Payum\Payrexx\Request\Api\CreateTransaction;

class CaptureAction implements ActionInterface, GatewayAwareInterface
{
Expand All @@ -42,8 +40,9 @@ public function execute($request)

$this->gateway->execute($httpRequest = new GetHttpRequest());

if (array_key_exists('redirect_status', $httpRequest->query)) {
if (\array_key_exists('redirect_status', $httpRequest->query)) {
$model->replace($httpRequest->query);

return;
}

Expand Down
14 changes: 6 additions & 8 deletions src/Action/ConvertPaymentAction.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

declare(strict_types=1);

/**
* @author Miguel Gomes
*
* instride AG
*
* LICENSE
Expand All @@ -13,8 +13,6 @@
* @copyright 2024 instride AG (https://instride.ch)
*/

declare(strict_types=1);

namespace Instride\Payum\Payrexx\Action;

use Payum\Core\Action\ActionInterface;
Expand All @@ -40,6 +38,7 @@ public function execute($request)
$details['surname'] = $customer->getLastname();
$details['company'] = $customer->getCompany();
$address = $customer->getDefaultAddress();

if ($address) {
$details['street'] = $address->getCompany() . ' ' . $address->getNumber();
$details['postcode'] = $address->getPostcode();
Expand All @@ -53,13 +52,12 @@ public function execute($request)
$details['amount'] = $payment->getTotalAmount();
$details['description'] = $payment->getDescription();

$request->setResult((array)$details);
$request->setResult((array) $details);
}

public function supports($request): bool
{
return
$request instanceof Convert &&
$request->getSource() instanceof PaymentInterface;
return $request instanceof Convert
&& $request->getSource() instanceof PaymentInterface;
}
}
8 changes: 3 additions & 5 deletions src/Action/NotifyAction.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

declare(strict_types=1);

/**
* @author Miguel Gomes
*
* instride AG
*
* LICENSE
Expand All @@ -13,16 +13,14 @@
* @copyright 2024 instride AG (https://instride.ch)
*/

declare(strict_types=1);

namespace Instride\Payum\Payrexx\Action;

use Instride\Payum\Payrexx\Request\GetHumanStatus;
use Payum\Core\Action\ActionInterface;
use Payum\Core\Exception\RequestNotSupportedException;
use Payum\Core\GatewayAwareInterface;
use Payum\Core\GatewayAwareTrait;
use Payum\Core\Request\Notify;
use Instride\Payum\Payrexx\Request\GetHumanStatus;

class NotifyAction implements ActionInterface, GatewayAwareInterface
{
Expand Down
30 changes: 18 additions & 12 deletions src/Action/NotifyNullAction.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

declare(strict_types=1);

/**
* @author Miguel Gomes
*
* instride AG
*
* LICENSE
Expand All @@ -13,13 +13,12 @@
* @copyright 2024 instride AG (https://instride.ch)
*/

declare(strict_types=1);

namespace Instride\Payum\Payrexx\Action;

use Instride\Payum\Payrexx\Api;
use Payrexx\Models\Request\Transaction;
use Payrexx\PayrexxException;
use Payum\Core\Request\Notify;
use Instride\Payum\Payrexx\Api;
use Payum\Core\Action\ActionInterface;
use Payum\Core\ApiAwareInterface;
use Payum\Core\ApiAwareTrait;
Expand Down Expand Up @@ -58,13 +57,13 @@ public function execute($request): void
return;
}

$transaction = new \Payrexx\Models\Request\Transaction();
$transaction = new Transaction();
$id = $parsedBody['transaction']['id'];
$transaction->setId($id);

try {
$transaction = $this->api->getApi()->getOne($transaction);
} catch (\Payrexx\PayrexxException $e) {
} catch (PayrexxException $e) {
return;
}

Expand All @@ -75,11 +74,19 @@ public function execute($request): void
$tokenHash = $parsedBody['transaction']['invoice']['paymentLink']['hash'] ?? null;

} catch (\Throwable $e) {
throw new HttpResponse($e->getMessage(), 500, ['Content-Type' => 'text/plain', 'X-Notify-Message' => $e->getMessage()]);
throw new HttpResponse(
$e->getMessage(),
500,
['Content-Type' => 'text/plain', 'X-Notify-Message' => $e->getMessage()]
);
}

if ($tokenHash === null) {
throw new HttpResponse('OK', 200, ['Content-Type' => 'text/plain', 'X-Notify-Message' => 'NO_TOKEN_HASH_FOUND']);
throw new HttpResponse(
'OK',
200,
['Content-Type' => 'text/plain', 'X-Notify-Message' => 'NO_TOKEN_HASH_FOUND']
);
}

try {
Expand All @@ -96,8 +103,7 @@ public function execute($request): void
*/
public function supports($request): bool
{
return
$request instanceof Notify &&
$request->getModel() === null;
return $request instanceof Notify
&& $request->getModel() === null;
}
}
16 changes: 8 additions & 8 deletions src/Action/StatusAction.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

declare(strict_types=1);

/**
* @author Miguel Gomes
*
* instride AG
*
* LICENSE
Expand All @@ -13,18 +13,16 @@
* @copyright 2024 instride AG (https://instride.ch)
*/

declare(strict_types=1);

namespace Instride\Payum\Payrexx\Action;

use Instride\Payum\Payrexx\Api;
use Instride\Payum\Payrexx\Request\GetHumanStatus;
use Payrexx\Models\Request\Transaction;
use Payum\Core\Action\ActionInterface;
use Payum\Core\ApiAwareInterface;
use Payum\Core\ApiAwareTrait;
use Payum\Core\Exception\RequestNotSupportedException;
use Payum\Core\Request\GetStatusInterface;
use Instride\Payum\Payrexx\Api;
use Instride\Payum\Payrexx\Request\GetHumanStatus;

class StatusAction implements ActionInterface, ApiAwareInterface
{
Expand All @@ -43,14 +41,15 @@ public function execute($request)
RequestNotSupportedException::assertSupports($this, $request);
$model = $request->getModel();


if (array_key_exists('gateway_id', $model)) {
if (\array_key_exists('gateway_id', $model)) {
if ($model['gateway_id'] === null) {
$request->markNew();

return;
}
} else {
$request->markNew();

return;
}

Expand All @@ -59,6 +58,7 @@ public function execute($request)

if (!$transaction instanceof Transaction) {
$request->markUnknown();

return;
}

Expand Down
Loading

0 comments on commit 02ae4e6

Please sign in to comment.