We will work on Apr 26th (Saturday) and will be off from Apr 30th (Wednesday) until May 2nd (Friday) for public holiday in our country

Commit 687dc086 authored by attilak's avatar attilak Committed by Rik ter Beek

- Add admin message to add the API key instead of the username and

password
- Remove username, password (test, live) from admin/store configuration/
required settings. Add API Key instead
- Get secure fields SDK based on isDemo
- Include checkout js components
- Remove CSE library and tokens
parent 4c911479
<?php
/**
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* Adyen Payment Module
*
* Copyright (c) 2018 Adyen B.V.
* This file is open source and available under the MIT license.
* See the LICENSE file for more info.
*
* Author: Adyen <magento@adyen.com>
*/
namespace Adyen\Payment\AdminMessage;
class APIKeyMessage implements \Magento\Framework\Notification\MessageInterface
{
/**
* @var \Adyen\Payment\Helper\Data
*/
protected $_adyenHelper;
/**
* @var \Magento\AdminNotification\Model\InboxFactory
*/
protected $_inboxFactory;
/**
* @var \Magento\Framework\App\Config\ScopeConfigInterface
*/
protected $scopeConfigInterface;
/**
* @var \Magento\Store\Model\StoreManagerInterface
*/
protected $storeManagerInterface;
/**
* @var \Magento\Backend\Model\Auth\Session
*/
protected $authSession;
/**
* Message identity
*/
const MESSAGE_IDENTITY = 'Adyen API Key Control message';
/**
* APIKeyMessage constructor.
*
* @param \Adyen\Payment\Helper\Data $adyenHelper
* @param \Magento\AdminNotification\Model\InboxFactory $inboxFactory
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfigInterface
*/
public function __construct(
\Adyen\Payment\Helper\Data $adyenHelper,
\Magento\AdminNotification\Model\InboxFactory $inboxFactory,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfigInterface,
\Magento\Store\Model\StoreManagerInterface $storeManagerInterface,
\Magento\Backend\Model\Auth\Session $authSession
) {
$this->_adyenHelper = $adyenHelper;
$this->_inboxFactory = $inboxFactory;
$this->scopeConfigInterface = $scopeConfigInterface;
$this->storeManagerInterface = $storeManagerInterface;
$this->authSession = $authSession;
}
/**
* Retrieve unique system message identity
*
* @return string
*/
public function getIdentity()
{
return self::MESSAGE_IDENTITY;
}
/**
* Check whether the system message should be shown
*
* @return bool
*/
public function isDisplayed()
{
// Only execute the query the first time you access the Admin page
if ($this->authSession->isFirstPageAfterLogin() && $this->_adyenHelper->getWsUsername()) {
try {
$title = "Adyen extension requires the API KEY!";
$messageData[] = array(
'severity' => $this->getSeverity(),
'date_added' => date("Y-m-d"),
'title' => $title,
'description' => "Please provide API-KEY for the webserver user " . $this->_adyenHelper->getWsUsername() . " for default/store " . $this->storeManagerInterface->getStore()->getName(),
'url' => "https://docs.adyen.com/developers/plug-ins-and-partners/magento-2/set-up-the-plugin-in-magento#step3configuretheplugininmagento",
);
/*
* 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(array_reverse($messageData));
/*
* Only show the message if the API Key is not set
*/
if (empty($this->_adyenHelper->getAPIKey())) {
return true;
}
} catch (\Exception $e) {
return false;
}
}
return false;
}
/**
* Retrieve system message text
*
* @return \Magento\Framework\Phrase
*/
public function getText()
{
$message = __("Please provide API-KEY for the webserver user " . $this->_adyenHelper->getWsUsername() . " for default/store" . $this->storeManagerInterface->getStore()->getName());
return __($message);
}
/**
* Retrieve system message severity
*
* @return int
*/
public function getSeverity()
{
return self::SEVERITY_CRITICAL;
}
}
......@@ -33,6 +33,8 @@ class Data extends AbstractHelper
const MODULE_NAME = 'adyen-magento2';
const TEST = 'test';
const LIVE = 'live';
const SECURE_FIELDS_SDK_TEST = "https://checkoutshopper-test.adyen.com/checkoutshopper/assets/js/sdk/checkoutSecuredFields.1.3.0.min.js";
const SECURE_FIELDS_SDK_LIVE = "https://checkoutshopper-live.adyen.com/checkoutshopper/assets/js/sdk/checkoutSecuredFields.1.3.0.min.js";
/**
* @var \Magento\Framework\Encryption\EncryptorInterface
......@@ -94,6 +96,16 @@ class Data extends AbstractHelper
*/
protected $adyenLogger;
/**
* @var \Magento\Framework\UrlInterface
*/
protected $urlInterface;
/**
* @var \Adyen\Service\ServiceFactory
*/
protected $adyenServiceFactory;
/**
* Data constructor.
*
......@@ -105,8 +117,13 @@ class Data extends AbstractHelper
* @param \Adyen\Payment\Model\ResourceModel\Billing\Agreement\CollectionFactory $billingAgreementCollectionFactory
* @param \Magento\Framework\View\Asset\Repository $assetRepo
* @param \Magento\Framework\View\Asset\Source $assetSource
* @param \Adyen\Payment\Model\ResourceModel\Notification\CollectionFactory $notificationFactory
* @param \Magento\Tax\Model\Config $taxConfig
* @param \Magento\Tax\Model\Calculation $taxCalculation
* @param \Magento\Framework\App\ProductMetadataInterface $productMetadata
* @param \Adyen\Payment\Logger\AdyenLogger $adyenLogger
* @param \Magento\Framework\UrlInterface $urlInterface
* @param \Adyen\Service\ServiceFactory $adyenServiceFactory
*/
public function __construct(
\Magento\Framework\App\Helper\Context $context,
......@@ -121,7 +138,10 @@ class Data extends AbstractHelper
\Magento\Tax\Model\Config $taxConfig,
\Magento\Tax\Model\Calculation $taxCalculation,
\Magento\Framework\App\ProductMetadataInterface $productMetadata,
\Adyen\Payment\Logger\AdyenLogger $adyenLogger
\Adyen\Payment\Logger\AdyenLogger $adyenLogger,
\Magento\Framework\UrlInterface $urlInterface,
\Adyen\Service\ServiceFactory $adyenServiceFactory
) {
parent::__construct($context);
$this->_encryptor = $encryptor;
......@@ -136,6 +156,8 @@ class Data extends AbstractHelper
$this->_taxCalculation = $taxCalculation;
$this->productMetadata = $productMetadata;
$this->adyenLogger = $adyenLogger;
$this->urlInterface = $urlInterface;
$this->adyenServiceFactory = $adyenServiceFactory;
}
/**
......@@ -596,37 +618,33 @@ class Data extends AbstractHelper
}
/**
* @desc Retrieve the webserver username
* @desc Retrieve the API key
* @return string
*/
public function getWsUsername($storeId = null)
public function getAPIKey($storeId = null)
{
if ($this->isDemoMode($storeId)) {
$wsUsername = trim($this->getAdyenAbstractConfigData('ws_username_test', $storeId));
$apiKey = $this->_encryptor->decrypt(trim($this->getAdyenAbstractConfigData('api_key_test',
$storeId)));
} else {
$wsUsername = trim($this->getAdyenAbstractConfigData('ws_username_live', $storeId));
$apiKey = $this->_encryptor->decrypt(trim($this->getAdyenAbstractConfigData('api_key_live',
$storeId)));
}
return $wsUsername;
return $apiKey;
}
/**
* @desc Retrieve the webserver password
* @desc Retrieve the webserver username
* @return string
*/
public function getWsPassword($storeId = null)
public function getWsUsername($storeId = null)
{
if ($this->isDemoMode($storeId)) {
$wsPassword = $this->_encryptor->decrypt(trim($this->getAdyenAbstractConfigData(
'ws_password_test',
$storeId
)));
$wsUsername = trim($this->getAdyenAbstractConfigData('ws_username_test', $storeId));
} else {
$wsPassword = $this->_encryptor->decrypt(trim($this->getAdyenAbstractConfigData(
'ws_password_live',
$storeId
)));
$wsUsername = trim($this->getAdyenAbstractConfigData('ws_username_live', $storeId));
}
return $wsPassword;
return $wsUsername;
}
/**
......@@ -1025,33 +1043,17 @@ class Data extends AbstractHelper
}
/**
* @param $storeId
* @return mixed
*/
public function getLibraryToken($storeId = null)
{
if ($this->isDemoMode($storeId)) {
$libraryToken = $this->getAdyenCcConfigData('cse_library_token_test', $storeId);
} else {
$libraryToken = $this->getAdyenCcConfigData('cse_library_token_live', $storeId);
}
return $libraryToken;
}
/**
* Returns the hosted location of the client side encryption file
* Retrieves secure field sdk url based on the demo mode
*
* @param null $storeId
* @return string
*/
public function getLibrarySource($storeId = null)
public function getSecureFieldsSdk()
{
$environment = self::LIVE;
if ($this->isDemoMode($storeId)) {
$environment = self::TEST;
if ($this->isDemoMode()) {
return self::SECURE_FIELDS_SDK_TEST;
} else {
return self::SECURE_FIELDS_SDK_LIVE;
}
return "https://" . $environment . ".adyen.com/hpp/cse/js/" . $this->getLibraryToken($storeId) . ".shtml";
}
/**
......@@ -1309,16 +1311,11 @@ class Data extends AbstractHelper
public function initializeAdyenClient($storeId = null, $apiKey = null)
{
// initialize client
$client = new \Adyen\Client();
if ($apiKey) {
$client->setXApiKey($apiKey);
} else {
$client->setUsername($this->getWsUsername($storeId));
$client->setPassword($this->getWsPassword($storeId));
}
$apiKey = $this->getAPIKey($storeId);
$client = new \Adyen\Client();
$client->setApplicationName("Magento 2 plugin");
$client->setXApiKey($apiKey);
$client->setAdyenPaymentSource($this->getModuleName(), $this->getModuleVersion());
......@@ -1343,5 +1340,47 @@ class Data extends AbstractHelper
public function createAdyenPosPaymentService($client)
{
return new \Adyen\Service\PosPayment($client);
}
return $client;
}
/**
* Retrieve origin keys for platform's base url
*
* @return string
* @throws \Adyen\AdyenException
*/
public function getOriginKeyForBaseUrl()
{
$originKey = "";
$baseUrl = $this->urlInterface->getBaseUrl();
if ($originKeys = $this->getOriginKeys($baseUrl)) {
$originKey = $originKeys[$baseUrl];
}
return $originKey;
}
/**
* Get origin keys for a specific url using the adyen api library client
*
* @param $url
* @return mixed
* @throws \Adyen\AdyenException
*/
private function getOriginKeys($url)
{
$params = array(
"originDomains" => array(
$url
)
);
$client = $this->initializeAdyenClient();
$service = $this->adyenServiceFactory->createCheckoutUtility($client);
$respone = $service->originKeys($params);
return $respone['originKeys'];
}
}
......@@ -131,11 +131,13 @@ class AdyenCcConfigProvider implements ConfigProviderInterface
$canCreateBillingAgreement = true;
}
$config['payment'] ['adyenCc']['librarySource'] = $this->_adyenHelper->getLibrarySource();
$config['payment']['adyenCc']['generationTime'] = date("c");
$config['payment']['adyenCc']['canCreateBillingAgreement'] = $canCreateBillingAgreement;
$config['payment']['adyenCc']['icons'] = $this->getIcons();
$config['payment']['adyenCc']['originKey'] = $this->_adyenHelper->getOriginKeyForBaseUrl();
$config['payment']['adyenCc']['secureFieldsSource'] = $this->_adyenHelper->getSecureFieldsSdk();
// has installments by default false
$config['payment']['adyenCc']['hasInstallments'] = false;
......
......@@ -5,6 +5,7 @@
<argument name="messages" xsi:type="array">
<item name="AdyenCronMessage" xsi:type="string">Adyen\Payment\AdminMessage\CronMessage</item>
<item name="AdyenVersionMessage" xsi:type="string">Adyen\Payment\AdminMessage\VersionMessage</item>
<item name="AdyenAPIKeyMessage" xsi:type="string">Adyen\Payment\AdminMessage\APIKeyMessage</item>
</argument>
</arguments>
</type>
......
......@@ -47,16 +47,6 @@
<source_model>Adyen\Payment\Model\Config\Source\CcType</source_model>
<config_path>payment/adyen_cc/cctypes</config_path>
</field>
<field id="cse_library_token_test" translate="label" type="text" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Library token of Test Adyen Web Service User</label>
<tooltip>Copy this from the Test Adyen Customer Area => Settings => Users => System => [web service user]=> Library token.</tooltip>
<config_path>payment/adyen_cc/cse_library_token_test</config_path>
</field>
<field id="cse_library_token_live" translate="label" type="text" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Library token of Live Adyen Web Service User</label>
<tooltip>Copy this from the Live Adyen Customer Area => Settings => Users => System => [web service user]=> Library token.</tooltip>
<config_path>payment/adyen_cc/cse_library_token_live</config_path>
</field>
<group id="adyen_cc_advanced_settings" translate="label" showInDefault="1" showInWebsite="1" showInStore="1" sortOrder="150">
<label>Advanced Settings</label>
......
......@@ -49,27 +49,17 @@
<config_path>payment/adyen_abstract/notification_password</config_path>
<tooltip>Set a password of your choice and copy it over to Adyen Customer Area => Settings => Server Communication => Standard Notification => Password.</tooltip>
</field>
<field id="ws_username_test" translate="label" type="text" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Webservice username for Test</label>
<tooltip>Find this in your Test Adyen Customer Area => Settings => Users => System. Normally this will be ws@Company.YourCompanyAccount. Copy and Paste the exact ws user name here.</tooltip>
<config_path>payment/adyen_abstract/ws_username_test</config_path>
</field>
<field id="ws_password_test" translate="label" type="obscure" sortOrder="60" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Webservice Password for Test</label>
<tooltip>Find this in your Test Adyen Customer Area => Settings => Users => System. Click on your web service user and generate a new password. Copy and Paste the exact password here.</tooltip>
<field id="api_key_test" translate="label" type="obscure" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="0">
<label>API key for Test</label>
<tooltip>If you don't know your Api-Key, log in to your Test Customer Area. Navigate to Settings > Users > System, and click on your webservice user, normally this will be ws@Company.YourCompanyAccount. Under Checkout token is your API Key.</tooltip>
<backend_model>Magento\Config\Model\Config\Backend\Encrypted</backend_model>
<config_path>payment/adyen_abstract/ws_password_test</config_path>
</field>
<field id="ws_username_live" translate="label" type="text" sortOrder="70" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Webservice username for Live</label>
<tooltip>This is only applicable if you have a Live account. Find this in your Live Adyen Customer Area => Settings => Users => System. Normally this will be ws@Company.YourCompanyAccount. Copy and Paste the exact ws user name here.</tooltip>
<config_path>payment/adyen_abstract/ws_username_live</config_path>
<config_path>payment/adyen_abstract/api_key_test</config_path>
</field>
<field id="ws_password_live" translate="label" type="obscure" sortOrder="80" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Webservice Password for Live</label>
<tooltip>This is only applicable if you have a Live account. Find this in your Live Adyen Customer Area => Settings => Users => System. Click on your web service user and generate a new password. Copy and Paste the exact password here.</tooltip>
<field id="api_key_live" translate="label" type="obscure" sortOrder="60" showInDefault="1" showInWebsite="1" showInStore="0">
<label>API key for Live</label>
<tooltip>If you don't know your Api-Key, log in to your Live Customer Area. Navigate to Settings > Users > System, and click on your webservice user, normally this will be ws@Company.YourCompanyAccount. Under Checkout token is your API Key.</tooltip>
<backend_model>Magento\Config\Model\Config\Backend\Encrypted</backend_model>
<config_path>payment/adyen_abstract/ws_password_live</config_path>
<config_path>payment/adyen_abstract/api_key_live</config_path>
</field>
<field id="capture_mode" translate="label" type="select" sortOrder="90" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Capture Delay</label>
......
......@@ -25,6 +25,8 @@
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/layout_generic.xsd">
<head>
<css src="Adyen_Payment::css/styles.css"/>
<script src="Adyen_Payment::js/adyen.2.0.0.js"></script>
<script src="Adyen_Payment::js/adyen.checkout.js"></script>
</head>
<body>
<referenceBlock name="checkout.root">
......
This diff is collapsed.
This diff is collapsed.
......@@ -70,12 +70,12 @@ define(
installments.setInstallments(0);
// include dynamic cse javascript
var dfScriptTag = document.createElement('script');
dfScriptTag.src = this.getLibrarySource();
dfScriptTag.type = "text/javascript";
document.body.appendChild(dfScriptTag);
// include secure fields sdk javascript
var secureFieldsScriptTag = document.createElement('script');
secureFieldsScriptTag.id = "secure-fields-script-tag";
secureFieldsScriptTag.src = this.getSecureFieldsSource();
secureFieldsScriptTag.type = "text/javascript";
document.body.appendChild(secureFieldsScriptTag)
//Set credit card number to credit card data object
this.creditCardNumber.subscribe(function (value) {
......@@ -134,6 +134,9 @@ define(
getCode: function () {
return 'adyen_cc';
},
getOriginKey: function () {
return window.checkoutConfig.payment.adyenCc.originKey;
},
getData: function () {
return {
'method': this.item.method,
......@@ -178,9 +181,9 @@ define(
var cardData = {
number: this.creditCardNumber(),
cvc: this.creditCardVerificationNumber(),
holderName: this.creditCardOwner(),
expiryMonth: this.creditCardExpMonth(),
expiryYear: this.creditCardExpYear(),
holderName: this.creditCardOwner(),
generationtime: generationtime
};
......@@ -227,9 +230,8 @@ define(
getCSEKey: function () {
return window.checkoutConfig.payment.adyenCc.cseKey;
},
getLibrarySource: function () {
return window.checkoutConfig.payment.adyenCc.librarySource;
getSecureFieldsSource: function () {
return window.checkoutConfig.payment.adyenCc.secureFieldsSource;
},
getGenerationTime: function () {
return window.checkoutConfig.payment.adyenCc.generationTime;
......
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