We will be off from 27/1 (Monday) to 31/1 (Friday) (GMT +7) for our Tet Holiday (Lunar New Year) in our country

Commit 5ad42460 authored by Rik ter Beek's avatar Rik ter Beek

optimize code and remove debugger

parent 205af285
...@@ -26,114 +26,123 @@ namespace Adyen\Payment\AdminMessage; ...@@ -26,114 +26,123 @@ namespace Adyen\Payment\AdminMessage;
class APIKeyMessage implements \Magento\Framework\Notification\MessageInterface class APIKeyMessage implements \Magento\Framework\Notification\MessageInterface
{ {
/** /**
* @var \Adyen\Payment\Helper\Data * @var \Adyen\Payment\Helper\Data
*/ */
protected $_adyenHelper; protected $adyenHelper;
/** /**
* @var \Magento\AdminNotification\Model\InboxFactory * @var \Magento\AdminNotification\Model\InboxFactory
*/ */
protected $_inboxFactory; protected $inboxFactory;
/** /**
* @var \Magento\Store\Model\StoreManagerInterface * @var \Magento\Store\Model\StoreManagerInterface
*/ */
protected $storeManagerInterface; protected $storeManagerInterface;
/** /**
* @var \Magento\Backend\Model\Auth\Session * @var \Magento\Backend\Model\Auth\Session
*/ */
protected $authSession; protected $authSession;
const MESSAGE_IDENTITY = 'Adyen API Key Control message'; const MESSAGE_IDENTITY = 'Adyen API Key Control message';
/** /**
* APIKeyMessage constructor. * APIKeyMessage constructor.
* *
* @param \Adyen\Payment\Helper\Data $adyenHelper * @param \Adyen\Payment\Helper\Data $adyenHelper
* @param \Magento\AdminNotification\Model\InboxFactory $inboxFactory * @param \Magento\AdminNotification\Model\InboxFactory $inboxFactory
*/ * @param \Magento\Store\Model\StoreManagerInterface $storeManagerInterface
public function __construct( * @param \Magento\Backend\Model\Auth\Session $authSession
\Adyen\Payment\Helper\Data $adyenHelper, */
\Magento\AdminNotification\Model\InboxFactory $inboxFactory, public function __construct(
\Magento\Store\Model\StoreManagerInterface $storeManagerInterface, \Adyen\Payment\Helper\Data $adyenHelper,
\Magento\Backend\Model\Auth\Session $authSession \Magento\AdminNotification\Model\InboxFactory $inboxFactory,
) { \Magento\Store\Model\StoreManagerInterface $storeManagerInterface,
$this->_adyenHelper = $adyenHelper; \Magento\Backend\Model\Auth\Session $authSession
$this->_inboxFactory = $inboxFactory; ) {
$this->storeManagerInterface = $storeManagerInterface; $this->adyenHelper = $adyenHelper;
$this->authSession = $authSession; $this->inboxFactory = $inboxFactory;
} $this->storeManagerInterface = $storeManagerInterface;
$this->authSession = $authSession;
/** }
* Retrieve unique system message identity
* /**
* @return string * Retrieve unique system message identity
*/ *
public function getIdentity() * @return string
{ */
return self::MESSAGE_IDENTITY; public function getIdentity()
} {
return self::MESSAGE_IDENTITY;
/** }
* Check whether the system message should be shown
* /**
* @return bool * Check whether the system message should be shown
*/ *
public function isDisplayed() * @return bool
{ */
// Only execute the query the first time you access the Admin page public function isDisplayed()
if ($this->authSession->isFirstPageAfterLogin() && !empty($this->_adyenHelper->getWsUsername()) && empty($this->_adyenHelper->getAPIKey())) { {
try {
$title = "Adyen extension requires the API KEY!222"; // Only execute the query the first time you access the Admin page
if ($this->authSession->isFirstPageAfterLogin() &&
$messageData[] = array( !empty($this->adyenHelper->getWsUsername()) &&
'severity' => $this->getSeverity(), empty($this->adyenHelper->getAPIKey())
'date_added' => date("Y-m-d"), ) {
'title' => $title, try {
'description' => $this->getText(), $title = 'Adyen extension requires the API KEY!';
'url' => "https://docs.adyen.com/developers/plug-ins-and-partners/magento-2/set-up-the-plugin-in-magento#step3configuretheplugininmagento",
); $messageData[] = [
'severity' => $this->getSeverity(),
/* 'date_added' => date('Y-m-d'),
* The parse function checks if the $versionData message exists in the inbox, 'title' => $title,
* otherwise it will create it and add it to the inbox. 'description' => $this->getText(),
*/ 'url' => 'https://docs.adyen.com/developers/plug-ins-and-partners/magento-2/' .
$this->_inboxFactory->create()->parse(array_reverse($messageData)); 'set-up-the-plugin-in-magento#step3configuretheplugininmagento',
return true; ];
} catch (\Exception $e) { /*
return false; * The parse function checks if the $versionData message exists in the inbox,
} * otherwise it will create it and add it to the inbox.
} */
$this->inboxFactory->create()->parse($messageData);
return false; return true;
}
} catch (\Exception $e) {
/** return false;
* Retrieve system message text }
* }
* @return \Magento\Framework\Phrase
*/ return false;
public function getText() }
{
if (!empty($this->_adyenHelper->getWsUsername())) { /**
$message = "Please provide API-KEY for the webservice user " . $this->_adyenHelper->getWsUsername() . " for default/store " . $this->storeManagerInterface->getStore()->getName(); * Retrieve system message text
}else{ *
$message = "Please provide API-KEY for default/store " . $this->storeManagerInterface->getStore()->getName(); * @return string
} * @throws \Magento\Framework\Exception\NoSuchEntityException
*/
return $message; public function getText()
} {
$message = '';
/** if (!empty($this->adyenHelper->getWsUsername())) {
* Retrieve system message severity $message = 'Please provide API-KEY for the webservice user ' .
* $this->adyenHelper->getWsUsername() . ' for default/store ' .
* @return int $this->storeManagerInterface->getStore()->getName();
*/ }
public function getSeverity()
{ return $message;
return self::SEVERITY_CRITICAL; }
}
/**
* Retrieve system message severity
*
* @return int
*/
public function getSeverity()
{
return self::SEVERITY_CRITICAL;
}
} }
...@@ -32,11 +32,6 @@ class RecurringDataBuilder implements BuilderInterface ...@@ -32,11 +32,6 @@ class RecurringDataBuilder implements BuilderInterface
*/ */
private $adyenHelper; private $adyenHelper;
/**
* @var \Adyen\Payment\Logger\AdyenLogger
*/
protected $_adyenLogger;
/** /**
* @var \Magento\Framework\App\State * @var \Magento\Framework\App\State
*/ */
...@@ -50,12 +45,10 @@ class RecurringDataBuilder implements BuilderInterface ...@@ -50,12 +45,10 @@ class RecurringDataBuilder implements BuilderInterface
*/ */
public function __construct( public function __construct(
\Adyen\Payment\Helper\Data $adyenHelper, \Adyen\Payment\Helper\Data $adyenHelper,
\Magento\Framework\Model\Context $context, \Magento\Framework\Model\Context $context
\Adyen\Payment\Logger\AdyenLogger $adyenLogger
) { ) {
$this->adyenHelper = $adyenHelper; $this->adyenHelper = $adyenHelper;
$this->appState = $context->getAppState(); $this->appState = $context->getAppState();
$this->_adyenLogger = $adyenLogger;
} }
...@@ -88,7 +81,7 @@ class RecurringDataBuilder implements BuilderInterface ...@@ -88,7 +81,7 @@ class RecurringDataBuilder implements BuilderInterface
$result['enableRecurring'] = true; $result['enableRecurring'] = true;
} }
if ($payment->getAdditionalInformation("store_cc") === "1") { if ($payment->getAdditionalInformation('store_cc') === '1') {
$result['paymentMethod']['storeDetails'] = true; $result['paymentMethod']['storeDetails'] = true;
} }
......
...@@ -27,49 +27,54 @@ use Magento\Payment\Gateway\Response\HandlerInterface; ...@@ -27,49 +27,54 @@ use Magento\Payment\Gateway\Response\HandlerInterface;
class CheckoutPaymentsDetailsHandler implements HandlerInterface class CheckoutPaymentsDetailsHandler implements HandlerInterface
{ {
/**
* @var \Adyen\Payment\Helper\Data
*/
protected $adyenHelper;
public function __construct( public function __construct(
\Adyen\Payment\Logger\AdyenLogger $adyenLogger,
\Adyen\Payment\Helper\Data $adyenHelper \Adyen\Payment\Helper\Data $adyenHelper
) { ) {
$this->_adyenLogger = $adyenLogger; $this->adyenHelper = $adyenHelper;
$this->_adyenHelper = $adyenHelper;
} }
/** /**
* @param array $handlingSubject * @param array $handlingSubject
* @param array $response * @param array $response
*/ */
public function handle(array $handlingSubject, array $response) public function handle(array $handlingSubject, array $response)
{ {
$payment = \Magento\Payment\Gateway\Helper\SubjectReader::readPayment($handlingSubject); $payment = \Magento\Payment\Gateway\Helper\SubjectReader::readPayment($handlingSubject);
/** @var OrderPaymentInterface $payment */ /** @var OrderPaymentInterface $payment */
$payment = $payment->getPayment(); $payment = $payment->getPayment();
// set transaction not to processing by default wait for notification // set transaction not to processing by default wait for notification
$payment->setIsTransactionPending(true); $payment->setIsTransactionPending(true);
// no not send order confirmation mail // no not send order confirmation mail
$payment->getOrder()->setCanSendNewEmailFlag(false); $payment->getOrder()->setCanSendNewEmailFlag(false);
if (!empty($response['pspReference'])) { if (!empty($response['pspReference'])) {
// set pspReference as transactionId // set pspReference as transactionId
$payment->setCcTransId($response['pspReference']); $payment->setCcTransId($response['pspReference']);
$payment->setLastTransId($response['pspReference']); $payment->setLastTransId($response['pspReference']);
// set transaction // set transaction
$payment->setTransactionId($response['pspReference']); $payment->setTransactionId($response['pspReference']);
} }
if (!empty($response['additionalData']) && !empty($response['additionalData']['recurring.recurringDetailReference'])){ if (!empty($response['additionalData']) &&
!empty($response['additionalData']['recurring.recurringDetailReference'])
) {
$order = $payment->getOrder(); $order = $payment->getOrder();
$this->_adyenHelper->createAdyenBillingAgreement($order, $response['additionalData']);
}
// do not close transaction so you can do a cancel() and void $this->adyenHelper->createAdyenBillingAgreement($order, $response['additionalData']);
$payment->setIsTransactionClosed(false); }
$payment->setShouldCloseParentTransaction(false);
} // do not close transaction so you can do a cancel() and void
$payment->setIsTransactionClosed(false);
$payment->setShouldCloseParentTransaction(false);
}
} }
...@@ -29,7 +29,7 @@ class Agreement extends \Magento\Paypal\Model\Billing\Agreement ...@@ -29,7 +29,7 @@ class Agreement extends \Magento\Paypal\Model\Billing\Agreement
/** /**
* @var \Adyen\Payment\Helper\Data * @var \Adyen\Payment\Helper\Data
*/ */
private $_adyenHelper; private $adyenHelper;
/** /**
* Agreement constructor. * Agreement constructor.
...@@ -66,7 +66,7 @@ class Agreement extends \Magento\Paypal\Model\Billing\Agreement ...@@ -66,7 +66,7 @@ class Agreement extends \Magento\Paypal\Model\Billing\Agreement
$data $data
); );
$this->_adyenHelper = $adyenHelper; $this->adyenHelper = $adyenHelper;
} }
/** /**
...@@ -105,7 +105,7 @@ class Agreement extends \Magento\Paypal\Model\Billing\Agreement ...@@ -105,7 +105,7 @@ class Agreement extends \Magento\Paypal\Model\Billing\Agreement
// Billing agreement is CC // Billing agreement is CC
if (isset($data['card']['number'])) { if (isset($data['card']['number'])) {
$ccType = $data['variant']; $ccType = $data['variant'];
$ccTypes = $this->_adyenHelper->getCcTypesAltData(); $ccTypes = $this->adyenHelper->getCcTypesAltData();
if (isset($ccTypes[$ccType])) { if (isset($ccTypes[$ccType])) {
$ccType = $ccTypes[$ccType]['name']; $ccType = $ccTypes[$ccType]['name'];
...@@ -123,7 +123,7 @@ class Agreement extends \Magento\Paypal\Model\Billing\Agreement ...@@ -123,7 +123,7 @@ class Agreement extends \Magento\Paypal\Model\Billing\Agreement
} }
if ($data['variant'] == 'paypal') { if ($data['variant'] == 'paypal') {
$email = ""; $email = '';
if (isset($data['tokenDetails']['tokenData']['EmailId'])) { if (isset($data['tokenDetails']['tokenData']['EmailId'])) {
$email = $data['tokenDetails']['tokenData']['EmailId']; $email = $data['tokenDetails']['tokenData']['EmailId'];
...@@ -150,9 +150,7 @@ class Agreement extends \Magento\Paypal\Model\Billing\Agreement ...@@ -150,9 +150,7 @@ class Agreement extends \Magento\Paypal\Model\Billing\Agreement
public function setAgreementData($data) public function setAgreementData($data)
{ {
if (is_array($data)) { if (is_array($data)) {
unset($data['creationDate']); unset($data['creationDate'], $data['recurringDetailReference'], $data['payment_method']);
unset($data['recurringDetailReference']);
unset($data['payment_method']);
} }
$this->setData('agreement_data', json_encode($data)); $this->setData('agreement_data', json_encode($data));
...@@ -174,27 +172,20 @@ class Agreement extends \Magento\Paypal\Model\Billing\Agreement ...@@ -174,27 +172,20 @@ class Agreement extends \Magento\Paypal\Model\Billing\Agreement
->setReferenceId($contractDetail['recurring.recurringDetailReference']); ->setReferenceId($contractDetail['recurring.recurringDetailReference']);
// Billing agreement is CC // Billing agreement is CC
/**
* $contractDetail['cardBin'] = $cardBin;
* $contractDetail['recurringDetailReference'] = $recurringDetailReference;
* $contractDetail['cardHolderName'] = $cardHolderName;
* $contractDetail['cardSummary'] = $cardSummary;
* $contractDetail['expiryDate'] = $expiryDate;
* $contractDetail['paymentMethod'] = $paymentMethod;
*/
if (isset($contractDetail['cardBin']) && if (isset($contractDetail['cardBin']) &&
isset($contractDetail['cardHolderName']) && isset($contractDetail['cardHolderName']) &&
isset($contractDetail['cardSummary']) && isset($contractDetail['cardSummary']) &&
isset($contractDetail['expiryDate']) && isset($contractDetail['expiryDate']) &&
isset($contractDetail['paymentMethod'])) { isset($contractDetail['paymentMethod'])) {
$ccType = $contractDetail['paymentMethod']; $ccType = $contractDetail['paymentMethod'];
$ccTypes = $this->_adyenHelper->getCcTypesAltData(); $ccTypes = $this->adyenHelper->getCcTypesAltData();
if (isset($ccTypes[$ccType])) { if (isset($ccTypes[$ccType])) {
$ccType = $ccTypes[$ccType]['name']; $ccType = $ccTypes[$ccType]['name'];
} }
$label = __('%1, %2, **** %3', $label = __(
'%1, %2, **** %3',
$ccType, $ccType,
$contractDetail['cardHolderName'], $contractDetail['cardHolderName'],
$contractDetail['cardSummary'] $contractDetail['cardSummary']
...@@ -203,7 +194,7 @@ class Agreement extends \Magento\Paypal\Model\Billing\Agreement ...@@ -203,7 +194,7 @@ class Agreement extends \Magento\Paypal\Model\Billing\Agreement
} }
$expiryDate = explode('/', $contractDetail['expiryDate']); $expiryDate = explode('/', $contractDetail['expiryDate']);
$recurringType = $this->_adyenHelper->getRecurringTypeFromOneclickRecurringSetting(); $recurringType = $this->adyenHelper->getRecurringTypeFromOneclickRecurringSetting();
$agreementData = [ $agreementData = [
'card' => [ 'card' => [
...@@ -219,6 +210,5 @@ class Agreement extends \Magento\Paypal\Model\Billing\Agreement ...@@ -219,6 +210,5 @@ class Agreement extends \Magento\Paypal\Model\Billing\Agreement
$this->setAgreementData($agreementData); $this->setAgreementData($agreementData);
return $this; return $this;
} }
} }
...@@ -285,7 +285,7 @@ define( ...@@ -285,7 +285,7 @@ define(
var form = 'form[data-role=' + codeValue + ']'; var form = 'form[data-role=' + codeValue + ']';
var validate = $(form).validation() && $(form).validation('isValid'); var validate = $(form).validation() && $(form).validation('isValid');
debugger;
// bcmc does not have any cvc // bcmc does not have any cvc
if (!validate || (isValid() == false && variant() != "bcmc")) { if (!validate || (isValid() == false && variant() != "bcmc")) {
return false; return false;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment