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 5c9e1a54 authored by attilak's avatar attilak

[WIP]

works until identifyShopper
parent 62663210
<?php
/**
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* Adyen Payment Module
*
* Copyright (c) 2019 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\Api;
interface AdyenInitiatePaymentsInterface
{
/**
* Returns string
*
* @api
* @param string $payload
* @return string
*/
public function initiate($payload);
}
\ No newline at end of file
......@@ -118,6 +118,8 @@ class Data extends AbstractHelper
*/
private $agreementResourceModel;
private $localeResolver;
/**
* Data constructor.
* @param \Magento\Framework\App\Helper\Context $context
......@@ -155,7 +157,8 @@ class Data extends AbstractHelper
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Framework\App\CacheInterface $cache,
\Adyen\Payment\Model\Billing\AgreementFactory $billingAgreementFactory,
\Adyen\Payment\Model\ResourceModel\Billing\Agreement $agreementResourceModel
\Adyen\Payment\Model\ResourceModel\Billing\Agreement $agreementResourceModel,
\Magento\Framework\Locale\ResolverInterface $localeResolver
) {
parent::__construct($context);
$this->_encryptor = $encryptor;
......@@ -174,6 +177,7 @@ class Data extends AbstractHelper
$this->cache = $cache;
$this->billingAgreementFactory = $billingAgreementFactory;
$this->agreementResourceModel = $agreementResourceModel;
$this->localeResolver = $localeResolver;
}
/**
......@@ -1096,6 +1100,32 @@ class Data extends AbstractHelper
return $this->scopeConfig->getValue($path, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId);
}
/**
* @param $store
* @return mixed|string
*/
public function getCurrentLocaleCode($store)
{
$localeCode = $this->getAdyenAbstractConfigData('shopper_locale', $store->getId());
if ($localeCode != "") {
return $localeCode;
}
$locale = $this->localeResolver->getLocale();
if ($locale) {
return $locale;
}
// should have the value if not fall back to default
$localeCode = $this->scopeConfig->getValue(
\Magento\Directory\Helper\Data::XML_PATH_DEFAULT_LOCALE,
\Magento\Store\Model\ScopeInterface::SCOPE_STORES,
$store->getCode()
);
return $localeCode;
}
public function getApplePayShippingTypes()
{
return [
......@@ -1334,11 +1364,15 @@ class Data extends AbstractHelper
* return the merchant account name defined in required settings.
*
* @param $paymentMethod
* @param int $storeId
* @param int|null $storeId
* @return string
*/
public function getAdyenMerchantAccount($paymentMethod, $storeId)
public function getAdyenMerchantAccount($paymentMethod, $storeId = null)
{
if (!$storeId) {
$storeId = $this->storeManager->getStore()->getId();
}
$merchantAccount = $this->getAdyenAbstractConfigData("merchant_account", $storeId);
$merchantAccountPos = $this->getAdyenPosCloudConfigData('pos_merchant_account', $storeId);
......@@ -1438,6 +1472,16 @@ class Data extends AbstractHelper
return new \Adyen\Client();
}
/**
* @return string
*/
public function getOrigin() {
$baseUrl = $this->storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_WEB);
$parsed = parse_url($baseUrl);
$origin = $parsed['scheme'] . "://" . $parsed['host'];
return $origin;
}
/**
* Retrieve origin keys for platform's base url
*
......@@ -1446,14 +1490,12 @@ class Data extends AbstractHelper
*/
public function getOriginKeyForBaseUrl()
{
$baseUrl = $this->storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_WEB);
$parsed = parse_url($baseUrl);
$domain = $parsed['scheme'] . "://" . $parsed['host'];
$origin = $this->getOrigin();
$storeId = $this->storeManager->getStore()->getId();
$cacheKey = 'Adyen_origin_key_for_' . $domain . '_' . $storeId;
$cacheKey = 'Adyen_origin_key_for_' . $origin . '_' . $storeId;
if (!$originKey = $this->cache->load($cacheKey)) {
if ($originKey = $this->getOriginKeyForUrl($domain, $storeId)) {
if ($originKey = $this->getOriginKeyForOrigin($origin, $storeId)) {
$this->cache->save($originKey, $cacheKey, array(), 60 * 60 * 24);
}
}
......@@ -1462,14 +1504,14 @@ class Data extends AbstractHelper
}
/**
* Get origin key for a specific url using the adyen api library client
* Get origin key for a specific origin using the adyen api library client
*
* @param $url
* @param $origin
* @param int|null $storeId
* @return string
* @throws \Adyen\AdyenException
*/
private function getOriginKeyForUrl($url, $storeId = null)
private function getOriginKeyForOrigin($origin, $storeId = null)
{
$params = array(
"originDomains" => array(
......
......@@ -198,7 +198,7 @@ class PaymentMethods extends AbstractHelper
),
],
"shopperReference" => $this->getCurrentShopperReference(),
"shopperLocale" => $this->getCurrentLocaleCode($store)
"shopperLocale" => $this->adyenHelper->getCurrentLocaleCode($store)
];
$billingAddress = $this->getQuote()->getBillingAddress();
......@@ -325,32 +325,6 @@ class PaymentMethods extends AbstractHelper
return "";
}
/**
* @param $store
* @return mixed|string
*/
protected function getCurrentLocaleCode($store)
{
$localeCode = $this->adyenHelper->getAdyenAbstractConfigData('shopper_locale', $store->getId());
if ($localeCode != "") {
return $localeCode;
}
$locale = $this->localeResolver->getLocale();
if ($locale) {
return $locale;
}
// should have the value if not fall back to default
$localeCode = $this->config->getValue(
\Magento\Directory\Helper\Data::XML_PATH_DEFAULT_LOCALE,
\Magento\Store\Model\ScopeInterface::SCOPE_STORES,
$store->getCode()
);
return $localeCode;
}
/**
* @var array
*/
......
<?php
/**
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* Adyen Payment module (https://www.adyen.com/)
*
* Copyright (c) 2019 Adyen BV (https://www.adyen.com/)
* See LICENSE.txt for license details.
*
* Author: Adyen <magento@adyen.com>
*/
namespace Adyen\Payment\Helper;
use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Framework\App\Helper\Context;
class Payments extends AbstractHelper
{
/**
* @var \Adyen\Payment\Helper\Data
*/
private $adyenHelper;
public function __construct(
\Adyen\Payment\Helper\Data $adyenHelper
)
{
$this->adyenHelper = $adyenHelper;
}
}
<?php
/**
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* Adyen Payment module (https://www.adyen.com/)
*
* Copyright (c) 2019 Adyen BV (https://www.adyen.com/)
* See LICENSE.txt for license details.
*
* Author: Adyen <magento@adyen.com>
*/
namespace Adyen\Payment\Model;
use Adyen\Payment\Api\AdyenInitiatePaymentsInterface;
class AdyenInitiatePayments implements AdyenInitiatePaymentsInterface
{
public function __construct()
{
}
public function initiate($payload)
{
$payload = json_decode($payload);
$paymentMethod = $payload;
return $payload;
}
}
\ No newline at end of file
......@@ -134,7 +134,7 @@ class AdyenHppConfigProvider implements ConfigProviderInterface
}
}
$config['payment']['adyenHpp']['locale'] = $this->adyenHelper->getStoreLocale($this->storeManager->getStore()->getId());
$config['payment']['adyenHpp']['locale'] = $this->adyenHelper->getCurrentLocaleCode($this->storeManager->getStore());
// add to config
$config['payment'] ['adyenHpp']['gender'] = $gender;
......
......@@ -40,6 +40,11 @@ class AdyenCcDataAssignObserver extends AbstractDataAssignObserver
const ENCRYPTED_EXPIRY_YEAR = 'expiryYear';
const HOLDER_NAME = 'holderName';
const VARIANT = 'variant';
const JAVA_ENABLED = 'java_enabled';
const SCREEN_COLOR_DEPTH = 'screen_color_depth';
const SCREEN_WIDTH = 'screen_width';
const SCREEN_HEIGHT = 'screen_hegiht';
const TIMEZONE_OFFSET = 'timezone_offset';
/**
* @var array
......@@ -53,7 +58,12 @@ class AdyenCcDataAssignObserver extends AbstractDataAssignObserver
self::ENCRYPTED_EXPIRY_MONTH,
self::ENCRYPTED_EXPIRY_YEAR,
self::HOLDER_NAME,
self::VARIANT
self::VARIANT,
self::JAVA_ENABLED,
self::SCREEN_COLOR_DEPTH,
self::SCREEN_WIDTH,
self::SCREEN_HEIGHT,
self::TIMEZONE_OFFSET
];
/**
......
This diff is collapsed.
......@@ -396,8 +396,6 @@
<!-- Authorization command -->
<virtualType name="AdyenPaymentCcAuthorizeCommand" type="Magento\Payment\Gateway\Command\GatewayCommand">
<arguments>
<argument name="requestBuilder" xsi:type="object">AdyenPaymentCcAuthorizeRequest</argument>
<argument name="transferFactory" xsi:type="object">Adyen\Payment\Gateway\Http\TransferFactory</argument>
<argument name="client" xsi:type="object">Adyen\Payment\Gateway\Http\Client\TransactionPayment</argument>
<argument name="validator" xsi:type="object">CheckoutResponseValidator</argument>
<argument name="handler" xsi:type="object">AdyenPaymentCcResponseHandlerComposite</argument>
......@@ -885,9 +883,14 @@
type="Adyen\Payment\Model\AdyenRequestMerchantSession"/>
<preference for="Adyen\Payment\Api\AdyenInitiateTerminalApiInterface"
type="Adyen\Payment\Model\AdyenInitiateTerminalApi"/>
<preference for="Adyen\Payment\Api\AdyenInitiatePaymentsInterface"
type="Adyen\Payment\Model\AdyenInitiatePayments"/>
<preference for="Magento\Checkout\Api\PaymentInformationManagementInterface"
type="Adyen\Payment\Model\AdyenPaymentInformationManagement"/>
<type name="Magento\Vault\Api\PaymentTokenRepositoryInterface">
<plugin name="AdyenPaymentVaultDeleteToken" type="Adyen\Payment\Plugin\PaymentVaultDeleteToken" sortOrder="10"/>
</type>
<type name="\Magento\Checkout\Model\PaymentInformationManagement">
<plugin name="AdyenPaymentInformationManagement" type="Adyen\Payment\Plugin\PaymentInformationManagement" sortOrder="20" disabled="false"/>
</type>
</config>
\ No newline at end of file
......@@ -57,4 +57,11 @@
<resource ref="anonymous"/>
</resources>
</route>
<route url="/V1/adyen/payments" method="POST">
<service class="Adyen\Payment\Api\AdyenInitiatePaymentsInterface" method="initiate"/>
<resources>
<resource ref="anonymous"/>
</resources>
</route>
</routes>
\ No newline at end of file
......@@ -30,9 +30,13 @@ define(
'Magento_Checkout/js/model/quote',
'Adyen_Payment/js/model/installments',
'mage/url',
'Magento_Vault/js/view/payment/vault-enabler'
'Magento_Vault/js/view/payment/vault-enabler',
'Magento_Checkout/js/model/url-builder',
'mage/storage',
'Magento_Checkout/js/model/full-screen-loader',
'Magento_Paypal/js/action/set-payment-method',
],
function ($, ko, Component, customer, creditCardData, additionalValidators, quote, installments, url, VaultEnabler) {
function ($, ko, Component, customer, creditCardData, additionalValidators, quote, installments, url, VaultEnabler, urlBuilder, storage, fullScreenLoader, setPaymentMethodAction) {
'use strict';
......@@ -194,7 +198,12 @@ define(
'expiryYear': this.expiryYear(),
'holderName': this.creditCardOwner(),
'store_cc': this.setStoreCc(),
'number_of_installments': this.installment()
'number_of_installments': this.installment(),
'java_enabled': navigator.javaEnabled(),
'screen_color_depth': screen.colorDepth,
'screen_width': screen.width,
'screen_hegiht': screen.height,
'timezone_offset': new Date().getTimezoneOffset()
}
};
this.vaultEnabler.visitAdditionalData(data);
......@@ -224,9 +233,39 @@ define(
}
if (this.validate() && additionalValidators.validate()) {
this.isPlaceOrderActionAllowed(false);
//this.isPlaceOrderActionAllowed(false);
this.getPlaceOrderDeferredObject()
fullScreenLoader.startLoader();
var serviceUrl = urlBuilder.createUrl('/adyen/payments', {});
var payload = {
"payload": JSON.stringify(self.getData()),
};
//update payment method information if additional data was changed
self.selectPaymentMethod();
setPaymentMethodAction(this.messageContainer).done(
function (response) {
console.log(response);
fullScreenLoader.stopLoader();
}
);
return false;
/*storage.post(
serviceUrl,
JSON.stringify(payload),
true
).done(function(response) {
console.log(response);
fullScreenLoader.stopLoader();
//this.isPlaceOrderActionAllowed(true);
});*/
/*this.getPlaceOrderDeferredObject()
.fail(
function () {
self.isPlaceOrderActionAllowed(true);
......@@ -240,7 +279,7 @@ define(
window.location.replace(url.build(window.checkoutConfig.payment[quote.paymentMethod().method].redirectUrl));
}
}
);
);*/
return true;
}
......
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