Skip to content

Commit

Permalink
fix merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinverschoor committed Nov 3, 2021
2 parents 34ea315 + 0b6c256 commit 2cacf9d
Show file tree
Hide file tree
Showing 22 changed files with 468 additions and 63 deletions.
37 changes: 19 additions & 18 deletions Controller/Checkout/Exchange.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@ public function __construct(

public function execute()
{
\Paynl\Config::setApiToken($this->config->getApiToken());

$params = $this->getRequest()->getParams();
$action = !empty($params['action']) ? strtolower($params['action']) : '';
$payOrderId = isset($params['order_id']) ? $params['order_id'] : null;
Expand All @@ -130,6 +128,20 @@ public function execute()
return $this->result->setContents('FALSE| order_id is not set in the request');
}

try {
$order = $this->orderRepository->get($orderEntityId);
if (empty($order)) {
$this->logger->critical('Cannot load order: ' . $orderEntityId);
throw new Exception('Cannot load order: ' . $orderEntityId);
}
} catch (\Exception $e) {
$this->logger->critical($e, $params);
return $this->result->setContents('FALSE| Error loading order. ' . $e->getMessage());
}

$this->config->setStore($order->getStore());
\Paynl\Config::setApiToken($this->config->getApiToken());

try {
$transaction = \Paynl\Transaction::get($payOrderId);
} catch (\Exception $e) {
Expand All @@ -145,8 +157,6 @@ public function execute()
return $this->result->setContents("TRUE| Ignoring pending");
}

$order = $this->orderRepository->get($orderEntityId);

if (method_exists($transaction, 'isPartialPayment')) {
if ($transaction->isPartialPayment()) {
if ($this->config->registerPartialPayments()) {
Expand All @@ -156,21 +166,12 @@ public function execute()
}
}

if (empty($order)) {
$this->logger->critical('Cannot load order: ' . $orderEntityId);
return $this->result->setContents('FALSE| Cannot load order');
}

$payment = $order->getPayment();
$info = $payment->getAdditionalInformation();
if (!empty($info['transactionId'])) {
if ($info['transactionId'] != $payOrderId) {
$this->logger->critical('Transaction not equal');
return $this->result->setContents('FALSE| Cannot load order');
}
} else {
$this->logger->critical('Transaction not set in order');
return $this->result->setContents('TRUE| Failed. Transaction not set.');
$orderEntityIdTransaction = $transaction->getExtra3();

if ($orderEntityId != $orderEntityIdTransaction) {
$this->logger->critical('Transaction mismatch ' . $orderEntityId . ' / ' . $orderEntityIdTransaction);
return $this->result->setContents('FALSE|Transaction mismatch');
}

if ($order->getTotalDue() <= 0) {
Expand Down
16 changes: 13 additions & 3 deletions Controller/Checkout/Finish.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ private function checkEmpty($field, $name, $errorCode, $desc = null)
public function execute()
{
$resultRedirect = $this->resultRedirectFactory->create();

\Paynl\Config::setApiToken($this->config->getApiToken());
$params = $this->getRequest()->getParams();
$payOrderId = empty($params['orderId']) ? (empty($params['orderid']) ? null : $params['orderid']) : $params['orderId'];
$orderStatusId = empty($params['orderStatusId']) ? null : (int)$params['orderStatusId'];
Expand All @@ -103,14 +101,20 @@ public function execute()
$order = $this->orderRepository->get($magOrderId);
$this->checkEmpty($order, 'order', 1013);

$this->config->setStore($order->getStore());
\Paynl\Config::setApiToken($this->config->getApiToken());

$payment = $order->getPayment();
$information = $payment->getAdditionalInformation();

$this->checkEmpty($information['transactionId'] == $payOrderId, '', 1014, 'transaction mismatch');

if (!empty($information['terminal_hash']) && !$bSuccess) {
$isPinTransaction = true;
$this->handlePin($information['terminal_hash'], $order);
$pinStatus = $this->handlePin($information['terminal_hash'], $order);
if (!empty($pinStatus)) {
$bSuccess = true;
}
}

if (empty($bSuccess) && !$isPinTransaction) {
Expand All @@ -128,6 +132,10 @@ public function execute()

$resultRedirect->setPath($successUrl, ['_query' => ['utm_nooverride' => '1']]);

if ($isPinTransaction && $pinStatus->getTransactionState() !== 'approved') {
$this->messageManager->addNoticeMessage(__('Order has been made and the payment is pending.'));
}

# Make the cart inactive
$session = $this->checkoutSession;
if (empty($order)) {
Expand Down Expand Up @@ -171,6 +179,8 @@ private function handlePin($hash, $order)
# Instore does not send a canceled exchange message, so cancel it here
$order->cancel();
$this->orderRepository->save($order);
return false;
}
return $status;
}
}
1 change: 1 addition & 0 deletions Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Config
/** @array Brands */
public $brands = [
"paynl_payment_afterpay" => "14",
"paynl_payment_afterpay_international" => "14",
"paynl_payment_alipay" => "82",
"paynl_payment_amazonpay" => "22",
"paynl_payment_amex" => "9",
Expand Down
12 changes: 12 additions & 0 deletions Model/Config/Source/Available/AfterpayInternational.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
/**
* Copyright © 2020 PAY. All rights reserved.
*/

namespace Paynl\Payment\Model\Config\Source\Available;


class AfterpayInternational extends Available
{
protected $_class = \Paynl\Payment\Model\Paymentmethod\AfterpayInternational::class;
}
141 changes: 141 additions & 0 deletions Model/Config/Source/PinTerminals.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
<?php

/**
* Copyright © 2020 PAY. All rights reserved.
*/

namespace Paynl\Payment\Model\Config\Source;

use \Magento\Framework\Option\ArrayInterface;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\RequestInterface;
use \Paynl\Payment\Model\Config;
use Paynl\Payment\Model\Paymentmethod\PaymentMethod;
use \Paynl\Paymentmethods;

class PinTerminals implements ArrayInterface
{

/**
* @var RequestInterface
*/
protected $_request;

/**
* @var \Magento\Store\Model\StoreManagerInterface
*/
protected $_storeManager;

/**
* @var ScopeConfigInterface
*/
protected $_scopeConfig;

/**
* @var Config
*/
protected $_config;

public function __construct(
Config $config,
RequestInterface $request,
ScopeConfigInterface $scopeConfig,
\Magento\Store\Model\StoreManagerInterface $storeManager
) {
$this->_config = $config;
$this->_request = $request;
$this->_scopeConfig = $scopeConfig;
$this->_storeManager = $storeManager;
}

/**
* Options getter
*
* @return array
*/
public function toOptionArray()
{
$arrOptions = $this->toArray();

$arrResult = [];
foreach ($arrOptions as $value => $label) {
$arrResult[] = ['value' => $value, 'label' => $label];
}
return $arrResult;
}

/**
* Get options in "key-value" format
*
* @return array
*/
public function toArray()
{
$terminalArr = [];
if ($this->_isConfigured()) {
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();

$cache = $objectManager->get(\Magento\Framework\App\CacheInterface::class);
$storeId = $this->_request->getParam('store');
$cacheName = 'paynl_terminals_' . $this->getConfigValue('payment/paynl_payment_instore/payment_option_id') . '_' . $storeId;
$terminalJson = $cache->load($cacheName);
if ($terminalJson) {
$terminalArr = json_decode($terminalJson);
} else {
try {
$terminals = \Paynl\Instore::getAllTerminals();
$terminals = $terminals->getList();

foreach ($terminals as $terminal) {
$terminal['visibleName'] = $terminal['name'];
array_push($terminalArr, $terminal);
}
$cache->save(json_encode($terminalArr), $cacheName);
} catch (\Paynl\Error\Error $e) {
// Probably instore is not activated, no terminals present
}
}
}
$optionArr = [];
$optionArr[0] = __('Choose the pin terminal');
foreach ($terminalArr as $terminal) {
$arr = (array)$terminal;
$optionArr[$arr['id']] = $arr['visibleName'];
}

return $optionArr;
}

protected function _isConfigured()
{
$storeId = $this->_request->getParam('store');
if ($storeId) {
$store = $this->_storeManager->getStore($storeId);
$this->_config->setStore($store);
}
$configured = $this->_config->configureSDK();
if ($configured) {
return true;
}

return false;
}

protected function getConfigValue($path)
{
$scopeType = ScopeConfigInterface::SCOPE_TYPE_DEFAULT;
$scopeValue = null;

$store = $this->_request->getParam('store');
$website = $this->_request->getParam('website');
if ($store) {
$scopeValue = $store;
$scopeType = ScopeInterface::SCOPE_STORE;
} elseif ($website) {
$scopeValue = $website;
$scopeType = ScopeInterface::SCOPE_WEBSITE;
}

return $this->_scopeConfig->getValue($path, $scopeType, $scopeValue);
}
}
15 changes: 11 additions & 4 deletions Model/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class ConfigProvider implements ConfigProviderInterface
*/
protected $methodCodes = [
'paynl_payment_afterpay',
'paynl_payment_afterpay_international',
'paynl_payment_alipay',
'paynl_payment_amazonpay',
'paynl_payment_amex',
Expand Down Expand Up @@ -111,7 +112,8 @@ public function getConfig()
foreach ($this->methodCodes as $code) {
if ($this->methods[$code]->isAvailable()) {
$config['payment']['instructions'][$code] = $this->getInstructions($code);
$config['payment']['banks'][$code] = $this->getBanks($code);
$config['payment']['paymentoptions'][$code] = $this->getPaymentOptions($code);
$config['payment']['defaultpaymentoption'][$code] = $this->getDefaultPaymentOption($code);
$config['payment']['icon'][$code] = $this->getIcon($code);
$config['payment']['showkvk'][$code] = $this->getKVK($code);
$config['payment']['showvat'][$code] = $this->getVAT($code);
Expand All @@ -121,7 +123,7 @@ public function getConfig()
$config['payment']['disallowedshipping'][$code] = $this->getDisallowedShippingMethods($code);
$config['payment']['currentipisvalid'][$code] = $this->methods[$code]->isCurrentIpValid();
$config['payment']['currentagentisvalid'][$code] = $this->methods[$code]->isCurrentAgentValid();
$config['payment']['defaultpaymentoption'][$code] = $this->methods[$code]->isDefaultPaymentOption();
$config['payment']['defaultpaymentmethod'][$code] = $this->methods[$code]->isDefaultPaymentOption();
}
}

Expand All @@ -144,9 +146,14 @@ protected function getInstructions($code)
return nl2br($this->escaper->escapeHtml($this->methods[$code]->getInstructions()));
}

protected function getBanks($code)
protected function getPaymentOptions($code)
{
return $this->methods[$code]->getBanks();
return $this->methods[$code]->getPaymentOptions();
}

protected function getDefaultPaymentOption($code)
{
return $this->methods[$code]->getDefaultPaymentOption();
}

protected function getKVK($code)
Expand Down
13 changes: 13 additions & 0 deletions Model/Paymentmethod/AfterpayInternational.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Paynl\Payment\Model\Paymentmethod;

class AfterpayInternational extends PaymentMethod
{
protected $_code = 'paynl_payment_afterpay_international';

protected function getDefaultPaymentOptionId()
{
return 2561;
}
}
10 changes: 5 additions & 5 deletions Model/Paymentmethod/Ideal.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ public function assignData(\Magento\Framework\DataObject $data)
parent::assignData($data);

if (is_array($data)) {
$this->getInfoInstance()->setAdditionalInformation('bank_id', $data['bank_id']);
$this->getInfoInstance()->setAdditionalInformation('payment_option', $data['payment_option']);
} elseif ($data instanceof \Magento\Framework\DataObject) {
$additional_data = $data->getAdditionalData();
if (isset($additional_data['bank_id'])) {
$bankId = $additional_data['bank_id'];
$this->getInfoInstance()->setAdditionalInformation('bank_id', $bankId);
if (isset($additional_data['payment_option'])) {
$paymentOption = $additional_data['payment_option'];
$this->getInfoInstance()->setAdditionalInformation('payment_option', $paymentOption);
}
}
return $this;
}

public function getBanks()
public function getPaymentOptions()
{
$show_banks = $this->_scopeConfig->getValue('payment/' . $this->_code . '/bank_selection', 'store');
if (!$show_banks) {
Expand Down
Loading

0 comments on commit 2cacf9d

Please sign in to comment.