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 625246a1 authored by Alexandros Moraitis's avatar Alexandros Moraitis Committed by GitHub

Merge pull request #518 from Adyen/develop

Release 4.5.0
parents 050b260d 39a88064
<?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 AdyenOriginKeyInterface
{
/**
* @return string
*/
public function getOriginKey();
}
\ No newline at end of file
......@@ -255,7 +255,7 @@ interface NotificationInterface
* @param string $additionalData
* @return $this
*/
public function setAddtionalData($additionalData);
public function setAdditionalData($additionalData);
/**
* Gets the Done for the notification.
......
......@@ -52,23 +52,31 @@ class Json extends \Magento\Framework\App\Action\Action
*/
protected $_adyenLogger;
/**
* @var \Magento\Framework\Serialize\SerializerInterface
*/
private $serializer;
/**
* Json constructor.
*
* @param \Magento\Framework\App\Action\Context $context
* @param \Adyen\Payment\Helper\Data $adyenHelper
* @param \Adyen\Payment\Logger\AdyenLogger $adyenLogger
* @param \Magento\Framework\Serialize\SerializerInterface $serializer
*/
public function __construct(
\Magento\Framework\App\Action\Context $context,
\Adyen\Payment\Helper\Data $adyenHelper,
\Adyen\Payment\Logger\AdyenLogger $adyenLogger
\Adyen\Payment\Logger\AdyenLogger $adyenLogger,
\Magento\Framework\Serialize\SerializerInterface $serializer
) {
parent::__construct($context);
$this->_objectManager = $context->getObjectManager();
$this->_resultFactory = $context->getResultFactory();
$this->_adyenHelper = $adyenHelper;
$this->_adyenLogger = $adyenLogger;
$this->serializer = $serializer;
// Fix for Magento2.3 adding isAjax to the request params
if(interface_exists("\Magento\Framework\App\CsrfAwareActionInterface")) {
......@@ -214,7 +222,7 @@ class Json extends \Magento\Framework\App\Action\Action
$notification->setLive($notificationMode);
if (isset($response['additionalData'])) {
$notification->setAddtionalData(serialize($response['additionalData']));
$notification->setAdditionalData($this->serializer->serialize($response['additionalData']));
}
if (isset($response['done'])) {
$notification->setDone($response['done']);
......
......@@ -77,15 +77,22 @@ class Redirect extends \Magento\Framework\App\Action\Action
* @var PaymentTokenFactoryInterface
*/
private $paymentTokenFactory;
/**
* @var OrderPaymentExtensionInterfaceFactory
*/
private $paymentExtensionFactory;
/**
* @var OrderPaymentResource
*/
private $orderPaymentResource;
/**
* @var \Magento\Framework\Serialize\SerializerInterface
*/
private $serializer;
/**
* Redirect constructor.
*
......@@ -94,6 +101,10 @@ class Redirect extends \Magento\Framework\App\Action\Action
* @param \Adyen\Payment\Helper\Data $adyenHelper
* @param \Adyen\Payment\Model\Api\PaymentRequest $paymentRequest
* @param \Magento\Sales\Api\OrderRepositoryInterface $orderRepository
* @param PaymentTokenFactoryInterface $paymentTokenFactory
* @param OrderPaymentExtensionInterfaceFactory $paymentExtensionFactory
* @param OrderPaymentResource $orderPaymentResource
* @param \Magento\Framework\Serialize\SerializerInterface $serializer
*/
public function __construct(
\Magento\Framework\App\Action\Context $context,
......@@ -103,7 +114,8 @@ class Redirect extends \Magento\Framework\App\Action\Action
\Magento\Sales\Api\OrderRepositoryInterface $orderRepository,
PaymentTokenFactoryInterface $paymentTokenFactory,
OrderPaymentExtensionInterfaceFactory $paymentExtensionFactory,
OrderPaymentResource $orderPaymentResource
OrderPaymentResource $orderPaymentResource,
\Magento\Framework\Serialize\SerializerInterface $serializer
) {
parent::__construct($context);
$this->_adyenLogger = $adyenLogger;
......@@ -113,6 +125,7 @@ class Redirect extends \Magento\Framework\App\Action\Action
$this->paymentTokenFactory = $paymentTokenFactory;
$this->paymentExtensionFactory = $paymentExtensionFactory;
$this->orderPaymentResource = $orderPaymentResource;
$this->serializer = $serializer;
if (interface_exists("\Magento\Framework\App\CsrfAwareActionInterface")) {
$request = $this->getRequest();
if ($request instanceof Http && $request->isPost()) {
......@@ -198,9 +211,9 @@ class Redirect extends \Magento\Framework\App\Action\Action
$extensionAttributes = $this->getExtensionAttributes($order->getPayment());
$extensionAttributes->setVaultPaymentToken($paymentToken);
$orderPayment = $order->getPayment()->setExtensionAttributes($extensionAttributes);
$add = unserialize($orderPayment->getAdditionalData());
$add = $this->serializer->unserialize($orderPayment->getAdditionalData());
$add['force_save'] = true;
$orderPayment->setAdditionalData(serialize($add));
$orderPayment->setAdditionalData($this->serializer->serialize($add));
$this->orderPaymentResource->save($orderPayment);
} catch (\Exception $e) {
$this->_adyenLogger->error((string)$e->getMessage());
......
......@@ -140,6 +140,13 @@ class CheckoutDataBuilder implements BuilderInterface
$request = array_merge($request, $openInvoiceFields);
}
// Ratepay specific Fingerprint
if ($payment->getAdditionalInformation("df_value") && $this->adyenHelper->isPaymentMethodRatepayMethod(
$payment->getAdditionalInformation(AdyenHppDataAssignObserver::BRAND_CODE)
)) {
$request['deviceFingerprint'] = $payment->getAdditionalInformation("df_value");
}
//Boleto data
if ($payment->getAdditionalInformation("social_security_number")) {
$request['socialSecurityNumber'] = $payment->getAdditionalInformation("social_security_number");
......
......@@ -52,8 +52,8 @@ class CustomerIpDataBuilder implements BuilderInterface
{
/** @var \Magento\Payment\Gateway\Data\PaymentDataObject $paymentDataObject */
$paymentDataObject = \Magento\Payment\Gateway\Helper\SubjectReader::readPayment($buildSubject);
$order = $paymentDataObject->getOrder();
$shopperIp = $paymentDataObject->getPayment()->getOrder()->getXForwardedFor();
return $this->adyenRequestsHelper->buildCustomerIpData([], $order->getRemoteIp());
return $this->adyenRequestsHelper->buildCustomerIpData([], $shopperIp);
}
}
......@@ -44,22 +44,30 @@ class InstallmentValidator extends AbstractValidator
*/
private $session;
/**
* @var \Magento\Framework\Serialize\SerializerInterface
*/
private $serializer;
/**
* InstallmentValidator constructor.
* @param \Magento\Payment\Gateway\Validator\ResultInterfaceFactory $resultFactory
* @param \Adyen\Payment\Logger\AdyenLogger $adyenLogger
* @param \Adyen\Payment\Helper\Data $adyenHelper
* @param \Magento\Framework\App\ObjectManager $objectManager
* @param \Magento\Checkout\Model\Session $session
* @param \Magento\Framework\Serialize\SerializerInterface $serializer
*/
public function __construct(
\Magento\Payment\Gateway\Validator\ResultInterfaceFactory $resultFactory,
\Adyen\Payment\Logger\AdyenLogger $adyenLogger,
\Adyen\Payment\Helper\Data $adyenHelper,
\Magento\Checkout\Model\Session $session
\Magento\Checkout\Model\Session $session,
\Magento\Framework\Serialize\SerializerInterface $serializer
) {
$this->adyenLogger = $adyenLogger;
$this->adyenHelper = $adyenHelper;
$this->session = $session;
$this->serializer = $serializer;
parent::__construct($resultFactory);
}
......@@ -77,7 +85,7 @@ class InstallmentValidator extends AbstractValidator
$installmentSelected = $payment->getAdditionalInformation('number_of_installments');
$ccType = $payment->getAdditionalInformation('cc_type');
if ($installmentsAvailable) {
$installments = unserialize($installmentsAvailable);
$installments = $this->serializer->unserialize($installmentsAvailable);
}
if ($installmentSelected && $installmentsAvailable) {
$isValid = false;
......
......@@ -131,6 +131,10 @@ class Data extends AbstractHelper
*/
private $helperBackend;
/**
* @var \Magento\Framework\Serialize\SerializerInterface
*/
private $serializer;
/**
* Data constructor.
......@@ -154,6 +158,7 @@ class Data extends AbstractHelper
* @param \Magento\Framework\Locale\ResolverInterface $localeResolver
* @param \Magento\Framework\App\Config\ScopeConfigInterface $config
* @param \Magento\Backend\Helper\Data $helperBackend
* @param \Magento\Framework\Serialize\SerializerInterface $serializer
*/
public function __construct(
\Magento\Framework\App\Helper\Context $context,
......@@ -175,7 +180,8 @@ class Data extends AbstractHelper
\Adyen\Payment\Model\ResourceModel\Billing\Agreement $agreementResourceModel,
\Magento\Framework\Locale\ResolverInterface $localeResolver,
\Magento\Framework\App\Config\ScopeConfigInterface $config,
\Magento\Backend\Helper\Data $helperBackend
\Magento\Backend\Helper\Data $helperBackend,
\Magento\Framework\Serialize\SerializerInterface $serializer
) {
parent::__construct($context);
$this->_encryptor = $encryptor;
......@@ -197,6 +203,7 @@ class Data extends AbstractHelper
$this->localeResolver = $localeResolver;
$this->config = $config;
$this->helperBackend = $helperBackend;
$this->serializer = $serializer;
}
/**
......@@ -955,7 +962,7 @@ class Data extends AbstractHelper
$installments = null;
$installmentsValue = $this->getAdyenCcConfigData('installments');
if ($installmentsValue) {
$installments = unserialize($installmentsValue);
$installments = $this->serializer->unserialize($installmentsValue);
}
if ($installments) {
......@@ -1003,6 +1010,19 @@ class Data extends AbstractHelper
return false;
}
/**
* @param $paymentMethod
* @return bool
*/
public function isPaymentMethodRatepayMethod($paymentMethod)
{
if (strpos($paymentMethod, 'ratepay') !== false) {
return true;
}
return false;
}
/**
* @param $paymentMethod
* @return bool
......
......@@ -67,12 +67,15 @@ class Requests extends AbstractHelper
}
/**
* @param $request
* @param array $request
* @param int $customerId
* @param $billingAddress
* @return mixed
* @param $storeId
* @param null $payment
* @param null $payload
* @return array
*/
public function buildCustomerData($request = [], $customerId = 0, $billingAddress, $storeId, $payment = null)
public function buildCustomerData($request = [], $customerId = 0, $billingAddress, $storeId, $payment = null, $payload = null)
{
if ($customerId > 0) {
$request['shopperReference'] = $customerId;
......@@ -83,6 +86,17 @@ class Requests extends AbstractHelper
$paymentMethod = $payment->getAdditionalInformation(AdyenHppDataAssignObserver::BRAND_CODE);
}
// In case of virtual product and guest checkout there is a workaround to get the guest's email address
if (!empty($payload['additional_data']['guestEmail'])) {
if ($this->adyenHelper->isPaymentMethodOpenInvoiceMethod($paymentMethod) &&
!$this->adyenHelper->isPaymentMethodAfterpayTouchMethod($paymentMethod)
) {
$request['paymentMethod']['personalDetails']['shopperEmail'] = $payload['additional_data']['guestEmail'];
} else {
$request['shopperEmail'] = $payload['additional_data']['guestEmail'];
}
}
if (!empty($billingAddress)) {
// Openinvoice (klarna and afterpay BUT not afterpay touch) methods requires different request format
if ($this->adyenHelper->isPaymentMethodOpenInvoiceMethod($paymentMethod) &&
......@@ -423,6 +437,7 @@ class Requests extends AbstractHelper
*/
public function buildVaultData($request = [], $payload)
{
if ($this->adyenHelper->isCreditCardVaultEnabled()) {
if (!empty($payload[PaymentInterface::KEY_ADDITIONAL_DATA][VaultConfigProvider::IS_ACTIVE_CODE]) &&
$payload[PaymentInterface::KEY_ADDITIONAL_DATA][VaultConfigProvider::IS_ACTIVE_CODE] === true
) {
......@@ -432,6 +447,7 @@ class Requests extends AbstractHelper
// explicity turn this off as merchants have recurring on by default
$request['enableRecurring'] = false;
}
}
return $request;
}
......
<?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\Model;
use Adyen\AdyenException;
use Adyen\Payment\Helper\Data as AdyenHelper;
use Magento\Framework\Exception\NoSuchEntityException as MagentoNoSuchEntityException;
class AdyenOriginKey implements \Adyen\Payment\Api\AdyenOriginKeyInterface
{
/**
* @var AdyenHelper
*/
private $helper;
public function __construct(AdyenHelper $helper)
{
$this->helper = $helper;
}
/**
* {@inheritDoc}
* @throws MagentoNoSuchEntityException
* @throws AdyenException
*/
public function getOriginKey()
{
return $this->helper->getOriginKeyForBaseUrl();
}
}
\ No newline at end of file
......@@ -131,10 +131,10 @@ class AdyenPaymentProcess implements AdyenPaymentProcessInterface
// Customer data builder
$customerId = $quote->getCustomerId();
$billingAddress = $quote->getBillingAddress();
$request = $this->adyenRequestHelper->buildCustomerData($request, $customerId, $billingAddress, $storeId);
$request = $this->adyenRequestHelper->buildCustomerData($request, $customerId, $billingAddress, $storeId, null, $payload);
// Customer Ip data builder
$shopperIp = $quote->getRemoteIp();
$shopperIp = $quote->getXForwardedFor();
$request = $this->adyenRequestHelper->buildCustomerIpData($request, $shopperIp);
// AddressDataBuilder
......
<?php
namespace Adyen\Payment\Model\Comment;
use Magento\Config\Model\Config\CommentInterface;
use Magento\Framework\Encryption\EncryptorInterface;
class ApiKeyEnding implements CommentInterface
{
/**
* @var EncryptorInterface
*/
private $encryptor;
/**
* ApiKeyEnding constructor.
*
* @param EncryptorInterface $encryptor Magento encryptor, used to decrypt the API key.
*/
public function __construct(EncryptorInterface $encryptor)
{
$this->encryptor = $encryptor;
}
/**
* Method magically called by Magento. This returns the last 4 digits in the merchant's API key.
*
* @param string $elementValue The value of the field with this commented. In this case, an encrypted API key.
* @return string Some HTML markup to be displayed in the admin panel.
*/
public function getCommentText($elementValue)
{
$apiKeyEnding = substr($this->encryptor->decrypt(trim($elementValue)), -4);
if (!$apiKeyEnding) {
return '';
}
return "Key stored ending in <strong>$apiKeyEnding</strong>";
}
}
\ No newline at end of file
......@@ -30,6 +30,11 @@ class Installments extends \Magento\Framework\App\Config\Value
*/
protected $mathRandom;
/**
* @var \Magento\Framework\Serialize\SerializerInterface
*/
private $serializer;
/**
* @param \Magento\Framework\Model\Context $context
* @param \Magento\Framework\Registry $registry
......@@ -46,11 +51,13 @@ class Installments extends \Magento\Framework\App\Config\Value
\Magento\Framework\App\Config\ScopeConfigInterface $config,
\Magento\Framework\App\Cache\TypeListInterface $cacheTypeList,
\Magento\Framework\Math\Random $mathRandom,
\Magento\Framework\Serialize\SerializerInterface $serializer,
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
array $data = []
) {
$this->mathRandom = $mathRandom;
$this->serializer = $serializer;
parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data);
}
......@@ -62,8 +69,7 @@ class Installments extends \Magento\Framework\App\Config\Value
public function beforeSave()
{
$value = $this->getValue();
$unserialized = @unserialize($value);
if ($unserialized !== false) {
if (!is_array($value)) {
return $this;
}
$result = [];
......@@ -94,7 +100,7 @@ class Installments extends \Magento\Framework\App\Config\Value
$finalResult[$key] = $installments;
}
$this->setValue(serialize($finalResult));
$this->setValue($this->serializer->serialize($finalResult));
return $this;
}
......@@ -106,7 +112,7 @@ class Installments extends \Magento\Framework\App\Config\Value
protected function _afterLoad()
{
$value = $this->getValue();
$value = unserialize($value);
$value = $this->serializer->unserialize($value);
if (is_array($value)) {
$value = $this->encodeArrayFieldValue($value);
$this->setValue($value);
......
......@@ -30,12 +30,18 @@ class InstallmentsPosCloud extends \Magento\Framework\App\Config\Value
*/
protected $mathRandom;
/**
* @var \Magento\Framework\Serialize\SerializerInterface
*/
private $serializer;
/**
* @param \Magento\Framework\Model\Context $context
* @param \Magento\Framework\Registry $registry
* @param \Magento\Framework\App\Config\ScopeConfigInterface $config
* @param \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList
* @param \Magento\Framework\Math\Random $mathRandom
* @param \Magento\Framework\Serialize\SerializerInterface $serializer
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
* @param array $data
......@@ -46,11 +52,13 @@ class InstallmentsPosCloud extends \Magento\Framework\App\Config\Value
\Magento\Framework\App\Config\ScopeConfigInterface $config,
\Magento\Framework\App\Cache\TypeListInterface $cacheTypeList,
\Magento\Framework\Math\Random $mathRandom,
\Magento\Framework\Serialize\SerializerInterface $serializer,
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
array $data = []
) {
$this->mathRandom = $mathRandom;
$this->serializer = $serializer;
parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data);
}
......@@ -62,9 +70,7 @@ class InstallmentsPosCloud extends \Magento\Framework\App\Config\Value
public function beforeSave()
{
$value = $this->getValue();
$unserialized = @unserialize($value);
if ($unserialized !== false) {
if (!is_array($value)) {
return $this;
}
$result = [];
......@@ -87,7 +93,7 @@ class InstallmentsPosCloud extends \Magento\Framework\App\Config\Value
asort($result);
$this->setValue(serialize($result));
$this->setValue($this->serializer->serialize($result));
return $this;
}
......@@ -100,12 +106,13 @@ class InstallmentsPosCloud extends \Magento\Framework\App\Config\Value
protected function _afterLoad()
{
$value = $this->getValue();
$value = unserialize($value);
if(!empty($value)) {
$value = $this->serializer->unserialize($value);
if (is_array($value)) {
$value = $this->encodeArrayFieldValue($value);
$this->setValue($value);
}
}
return $this;
}
......
......@@ -219,6 +219,11 @@ class Cron
*/
private $transactionBuilder;
/**
* @var \Magento\Framework\Serialize\SerializerInterface
*/
private $serializer;
/**
* Cron constructor.
*
......@@ -263,7 +268,8 @@ class Cron
SearchCriteriaBuilder $searchCriteriaBuilder,
OrderRepository $orderRepository,
\Adyen\Payment\Model\ResourceModel\Billing\Agreement $agreementResourceModel,
\Magento\Sales\Model\Order\Payment\Transaction\Builder $transactionBuilder
\Magento\Sales\Model\Order\Payment\Transaction\Builder $transactionBuilder,
\Magento\Framework\Serialize\SerializerInterface $serializer
) {
$this->_scopeConfig = $scopeConfig;
$this->_adyenLogger = $adyenLogger;
......@@ -285,6 +291,7 @@ class Cron
$this->orderRepository = $orderRepository;
$this->agreementResourceModel = $agreementResourceModel;
$this->transactionBuilder = $transactionBuilder;
$this->serializer = $serializer;
}
/**
......@@ -501,8 +508,7 @@ class Cron
$this->_reason = $notification->getPaymentMethod();
$this->_value = $notification->getAmountValue();
$additionalData = unserialize($notification->getAdditionalData());
$additionalData = !empty($notification->getAdditionalData()) ? $this->serializer->unserialize($notification->getAdditionalData()) : "";
// boleto data
if ($this->_paymentMethodCode() == "adyen_boleto") {
......@@ -672,7 +678,8 @@ class Cron
{
$this->_adyenLogger->addAdyenNotificationCronjob('Updating the Adyen attributes of the order');
$additionalData = unserialize($notification->getAdditionalData());
$additionalData = !empty($notification->getAdditionalData()) ? $this->serializer->unserialize($notification->getAdditionalData()) : "";
$_paymentCode = $this->_paymentMethodCode();
if ($this->_eventCode == Notification::AUTHORISATION
......
......@@ -333,7 +333,7 @@ class Notification extends \Magento\Framework\Model\AbstractModel implements Not
* @param string $additionalData
* @return $this
*/
public function setAddtionalData($additionalData)
public function setAdditionalData($additionalData)
{
return $this->setData(self::ADDITIONAL_DATA, $additionalData);
}
......
......@@ -69,6 +69,10 @@ class AdyenCcConfigProvider implements ConfigProviderInterface
*/
private $storeManager;
/**
* @var \Magento\Framework\Serialize\SerializerInterface
*/
private $serializer;
/**
* AdyenCcConfigProvider constructor.
......@@ -80,6 +84,7 @@ class AdyenCcConfigProvider implements ConfigProviderInterface
* @param \Magento\Framework\View\Asset\Source $assetSource
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Payment\Model\CcConfig $ccConfig
* @param \Magento\Framework\Serialize\SerializerInterface $serializer
*/
public function __construct(
\Magento\Payment\Helper\Data $paymentHelper,
......@@ -88,7 +93,8 @@ class AdyenCcConfigProvider implements ConfigProviderInterface
\Magento\Framework\UrlInterface $urlBuilder,
\Magento\Framework\View\Asset\Source $assetSource,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Payment\Model\CcConfig $ccConfig
\Magento\Payment\Model\CcConfig $ccConfig,
\Magento\Framework\Serialize\SerializerInterface $serializer
) {
$this->_paymentHelper = $paymentHelper;
$this->_adyenHelper = $adyenHelper;
......@@ -97,6 +103,7 @@ class AdyenCcConfigProvider implements ConfigProviderInterface
$this->_assetSource = $assetSource;
$this->ccConfig = $ccConfig;
$this->storeManager = $storeManager;
$this->serializer = $serializer;
}
/**
......@@ -156,7 +163,7 @@ class AdyenCcConfigProvider implements ConfigProviderInterface
$installments = $this->_adyenHelper->getAdyenCcConfigData('installments');
if ($installmentsEnabled && $installments) {
$config['payment']['adyenCc']['installments'] = unserialize($installments);
$config['payment']['adyenCc']['installments'] = $this->serializer->unserialize($installments);
$config['payment']['adyenCc']['hasInstallments'] = true;
} else {
$config['payment']['adyenCc']['installments'] = [];
......
......@@ -144,7 +144,7 @@ class AdyenHppConfigProvider implements ConfigProviderInterface
$config['payment'] ['adyenHpp']['genderTypes'] = \Adyen\Payment\Model\Gender::getGenderTypes();
$config['payment'] ['adyenHpp']['ratePayId'] = $this->adyenHelper->getRatePayId();
$config['payment'] ['adyenHpp']['deviceIdentToken'] = md5($this->session->getQuoteId() . date('c'));
$config['payment'] ['adyenHpp']['deviceIdentToken'] = hash("sha256",$this->session->getQuoteId() . date('c'));
$config['payment'] ['adyenHpp']['nordicCountries'] = ['SE', 'NO', 'DK', 'FI'];
return $config;
......
......@@ -53,22 +53,32 @@ class AdyenPosCloudConfigProvider implements ConfigProviderInterface
*/
protected $adyenHelper;
/**
* @var \Magento\Framework\Serialize\SerializerInterface
*/
private $serializer;
/**
* AdyenHppConfigProvider constructor.
*
* @param PaymentHelper $paymentHelper
* @param \Magento\Framework\App\RequestInterface $request
* @param \Magento\Framework\UrlInterface $urlBuilder
* @param \Adyen\Payment\Helper\PaymentMethods $paymentMethodsHelper
* @param \Adyen\Payment\Helper\Data $adyenHelper
* @param \Magento\Framework\Serialize\SerializerInterface $serializer
*/
public function __construct(
\Magento\Framework\App\RequestInterface $request,
\Magento\Framework\UrlInterface $urlBuilder,
\Adyen\Payment\Helper\PaymentMethods $paymentMethodsHelper,
\Adyen\Payment\Helper\Data $adyenHelper
\Adyen\Payment\Helper\Data $adyenHelper,
\Magento\Framework\Serialize\SerializerInterface $serializer
) {
$this->request = $request;
$this->urlBuilder = $urlBuilder;
$this->paymentMethodsHelper = $paymentMethodsHelper;
$this->adyenHelper = $adyenHelper;
$this->serializer = $serializer;
}
/**
......@@ -91,7 +101,9 @@ class AdyenPosCloudConfigProvider implements ConfigProviderInterface
]
];
if ($this->adyenHelper->getAdyenPosCloudConfigDataFlag("active")) {
$config['payment']['adyenPos']['connectedTerminals'] = $this->getConnectedTerminals();
}
// has installments by default false
$config['payment']['adyenPos']['hasInstallments'] = false;
......@@ -101,7 +113,7 @@ class AdyenPosCloudConfigProvider implements ConfigProviderInterface
$installments = $this->adyenHelper->getAdyenPosCloudConfigData('installments');
if ($installmentsEnabled && $installments) {
$config['payment']['adyenPos']['installments'] = unserialize($installments);
$config['payment']['adyenPos']['installments'] = $this->serializer->unserialize($installments);
$config['payment']['adyenPos']['hasInstallments'] = true;
} else {
$config['payment']['adyenPos']['installments'] = [];
......
<?php
namespace Adyen\Payment\Test\Comment;
use Adyen\Payment\Model\Comment\ApiKeyEnding;
use Magento\Framework\Encryption\Encryptor;
use PHPUnit\Framework\TestCase;
use PHPUnit_Framework_MockObject_MockObject as MockObject;
class ApiKeyEndingTest extends TestCase
{
/**
* @var ApiKeyEnding
*/
private $apiKeyEndingComment;
public function setUp()
{
/** @var MockObject|Encryptor $encryptor */
$encryptor = $this->createMock(Encryptor::class);
$map = [
['4321', '1234'],
['asdfasdfasdf', 'qwerqwerqwer']
];
$encryptor->method('decrypt')
->will($this->returnValueMap($map));
$this->apiKeyEndingComment = new ApiKeyEnding($encryptor);
}
public function testCommentReturnsJustTheEnding()
{
$this->assertEquals('Key stored ending in <strong>1234</strong>', $this->apiKeyEndingComment->getCommentText('4321'));
$this->assertEquals('Key stored ending in <strong>qwer</strong>', $this->apiKeyEndingComment->getCommentText('asdfasdfasdf'));
}
}
......@@ -50,6 +50,15 @@ class DataTest extends \PHPUnit\Framework\TestCase
$notificationFactory = $this->getSimpleMock(\Adyen\Payment\Model\ResourceModel\Notification\CollectionFactory::class);
$taxConfig = $this->getSimpleMock(\Magento\Tax\Model\Config::class);
$taxCalculation = $this->getSimpleMock(\Magento\Tax\Model\Calculation::class);
$productMetadata = $this->getSimpleMock(\Magento\Framework\App\ProductMetadata::class);
$adyenLogger = $this->getSimpleMock(\Adyen\Payment\Logger\AdyenLogger::class);
$storeManager = $this->getSimpleMock(\Magento\Store\Model\StoreManager::class);
$cache = $this->getSimpleMock(\Magento\Framework\App\CacheInterface::class);
$billingAgreementFactory = $this->getSimpleMock(\Adyen\Payment\Model\Billing\AgreementFactory::class);
$agreementResourceModel = $this->getSimpleMock(\Adyen\Payment\Model\ResourceModel\Billing\Agreement::class);
$localeResolver = $this->getSimpleMock(\Magento\Framework\Locale\ResolverInterface::class);
$config = $this->getSimpleMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
$helperBackend = $this->getSimpleMock(\Magento\Backend\Helper\Data::class);
$this->dataHelper = new \Adyen\Payment\Helper\Data(
$context,
......@@ -62,7 +71,16 @@ class DataTest extends \PHPUnit\Framework\TestCase
$assetSource,
$notificationFactory,
$taxConfig,
$taxCalculation
$taxCalculation,
$productMetadata,
$adyenLogger,
$storeManager,
$cache,
$billingAgreementFactory,
$agreementResourceModel,
$localeResolver,
$config,
$helperBackend
);
}
......
<?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\Model;
use Adyen\Payment\Helper\Data as AdyenHelper;
use PHPUnit\Framework\TestCase;
use PHPUnit_Framework_MockObject_MockObject as MockObject;
class AdyenOriginKeyTest extends TestCase
{
/** @var AdyenHelper|MockObject */
private $helper;
protected function setUp()
{
$this->helper = $this->getMockBuilder(AdyenHelper::class)
->disableOriginalConstructor()
->getMock();
}
/** @throws \Exception */
public function testGetOriginKey()
{
$this->helper->method('getOriginKeyForBaseUrl')
->willReturn('something');
$module = new AdyenOriginKey($this->helper);
$this->assertEquals('something', $module->getOriginKey());
}
/** @throws \Exception */
public function testGetOriginKeyDoesNotHandleExceptions()
{
$this->helper->method('getOriginKeyForBaseUrl')
->willThrowException(new \Exception('Some error message', 400));
$module = new AdyenOriginKey($this->helper);
$this->expectException(\Exception::class);
$this->expectExceptionMessage('Some error message');
$this->expectExceptionCode(400);
$module->getOriginKey();
}
}
<?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>
*/
require __DIR__.'/../vendor/autoload.php';
require __DIR__.'/../../../../vendor/autoload.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>
-->
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/6.3/phpunit.xsd"
bootstrap="./bootstrap.php"
>
<testsuites>
<testsuite name="default">
<directory>.</directory>
</testsuite>
</testsuites>
</phpunit>
......@@ -2,7 +2,7 @@
"name": "adyen/module-payment",
"description": "Official Magento2 Plugin to connect to Payment Service Provider Adyen.",
"type": "magento2-module",
"version": "4.4.0",
"version": "4.5.0",
"license": [
"OSL-3.0",
"AFL-3.0"
......@@ -16,7 +16,11 @@
"require": {
"adyen/php-api-library": "~2.1",
"magento/framework": ">=101.0.8 <102 || >=102.0.1",
"magento/module-vault": "101.*"
"magento/module-vault": "101.*",
"php": "~7.0.13|~7.1.0"
},
"require-dev": {
"phpunit/phpunit": "~6.5.0"
},
"autoload": {
"files": [
......@@ -30,5 +34,11 @@
"psr-4": {
"Adyen\\Payment\\Tests\\": "tests/"
}
},
"scripts": {
"test": [
"Composer\\Config::disableProcessTimeout",
"vendor/bin/phpunit -c Test/phpunit.xml"
]
}
}
......@@ -58,12 +58,14 @@
<tooltip>Copy this from the Test Adyen Customer Area => Settings => Users => System => [web service user]=> Checkout API Key.</tooltip>
<backend_model>Magento\Config\Model\Config\Backend\Encrypted</backend_model>
<config_path>payment/adyen_pos_cloud/api_key_test</config_path>
<comment model="Adyen\Payment\Model\Comment\ApiKeyEnding" />
</field>
<field id="api_key_live" translate="label" type="obscure" sortOrder="70" showInDefault="1" showInWebsite="1" showInStore="0">
<label>API key for Cloud API LIVE</label>
<tooltip>Copy this from the Live Adyen Customer Area => Settings => Users => System => [web service user]=> Checkout API Key.</tooltip>
<backend_model>Magento\Config\Model\Config\Backend\Encrypted</backend_model>
<config_path>payment/adyen_pos_cloud/api_key_live</config_path>
<comment model="Adyen\Payment\Model\Comment\ApiKeyEnding" />
</field>
<field id="capture_mode_pos" translate="label" type="select" sortOrder="90" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Capture Delay</label>
......
......@@ -54,12 +54,14 @@
<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/api_key_test</config_path>
<comment model="Adyen\Payment\Model\Comment\ApiKeyEnding" />
</field>
<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/api_key_live</config_path>
<comment model="Adyen\Payment\Model\Comment\ApiKeyEnding" />
</field>
<field id="live_endpoint_url_prefix" translate="label" type="text" sortOrder="70" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Live endpoint prefix</label>
......
......@@ -958,8 +958,45 @@
<type name="Adyen\Payment\Helper\Data">
<arguments>
<argument name="dataStorage" xsi:type="object">adyenPaymentConfigDataStorage</argument>
<argument name="serializer" xsi:type="object">Magento\Framework\Serialize\Serializer\Serialize</argument>
</arguments>
</type>
<type name="Adyen\Payment\Model\Config\Backend\Installments">
<arguments>
<argument name="serializer" xsi:type="object">Magento\Framework\Serialize\Serializer\Serialize</argument>
</arguments>
</type>
<type name="Adyen\Payment\Model\Config\Backend\InstallmentsPosCloud">
<arguments>
<argument name="serializer" xsi:type="object">Magento\Framework\Serialize\Serializer\Serialize</argument>
</arguments>
</type>
<type name="Adyen\Payment\Gateway\Validator\InstallmentValidator">
<arguments>
<argument name="serializer" xsi:type="object">Magento\Framework\Serialize\Serializer\Serialize</argument>
</arguments>
</type>
<type name="Adyen\Payment\Model\Ui\AdyenPosCloudConfigProvider">
<arguments>
<argument name="serializer" xsi:type="object">Magento\Framework\Serialize\Serializer\Serialize</argument>
</arguments>
</type>
<type name="Adyen\Payment\Model\Ui\AdyenCcConfigProvider">
<arguments>
<argument name="serializer" xsi:type="object">Magento\Framework\Serialize\Serializer\Serialize</argument>
</arguments>
</type>
<type name="Adyen\Payment\Model\Cron">
<arguments>
<argument name="serializer" xsi:type="object">Magento\Framework\Serialize\Serializer\Serialize</argument>
</arguments>
</type>
<type name="Adyen\Payment\Controller\Process\Json">
<arguments>
<argument name="serializer" xsi:type="object">Magento\Framework\Serialize\Serializer\Serialize</argument>
</arguments>
</type>
<preference for="Adyen\Payment\Api\GuestAdyenPaymentMethodManagementInterface"
type="Adyen\Payment\Model\GuestAdyenPaymentMethodManagement"/>
<preference for="Adyen\Payment\Api\AdyenPaymentMethodManagementInterface"
......@@ -972,6 +1009,8 @@
type="Adyen\Payment\Model\AdyenPaymentProcess"/>
<preference for="Adyen\Payment\Api\AdyenThreeDS2ProcessInterface"
type="Adyen\Payment\Model\AdyenThreeDS2Process"/>
<preference for="Adyen\Payment\Api\AdyenOriginKeyInterface"
type="Adyen\Payment\Model\AdyenOriginKey"/>
<type name="Magento\Vault\Api\PaymentTokenRepositoryInterface">
<plugin name="AdyenPaymentVaultDeleteToken" type="Adyen\Payment\Plugin\PaymentVaultDeleteToken" sortOrder="10"/>
</type>
......
......@@ -24,7 +24,7 @@
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Adyen_Payment" setup_version="4.4.0">
<module name="Adyen_Payment" setup_version="4.5.0">
<sequence>
<module name="Magento_Sales"/>
<module name="Magento_Quote"/>
......
......@@ -71,4 +71,11 @@
<resource ref="anonymous"/>
</resources>
</route>
<route url="/V1/adyen/originKey" method="GET">
<service class="Adyen\Payment\Api\AdyenOriginKeyInterface" method="getOriginKey"/>
<resources>
<resource ref="anonymous"/>
</resources>
</route>
</routes>
\ No newline at end of file
......@@ -24,6 +24,7 @@
define(
[
'jquery',
'ko',
'Magento_Checkout/js/model/quote',
'Magento_Checkout/js/view/payment/default',
'Magento_Checkout/js/action/place-order',
......@@ -34,8 +35,10 @@ define(
'Magento_Ui/js/model/messages',
'mage/translate',
],
function ($, quote, Component, placeOrderAction, additionalValidators, urlBuilder, storage, url, Messages, $t) {
function ($, ko, quote, Component, placeOrderAction, additionalValidators, urlBuilder, storage, url, Messages, $t) {
'use strict';
var canMakeApplePayPayments = ko.observable(false);
var applePayVersion = 6;
return Component.extend({
self: this,
defaults: {
......@@ -78,11 +81,12 @@ define(
var request = {
countryCode: quote.billingAddress().countryId,
currencyCode: quote.totals().quote_currency_code,
supportedNetworks: ['visa', 'masterCard', 'amex', 'discover'],
supportedNetworks: ['visa', 'masterCard', 'amex', 'discover', 'maestro', 'vPay', 'jcb', 'elo'],
merchantCapabilities: ['supports3DS'],
total: {label: $t('Grand Total'), amount: quote.totals().base_grand_total}
};
var session = new ApplePaySession(2, request);
var session = new ApplePaySession(applePayVersion, request);
session.onvalidatemerchant = function (event) {
var promise = self.performValidation(event.validationURL);
promise.then(function (merchantSession) {
......@@ -139,7 +143,16 @@ define(
return window.checkoutConfig.payment.adyen.showLogo;
},
isApplePayAllowed: function () {
if (window.ApplePaySession) {
var self = this;
// validate if applepay is allowed, it will be picked up by the isApplePayVisible method
var promise = window.ApplePaySession.canMakePaymentsWithActiveCard(self.getMerchantIdentifier());
promise.then(function (canMakePayments) {
if (canMakePayments)
canMakeApplePayPayments(true);
});
if (window.ApplePaySession && window.ApplePaySession.supportsVersion(applePayVersion) ) {
return true;
}
return false;
......@@ -177,6 +190,12 @@ define(
deferred.resolve(true);
}
);
},
isApplePayVisible: function() {
return canMakeApplePayPayments();
},
getMerchantIdentifier: function() {
return window.checkoutConfig.payment.adyen_apple_pay.merchant_identifier;
}
});
}
......
......@@ -280,6 +280,7 @@ define(
var data = {
'method': this.item.method,
additional_data: {
'guestEmail': quote.guestEmail,
'cc_type': this.creditCardType(),
'number': this.creditCardNumber(),
'cvc': this.securityCode(),
......
......@@ -22,7 +22,7 @@
*/
-->
<!-- ko if: isApplePayAllowed() -->
<div class="payment-method" data-bind="css: {'_active': (getCode() == isChecked())}">
<div class="payment-method" data-bind="css: {'_active': (getCode() == isChecked())}, visible: isApplePayVisible()">
<div class="payment-method-title field choice">
<input type="radio"
name="payment[method]"
......
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