Skip to content

Commit

Permalink
Adapter implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
krzGablo committed Feb 29, 2024
1 parent e2f92b0 commit 3459e5e
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 92 deletions.
12 changes: 6 additions & 6 deletions Model/ApiFacade/Refund/RefundCardOriginApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ public function makeCardRefund($payment, $amount, $currency = '985')
{
$transactionId = $payment->getParentTransactionId();
$this->setAmount($amount)->setCurrency($currency);
$result = $this->refund($transactionId, __('Zwrot do zamówienia ') . $payment->getOrder()->getRealOrderId());
$result = $this->refund($transactionId, __('Zwrot do zamówienia ').$payment->getOrder()->getRealOrderId());

if (1 === (int)$result['result'] && isset($result['status']) && 'correct' === $result['status']) {
if (1 === (int) $result['result'] && isset($result['status']) && 'correct' === $result['status']) {
return $result['sale_auth'];
}
$errDesc = isset($result['err_desc']) ? ' error description: ' . $result['err_desc'] : '';
$errCode = isset($result['err_code']) ? ' error code: ' . $result['err_code'] : '';
$reason = isset($result['reason']) ? ' reason: ' . $result['reason'] : '';
throw new Exception(__('Payment refunding error. -' . $errCode . $errDesc . $reason));
$errDesc = isset($result['err_desc']) ? ' error description: '.$result['err_desc'] : '';
$errCode = isset($result['err_code']) ? ' error code: '.$result['err_code'] : '';
$reason = isset($result['reason']) ? ' reason: '.$result['reason'] : '';
throw new Exception(__('Payment refunding error. -'.$errCode.$errDesc.$reason));
}
}
16 changes: 8 additions & 8 deletions Model/MethodListPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ class MethodListPlugin
private $constraintValidator;

public function __construct(
Data $data,
ScopeConfigInterface $scopeConfig,
OnsiteChannels $onsiteChannels,
Data $data,
ScopeConfigInterface $scopeConfig,
OnsiteChannels $onsiteChannels,
StoreManagerInterface $storeManager,
TpayPayment $tpay,
TpayConfigInterface $tpayConfig,
Session $checkoutSession,
TransactionApiFacade $transactions,
ConstraintValidator $constraintValidator
TpayPayment $tpay,
TpayConfigInterface $tpayConfig,
Session $checkoutSession,
TransactionApiFacade $transactions,
ConstraintValidator $constraintValidator
) {
$this->data = $data;
$this->scopeConfig = $scopeConfig;
Expand Down
1 change: 0 additions & 1 deletion Model/TokenRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace tpaycom\magento2basic\Model;

use tpaycom\magento2basic\Model\Api\Data\TokensInterface;
use tpaycom\magento2basic\Model\TokenFactory;
use tpaycom\magento2basic\Model\Api\TokenRepositoryInterface;
use tpaycom\magento2basic\Model\ResourceModel\Token as TokenResourceModel;

Expand Down
13 changes: 6 additions & 7 deletions Model/TpayConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,13 @@ class TpayConfigProvider implements ConfigProviderInterface
protected $transactionApi;

public function __construct(
PaymentHelper $paymentHelper,
Repository $assetRepository,
PaymentHelper $paymentHelper,
Repository $assetRepository,
StoreManagerInterface $storeManager,
TpayTokensService $tokensService,
TransactionApiFacade $transactionApiFacade,
TpayConfigInterface $tpayConfig
)
{
TpayTokensService $tokensService,
TransactionApiFacade $transactionApiFacade,
TpayConfigInterface $tpayConfig
) {
$this->paymentHelper = $paymentHelper;
$this->transactionApi = $transactionApiFacade;
$this->configFacade = new ConfigFacade($this->getPaymentMethodInstance(), $tpayConfig, $assetRepository, $tokensService, $storeManager);
Expand Down
60 changes: 31 additions & 29 deletions Model/TpayPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,25 +82,24 @@ class TpayPayment extends Adapter implements TpayInterface
private $_title;

public function __construct(
UrlInterface $urlBuilder,
Session $checkoutSession,
OrderRepositoryInterface $orderRepository,
Escaper $escaper,
StoreManager $storeManager,
ConfigurationProvider $configurationProvider,
PaymentInterface $infoInstance,
ManagerInterface $eventManager,
UrlInterface $urlBuilder,
Session $checkoutSession,
OrderRepositoryInterface $orderRepository,
Escaper $escaper,
StoreManager $storeManager,
ConfigurationProvider $configurationProvider,
PaymentInterface $infoInstance,
ManagerInterface $eventManager,
ValueHandlerPoolInterface $valueHandlerPool,
PaymentDataObjectFactory $paymentDataObjectFactory,
string $code,
string $formBlockType,
string $infoBlockType,
CommandPoolInterface $commandPool = null,
ValidatorPoolInterface $validatorPool = null,
CommandManagerInterface $commandExecutor = null,
LoggerInterface $logger = null
)
{
PaymentDataObjectFactory $paymentDataObjectFactory,
string $code,
string $formBlockType,
string $infoBlockType,
?CommandPoolInterface $commandPool = null,
?ValidatorPoolInterface $validatorPool = null,
?CommandManagerInterface $commandExecutor = null,
?LoggerInterface $logger = null
) {
$this->urlBuilder = $urlBuilder;
$this->escaper = $escaper;
$this->checkoutSession = $checkoutSession;
Expand All @@ -124,7 +123,7 @@ public function __construct(

public function getPaymentRedirectUrl(): string
{
return $this->urlBuilder->getUrl('magento2basic/tpay/redirect', ['uid' => time() . uniqid('', true)]);
return $this->urlBuilder->getUrl('magento2basic/tpay/redirect', ['uid' => time().uniqid('', true)]);
}

public function setCode(string $code)
Expand All @@ -151,9 +150,9 @@ public function getTpayFormData(?string $orderId = null): array
{
$order = $this->getOrder($orderId);
$billingAddress = $order->getBillingAddress();
$amount = number_format((float)$order->getGrandTotal(), 2, '.', '');
$amount = number_format((float) $order->getGrandTotal(), 2, '.', '');
$crc = base64_encode($orderId);
$name = $billingAddress->getData('firstname') . ' ' . $billingAddress->getData('lastname');
$name = $billingAddress->getData('firstname').' '.$billingAddress->getData('lastname');
$phone = $billingAddress->getData('telephone');

$om = ObjectManager::getInstance();
Expand All @@ -164,7 +163,7 @@ public function getTpayFormData(?string $orderId = null): array
'email' => $this->escaper->escapeHtml($order->getCustomerEmail()),
'name' => $this->escaper->escapeHtml($name),
'amount' => $amount,
'description' => 'Zamówienie ' . $orderId,
'description' => 'Zamówienie '.$orderId,
'crc' => $crc,
'address' => $this->escaper->escapeHtml($order->getBillingAddress()->getData('street')),
'city' => $this->escaper->escapeHtml($order->getBillingAddress()->getData('city')),
Expand All @@ -175,7 +174,7 @@ public function getTpayFormData(?string $orderId = null): array
'return_url' => $this->urlBuilder->getUrl('magento2basic/tpay/success'),
'phone' => $phone,
'online' => $this->configurationProvider->onlyOnlineChannels() ? 1 : 0,
'module' => 'Magento ' . $this->getMagentoVersion(),
'module' => 'Magento '.$this->getMagentoVersion(),
'currency' => $this->getISOCurrencyCode($order->getOrderCurrencyCode()),
'language' => $language,
];
Expand Down Expand Up @@ -206,7 +205,6 @@ public function assignData(DataObject $data)
$additionalData = $data->getData('additional_data');

$info = $this->getInfoInstance();
// $info = $this->infoInstance;
$info->setAdditionalInformation(static::GROUP, array_key_exists(static::GROUP, $additionalData) ? $additionalData[static::GROUP] : '');
$info->setAdditionalInformation(static::BLIK_CODE, array_key_exists(static::BLIK_CODE, $additionalData) ? $additionalData[static::BLIK_CODE] : '');
$info->setAdditionalInformation('channel', $additionalData['channel'] ?? null);
Expand All @@ -215,21 +213,23 @@ public function assignData(DataObject $data)
$info->setAdditionalInformation(static::CARD_VENDOR, isset($additionalData[static::CARD_VENDOR]) && in_array($additionalData[static::CARD_VENDOR], $this->supportedVendors) ? $additionalData[static::CARD_VENDOR] : 'undefined');
$info->setAdditionalInformation(static::CARD_SAVE, isset($additionalData[static::CARD_SAVE]) ? '1' === $additionalData[static::CARD_SAVE] : false);
$info->setAdditionalInformation(static::CARD_ID, isset($additionalData[static::CARD_ID]) && is_numeric($additionalData[static::CARD_ID]) ? $additionalData[static::CARD_ID] : false);
$info->setAdditionalInformation(static::SHORT_CODE, isset($additionalData[static::SHORT_CODE]) && is_numeric($additionalData[static::SHORT_CODE]) ? '****' . $additionalData[static::SHORT_CODE] : false);
$info->setAdditionalInformation(static::SHORT_CODE, isset($additionalData[static::SHORT_CODE]) && is_numeric($additionalData[static::SHORT_CODE]) ? '****'.$additionalData[static::SHORT_CODE] : false);

return $this;
}

/**
* @param float $amount
* @return $this
*
* @throws \Exception
*
* @return $this
*/
public function refund(InfoInterface $payment, $amount)
{
$refundService = new RefundApiFacade($this->configurationProvider);

$refundResult = $refundService->makeRefund($payment, (float)$amount);
$refundResult = $refundService->makeRefund($payment, (float) $amount);
try {
if ($refundResult) {
$payment
Expand All @@ -249,7 +249,7 @@ public function refund(InfoInterface $payment, $amount)
/** @return float current cart total */
public function getCheckoutTotal()
{
$amount = (float)$this->getCheckout()->getQuote()->getBaseGrandTotal();
$amount = (float) $this->getCheckout()->getQuote()->getBaseGrandTotal();

if (!$amount) {
$orderId = $this->getCheckout()->getLastRealOrderId();
Expand Down Expand Up @@ -282,6 +282,7 @@ public function isCustomerLoggedIn(): bool

/**
* @param string $orderId
*
* @return string
*/
public function getCustomerId($orderId)
Expand All @@ -293,6 +294,7 @@ public function getCustomerId($orderId)

/**
* @param string $orderId
*
* @return bool
*/
public function isCustomerGuest($orderId)
Expand Down Expand Up @@ -325,7 +327,7 @@ public function isCartValid(?float $grandTotal = null): bool

protected function checkBlikAmount(): bool
{
return (bool)($this->getCheckoutTotal() >= $this->minAmountBlik);
return (bool) ($this->getCheckoutTotal() >= $this->minAmountBlik);
}

protected function getCheckout(): Session
Expand Down
29 changes: 15 additions & 14 deletions Provider/ConfigurationProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
class ConfigurationProvider implements TpayConfigInterface
{
private const BASE_CONFIG_PATH = 'payment/tpaycom_magento2basic/';

protected $termsURL = 'https://secure.tpay.com/regulamin.pdf';

/** @var ScopeConfigInterface */
Expand All @@ -24,7 +25,7 @@ public function __construct(ScopeConfigInterface $scopeConfig)

public function getBlikLevelZeroStatus(): bool
{
return (bool)$this->getConfigData('general_settings/blik_level_zero');
return (bool) $this->getConfigData('general_settings/blik_level_zero');
}

public function getApiKey(): ?string
Expand Down Expand Up @@ -64,7 +65,7 @@ public function getOpenApiPassword(): ?string

public function getMerchantId(): ?int
{
return (int)$this->getConfigData('general_settings/merchant_id');
return (int) $this->getConfigData('general_settings/merchant_id');
}

public function getOpenApiClientId(): ?string
Expand All @@ -79,12 +80,12 @@ public function getSecurityCode(?int $storeId = null): ?string

public function onlyOnlineChannels(): bool
{
return (bool)$this->getConfigData('general_settings/show_payment_channels_online');
return (bool) $this->getConfigData('general_settings/show_payment_channels_online');
}

public function redirectToChannel(): bool
{
return (bool)$this->getConfigData('general_settings/redirect_directly_to_channel');
return (bool) $this->getConfigData('general_settings/redirect_directly_to_channel');
}

public function getCardTitle(): ?string
Expand All @@ -94,42 +95,42 @@ public function getCardTitle(): ?string

public function isOriginApiEnabled(): bool
{
return (bool)$this->getConfigData('originapi_settings/origin_api_active');
return (bool) $this->getConfigData('originapi_settings/origin_api_active');
}

public function isOpenApiEnabled(): bool
{
return (bool)$this->getConfigData('openapi_settings/open_api_active');
return (bool) $this->getConfigData('openapi_settings/open_api_active');
}

public function isCardEnabled(): bool
{
return (bool)$this->getConfigData('cardpayment_settings/cardpayment_api_active');
return (bool) $this->getConfigData('cardpayment_settings/cardpayment_api_active');
}

public function isOriginApiCardUse(): bool
{
return (bool)$this->getConfigData('cardpayment_settings/cardpayment_origin_api_use');
return (bool) $this->getConfigData('cardpayment_settings/cardpayment_origin_api_use');
}

public function useSandboxMode(?int $storeId = null): bool
{
return (bool)$this->getConfigData('general_settings/use_sandbox', $storeId);
return (bool) $this->getConfigData('general_settings/use_sandbox', $storeId);
}

public function getMinOrderTotal()
{
return (bool)$this->getConfigData('sale_settings/min_order_total');
return (bool) $this->getConfigData('sale_settings/min_order_total');
}

public function getMaxOrderTotal()
{
return (bool)$this->getConfigData('sale_settings/max_order_total');
return (bool) $this->getConfigData('sale_settings/max_order_total');
}

public function getCardSaveEnabled(): bool
{
return (bool)$this->getConfigData('cardpayment_settings/card_save_enabled');
return (bool) $this->getConfigData('cardpayment_settings/card_save_enabled');
}

public function getRSAKey(): ?string
Expand All @@ -149,7 +150,7 @@ public function getVerificationCode(): string

public function isAllowSpecific(): bool
{
return (bool)$this->getConfigData('sale_settings/allowspecific') ?? false;
return (bool) $this->getConfigData('sale_settings/allowspecific') ?? false;
}

public function getSpecificCountry(): array
Expand Down Expand Up @@ -183,6 +184,6 @@ public function getMagentoVersion()

public function getConfigData($field, $storeId = null)
{
return $this->scopeConfig->getValue(self::BASE_CONFIG_PATH . $field, ScopeInterface::SCOPE_STORE, $storeId);
return $this->scopeConfig->getValue(self::BASE_CONFIG_PATH.$field, ScopeInterface::SCOPE_STORE, $storeId);
}
}
Loading

0 comments on commit 3459e5e

Please sign in to comment.