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

#67 Adyen PayByMail is now using the Facade implementation and fixes that HPP...

#67 Adyen PayByMail is now using the Facade implementation and fixes that HPP and POS are not available for backend orders, removed unused variable in OneClick form block removed unused AdyenAbstract method.
parent aa9e2b6a
...@@ -30,11 +30,6 @@ class Oneclick extends \Adyen\Payment\Block\Form\Cc ...@@ -30,11 +30,6 @@ class Oneclick extends \Adyen\Payment\Block\Form\Cc
*/ */
protected $_template = 'Adyen_Payment::form/oneclick.phtml'; protected $_template = 'Adyen_Payment::form/oneclick.phtml';
/**
* @var \Adyen\Payment\Model\AdyenOneclickConfigProvider
*/
protected $_oneclickConfig;
/** /**
* @var \Magento\Backend\Model\Session\Quote * @var \Magento\Backend\Model\Session\Quote
*/ */
...@@ -54,12 +49,10 @@ class Oneclick extends \Adyen\Payment\Block\Form\Cc ...@@ -54,12 +49,10 @@ class Oneclick extends \Adyen\Payment\Block\Form\Cc
\Magento\Payment\Model\Config $paymentConfig, \Magento\Payment\Model\Config $paymentConfig,
\Adyen\Payment\Helper\Data $adyenHelper, \Adyen\Payment\Helper\Data $adyenHelper,
\Magento\Checkout\Model\Session $checkoutSession, \Magento\Checkout\Model\Session $checkoutSession,
\Adyen\Payment\Model\AdyenOneclickConfigProvider $oneclickConfigProvider,
\Magento\Backend\Model\Session\Quote $sessionQuote, \Magento\Backend\Model\Session\Quote $sessionQuote,
array $data = [] array $data = []
) { ) {
parent::__construct($context, $paymentConfig, $adyenHelper, $checkoutSession, $data); parent::__construct($context, $paymentConfig, $adyenHelper, $checkoutSession, $data);
$this->_oneclickConfig = $oneclickConfigProvider;
$this->_sessionQuote = $sessionQuote; $this->_sessionQuote = $sessionQuote;
} }
......
<?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 PayByMailCommand implements CommandInterface
{
/**
* @var \Adyen\Payment\Helper\Data
*/
protected $_adyenHelper;
/**
* @var ResolverInterface
*/
protected $_resolver;
/**
* @var \Adyen\Payment\Logger\AdyenLogger
*/
protected $_adyenLogger;
/**
* PayByMailCommand constructor.
*
* @param \Adyen\Payment\Helper\Data $adyenHelper
* @param \Magento\Framework\Locale\ResolverInterface $resolver
* @param \Adyen\Payment\Logger\AdyenLogger $adyenLogger
*/
public function __construct(
\Adyen\Payment\Helper\Data $adyenHelper,
\Magento\Framework\Locale\ResolverInterface $resolver,
\Adyen\Payment\Logger\AdyenLogger $adyenLogger
) {
$this->_adyenHelper = $adyenHelper;
$this->_resolver = $resolver;
$this->_adyenLogger = $adyenLogger;
}
/**
* @param array $commandSubject
* @return $this
*/
public function execute(array $commandSubject)
{
$payment =\Magento\Payment\Gateway\Helper\SubjectReader::readPayment($commandSubject);
$payment = $payment->getPayment();
// do not let magento set status to processing
$payment->setIsTransactionPending(true);
// generateUrl
$payment->setAdditionalInformation('payment_url', $this->_generatePaymentUrl($payment));
return $this;
}
/**
* @param $payment
* @return string
*/
protected function _generatePaymentUrl($payment)
{
$url = $this->getFormUrl();
$fields = $this->getFormFields($payment);
$count = 1;
$size = count($fields);
foreach ($fields as $field => $value) {
if ($count == 1) {
$url .= "?";
}
$url .= urlencode($field) . "=" . urlencode($value);
if ($count != $size) {
$url .= "&";
}
++$count;
}
return $url;
}
/**
* @return string
*/
public function getFormUrl()
{
if ($this->_adyenHelper->isDemoMode()) {
$url = 'https://test.adyen.com/hpp/pay.shtml';
} else {
$url = 'https://live.adyen.com/hpp/pay.shtml';
}
return $url;
}
/**
* @param $payment
* @return array
*/
protected function getFormFields($payment)
{
$order = $payment->getOrder();
$realOrderId = $order->getRealOrderId();
$orderCurrencyCode = $order->getOrderCurrencyCode();
// check if paybymail has it's own skin
$skinCode = trim($this->_adyenHelper->getAdyenHppConfigData('skin_code'));
if ($skinCode == "") {
// use HPP skin and HMAC
$skinCode = $this->_adyenHelper->getAdyenHppConfigData('skin_code');
$hmacKey = $this->_adyenHelper->getHmac();
} else {
// use pay_by_mail skin and hmac
$hmacKey = $this->_adyenHelper->getHmacPayByMail();
}
$amount = $this->_adyenHelper->formatAmount($order->getGrandTotal(), $orderCurrencyCode);
$merchantAccount = trim($this->_adyenHelper->getAdyenAbstractConfigData('merchant_account'));
$shopperEmail = $order->getCustomerEmail();
$customerId = $order->getCustomerId();
$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 (is_object($order->getBillingAddress()) && $order->getBillingAddress()->getCountry() != "") {
$countryCode = $order->getBillingAddress()->getCountry();
} else {
$countryCode = "";
}
}
$deliveryDays = $this->_adyenHelper->getAdyenHppConfigData('delivery_days');
$deliveryDays = (!empty($deliveryDays)) ? $deliveryDays : 5;
$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;
if ($countryCode != "") {
$formFields['countryCode'] = $countryCode;
}
$formFields['shopperEmail'] = $shopperEmail;
// recurring
$recurringType = trim($this->_adyenHelper->getAdyenAbstractConfigData('recurring_type'));
$formFields['recurringContract'] = $recurringType;
$sessionValidity = $this->_adyenHelper->getAdyenPayByMailConfigData('session_validity');
if ($sessionValidity == "") {
$sessionValidity = 3;
}
$formFields['sessionValidity'] = date("c", strtotime("+". $sessionValidity. " days"));
$formFields['shopperReference'] = (!empty($customerId)) ? $customerId : self::GUEST_ID . $realOrderId;
// 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));
return $formFields;
}
/**
* The character escape function is called from the array_map function in _signRequestParams
*
* @param $val
* @return mixed
*/
protected function escapeString($val)
{
return str_replace(':', '\\:', str_replace('\\', '\\\\', $val));
}
}
\ 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\Model\Method;
use Magento\Framework\DataObject;
use Magento\Payment\Model\Method\ConfigInterface;
use Magento\Payment\Model\Method\Online\GatewayInterface;
/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class AdyenAbstract extends \Magento\Payment\Model\Method\AbstractMethod implements GatewayInterface
{
const METHOD_CODE = 'adyen_abstract';
/**
* @var string
*/
protected $_code = self::METHOD_CODE;
/**
* @var bool
*/
protected $_isGateway = false;
/**
* @var bool
*/
protected $_canAuthorize = false;
/**
* @var bool
*/
protected $_isInitializeNeeded = false;
/**
* Post request to gateway and return response
*
* @param DataObject $request
* @param ConfigInterface $config
*/
public function postRequest(DataObject $request, ConfigInterface $config)
{
// Not needed only used for global configuration settings
}
}
\ No newline at end of file
...@@ -20,18 +20,17 @@ ...@@ -20,18 +20,17 @@
* *
* Author: Adyen <magento@adyen.com> * Author: Adyen <magento@adyen.com>
*/ */
namespace Adyen\Payment\Model;
namespace Adyen\Payment\Model\Ui;
use Magento\Checkout\Model\ConfigProviderInterface; use Magento\Checkout\Model\ConfigProviderInterface;
use Magento\Payment\Helper\Data as PaymentHelper; use Magento\Payment\Helper\Data as PaymentHelper;
use Magento\Directory\Helper\Data;
class AdyenGenericConfigProvider implements ConfigProviderInterface class AdyenPayByMailConfigProvider implements ConfigProviderInterface
{ {
/** const CODE = 'adyen_pay_by_mail';
* @var \Magento\Payment\Model\Method\AbstractMethod[]
*/
protected $_methods = [];
/** /**
* @var PaymentHelper * @var PaymentHelper
...@@ -44,67 +43,63 @@ class AdyenGenericConfigProvider implements ConfigProviderInterface ...@@ -44,67 +43,63 @@ class AdyenGenericConfigProvider implements ConfigProviderInterface
protected $_adyenHelper; protected $_adyenHelper;
/** /**
* @var string[] * Request object
*
* @var \Magento\Framework\App\RequestInterface
*/
protected $_request;
/**
* @var \Magento\Framework\UrlInterface
*/ */
protected $_methodCodes = [ protected $_urlBuilder;
\Adyen\Payment\Model\Method\Pos::METHOD_CODE,
];
/** /**
* AdyenGenericConfigProvider constructor. * AdyenHppConfigProvider constructor.
* *
* @param PaymentHelper $paymentHelper * @param PaymentHelper $paymentHelper
* @param \Adyen\Payment\Helper\Data $adyenHelper * @param \Adyen\Payment\Helper\Data $adyenHelper
*/ */
public function __construct( public function __construct(
PaymentHelper $paymentHelper, 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->_paymentHelper = $paymentHelper;
$this->_adyenHelper = $adyenHelper; $this->_adyenHelper = $adyenHelper;
$this->_request = $request;
foreach ($this->_methodCodes as $code) { $this->_urlBuilder = $urlBuilder;
$this->_methods[$code] = $this->_paymentHelper->getMethodInstance($code);
}
} }
/** /**
* Define foreach payment methods the RedirectUrl * Set configuration for AdyenHPP payemnt method
* *
* @return array * @return array
*/ */
public function getConfig() public function getConfig()
{ {
// set to active
$config = [ $config = [
'payment' => [] 'payment' => [
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()) {
$config['payment'][$code] = [
'redirectUrl' => $this->getMethodRedirectUrl($code)
];
}
}
// show logos turned on by default
if ($this->_adyenHelper->showLogos()) {
$config['payment']['adyen']['showLogo'] = true;
} else {
$config['payment']['adyen']['showLogo'] = false;
}
return $config; return $config;
} }
/** /**
* Return redirect URL for method * Retrieve request object
* *
* @param string $code * @return \Magento\Framework\App\RequestInterface
* @return mixed
*/ */
protected function getMethodRedirectUrl($code) protected function _getRequest()
{ {
return $this->_methods[$code]->getCheckoutRedirectUrl(); return $this->_request;
} }
} }
\ No newline at end of file
...@@ -104,7 +104,7 @@ ...@@ -104,7 +104,7 @@
<can_use_checkout>1</can_use_checkout> <can_use_checkout>1</can_use_checkout>
<can_capture>1</can_capture> <can_capture>1</can_capture>
<can_capture_partial>1</can_capture_partial> <can_capture_partial>1</can_capture_partial>
<can_use_internal>1</can_use_internal> <can_use_internal>0</can_use_internal>
<can_refund_partial_per_invoice>1</can_refund_partial_per_invoice> <can_refund_partial_per_invoice>1</can_refund_partial_per_invoice>
<can_refund>1</can_refund> <can_refund>1</can_refund>
<can_void>1</can_void> <can_void>1</can_void>
...@@ -145,7 +145,7 @@ ...@@ -145,7 +145,7 @@
<can_use_checkout>1</can_use_checkout> <can_use_checkout>1</can_use_checkout>
<can_capture>1</can_capture> <can_capture>1</can_capture>
<can_capture_partial>1</can_capture_partial> <can_capture_partial>1</can_capture_partial>
<can_use_internal>1</can_use_internal> <can_use_internal>0</can_use_internal>
<can_refund_partial_per_invoice>1</can_refund_partial_per_invoice> <can_refund_partial_per_invoice>1</can_refund_partial_per_invoice>
<can_refund>1</can_refund> <can_refund>1</can_refund>
<can_void>1</can_void> <can_void>1</can_void>
...@@ -154,13 +154,23 @@ ...@@ -154,13 +154,23 @@
</adyen_pos> </adyen_pos>
<adyen_pay_by_mail> <adyen_pay_by_mail>
<active>0</active> <active>0</active>
<model>Adyen\Payment\Model\Method\PayByMail</model> <model>AdyenPaymentPayByMailFacade</model>
<order_status>pending</order_status> <order_status>pending</order_status>
<title>Adyen PayByMail</title> <title>Adyen PayByMail</title>
<allowspecific>0</allowspecific> <allowspecific>0</allowspecific>
<sort_order>6</sort_order> <sort_order>6</sort_order>
<session_validity>3</session_validity> <session_validity>3</session_validity>
<payment_action>authorize</payment_action> <payment_action>authorize</payment_action>
<is_gateway>1</is_gateway>
<can_use_checkout>0</can_use_checkout>
<can_authorize>1</can_authorize>
<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> <group>adyen</group>
</adyen_pay_by_mail> </adyen_pay_by_mail>
<adyen_boleto> <adyen_boleto>
......
...@@ -86,6 +86,16 @@ ...@@ -86,6 +86,16 @@
<argument name="commandPool" xsi:type="object">AdyenPaymentPosCommandPool</argument> <argument name="commandPool" xsi:type="object">AdyenPaymentPosCommandPool</argument>
</arguments> </arguments>
</virtualType> </virtualType>
<virtualType name="AdyenPaymentPayByMailFacade" type="Magento\Payment\Model\Method\Adapter">
<arguments>
<argument name="code" xsi:type="const">Adyen\Payment\Model\Ui\AdyenPayByMailConfigProvider::CODE</argument>
<argument name="formBlockType" xsi:type="string">Adyen\Payment\Block\Form\PayByMail</argument>
<argument name="infoBlockType" xsi:type="string">Adyen\Payment\Block\Info\PayByMail</argument>
<argument name="valueHandlerPool" xsi:type="object">AdyenPaymentPayByMailValueHandlerPool</argument>
<argument name="validatorPool" xsi:type="object">AdyenPaymentPayByMailValidatorPool</argument>
<argument name="commandPool" xsi:type="object">AdyenPaymentPayByMailCommandPool</argument>
</arguments>
</virtualType>
<!-- Value handlers infrastructure --> <!-- Value handlers infrastructure -->
<virtualType name="AdyenPaymentCcValueHandlerPool" type="Magento\Payment\Gateway\Config\ValueHandlerPool"> <virtualType name="AdyenPaymentCcValueHandlerPool" type="Magento\Payment\Gateway\Config\ValueHandlerPool">
...@@ -166,6 +176,19 @@ ...@@ -166,6 +176,19 @@
</arguments> </arguments>
</virtualType> </virtualType>
<virtualType name="AdyenPaymentPayByMailValueHandlerPool" type="Magento\Payment\Gateway\Config\ValueHandlerPool">
<arguments>
<argument name="handlers" xsi:type="array">
<item name="default" xsi:type="string">AdyenPaymentPayByMailConfigValueHandler</item>
</argument>
</arguments>
</virtualType>
<virtualType name="AdyenPaymentPayByMailConfigValueHandler" type="Magento\Payment\Gateway\Config\ConfigValueHandler">
<arguments>
<argument name="configInterface" xsi:type="object">AdyenPaymentPayByMailConfig</argument>
</arguments>
</virtualType>
<!-- Configuration reader --> <!-- Configuration reader -->
<virtualType name="AdyenPaymentCcConfig" type="Magento\Payment\Gateway\Config\Config"> <virtualType name="AdyenPaymentCcConfig" type="Magento\Payment\Gateway\Config\Config">
<arguments> <arguments>
...@@ -197,7 +220,11 @@ ...@@ -197,7 +220,11 @@
<argument name="methodCode" xsi:type="const">Adyen\Payment\Model\Ui\AdyenPosConfigProvider::CODE</argument> <argument name="methodCode" xsi:type="const">Adyen\Payment\Model\Ui\AdyenPosConfigProvider::CODE</argument>
</arguments> </arguments>
</virtualType> </virtualType>
<virtualType name="AdyenPaymentPayByMailConfig" type="Magento\Payment\Gateway\Config\Config">
<arguments>
<argument name="methodCode" xsi:type="const">Adyen\Payment\Model\Ui\AdyenPayByMailConfigProvider::CODE</argument>
</arguments>
</virtualType>
<!-- Commands infrastructure --> <!-- Commands infrastructure -->
<virtualType name="AdyenPaymentCcCommandPool" type="Magento\Payment\Gateway\Command\CommandPool"> <virtualType name="AdyenPaymentCcCommandPool" type="Magento\Payment\Gateway\Command\CommandPool">
...@@ -274,6 +301,18 @@ ...@@ -274,6 +301,18 @@
</arguments> </arguments>
</virtualType> </virtualType>
<virtualType name="AdyenPaymentPayByMailCommandPool" type="Magento\Payment\Gateway\Command\CommandPool">
<arguments>
<argument name="commands" xsi:type="array">
<item name="authorize" xsi:type="string">Adyen\Payment\Gateway\Command\PayByMailCommand</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>
<!-- Authorization command --> <!-- Authorization command -->
<virtualType name="AdyenPaymentCcAuthorizeCommand" type="Magento\Payment\Gateway\Command\GatewayCommand"> <virtualType name="AdyenPaymentCcAuthorizeCommand" type="Magento\Payment\Gateway\Command\GatewayCommand">
<arguments> <arguments>
...@@ -323,6 +362,7 @@ ...@@ -323,6 +362,7 @@
<argument name="handler" xsi:type="object">AdyenPaymentBoletoResponseHandlerComposite</argument> <argument name="handler" xsi:type="object">AdyenPaymentBoletoResponseHandlerComposite</argument>
</arguments> </arguments>
</virtualType> </virtualType>
<!-- Capture command --> <!-- Capture command -->
<virtualType name="AdyenPaymentCaptureCommand" type="Magento\Payment\Gateway\Command\GatewayCommand"> <virtualType name="AdyenPaymentCaptureCommand" type="Magento\Payment\Gateway\Command\GatewayCommand">
<arguments> <arguments>
...@@ -429,6 +469,7 @@ ...@@ -429,6 +469,7 @@
</virtualType> </virtualType>
<!--not used right this one below never loaded in looks like--> <!--not used right this one below never loaded in looks like-->
<!--<type name="Adyen\Payment\Gateway\Request\SepaAuthorizationDataBuilder">--> <!--<type name="Adyen\Payment\Gateway\Request\SepaAuthorizationDataBuilder">-->
<!--<arguments>--> <!--<arguments>-->
...@@ -606,6 +647,20 @@ ...@@ -606,6 +647,20 @@
</arguments> </arguments>
</virtualType> </virtualType>
<virtualType name="AdyenPaymentPayByMailValidatorPool" type="Magento\Payment\Gateway\Validator\ValidatorPool">
<arguments>
<argument name="validators" xsi:type="array">
<item name="country" xsi:type="string">AdyenPayByMailCountryValidator</item>
</argument>
</arguments>
</virtualType>
<!--FIXME: Config does not exists-->
<virtualType name="AdyenPayByMailCountryValidator" type="Magento\Payment\Gateway\Validator\CountryValidator">
<arguments>
<argument name="config" xsi:type="object">Adyen\Payment\Gateway\Config\PayByMailConfig</argument>
</arguments>
</virtualType>
<!--General Response validator--> <!--General Response validator-->
<virtualType name="GeneralResponseValidator" type="Adyen\Payment\Gateway\Validator\GeneralResponseValidator"> <virtualType name="GeneralResponseValidator" type="Adyen\Payment\Gateway\Validator\GeneralResponseValidator">
......
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