Skip to content

Commit

Permalink
Fix static analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
arti0090 committed Sep 11, 2024
1 parent ddf63ec commit 69bc7fd
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 18 deletions.
3 changes: 2 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
parameters:
level: max
reportUnmatchedIgnoredErrors: false
checkMissingIterableValueType: false
paths:
- src

Expand All @@ -11,6 +10,8 @@ parameters:
- 'tests/Application/src/**.php'

ignoreErrors:
- identifier: missingType.iterableValue
- identifier: missingType.generics
- '/Parameter #1 \$configuration of method Symfony\\Component\\DependencyInjection\\Extension\\Extension::processConfiguration\(\) expects Symfony\\Component\\Config\\Definition\\ConfigurationInterface, Symfony\\Component\\Config\\Definition\\ConfigurationInterface\|null given\./'
- '/Parameter \#1 \$request \([^)]+\) of method [^:]+::execute\(\) should be contravariant with parameter \$request \(mixed\) of method Payum\\Core\\Action\\ActionInterface::execute\(\)/'
- '/Parameter \$event of method CommerceWeavers\\SyliusTpayPlugin\\Refunding\\Workflow\\Listener\\DispatchRefundListener::__invoke\(\) has invalid type Symfony\\Component\\Workflow\\Event\\TransitionEvent\./'
Expand Down
7 changes: 5 additions & 2 deletions src/Form/DataTransformer/PaymentDetailsTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,20 @@
namespace CommerceWeavers\SyliusTpayPlugin\Form\DataTransformer;

use Symfony\Component\Form\DataTransformerInterface;
use Webmozart\Assert\Assert;

class PaymentDetailsTransformer implements DataTransformerInterface
{
public function transform($value): string
public function transform(mixed $value): string
{
if (!$value || !array_key_exists('blik', $value)) {
Assert::isArray($value);
if ($value === [] || !array_key_exists('blik', $value)) {
return '';
}

return $value['blik'];
}

public function reverseTransform($value): array
{
return ['blik' => $value];
Expand Down
15 changes: 12 additions & 3 deletions src/Payum/Action/Api/CreateBlik0TransactionAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Routing\RouterInterface;
use Tpay\OpenApi\Api\TpayApi;
use Webmozart\Assert\Assert;

/**
* @property TpayApi $api
Expand All @@ -21,7 +22,7 @@ final class CreateBlik0TransactionAction extends BaseApiAwareAction implements G
{
use GenericTokenFactoryAwareTrait;

public function __construct (
public function __construct(
private RouterInterface $router,
private string $successRoute,
private string $errorRoute,
Expand All @@ -38,17 +39,25 @@ public function execute($request): void
/** @var PaymentInterface $model */
$model = $request->getModel();
$details = $model->getDetails();
$token = $request->getToken();
Assert::notNull($token);

$order = $model->getOrder();
Assert::notNull($order);
$customer = $order->getCustomer();
Assert::notNull($customer);
$localeCode = $order->getLocaleCode();
Assert::notNull($localeCode);
$billingAddress = $order->getBillingAddress();
$notifyToken = $this->createNotifyToken($model, $request->getToken(), $localeCode);
Assert::notNull($billingAddress);
$notifyToken = $this->createNotifyToken($model, $token, $localeCode);
$amount = $model->getAmount();
Assert::notNull($amount);

$blikToken = $model->getDetails()['tpay']['blik'];

$response = $this->api->transactions()->createTransaction([
'amount' => number_format($model->getAmount() / 100, 2, thousands_separator: ''),
'amount' => number_format($amount / 100, 2, thousands_separator: ''),
'description' => sprintf('zamówienie #%s', $order->getNumber()), // TODO: Introduce translations
'payer' => [
'email' => $customer->getEmail(),
Expand Down
9 changes: 4 additions & 5 deletions src/Payum/Action/CaptureAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace CommerceWeavers\SyliusTpayPlugin\Payum\Action;

use CommerceWeavers\SyliusTpayPlugin\Payum\Factory\CreateBlik0TransactionFactory;
use CommerceWeavers\SyliusTpayPlugin\Payum\Factory\CreateTransactionFactoryInterface;
use Payum\Core\Action\ActionInterface;
use Payum\Core\GatewayAwareInterface;
Expand Down Expand Up @@ -33,7 +32,7 @@ public function execute($request): void

if ($this->transactionIsBlik($model)) {
$this->gateway->execute(
$this->createBlik0TransactionFactory->createNewWithModel($request->getToken())
$this->createBlik0TransactionFactory->createNewWithModel($request->getToken()),
);

return;
Expand All @@ -53,10 +52,10 @@ public function supports($request): bool
return $request instanceof Capture && $request->getModel() instanceof PaymentInterface;
}

private function transactionIsBlik($model): bool
private function transactionIsBlik(PaymentInterface $model): bool
{
return array_key_exists('tpay', $model->getDetails())
&& array_key_exists('blik', $model->getDetails()['tpay'])
return array_key_exists('tpay', $model->getDetails()) &&
array_key_exists('blik', $model->getDetails()['tpay'])
;
}
}
8 changes: 1 addition & 7 deletions src/Payum/Request/Api/CreateBlik0Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,9 @@

class CreateBlik0Transaction extends Generic
{
public function __construct (
private string $afterUrl,
public function __construct(
mixed $model,
) {
parent::__construct($model);
}

public function getAfterUrl(): string
{
return $this->afterUrl;
}
}

0 comments on commit 69bc7fd

Please sign in to comment.