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 703b5e20 authored by Rik ter Beek's avatar Rik ter Beek Committed by GitHub

PW-300 Hosted CSE solution, change from CSE key to library token (#230)

* PW-300 Hosted CSE solution, change from CSE key to library token

* use test or live url depending if running on test or live. adyen is already loaded through adyen_cc payment method so can be ignored for adyen_oneclick methdo

* add storeId into call
parent 279ee778
......@@ -67,7 +67,8 @@ class Cc extends \Magento\Payment\Block\Form\Cc
\Adyen\Payment\Helper\Data $adyenHelper,
\Magento\Checkout\Model\Session $checkoutSession,
array $data = []
) {
)
{
parent::__construct($context, $paymentConfig);
$this->_adyenHelper = $adyenHelper;
$this->_appState = $context->getAppState();
......@@ -79,7 +80,7 @@ class Cc extends \Magento\Payment\Block\Form\Cc
* @return mixed
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function getCsePublicKey()
public function getLibrarySource()
{
// get storeId for admin
if (!$this->_appState->getAreaCode() === \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE) {
......@@ -88,15 +89,7 @@ class Cc extends \Magento\Payment\Block\Form\Cc
$storeId = null;
}
$demoMode = $this->_adyenHelper->getAdyenAbstractConfigDataFlag('demo_mode', $storeId);
if($demoMode) {
$cseKey = $this->_adyenHelper->getAdyenCcConfigData('cse_publickey_test', $storeId);
} else {
$cseKey = $this->_adyenHelper->getAdyenCcConfigData('cse_publickey_live', $storeId);
}
return $cseKey;
return $this->_adyenHelper->getLibrarySource($storeId);
}
/**
......@@ -111,7 +104,7 @@ class Cc extends \Magento\Payment\Block\Form\Cc
$this->getCheckoutSession();
$store = $this->_checkoutSession->getQuote()->getStore();
$enableMoto = $this->_adyenHelper->getAdyenCcConfigDataFlag('enable_moto', $store->getId());
if($enableMoto) {
if ($enableMoto) {
return false;
}
}
......
......@@ -47,7 +47,8 @@ class CcAuthorizationDataBuilder implements BuilderInterface
public function __construct(
\Adyen\Payment\Helper\Data $adyenHelper,
\Magento\Framework\Model\Context $context
) {
)
{
$this->adyenHelper = $adyenHelper;
$this->appState = $context->getAppState();
}
......@@ -65,38 +66,30 @@ class CcAuthorizationDataBuilder implements BuilderInterface
$storeId = $order->getStoreId();
$request = [];
if ($this->adyenHelper->getAdyenCcConfigDataFlag('cse_enabled', $storeId)) {
$request['additionalData']['card.encrypted.json'] =
$payment->getAdditionalInformation(AdyenCcDataAssignObserver::ENCRYPTED_DATA);
// Remove from additional data
$payment->unsAdditionalInformation(AdyenCcDataAssignObserver::ENCRYPTED_DATA);
} else {
$requestCreditCardDetails = [
"expiryMonth" => $payment->getCcExpMonth(),
"expiryYear" => $payment->getCcExpYear(),
"holderName" => $payment->getCcOwner(),
"number" => $payment->getCcNumber(),
"cvc" => $payment->getCcCid(),
];
$cardDetails['card'] = $requestCreditCardDetails;
$request = array_merge($request, $cardDetails);
}
$request['additionalData']['card.encrypted.json'] =
$payment->getAdditionalInformation(AdyenCcDataAssignObserver::ENCRYPTED_DATA);
// Remove from additional data
$payment->unsAdditionalInformation(AdyenCcDataAssignObserver::ENCRYPTED_DATA);
/**
* if MOTO for backend is enabled use MOTO as shopper interaction type
*/
$enableMoto = $this->adyenHelper->getAdyenCcConfigDataFlag('enable_moto', $storeId);
if ($this->appState->getAreaCode() === \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE &&
$enableMoto) {
$enableMoto
) {
$request['shopperInteraction'] = "Moto";
}
// if installments is set add it into the request
if ($payment->getAdditionalInformation('number_of_installments') &&
$payment->getAdditionalInformation('number_of_installments') > 0) {
$payment->getAdditionalInformation('number_of_installments') > 0
) {
$request['installments']['value'] = $payment->getAdditionalInformation('number_of_installments');
}
return $request;
}
}
\ No newline at end of file
......@@ -31,6 +31,9 @@ use Magento\Framework\App\Helper\AbstractHelper;
class Data extends AbstractHelper
{
const TEST = 'test';
const LIVE = 'live';
/**
* @var \Magento\Framework\Encryption\EncryptorInterface
*/
......@@ -88,7 +91,8 @@ class Data extends AbstractHelper
\Magento\Framework\View\Asset\Repository $assetRepo,
\Magento\Framework\View\Asset\Source $assetSource,
\Adyen\Payment\Model\Resource\Notification\CollectionFactory $notificationFactory
) {
)
{
parent::__construct($context);
$this->_encryptor = $encryptor;
$this->_dataStorage = $dataStorage;
......@@ -873,4 +877,33 @@ class Data extends AbstractHelper
return count($notifications);
}
/**
* @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
*
* @param null $storeId
* @return string
*/
public function getLibrarySource($storeId = null)
{
$environment = self::LIVE;
if ($this->isDemoMode($storeId)) {
$environment = self::TEST;
}
return "https://" . $environment . ".adyen.com/hpp/cse/js/" . $this->getLibraryToken($storeId) . ".shtml";
}
}
\ No newline at end of file
......@@ -64,7 +64,7 @@ class AdyenCcConfigProvider implements ConfigProviderInterface
* @var \Magento\Payment\Model\CcConfig
*/
private $ccConfig;
/**
* AdyenCcConfigProvider constructor.
......@@ -84,7 +84,8 @@ class AdyenCcConfigProvider implements ConfigProviderInterface
\Magento\Framework\UrlInterface $urlBuilder,
Source $assetSource,
\Magento\Payment\Model\CcConfig $ccConfig
) {
)
{
$this->_paymentHelper = $paymentHelper;
$this->_adyenHelper = $adyenHelper;
$this->_request = $request;
......@@ -123,25 +124,13 @@ class AdyenCcConfigProvider implements ConfigProviderInterface
]
]);
$demoMode = $this->_adyenHelper->getAdyenAbstractConfigDataFlag('demo_mode');
if ($demoMode) {
$cseKey = $this->_adyenHelper->getAdyenCcConfigData('cse_publickey_test');
} else {
$cseKey = $this->_adyenHelper->getAdyenCcConfigData('cse_publickey_live');
}
$cseEnabled = $this->_adyenHelper->getAdyenCcConfigDataFlag('cse_enabled');
$recurringType = $this->_adyenHelper->getAdyenAbstractConfigData('recurring_type');
$canCreateBillingAgreement = false;
if ($recurringType == "ONECLICK" || $recurringType == "ONECLICK,RECURRING") {
$canCreateBillingAgreement = true;
}
$config['payment'] ['adyenCc']['cseKey'] = $cseKey;
$config['payment'] ['adyenCc']['cseEnabled'] = $cseEnabled;
$config['payment'] ['adyenCc']['cseEnabled'] = $cseEnabled;
$config['payment'] ['adyenCc']['librarySource'] = $this->_adyenHelper->getLibrarySource();
$config['payment']['adyenCc']['generationTime'] = date("c");
$config['payment']['adyenCc']['canCreateBillingAgreement'] = $canCreateBillingAgreement;
$config['payment']['adyenCc']['icons'] = $this->getIcons();
......@@ -250,7 +239,7 @@ class AdyenCcConfigProvider implements ConfigProviderInterface
{
return $this->ccConfig->getCvvImageUrl();
}
/**
* Retrieve request object
*
......
......@@ -90,7 +90,8 @@ class AdyenOneclickConfigProvider implements ConfigProviderInterface
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Framework\UrlInterface $urlBuilder,
\Magento\Payment\Model\CcConfig $ccConfig
) {
)
{
$this->_adyenHelper = $adyenHelper;
$this->_request = $request;
$this->_customerSession = $customerSession;
......@@ -130,25 +131,13 @@ class AdyenOneclickConfigProvider implements ConfigProviderInterface
]
]);
$demoMode = $this->_adyenHelper->getAdyenAbstractConfigDataFlag('demo_mode');
if ($demoMode) {
$cseKey = $this->_adyenHelper->getAdyenCcConfigData('cse_publickey_test');
} else {
$cseKey = $this->_adyenHelper->getAdyenCcConfigData('cse_publickey_live');
}
$cseEnabled = $this->_adyenHelper->getAdyenCcConfigDataFlag('cse_enabled');
$recurringType = $this->_adyenHelper->getAdyenAbstractConfigData('recurring_type');
$canCreateBillingAgreement = false;
if ($recurringType == "ONECLICK" || $recurringType == "ONECLICK,RECURRING") {
$canCreateBillingAgreement = true;
}
$config['payment'] ['adyenOneclick']['cseKey'] = $cseKey;
$config['payment'] ['adyenOneclick']['cseEnabled'] = $cseEnabled;
$config['payment'] ['adyenOneclick']['cseEnabled'] = $cseEnabled;
$config['payment'] ['adyenOneclick']['librarySource'] = $this->_adyenHelper->getLibrarySource();
$config['payment']['adyenOneclick']['generationTime'] = date("c");
$config['payment']['adyenOneclick']['canCreateBillingAgreement'] = $canCreateBillingAgreement;
......@@ -178,9 +167,9 @@ class AdyenOneclickConfigProvider implements ConfigProviderInterface
$recurringType = $this->_getRecurringContractType();
$billingAgreements = $this->_adyenHelper->getOneClickPaymentMethods(
$customerId,
$storeId,
$grandTotal,
$customerId,
$storeId,
$grandTotal,
$recurringType
);
}
......@@ -227,7 +216,6 @@ class AdyenOneclickConfigProvider implements ConfigProviderInterface
}
/**
* Retrieve credit card expire months
*
......
......@@ -47,20 +47,15 @@
<source_model>Adyen\Payment\Model\Config\Source\CcType</source_model>
<config_path>payment/adyen_cc/cctypes</config_path>
</field>
<!--<field id="cse_enabled" translate="label" type="select" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="1">-->
<!--<label>Enable CSE</label>-->
<!--<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>-->
<!--<config_path>payment/adyen_cc/cse_enabled</config_path>-->
<!--</field>-->
<field id="cse_publickey_test" translate="label" type="textarea" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Enter CSE Public Key of Test Adyen Web Service User</label>
<depends><field id="cse_enabled">1</field></depends>
<config_path>payment/adyen_cc/cse_publickey_test</config_path>
<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_publickey_live" translate="label" type="textarea" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Enter CSE Public Key of Live Adyen Web Service User</label>
<depends><field id="cse_enabled">1</field></depends>
<config_path>payment/adyen_cc/cse_publickey_live</config_path>
<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" sortOrder="150">
......
......@@ -45,7 +45,6 @@
<sort_order>2</sort_order>
<cctypes>AE,VI,MC,DI</cctypes>
<useccv>1</useccv>
<cse_enabled>1</cse_enabled>
<enable_moto>0</enable_moto>
<payment_action>authorize</payment_action>
<is_gateway>1</is_gateway>
......@@ -71,7 +70,6 @@
<recurring_payment_type>ONECLICK</recurring_payment_type>
<payment_action>authorize</payment_action>
<useccv>1</useccv>
<cse_enabled>1</cse_enabled>
<enable_moto>0</enable_moto>
<payment_action>authorize</payment_action>
<is_gateway>1</is_gateway>
......
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -5,9 +5,6 @@
/*jshint browser:true jquery:true*/
/*global alert*/
var config = {
paths: {
'adyen/encrypt' : 'Adyen_Payment/js/view/payment/adyen.encrypt.min'
},
config: {
mixins: {
'Adyen_Payment/js/action/place-order': {
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -34,9 +34,8 @@ define(
'Magento_Checkout/js/model/quote',
'ko',
'Adyen_Payment/js/model/installments',
'adyen/encrypt'
],
function (_, $, Component, placeOrderAction, $t, additionalValidators, customer, creditCardData, quote, ko, installments, adyenEncrypt) {
function (_, $, Component, placeOrderAction, $t, additionalValidators, customer, creditCardData, quote, ko, installments) {
'use strict';
var cvcLength = ko.observable(4);
......@@ -69,21 +68,27 @@ define(
return this;
},
getInstallments: installments.getInstallments(),
initialize: function() {
initialize: function () {
var self = this;
this._super();
// include dynamic cse javascript
var dfScriptTag = document.createElement('script');
dfScriptTag.src = this.getLibrarySource();
dfScriptTag.type = "text/javascript";
document.body.appendChild(dfScriptTag);
//Set credit card number to credit card data object
this.creditCardNumber.subscribe(function(value) {
this.creditCardNumber.subscribe(function (value) {
// installments enabled ??
var allInstallments = self.getAllInstallments();
// what card is this ??
var creditcardType = creditCardData.creditCard.type;
if(creditcardType) {
if (creditcardType) {
cvcLength(4);
if (creditcardType != "AE"){
if (creditcardType != "AE") {
cvcLength(3);
}
if (creditcardType in allInstallments) {
......@@ -93,13 +98,13 @@ define(
var numberOfInstallments = 0;
$.each(installmentCreditcard, function (amount, installment) {
if(grandTotal <= amount) {
if (grandTotal <= amount) {
numberOfInstallments = installment;
return false;
}
});
if(numberOfInstallments > 0) {
if (numberOfInstallments > 0) {
installments.setInstallments(numberOfInstallments);
}
} else {
......@@ -108,16 +113,16 @@ define(
}
});
},
setPlaceOrderHandler: function(handler) {
setPlaceOrderHandler: function (handler) {
this.placeOrderHandler = handler;
},
setValidateHandler: function(handler) {
setValidateHandler: function (handler) {
this.validateHandler = handler;
},
getCode: function() {
getCode: function () {
return 'adyen_cc';
},
getData: function() {
getData: function () {
return {
'method': this.item.method,
additional_data: {
......@@ -129,16 +134,16 @@ define(
}
};
},
getCvcLength: function() {
getCvcLength: function () {
return cvcLength();
},
isActive: function() {
isActive: function () {
return true;
},
/**
* @override
*/
placeOrder: function(data, event) {
placeOrder: function (data, event) {
var self = this,
placeOrder;
......@@ -146,19 +151,18 @@ define(
event.preventDefault();
}
var cse_key = this.getCSEKey();
var options = {};
var cseInstance = adyenEncrypt.createEncryption(cse_key, options);
var options = {};
var cseInstance = adyen.createEncryption(options);
var generationtime = self.getGenerationTime();
var cardData = {
number : self.creditCardNumber(),
cvc : self.creditCardVerificationNumber(),
holderName : self.creditCardOwner(),
expiryMonth : self.creditCardExpMonth(),
expiryYear : self.creditCardExpYear(),
generationtime : generationtime
number: self.creditCardNumber(),
cvc: self.creditCardVerificationNumber(),
holderName: self.creditCardOwner(),
expiryMonth: self.creditCardExpMonth(),
expiryYear: self.creditCardExpYear(),
generationtime: generationtime
};
var data = cseInstance.encrypt(cardData);
......@@ -168,44 +172,41 @@ define(
this.isPlaceOrderActionAllowed(false);
placeOrder = placeOrderAction(this.getData(), this.redirectAfterPlaceOrder);
$.when(placeOrder).fail(function(response) {
$.when(placeOrder).fail(function (response) {
self.isPlaceOrderActionAllowed(true);
});
return true;
}
return false;
},
getControllerName: function() {
getControllerName: function () {
return window.checkoutConfig.payment.iframe.controllerName[this.getCode()];
},
getPlaceOrderUrl: function() {
getPlaceOrderUrl: function () {
return window.checkoutConfig.payment.iframe.placeOrderUrl[this.getCode()];
},
context: function() {
context: function () {
return this;
},
isCseEnabled: function() {
return window.checkoutConfig.payment.adyenCc.cseEnabled;
},
getCSEKey: function() {
return window.checkoutConfig.payment.adyenCc.cseKey;
getLibrarySource: function () {
return window.checkoutConfig.payment.adyenCc.librarySource;
},
getGenerationTime: function() {
getGenerationTime: function () {
return window.checkoutConfig.payment.adyenCc.generationTime;
},
canCreateBillingAgreement: function() {
if(customer.isLoggedIn()) {
canCreateBillingAgreement: function () {
if (customer.isLoggedIn()) {
return window.checkoutConfig.payment.adyenCc.canCreateBillingAgreement;
}
return false;
},
isShowLegend: function() {
isShowLegend: function () {
return true;
},
validate: function () {
var form = 'form[data-role=adyen-cc-form]';
var validate = $(form).validation() && $(form).validation('isValid');
var validate = $(form).validation() && $(form).validation('isValid');
// add extra validation because jqeury validation will not work on non name attributes
var ccNumber = Boolean($(form + ' #creditCardNumber').valid());
var owner = Boolean($(form + ' #creditCardHolderName').valid());
......@@ -213,13 +214,13 @@ define(
var expiration_yr = Boolean($(form + ' #adyen_cc_expiration_yr').valid());
var cid = Boolean($(form + ' #adyen_cc_cc_cid').valid());
if(!validate || !ccNumber || !owner || !expiration || !expiration_yr || !cid) {
if (!validate || !ccNumber || !owner || !expiration || !expiration_yr || !cid) {
return false;
}
return true;
},
showLogo: function() {
showLogo: function () {
return window.checkoutConfig.payment.adyen.showLogo;
},
getIcons: function (type) {
......@@ -227,10 +228,10 @@ define(
? window.checkoutConfig.payment.adyenCc.icons[type]
: false
},
hasInstallments: function() {
hasInstallments: function () {
return window.checkoutConfig.payment.adyenCc.hasInstallments;
},
getAllInstallments: function() {
getAllInstallments: function () {
return window.checkoutConfig.payment.adyenCc.installments;
}
});
......
......@@ -45,7 +45,6 @@
</div>
<form class="form" id="adyen-cc-form" data-role="adyen-cc-form" action="#" method="post" data-bind="mageInit: {
'transparent':{
'context': context(),
......@@ -54,13 +53,15 @@
}, 'validation':[]}">
<fieldset data-bind="attr: {class: 'fieldset payment items ccard ' + getCode(), id: 'payment_form_' + getCode()}">
<fieldset
data-bind="attr: {class: 'fieldset payment items ccard ' + getCode(), id: 'payment_form_' + getCode()}">
<!-- ko if: (isShowLegend())-->
<legend class="legend">
<span><!-- ko text: $t('Credit Card Information')--><!-- /ko --></span>
</legend><br />
</legend>
<br/>
<!-- /ko -->
<div class="field type required">
<label data-bind="attr: {for: getCode() + '_cc_type'}" class="label">
<span><!-- ko text: $t('Credit Card Type')--><!-- /ko --></span>
......@@ -125,7 +126,7 @@
value: creditCardOwner,
valueUpdate: 'keyup' "
data-validate="{required:true}"
/>
/>
</div>
</div>
<div class="field date required" data-bind="attr: {id: getCode() + '_cc_type_exp_div'}">
......@@ -136,9 +137,9 @@
<div class="fields group group-2">
<div class="field no-label month">
<div class="control">
<select class="select select-month"
data-encrypted-name="expiryMonth"
data-bind="attr: {id: getCode() + '_expiration', 'data-container': getCode() + '-cc-month', 'data-validate': JSON.stringify({required:true, 'validate-cc-exp':'#' + getCode() + '_expiration_yr'})},
<select class="select select-month"
data-encrypted-name="expiryMonth"
data-bind="attr: {id: getCode() + '_expiration', 'data-container': getCode() + '-cc-month', 'data-validate': JSON.stringify({required:true, 'validate-cc-exp':'#' + getCode() + '_expiration_yr'})},
enable: isActive($parents),
options: getCcMonthsValues(),
optionsValue: 'value',
......@@ -187,9 +188,9 @@
oninput:'javascript: if (this.value.length > this.maxLength) this.value = this.value.slice(0, this.maxLength);'
},
enable: isActive($parents),
value: creditCardVerificationNumber",
value: creditCardVerificationNumber" ,
data-validate="{required:true}"
/>
/>
<div class="field-tooltip toggle">
<span class="field-tooltip-action action-cvv"
tabindex="0"
......@@ -208,21 +209,22 @@
<!-- ko if: (hasInstallments())-->
<div class="field required" data-bind="attr: {id: getCode() + '_installments_div'}, visible: getInstallments().length > 0">
<div class="field required"
data-bind="attr: {id: getCode() + '_installments_div'}, visible: getInstallments().length > 0">
<label data-bind="attr: {for: getCode() + '_installments'}" class="label">
<span><!-- ko text: $t('Installments')--><!-- /ko --></span>
</label>
<div class="control">
<select class="select"
name="payment[number_of_installments]"
data-bind="attr: {id: getCode() + '_installments', 'data-container': getCode() + '-installments', 'data-validate': JSON.stringify({required:true})},
<select class="select"
name="payment[number_of_installments]"
data-bind="attr: {id: getCode() + '_installments', 'data-container': getCode() + '-installments', 'data-validate': JSON.stringify({required:true})},
enable: isActive($parents),
options: getInstallments,
optionsValue: 'value',
optionsText: 'key',
optionsCaption: $t('Installments'),
value: installment"
data-validate="{required:true}">
data-validate="{required:true}">
</select>
</div>
</div>
......@@ -239,7 +241,7 @@
autocomplete="off"
class="checkbox"
data-bind="attr: {title: $t('Remember Me')}, checked: setStoreCc"
/>
/>
<label data-bind="attr: {for: getCode() + '_remember_details'}" class="label">
<span><!-- ko text: $t('Remember these details')--><!-- /ko --></span>
</label>
......@@ -248,19 +250,14 @@
<!-- /ko -->
<!-- ko if: (isCseEnabled())-->
<input type="hidden"
name="payment[generationtime]"
class="input-text"
value=""
data-encrypted-name="generationtime"
data-bind="attr: {id: getCode() + '_generationtime', 'data-container': getCode() + '-generationtime'},
value: getGenerationTime()
">
<!-- /ko -->
<input type="hidden"
name="payment[generationtime]"
class="input-text"
value=""
data-encrypted-name="generationtime"
data-bind="attr: {id: getCode() + '_generationtime', 'data-container': getCode() + '-generationtime'},
value: getGenerationTime()"
/>
</fieldset>
</form>
......
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