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
*/
protected $_template = 'Adyen_Payment::form/oneclick.phtml';
/**
* @var \Adyen\Payment\Model\AdyenOneclickConfigProvider
*/
protected $_oneclickConfig;
/**
* @var \Magento\Backend\Model\Session\Quote
*/
......@@ -54,12 +49,10 @@ class Oneclick extends \Adyen\Payment\Block\Form\Cc
\Magento\Payment\Model\Config $paymentConfig,
\Adyen\Payment\Helper\Data $adyenHelper,
\Magento\Checkout\Model\Session $checkoutSession,
\Adyen\Payment\Model\AdyenOneclickConfigProvider $oneclickConfigProvider,
\Magento\Backend\Model\Session\Quote $sessionQuote,
array $data = []
) {
parent::__construct($context, $paymentConfig, $adyenHelper, $checkoutSession, $data);
$this->_oneclickConfig = $oneclickConfigProvider;
$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 @@
*
* 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;
use Magento\Directory\Helper\Data;
class AdyenGenericConfigProvider implements ConfigProviderInterface
class AdyenPayByMailConfigProvider implements ConfigProviderInterface
{
/**
* @var \Magento\Payment\Model\Method\AbstractMethod[]
*/
protected $_methods = [];
const CODE = 'adyen_pay_by_mail';
/**
* @var PaymentHelper
......@@ -44,67 +43,63 @@ class AdyenGenericConfigProvider implements ConfigProviderInterface
protected $_adyenHelper;
/**
* @var string[]
* Request object
*
* @var \Magento\Framework\App\RequestInterface
*/
protected $_request;
/**
* @var \Magento\Framework\UrlInterface
*/
protected $_methodCodes = [
\Adyen\Payment\Model\Method\Pos::METHOD_CODE,
];
protected $_urlBuilder;
/**
* AdyenGenericConfigProvider constructor.
* AdyenHppConfigProvider constructor.
*
* @param PaymentHelper $paymentHelper
* @param \Adyen\Payment\Helper\Data $adyenHelper
*/
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;
}
/**
* Define foreach payment methods the RedirectUrl
* Set configuration for AdyenHPP payemnt method
*
* @return array
*/
public function getConfig()
{
// set to active
$config = [
'payment' => []
];
foreach ($this->_methodCodes as $code) {
if ($this->_methods[$code]->isAvailable()) {
$config['payment'][$code] = [
'redirectUrl' => $this->getMethodRedirectUrl($code)
'payment' => [
self::CODE => [
'isActive' => true,
'redirectUrl' => $this->_urlBuilder->getUrl(
'adyen/process/redirect', ['_secure' => $this->_getRequest()->isSecure()])
]
]
];
}
}
// show logos turned on by default
if ($this->_adyenHelper->showLogos()) {
$config['payment']['adyen']['showLogo'] = true;
} else {
$config['payment']['adyen']['showLogo'] = false;
}
return $config;
}
/**
* Return redirect URL for method
* Retrieve request object
*
* @param string $code
* @return mixed
* @return \Magento\Framework\App\RequestInterface
*/
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 @@
<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_use_internal>0</can_use_internal>
<can_refund_partial_per_invoice>1</can_refund_partial_per_invoice>
<can_refund>1</can_refund>
<can_void>1</can_void>
......@@ -145,7 +145,7 @@
<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_use_internal>0</can_use_internal>
<can_refund_partial_per_invoice>1</can_refund_partial_per_invoice>
<can_refund>1</can_refund>
<can_void>1</can_void>
......@@ -154,13 +154,23 @@
</adyen_pos>
<adyen_pay_by_mail>
<active>0</active>
<model>Adyen\Payment\Model\Method\PayByMail</model>
<model>AdyenPaymentPayByMailFacade</model>
<order_status>pending</order_status>
<title>Adyen PayByMail</title>
<allowspecific>0</allowspecific>
<sort_order>6</sort_order>
<session_validity>3</session_validity>
<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>
</adyen_pay_by_mail>
<adyen_boleto>
......
......@@ -86,6 +86,16 @@
<argument name="commandPool" xsi:type="object">AdyenPaymentPosCommandPool</argument>
</arguments>
</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 -->
<virtualType name="AdyenPaymentCcValueHandlerPool" type="Magento\Payment\Gateway\Config\ValueHandlerPool">
......@@ -166,6 +176,19 @@
</arguments>
</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 -->
<virtualType name="AdyenPaymentCcConfig" type="Magento\Payment\Gateway\Config\Config">
<arguments>
......@@ -197,7 +220,11 @@
<argument name="methodCode" xsi:type="const">Adyen\Payment\Model\Ui\AdyenPosConfigProvider::CODE</argument>
</arguments>
</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 -->
<virtualType name="AdyenPaymentCcCommandPool" type="Magento\Payment\Gateway\Command\CommandPool">
......@@ -274,6 +301,18 @@
</arguments>
</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 -->
<virtualType name="AdyenPaymentCcAuthorizeCommand" type="Magento\Payment\Gateway\Command\GatewayCommand">
<arguments>
......@@ -323,6 +362,7 @@
<argument name="handler" xsi:type="object">AdyenPaymentBoletoResponseHandlerComposite</argument>
</arguments>
</virtualType>
<!-- Capture command -->
<virtualType name="AdyenPaymentCaptureCommand" type="Magento\Payment\Gateway\Command\GatewayCommand">
<arguments>
......@@ -429,6 +469,7 @@
</virtualType>
<!--not used right this one below never loaded in looks like-->
<!--<type name="Adyen\Payment\Gateway\Request\SepaAuthorizationDataBuilder">-->
<!--<arguments>-->
......@@ -606,6 +647,20 @@
</arguments>
</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-->
<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