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 43ca397e authored by Rik ter Beek's avatar Rik ter Beek

#67 Adyen Hpp is now using the Facade implementation

parent 0a20e07d
......@@ -28,7 +28,11 @@ use Symfony\Component\Config\Definition\Exception\Exception;
class Redirect extends \Magento\Payment\Block\Form
{
/**
* @var \Magento\Sales\Model\OrderFactory
*/
protected $_orderFactory;
/**
* @var \Magento\Checkout\Model\Session
*/
......@@ -39,6 +43,21 @@ class Redirect extends \Magento\Payment\Block\Form
*/
protected $_order;
/**
* @var \Adyen\Payment\Helper\Data
*/
protected $_adyenHelper;
/**
* @var ResolverInterface
*/
protected $_resolver;
/**
* @var \Adyen\Payment\Logger\AdyenLogger
*/
protected $_adyenLogger;
/**
* Redirect constructor.
*
......@@ -46,17 +65,29 @@ class Redirect extends \Magento\Payment\Block\Form
* @param array $data
* @param \Magento\Sales\Model\OrderFactory $orderFactory
* @param \Magento\Checkout\Model\Session $checkoutSession
* @param \Adyen\Payment\Helper\Data $adyenHelper
*/
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
array $data = [],
\Magento\Sales\Model\OrderFactory $orderFactory,
\Magento\Checkout\Model\Session $checkoutSession
\Magento\Checkout\Model\Session $checkoutSession,
\Adyen\Payment\Helper\Data $adyenHelper,
\Magento\Framework\Locale\ResolverInterface $resolver,
\Adyen\Payment\Logger\AdyenLogger $adyenLogger
) {
$this->_orderFactory = $orderFactory;
$this->_checkoutSession = $checkoutSession;
parent::__construct($context, $data);
$this->_getOrder();
$this->_adyenHelper = $adyenHelper;
$this->_resolver = $resolver;
$this->_adyenLogger = $adyenLogger;
if (!$this->_order) {
$incrementId = $this->_getCheckout()->getLastRealOrderId();
$this->_order = $this->_orderFactory->create()->loadByIncrementId($incrementId);
}
}
......@@ -73,19 +104,46 @@ class Redirect extends \Magento\Payment\Block\Form
*/
public function getFormUrl()
{
$result = "";
$url = "";
try {
$order = $this->_order;
if($order->getPayment())
{
$result = $this->_order->getPayment()->getMethodInstance()->getFormUrl();
if ($this->_order->getPayment()) {
$paymentRoutine = $this->_adyenHelper->getAdyenHppConfigData('payment_routine');
switch ($this->_adyenHelper->isDemoMode()) {
case true:
if ($paymentRoutine == 'single' && $this->getPaymentMethodSelectionOnAdyen()) {
$url = 'https://test.adyen.com/hpp/pay.shtml';
} else {
$url = ($this->getPaymentMethodSelectionOnAdyen())
? 'https://test.adyen.com/hpp/select.shtml'
: "https://test.adyen.com/hpp/details.shtml";
}
break;
default:
if ($paymentRoutine == 'single' && $this->getPaymentMethodSelectionOnAdyen()) {
$url = 'https://live.adyen.com/hpp/pay.shtml';
} else {
$url = ($this->getPaymentMethodSelectionOnAdyen())
? 'https://live.adyen.com/hpp/select.shtml'
: "https://live.adyen.com/hpp/details.shtml";
}
break;
}
}
} catch(Exception $e) {
// do nothing for now
throw($e);
}
return $result;
return $url;
}
/**
* @return mixed
*/
public function getPaymentMethodSelectionOnAdyen()
{
return $this->_adyenHelper->getAdyenHppConfigDataFlag('payment_selection_on_adyen');
}
/**
......@@ -93,31 +151,115 @@ class Redirect extends \Magento\Payment\Block\Form
*/
public function getFormFields()
{
$result = array();
$formFields = [];
try {
if($this->_order->getPayment())
{
$result = $this->_order->getPayment()->getMethodInstance()->getFormFields();
if ($this->_order->getPayment()) {
$realOrderId = $this->_order->getRealOrderId();
$orderCurrencyCode = $this->_order->getOrderCurrencyCode();
$skinCode = trim($this->_adyenHelper->getAdyenHppConfigData('skin_code'));
$amount = $this->_adyenHelper->formatAmount(
$this->_order->getGrandTotal(), $orderCurrencyCode
);
$merchantAccount = trim($this->_adyenHelper->getAdyenAbstractConfigData('merchant_account'));
$shopperEmail = $this->_order->getCustomerEmail();
$customerId = $this->_order->getCustomerId();
$shopperIP = $this->_order->getRemoteIp();
$browserInfo = $_SERVER['HTTP_USER_AGENT'];
$deliveryDays = $this->_adyenHelper->getAdyenHppConfigData('delivery_days');
$shopperLocale = trim($this->_adyenHelper->getAdyenHppConfigData('shopper_locale'));
$shopperLocale = (!empty($shopperLocale)) ? $shopperLocale : $this->_resolver->getLocale();
$countryCode = trim($this->_adyenHelper->getAdyenHppConfigData('country_code'));
$countryCode = (!empty($countryCode)) ? $countryCode : false;
// if directory lookup is enabled use the billingadress as countrycode
if ($countryCode == false) {
if ($this->_order->getBillingAddress() &&
$this->_order->getBillingAddress()->getCountryId() != "") {
$countryCode = $this->_order->getBillingAddress()->getCountryId();
}
}
$formFields = [];
$formFields['merchantAccount'] = $merchantAccount;
$formFields['merchantReference'] = $realOrderId;
$formFields['paymentAmount'] = (int)$amount;
$formFields['currencyCode'] = $orderCurrencyCode;
$formFields['shipBeforeDate'] = date(
"Y-m-d",
mktime(date("H"), date("i"), date("s"), date("m"), date("j") + $deliveryDays, date("Y"))
);
$formFields['skinCode'] = $skinCode;
$formFields['shopperLocale'] = $shopperLocale;
$formFields['countryCode'] = $countryCode;
$formFields['shopperIP'] = $shopperIP;
$formFields['browserInfo'] = $browserInfo;
$formFields['sessionValidity'] = date(
DATE_ATOM,
mktime(date("H") + 1, date("i"), date("s"), date("m"), date("j"), date("Y"))
);
$formFields['shopperEmail'] = $shopperEmail;
// recurring
$recurringType = trim($this->_adyenHelper->getAdyenAbstractConfigData(
'recurring_type')
);
$brandCode = $this->_order->getPayment()->getAdditionalInformation("brand_code");
// Paypal does not allow ONECLICK,RECURRING only RECURRING
if ($brandCode == "paypal" && $recurringType == 'ONECLICK,RECURRING') {
$recurringType = "RECURRING";
}
$formFields['recurringContract'] = $recurringType;
$formFields['shopperReference'] = (!empty($customerId)) ? $customerId : self::GUEST_ID . $realOrderId;
//blocked methods
$formFields['blockedMethods'] = "";
$baseUrl = $this->_storeManager->getStore($this->getStore())
->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_LINK);
$formFields['resURL'] = $baseUrl . 'adyen/process/result';
$hmacKey = $this->_adyenHelper->getHmac();
if ($brandCode) {
$formFields['brandCode'] = $brandCode;
}
$issuerId = $this->_order->getPayment()->getAdditionalInformation("issuer_id");
if ($issuerId) {
$formFields['issuerId'] = $issuerId;
}
// Sort the array by key using SORT_STRING order
ksort($formFields, SORT_STRING);
// Generate the signing data string
$signData = implode(":", array_map([$this, 'escapeString'],
array_merge(array_keys($formFields), array_values($formFields))));
$merchantSig = base64_encode(hash_hmac('sha256', $signData, pack("H*", $hmacKey), true));
$formFields['merchantSig'] = $merchantSig;
$this->_adyenLogger->addAdyenDebug(print_r($formFields, true));
}
} catch(Exception $e) {
// do nothing for now
}
return $result;
return $formFields;
}
/**
* Get order object
* The character escape function is called from the array_map function in _signRequestParams
*
* @return \Magento\Sales\Model\Order
* @param $val
* @return mixed
*/
protected function _getOrder()
protected function escapeString($val)
{
if (!$this->_order) {
$incrementId = $this->_getCheckout()->getLastRealOrderId();
$this->_order = $this->_orderFactory->create()->loadByIncrementId($incrementId);
}
return $this->_order;
return str_replace(':', '\\:', str_replace('\\', '\\\\', $val));
}
/**
......
<?php
/**
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* Adyen Payment module (https://www.adyen.com/)
*
* Copyright (c) 2015 Adyen BV (https://www.adyen.com/)
* See LICENSE.txt for license details.
*
* Author: Adyen <magento@adyen.com>
*/
namespace Adyen\Payment\Gateway\Command;
use Magento\Payment\Gateway\Command;
use Magento\Payment\Gateway\CommandInterface;
class HppCommand implements CommandInterface
{
/**
* @var \Adyen\Payment\Helper\Data
*/
protected $_adyenHelper;
/**
* HppCommand constructor.
*
* @param \Adyen\Payment\Helper\Data $adyenHelper
*/
public function __construct(\Adyen\Payment\Helper\Data $adyenHelper)
{
$this->_adyenHelper = $adyenHelper;
}
/**
* @param array $commandSubject
* @return $this
*/
public function execute(array $commandSubject)
{
$payment =\Magento\Payment\Gateway\Helper\SubjectReader::readPayment($commandSubject);
$stateObject = \Magento\Payment\Gateway\Helper\SubjectReader::readStateObject($commandSubject);
// do not send email
$payment = $payment->getPayment();
$payment->getOrder()->setCanSendNewEmailFlag(false);
// update status and state
$stateObject->setState(\Magento\Sales\Model\Order::STATE_NEW);
$stateObject->setStatus($this->_adyenHelper->getAdyenAbstractConfigData('order_status'));
$stateObject->setIsNotified(false);
return $this;
}
}
\ No newline at end of file
......@@ -47,7 +47,6 @@ class AdyenGenericConfigProvider implements ConfigProviderInterface
* @var string[]
*/
protected $_methodCodes = [
\Adyen\Payment\Model\Method\Hpp::METHOD_CODE,
\Adyen\Payment\Model\Method\Pos::METHOD_CODE,
];
......
......@@ -292,7 +292,7 @@ class Hpp extends \Magento\Payment\Model\Method\AbstractMethod implements Gatewa
*/
public function getFormUrl()
{
$paymentRoutine = $this->getConfigData('payment_routine');
$paymentRoutine = $this->getConfigData('payment_routine');
switch ($this->_adyenHelper->isDemoMode()) {
case true:
......
......@@ -21,7 +21,7 @@
* Author: Adyen <magento@adyen.com>
*/
namespace Adyen\Payment\Model;
namespace Adyen\Payment\Model\Ui;
use Magento\Checkout\Model\ConfigProviderInterface;
use Magento\Payment\Helper\Data as PaymentHelper;
......@@ -30,6 +30,8 @@ use Magento\Directory\Helper\Data;
class AdyenHppConfigProvider implements ConfigProviderInterface
{
const CODE = 'adyen_hpp';
/**
* @var PaymentHelper
*/
......@@ -41,16 +43,16 @@ class AdyenHppConfigProvider implements ConfigProviderInterface
protected $_adyenHelper;
/**
* @var string[]
* Request object
*
* @var \Magento\Framework\App\RequestInterface
*/
protected $_methodCodes = [
'adyen_hpp'
];
protected $_request;
/**
* @var \Magento\Payment\Model\Method\AbstractMethod[]
* @var \Magento\Framework\UrlInterface
*/
protected $methods = [];
protected $_urlBuilder;
/**
* AdyenHppConfigProvider constructor.
......@@ -60,14 +62,14 @@ class AdyenHppConfigProvider implements ConfigProviderInterface
*/
public function __construct(
PaymentHelper $paymentHelper,
\Adyen\Payment\Helper\Data $adyenHelper
\Adyen\Payment\Helper\Data $adyenHelper,
\Magento\Framework\App\RequestInterface $request,
\Magento\Framework\UrlInterface $urlBuilder
) {
$this->_paymentHelper = $paymentHelper;
$this->_adyenHelper = $adyenHelper;
foreach ($this->_methodCodes as $code) {
$this->methods[$code] = $this->_paymentHelper->getMethodInstance($code);
}
$this->_request = $request;
$this->_urlBuilder = $urlBuilder;
}
/**
......@@ -77,20 +79,31 @@ class AdyenHppConfigProvider implements ConfigProviderInterface
*/
public function getConfig()
{
// set to active
$config = [
'payment' => [
'adyenHpp' => [
self::CODE => [
'isActive' => true,
'redirectUrl' => $this->_urlBuilder->getUrl(
'adyen/process/redirect', ['_secure' => $this->_getRequest()->isSecure()])
]
]
];
foreach ($this->_methodCodes as $code) {
if ($this->methods[$code]->isAvailable()) {
$paymentMethodSelectionOnAdyen =
$this->_adyenHelper->getAdyenHppConfigDataFlag('payment_selection_on_adyen');
$config['payment'] ['adyenHpp']['isPaymentMethodSelectionOnAdyen'] = $paymentMethodSelectionOnAdyen;
}
}
$paymentMethodSelectionOnAdyen =
$this->_adyenHelper->getAdyenHppConfigDataFlag('payment_selection_on_adyen');
$config['payment'] ['adyenHpp']['isPaymentMethodSelectionOnAdyen'] = $paymentMethodSelectionOnAdyen;
return $config;
}
/**
* Retrieve request object
*
* @return \Magento\Framework\App\RequestInterface
*/
protected function _getRequest()
{
return $this->_request;
}
}
\ No newline at end of file
<?php
/**
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* Adyen Payment module (https://www.adyen.com/)
*
* Copyright (c) 2015 Adyen BV (https://www.adyen.com/)
* See LICENSE.txt for license details.
*
* Author: Adyen <magento@adyen.com>
*/
namespace Adyen\Payment\Observer;
use Magento\Framework\Event\Observer;
use Magento\Payment\Observer\AbstractDataAssignObserver;
use Magento\Quote\Api\Data\PaymentInterface;
/**
* Class DataAssignObserver
*/
class AdyenHppDataAssignObserver extends AbstractDataAssignObserver
{
const BRAND_CODE = 'brand_code';
const ISSUER_ID = 'issuer_id';
/**
* @var array
*/
protected $additionalInformationList = [
self::BRAND_CODE,
self::ISSUER_ID
];
/**
* @param Observer $observer
* @return void
*/
public function execute(Observer $observer)
{
$data = $this->readDataArgument($observer);
$additionalData = $data->getData(PaymentInterface::KEY_ADDITIONAL_DATA);
if (!is_array($additionalData)) {
return;
}
$paymentInfo = $this->readPaymentModelArgument($observer);
foreach ($this->additionalInformationList as $additionalInformationKey) {
if (isset($additionalData[$additionalInformationKey])) {
$paymentInfo->setAdditionalInformation(
$additionalInformationKey,
$additionalData[$additionalInformationKey]
);
}
}
}
}
......@@ -88,7 +88,7 @@
</adyen_oneclick>
<adyen_hpp>
<active>0</active>
<model>Adyen\Payment\Model\Method\Hpp</model>
<model>AdyenPaymentHppFacade</model>
<order_status>pending</order_status>
<title>Adyen HPP</title>
<payment_selection_on_adyen>0</payment_selection_on_adyen>
......@@ -99,6 +99,16 @@
<place_order_url>adyen/process/redirect</place_order_url>
<order_place_redirect_url>adyen/process/redirect</order_place_redirect_url>
<payment_action>order</payment_action>
<can_initialize>1</can_initialize>
<is_gateway>1</is_gateway>
<can_use_checkout>1</can_use_checkout>
<can_capture>1</can_capture>
<can_capture_partial>1</can_capture_partial>
<can_use_internal>1</can_use_internal>
<can_refund_partial_per_invoice>1</can_refund_partial_per_invoice>
<can_refund>1</can_refund>
<can_void>1</can_void>
<can_cancel>1</can_cancel>
<group>adyen</group>
</adyen_hpp>
<adyen_sepa>
......
......@@ -46,6 +46,16 @@
<argument name="commandPool" xsi:type="object">AdyenPaymentOneclickCommandPool</argument>
</arguments>
</virtualType>
<virtualType name="AdyenPaymentHppFacade" type="Magento\Payment\Model\Method\Adapter">
<arguments>
<argument name="code" xsi:type="const">Adyen\Payment\Model\Ui\AdyenHppConfigProvider::CODE</argument>
<argument name="formBlockType" xsi:type="string">Adyen\Payment\Block\Form\Hpp</argument>
<argument name="infoBlockType" xsi:type="string">Adyen\Payment\Block\Info\Hpp</argument>
<argument name="valueHandlerPool" xsi:type="object">AdyenPaymentHppValueHandlerPool</argument>
<argument name="validatorPool" xsi:type="object">AdyenPaymentHppValidatorPool</argument>
<argument name="commandPool" xsi:type="object">AdyenPaymentHppCommandPool</argument>
</arguments>
</virtualType>
<virtualType name="AdyenPaymentSepaFacade" type="Magento\Payment\Model\Method\Adapter">
<arguments>
<argument name="code" xsi:type="const">Adyen\Payment\Model\Ui\AdyenSepaConfigProvider::CODE</argument>
......@@ -94,6 +104,19 @@
</arguments>
</virtualType>
<virtualType name="AdyenPaymentHppValueHandlerPool" type="Magento\Payment\Gateway\Config\ValueHandlerPool">
<arguments>
<argument name="handlers" xsi:type="array">
<item name="default" xsi:type="string">AdyenPaymentHppConfigValueHandler</item>
</argument>
</arguments>
</virtualType>
<virtualType name="AdyenPaymentHppConfigValueHandler" type="Magento\Payment\Gateway\Config\ConfigValueHandler">
<arguments>
<argument name="configInterface" xsi:type="object">AdyenPaymentHppConfig</argument>
</arguments>
</virtualType>
<virtualType name="AdyenPaymentSepaValueHandlerPool" type="Magento\Payment\Gateway\Config\ValueHandlerPool">
<arguments>
<argument name="handlers" xsi:type="array">
......@@ -131,6 +154,11 @@
<argument name="methodCode" xsi:type="const">Adyen\Payment\Model\Ui\AdyenOneclickConfigProvider::CODE</argument>
</arguments>
</virtualType>
<virtualType name="AdyenPaymentHppConfig" type="Magento\Payment\Gateway\Config\Config">
<arguments>
<argument name="methodCode" xsi:type="const">Adyen\Payment\Model\Ui\AdyenHppConfigProvider::CODE</argument>
</arguments>
</virtualType>
<virtualType name="AdyenPaymentSepaConfig" type="Magento\Payment\Gateway\Config\Config">
<arguments>
<argument name="methodCode" xsi:type="const">Adyen\Payment\Model\Ui\AdyenSepaConfigProvider::CODE</argument>
......@@ -170,6 +198,18 @@
</arguments>
</virtualType>
<virtualType name="AdyenPaymentHppCommandPool" type="Magento\Payment\Gateway\Command\CommandPool">
<arguments>
<argument name="commands" xsi:type="array">
<item name="initialize" xsi:type="string">Adyen\Payment\Gateway\Command\HppCommand</item>
<item name="capture" xsi:type="string">AdyenPaymentCaptureCommand</item>
<item name="void" xsi:type="string">AdyenPaymentCancelCommand</item>
<item name="refund" xsi:type="string">AdyenPaymentRefundCommand</item>
<item name="cancel" xsi:type="string">AdyenPaymentCancelCommand</item>
</argument>
</arguments>
</virtualType>
<virtualType name="AdyenPaymentSepaCommandPool" type="Magento\Payment\Gateway\Command\CommandPool">
<arguments>
<argument name="commands" xsi:type="array">
......@@ -463,6 +503,20 @@
</arguments>
</virtualType>
<virtualType name="AdyenPaymentHppValidatorPool" type="Magento\Payment\Gateway\Validator\ValidatorPool">
<arguments>
<argument name="validators" xsi:type="array">
<item name="country" xsi:type="string">AdyenHppCountryValidator</item>
</argument>
</arguments>
</virtualType>
<!--FIXME: Config does not exists-->
<virtualType name="AdyenHppCountryValidator" type="Magento\Payment\Gateway\Validator\CountryValidator">
<arguments>
<argument name="config" xsi:type="object">Adyen\Payment\Gateway\Config\HppConfig</argument>
</arguments>
</virtualType>
<virtualType name="AdyenPaymentSepaValidatorPool" type="Magento\Payment\Gateway\Validator\ValidatorPool">
<arguments>
<argument name="validators" xsi:type="array">
......
......@@ -29,10 +29,13 @@
<event name="payment_method_assign_data_adyen_oneclick">
<observer name="adyen_cc_gateway_data_assign" instance="Adyen\Payment\Observer\AdyenOneclickDataAssignObserver" />
</event>
<event name="payment_method_assign_data_adyen_hpp">
<observer name="adyen_hpp_gateway_data_assign" instance="Adyen\Payment\Observer\AdyenHppDataAssignObserver" />
</event>
<event name="payment_method_assign_data_adyen_sepa">
<observer name="adyen_sepa_gateway_data_assign" instance="Adyen\Payment\Observer\AdyenSepaDataAssignObserver" />
</event>
<event name="payment_method_assign_data_adyen_boleto">
<observer name="adyen_sepa_gateway_data_assign" instance="Adyen\Payment\Observer\AdyenBoletoDataAssignObserver" />
<observer name="adyen_boleto_gateway_data_assign" instance="Adyen\Payment\Observer\AdyenBoletoDataAssignObserver" />
</event>
</config>
......@@ -30,7 +30,7 @@
<item name="adyen_generic_config_provider" xsi:type="object">Adyen\Payment\Model\AdyenGenericConfigProvider</item>
<item name="adyen_cc_config_provider" xsi:type="object">Adyen\Payment\Model\Ui\AdyenCcConfigProvider</item>
<item name="adyen_oneclick_config_provider" xsi:type="object">Adyen\Payment\Model\Ui\AdyenOneclickConfigProvider</item>
<item name="adyen_hpp_config_provider" xsi:type="object">Adyen\Payment\Model\AdyenHppConfigProvider</item>
<item name="adyen_hpp_config_provider" xsi:type="object">Adyen\Payment\Model\Ui\AdyenHppConfigProvider</item>
<item name="adyen_sepa_config_provider" xsi:type="object">Adyen\Payment\Model\Ui\AdyenSepaConfigProvider</item>
<item name="adyen_boleto_config_provider" xsi:type="object">Adyen\Payment\Model\Ui\AdyenBoletoConfigProvider</item>
</argument>
......
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