Skip to content

Commit

Permalink
Merge branch 'fix/DX-76-159-fixes' into DX-161
Browse files Browse the repository at this point in the history
  • Loading branch information
s4ddly authored Oct 31, 2023
2 parents 16741ae + 163154d commit 2efe39f
Show file tree
Hide file tree
Showing 29 changed files with 299 additions and 487 deletions.
2 changes: 2 additions & 0 deletions .dev-tools/.php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

require __DIR__.'/vendor/tpay-com/coding-standards/bootstrap.php';

$config = Tpay\CodingStandards\PhpCsFixerConfigFactory::createWithLegacyRules()
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/.dev-tools/vendor/
/.dev-tools/.php-cs-fixer.cache
vendor
.idea
12 changes: 4 additions & 8 deletions Api/Sales/OrderRepositoryInterface.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
<?php

declare(strict_types=1);

namespace tpaycom\magento2basic\Api\Sales;

use Magento\Sales\Api\OrderRepositoryInterface as MagentoOrderRepositoryInterface;

interface OrderRepositoryInterface extends MagentoOrderRepositoryInterface
{
/**
* Return new instance of Order by increment ID
*
* @param string $incrementId
*
* @return \Magento\Sales\Api\Data\OrderInterface
*/
public function getByIncrementId($incrementId);
/** Return new instance of Order by increment ID */
public function getByIncrementId(string $incrementId): \Magento\Sales\Api\Data\OrderInterface;
}
133 changes: 43 additions & 90 deletions Api/TpayInterface.php
Original file line number Diff line number Diff line change
@@ -1,100 +1,53 @@
<?php

declare(strict_types=1);

namespace tpaycom\magento2basic\Api;

/**
* @api
*/
interface TpayInterface
{
const CODE = 'tpaycom_magento2basic';
const CHANNEL = 'group';
const BLIK_CODE = 'blik_code';
const TERMS_ACCEPT = 'accept_tos';

/**
* Return string for redirection
*
* @return string
*/
public function getRedirectURL();

/**
* Return data for form
*
* @param null|int $orderId
*
* @return array
*/
public function getTpayFormData($orderId = null);

/** @return string */
public function getApiPassword();

/** @return string */
public function getApiKey();

/** @return string */
public function getSecurityCode();

/** @return int */
public function getMerchantId();

/**
* Check that the BLIK Level 0 should be active on a payment channels list
*
* @return bool
*/
public function checkBlikLevel0Settings();

/** @return bool */
public function getBlikLevelZeroStatus();

/** @return bool */
public function onlyOnlineChannels();

/** @return bool */
public function redirectToChannel();

/**
* Return url to redirect after placed order
*
* @return string
*/
public function getPaymentRedirectUrl();

/**
* Return url for a tpay.com terms
*
* @return string
*/
public function getTermsURL();

/**
* Check if send an email about the new invoice to customer
*
* @return string
*/
public function getInvoiceSendMail();

/**
* Check if Tpay notification server IP is forwarded by proxy
*
* @return bool
*/
public function getCheckProxy();

/**
* Check Tpay notification server IP
*
* @return bool
*/
public function getCheckTpayIP();

/**
* Check if checkout amount is in range of installments payment channel
*
* @return bool
*/
public function getInstallmentsAmountValid();
public const CODE = 'tpaycom_magento2basic';
public const CHANNEL = 'group';
public const BLIK_CODE = 'blik_code';
public const TERMS_ACCEPT = 'accept_tos';

/** Return string for redirection */
public function getRedirectURL(): string;

/** Return data for form */
public function getTpayFormData(?string $orderId = null): array;

public function getApiPassword(): string;

public function getApiKey(): string;

public function getSecurityCode(): string;

public function getMerchantId(): int;

/** Check that the BLIK Level 0 should be active on a payment channels list */
public function checkBlikLevel0Settings(): bool;

public function getBlikLevelZeroStatus(): bool;

public function onlyOnlineChannels(): bool;

public function redirectToChannel(): bool;

/** Return url to redirect after placed order */
public function getPaymentRedirectUrl(): string;

/** Return url for a tpay.com terms */
public function getTermsURL(): string;

/** Check if send an email about the new invoice to customer */
public function getInvoiceSendMail(): string;

public function useSandboxMode(): bool;

/** Check if checkout amount is in range of installments payment channel */
public function getInstallmentsAmountValid(): bool;
}
8 changes: 5 additions & 3 deletions Controller/Tpaycom.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
<?php

declare(strict_types=1);

namespace tpaycom\magento2basic\Controller;

abstract class Tpaycom extends \Magento\Framework\App\Action\Action
{
// Check Real IP if server is proxy, balancer...
const CHECK_REAL_IP = false;
public const CHECK_REAL_IP = false;

// Local IP address
const LOCAL_IP = '127.0.0.1';
public const LOCAL_IP = '127.0.0.1';

// STR EMPTY
const STR_EMPTY = '';
public const STR_EMPTY = '';

/** @var \Magento\Customer\Model\Session */
protected $_customerSession;
Expand Down
33 changes: 9 additions & 24 deletions Controller/tpay/Create.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<?php

declare(strict_types=1);

namespace tpaycom\magento2basic\Controller\tpay;

use Magento\Checkout\Model\Session;
use Magento\Framework\App\Action\Action;
use Magento\Framework\App\Action\Context;
use Magento\Framework\DataObject;
use tpaycom\magento2basic\Api\TpayInterface;
use tpaycom\magento2basic\Model\TransactionModel;
use tpaycom\magento2basic\Model\TransactionModelFactory;
Expand Down Expand Up @@ -47,27 +48,20 @@ public function __construct(

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

if ($orderId) {
/** @var DataObject $payment */
$payment = $this->tpayService->getPayment($orderId);

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

$this->transaction = $this->transactionFactory->create(
[
'apiPassword' => $this->tpay->getApiPassword(),
'apiKey' => $this->tpay->getApiKey(),
'merchantId' => $this->tpay->getMerchantId(),
'merchantSecret' => $this->tpay->getSecurityCode(),
'isProd' => !$this->tpay->useSandboxMode(),
]
);
$additionalPaymentInformation = $paymentData['additional_information'];

/** @var array<string> $transaction */
$transaction = $this->prepareTransaction($orderId, $additionalPaymentInformation);

if (!isset($transaction['title'], $transaction['url'])) {
Expand Down Expand Up @@ -103,33 +97,24 @@ public function execute()
}
}

/**
* Send BLIK code for transaction id
*
* @param string $blikTransactionId
* @param string $blikCode
*
* @return bool
*/
protected function blikPay($blikTransactionId, $blikCode)
/** Send BLIK code for transaction id */
protected function blikPay(string $blikTransactionId, string $blikCode): bool
{
/** @var array<string, mixed> $apiResult */
$apiResult = $this->transaction->blik($blikTransactionId, $blikCode);

return isset($apiResult['result']) && 1 === $apiResult['result'];
return array_key_exists('result', $apiResult) && 1 === $apiResult['result'];
}

/**
* @param mixed $orderId
* @param array{blik_code: string, group: int|string} $additionalPaymentInformation
*/
private function prepareTransaction($orderId, array $additionalPaymentInformation)
{
$data = $this->tpay->getTpayFormData($orderId);
if (6 === strlen($additionalPaymentInformation['blik_code'])) {
$data['group'] = TransactionModel::BLIK_CHANNEL;
} else {
$data['group'] = (int) $additionalPaymentInformation['group'];
if ($this->tpay->redirectToChannel()) {
$data['direct'] = 1;
}
}

return $this->transaction->create($data);
Expand Down
2 changes: 2 additions & 0 deletions Controller/tpay/Error.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace tpaycom\magento2basic\Controller\tpay;

use Magento\Framework\App\Action\Action;
Expand Down
Loading

0 comments on commit 2efe39f

Please sign in to comment.