Skip to content
This repository has been archived by the owner on Mar 15, 2024. It is now read-only.

Commit

Permalink
Add missing typehints (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
kubawerlos committed Aug 21, 2023
1 parent cd837dd commit ff0b608
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 36 deletions.
4 changes: 2 additions & 2 deletions .dev-tools/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"kubawerlos/composer-smaller-lock": "^1.0.1",
"kubawerlos/php-cs-fixer-custom-fixers": "^3.16.2",
"magento/magento2ce": "^2.4",
"php-cs-fixer/shim": "^3.22",
"phpstan/phpstan": "^1.10.28",
"php-cs-fixer/shim": "^3.23",
"phpstan/phpstan": "^1.10.29",
"tpay-com/tpay-php": "^2.3.4",
"vimeo/psalm": "^5.14.1"
},
Expand Down
58 changes: 31 additions & 27 deletions .dev-tools/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .dev-tools/phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
parameters:
level: 0
level: 1
paths:
- ../
excludePaths:
Expand Down
20 changes: 19 additions & 1 deletion Controller/tpaycards/CardPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class CardPayment extends Action
private $cardTransactionFactory;
private $registry;
private $modelContext;

/** @var TpayTokensService */
private $tokensService;

/**
Expand Down Expand Up @@ -96,10 +98,15 @@ public function __construct(
*/
public function execute()
{
/** @var int $orderId */
$orderId = $this->checkoutSession->getLastRealOrderId();

if ($orderId) {
$payment = $this->tpayService->getPayment($orderId);

/** @var array<string> $paymentData */
$paymentData = $payment->getData();

$this->tpayService->setOrderStatePendingPayment($orderId);
$additionalPaymentInformation = $paymentData['additional_information'];
$this->tpayPaymentConfig = $this->tpay->getTpayFormData($orderId);
Expand Down Expand Up @@ -128,7 +135,9 @@ public function execute()
private function processSavedCardPayment($orderId, $cardId)
{
$customerTokens = $this->tokensService->getCustomerTokens($this->tpay->getCustomerId($orderId));

$isValid = false;
$token = '';
foreach ($customerTokens as $key => $value) {
if ((int)$value['tokenId'] === $cardId) {
// tokenId belongs to current customer
Expand All @@ -138,8 +147,11 @@ private function processSavedCardPayment($orderId, $cardId)
}
if ($isValid) {
try {
/** @var array<string> $paymentResult */
$paymentResult = $this->cardTransactionModel->presale($this->tpayPaymentConfig['description'], $token);

if (isset($paymentResult['sale_auth'])) {
/** @var array<string> $paymentResult */
$paymentResult = $this->cardTransactionModel->sale($paymentResult['sale_auth'], $token);
}
if (
Expand Down Expand Up @@ -181,11 +193,14 @@ private function processSavedCardPayment($orderId, $cardId)
private function trySaleAgain($orderId)
{
$this->cardTransactionModel->setCardData(null);

/** @var array<string> $result */
$result = $this->cardTransactionModel->registerSale(
$this->tpayPaymentConfig['name'],
$this->tpayPaymentConfig['email'],
$this->tpayPaymentConfig['description']
);

if (isset($result['sale_auth'])) {
$url = 'https://secure.tpay.com/cards?sale_auth='.$result['sale_auth'];
$this->tpayService->addCommentToHistory(
Expand Down Expand Up @@ -249,7 +264,7 @@ private function processNewCardPayment($orderId, $additionalPaymentInformation)
/**
* Create card payment for transaction data
*
* @return array
* @return array<string, string>
*/
private function createNewCardPayment(array $additionalPaymentInformation)
{
Expand All @@ -263,6 +278,9 @@ private function createNewCardPayment(array $additionalPaymentInformation)
);
}

/**
* @param array<string> $tpayResponse
*/
private function validateNon3dsSign($tpayResponse)
{
$testMode = isset($tpayResponse['test_mode']) ? '1' : '';
Expand Down
12 changes: 12 additions & 0 deletions Controller/tpaycards/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ public function __construct(
public function execute()
{
try {
/** @var array<string> $validParams */
$validParams = $this->cardTransactionModel->handleNotification();

isset($validParams['type']) && 'deregister' === $validParams['type']
? $this->deregisterCard($validParams) : $this->processSaleNotification($validParams);

Expand Down Expand Up @@ -150,6 +152,13 @@ private function deregisterCard($validParams)
->deleteCustomerToken($validParams['cli_auth']);
}

/**
* @param array<string> $validParams
*
* @throws \tpayLibs\src\_class_tpay\Utilities\TException
*
* @return void
*/
private function processSaleNotification($validParams)
{
$orderId = $validParams['order_id'];
Expand All @@ -171,7 +180,10 @@ private function processSaleNotification($validParams)
);
$this->tpayService->setOrderStatus($orderId, $validParams, $this->tpay);
$payment = $this->tpayService->getPayment($orderId);

/** @var array<string> $paymentData */
$paymentData = $payment->getData();

$additionalPaymentInformation = $paymentData['additional_information'];

if (isset($validParams['cli_auth'])) {
Expand Down
3 changes: 3 additions & 0 deletions Controller/tpaycards/Redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ public function __construct(
*/
public function execute()
{
/** @var string $uid */
$uid = $this->getRequest()->getParam('uid');

/** @var int $orderId */
$orderId = $this->checkoutSession->getLastRealOrderId();

if (!$orderId || !$uid) {
Expand Down
5 changes: 3 additions & 2 deletions Model/Config/Source/HashTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ public function toOptionArray()
return $ret;
}

/*
/**
* Get options in "key-value" format
* @return array
*
* @return array<string>
*/
public function toArray()
{
Expand Down

0 comments on commit ff0b608

Please sign in to comment.