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

#67 Adyen Pos is now using the Facade implementation

parent 43ca397e
...@@ -39,6 +39,17 @@ class Pos extends \Magento\Payment\Block\Form ...@@ -39,6 +39,17 @@ class Pos extends \Magento\Payment\Block\Form
*/ */
protected $_order; protected $_order;
/**
* @var \Adyen\Payment\Helper\Data
*/
protected $_adyenHelper;
/**
* @var \Adyen\Payment\Logger\AdyenLogger
*/
protected $_adyenLogger;
/** /**
* Pos constructor. * Pos constructor.
* *
...@@ -46,17 +57,29 @@ class Pos extends \Magento\Payment\Block\Form ...@@ -46,17 +57,29 @@ class Pos extends \Magento\Payment\Block\Form
* @param array $data * @param array $data
* @param \Magento\Sales\Model\OrderFactory $orderFactory * @param \Magento\Sales\Model\OrderFactory $orderFactory
* @param \Magento\Checkout\Model\Session $checkoutSession * @param \Magento\Checkout\Model\Session $checkoutSession
* @param \Adyen\Payment\Helper\Data $adyenHelper
* @param \Adyen\Payment\Logger\AdyenLogger $adyenLogger
*/ */
public function __construct( public function __construct(
\Magento\Framework\View\Element\Template\Context $context, \Magento\Framework\View\Element\Template\Context $context,
array $data = [], array $data = [],
\Magento\Sales\Model\OrderFactory $orderFactory, \Magento\Sales\Model\OrderFactory $orderFactory,
\Magento\Checkout\Model\Session $checkoutSession \Magento\Checkout\Model\Session $checkoutSession,
\Adyen\Payment\Helper\Data $adyenHelper,
\Adyen\Payment\Logger\AdyenLogger $adyenLogger
) { ) {
$this->_orderFactory = $orderFactory; $this->_orderFactory = $orderFactory;
$this->_checkoutSession = $checkoutSession; $this->_checkoutSession = $checkoutSession;
parent::__construct($context, $data); parent::__construct($context, $data);
$this->_getOrder();
$this->_request = $context->getRequest();
$this->_adyenHelper = $adyenHelper;
$this->_adyenLogger = $adyenLogger;
if (!$this->_order) {
$incrementId = $this->_getCheckout()->getLastRealOrderId();
$this->_order = $this->_orderFactory->create()->loadByIncrementId($incrementId);
}
} }
/** /**
...@@ -72,33 +95,162 @@ class Pos extends \Magento\Payment\Block\Form ...@@ -72,33 +95,162 @@ class Pos extends \Magento\Payment\Block\Form
*/ */
public function getLaunchLink() public function getLaunchLink()
{ {
$result = ""; $launchlink = "";
try { try {
$order = $this->_order; if($this->_order->getPayment())
if($order->getPayment())
{ {
$result = $this->_order->getPayment()->getMethodInstance()->getLaunchLink();
$realOrderId = $this->_order->getRealOrderId();
$orderCurrencyCode = $this->_order->getOrderCurrencyCode();
$amount = $this->_adyenHelper->formatAmount(
$this->_order->getGrandTotal(), $orderCurrencyCode
);
$shopperEmail = $this->_order->getCustomerEmail();
$customerId = $this->_order->getCustomerId();
$callbackUrl = $this->_urlBuilder->getUrl('adyen/process/resultpos',
['_secure' => $this->_getRequest()->isSecure()]);
$addReceiptOrderLines = $this->_adyenHelper->getAdyenPosConfigData("add_receipt_order_lines");
$recurringContract = $this->_adyenHelper->getAdyenPosConfigData('recurring_type');
$currencyCode = $orderCurrencyCode;
$paymentAmount = $amount;
$merchantReference = $realOrderId;
$shopperReference = (!empty($customerId)) ? $customerId : self::GUEST_ID . $realOrderId;
$shopperEmail = $shopperEmail;
$recurringParams = "";
if ($this->_order->getPayment()->getAdditionalInformation("store_cc") != "") {
$recurringParams = "&recurringContract=" . urlencode($recurringContract) . "&shopperReference=" .
urlencode($shopperReference) . "&shopperEmail=" . urlencode($shopperEmail);
}
$receiptOrderLines = "";
if ($addReceiptOrderLines) {
$orderLines = base64_encode($this->_getReceiptOrderLines($this->_order));
$receiptOrderLines = "&receiptOrderLines=" . urlencode($orderLines);
}
// extra parameters so that you alway's return these paramters from the application
$extraParamaters = urlencode("/?originalCustomCurrency=".$currencyCode."&originalCustomAmount=".
$paymentAmount. "&originalCustomMerchantReference=".
$merchantReference . "&originalCustomSessionId=".session_id());
$launchlink = "adyen://payment?sessionId=".session_id()."&amount=".$paymentAmount.
"&currency=".$currencyCode."&merchantReference=".$merchantReference. $recurringParams .
$receiptOrderLines . "&callback=".$callbackUrl . $extraParamaters;
// cash not working see ticket
// https://youtrack.is.adyen.com/issue/IOS-130#comment=102-20285
// . "&transactionType=CASH";
$this->_adyenLogger->addAdyenDebug(print_r($launchlink, true));
} }
} catch(Exception $e) { } catch(Exception $e) {
// do nothing for now // do nothing for now
throw($e); throw($e);
} }
return $result; return $launchlink;
} }
/** /**
* Get order object * @param \Magento\Sales\Model\Order $order
* * @return string
* @return \Magento\Sales\Model\Order
*/ */
protected function _getOrder() protected function _getReceiptOrderLines(\Magento\Sales\Model\Order $order)
{ {
if (!$this->_order) { $myReceiptOrderLines = "";
$incrementId = $this->_getCheckout()->getLastRealOrderId();
$this->_order = $this->_orderFactory->create()->loadByIncrementId($incrementId); $currency = $order->getOrderCurrencyCode();
$formattedAmountValue = $this->_currencyFactory->create()->format(
$order->getGrandTotal(),
['display'=>\Magento\Framework\Currency::NO_SYMBOL],
false
);
$taxAmount = $order->getTaxAmount();
$formattedTaxAmount = $this->_currencyFactory->create()->format(
$taxAmount,
['display'=>\Magento\Framework\Currency::NO_SYMBOL],
false
);
$myReceiptOrderLines .= "---||C\n".
"====== YOUR ORDER DETAILS ======||CB\n".
"---||C\n".
" No. Description |Piece Subtotal|\n";
foreach ($order->getItemsCollection() as $item) {
//skip dummies
if ($item->isDummy()) {
continue;
};
$singlePriceFormat = $this->_currencyFactory->create()->format(
$item->getPriceInclTax(),
['display'=>\Magento\Framework\Currency::NO_SYMBOL],
false
);
$itemAmount = $item->getPriceInclTax() * (int) $item->getQtyOrdered();
$itemAmountFormat = $this->_currencyFactory->create()->format(
$itemAmount,
['display'=>\Magento\Framework\Currency::NO_SYMBOL],
false
);
$myReceiptOrderLines .= " " . (int) $item->getQtyOrdered() . " " . trim(substr($item->getName(), 0, 25)) .
"| " . $currency . " " . $singlePriceFormat . " " . $currency . " " . $itemAmountFormat . "|\n";
}
//discount cost
if ($order->getDiscountAmount() > 0 || $order->getDiscountAmount() < 0) {
$discountAmountFormat = $this->_currencyFactory->create()->format(
$order->getDiscountAmount(),
['display'=>\Magento\Framework\Currency::NO_SYMBOL],
false
);
$myReceiptOrderLines .= " " . 1 . " " . $this->__('Total Discount') . "| " .
$currency . " " . $discountAmountFormat ."|\n";
}
//shipping cost
if ($order->getShippingAmount() > 0 || $order->getShippingTaxAmount() > 0) {
$shippingAmountFormat = $this->_currencyFactory->create()->format(
$order->getShippingAmount(),
['display'=>\Magento\Framework\Currency::NO_SYMBOL],
false
);
$myReceiptOrderLines .= " " . 1 . " " . $order->getShippingDescription() . "| " .
$currency . " " . $shippingAmountFormat ."|\n";
} }
return $this->_order;
if ($order->getPaymentFeeAmount() > 0) {
$paymentFeeAmount = $this->_currencyFactory->create()->format(
$order->getPaymentFeeAmount(),
['display'=>\Magento\Framework\Currency::NO_SYMBOL],
false
);
$myReceiptOrderLines .= " " . 1 . " " . $this->__('Payment Fee') . "| " .
$currency . " " . $paymentFeeAmount ."|\n";
}
$myReceiptOrderLines .= "|--------|\n".
"|Order Total: ".$currency." ".$formattedAmountValue."|B\n".
"|Tax: ".$currency." ".$formattedTaxAmount."|B\n".
"||C\n";
/*
* New header for card details section!
* Default location is After Header so simply add to Order Details as separator
*/
$myReceiptOrderLines .= "---||C\n".
"====== YOUR PAYMENT DETAILS ======||CB\n".
"---||C\n";
return $myReceiptOrderLines;
} }
/** /**
...@@ -110,4 +262,14 @@ class Pos extends \Magento\Payment\Block\Form ...@@ -110,4 +262,14 @@ class Pos extends \Magento\Payment\Block\Form
{ {
return $this->_checkoutSession; return $this->_checkoutSession;
} }
/**
* 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\Gateway\Command;
use Magento\Payment\Gateway\Command;
use Magento\Payment\Gateway\CommandInterface;
class PosCommand 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
This diff is collapsed.
This diff is collapsed.
<?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\Ui;
use Magento\Checkout\Model\ConfigProviderInterface;
use Magento\Payment\Helper\Data as PaymentHelper;
use Magento\Directory\Helper\Data;
class AdyenPosConfigProvider implements ConfigProviderInterface
{
const CODE = 'adyen_pos';
/**
* @var PaymentHelper
*/
protected $_paymentHelper;
/**
* @var \Adyen\Payment\Helper\Data
*/
protected $_adyenHelper;
/**
* Request object
*
* @var \Magento\Framework\App\RequestInterface
*/
protected $_request;
/**
* @var \Magento\Framework\UrlInterface
*/
protected $_urlBuilder;
/**
* AdyenHppConfigProvider constructor.
*
* @param PaymentHelper $paymentHelper
* @param \Adyen\Payment\Helper\Data $adyenHelper
*/
public function __construct(
PaymentHelper $paymentHelper,
\Adyen\Payment\Helper\Data $adyenHelper,
\Magento\Framework\App\RequestInterface $request,
\Magento\Framework\UrlInterface $urlBuilder
) {
$this->_paymentHelper = $paymentHelper;
$this->_adyenHelper = $adyenHelper;
$this->_request = $request;
$this->_urlBuilder = $urlBuilder;
}
/**
* Set configuration for AdyenHPP payemnt method
*
* @return array
*/
public function getConfig()
{
// set to active
$config = [
'payment' => [
self::CODE => [
'isActive' => true,
'redirectUrl' => $this->_urlBuilder->getUrl(
'adyen/process/redirect', ['_secure' => $this->_getRequest()->isSecure()])
]
]
];
return $config;
}
/**
* Retrieve request object
*
* @return \Magento\Framework\App\RequestInterface
*/
protected function _getRequest()
{
return $this->_request;
}
}
\ No newline at end of file
...@@ -132,7 +132,7 @@ ...@@ -132,7 +132,7 @@
</adyen_sepa> </adyen_sepa>
<adyen_pos> <adyen_pos>
<active>0</active> <active>0</active>
<model>Adyen\Payment\Model\Method\Pos</model> <model>AdyenPaymentPosFacade</model>
<order_status>pending</order_status> <order_status>pending</order_status>
<title>Adyen POS</title> <title>Adyen POS</title>
<allowspecific>0</allowspecific> <allowspecific>0</allowspecific>
...@@ -140,6 +140,16 @@ ...@@ -140,6 +140,16 @@
<place_order_url>adyen/process/redirect</place_order_url> <place_order_url>adyen/process/redirect</place_order_url>
<order_place_redirect_url>adyen/process/redirect</order_place_redirect_url> <order_place_redirect_url>adyen/process/redirect</order_place_redirect_url>
<payment_action>order</payment_action> <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> <group>adyen</group>
</adyen_pos> </adyen_pos>
<adyen_pay_by_mail> <adyen_pay_by_mail>
......
...@@ -76,6 +76,16 @@ ...@@ -76,6 +76,16 @@
<argument name="commandPool" xsi:type="object">AdyenPaymentBoletoCommandPool</argument> <argument name="commandPool" xsi:type="object">AdyenPaymentBoletoCommandPool</argument>
</arguments> </arguments>
</virtualType> </virtualType>
<virtualType name="AdyenPaymentPosFacade" type="Magento\Payment\Model\Method\Adapter">
<arguments>
<argument name="code" xsi:type="const">Adyen\Payment\Model\Ui\AdyenPosConfigProvider::CODE</argument>
<argument name="formBlockType" xsi:type="string">Adyen\Payment\Block\Form\Pos</argument>
<argument name="infoBlockType" xsi:type="string">Adyen\Payment\Block\Info\Pos</argument>
<argument name="valueHandlerPool" xsi:type="object">AdyenPaymentPosValueHandlerPool</argument>
<argument name="validatorPool" xsi:type="object">AdyenPaymentPosValidatorPool</argument>
<argument name="commandPool" xsi:type="object">AdyenPaymentPosCommandPool</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">
...@@ -143,6 +153,19 @@ ...@@ -143,6 +153,19 @@
</arguments> </arguments>
</virtualType> </virtualType>
<virtualType name="AdyenPaymentPosValueHandlerPool" type="Magento\Payment\Gateway\Config\ValueHandlerPool">
<arguments>
<argument name="handlers" xsi:type="array">
<item name="default" xsi:type="string">AdyenPaymentPosConfigValueHandler</item>
</argument>
</arguments>
</virtualType>
<virtualType name="AdyenPaymentPosConfigValueHandler" type="Magento\Payment\Gateway\Config\ConfigValueHandler">
<arguments>
<argument name="configInterface" xsi:type="object">AdyenPaymentPosConfig</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>
...@@ -169,6 +192,11 @@ ...@@ -169,6 +192,11 @@
<argument name="methodCode" xsi:type="const">Adyen\Payment\Model\Ui\AdyenBoletoConfigProvider::CODE</argument> <argument name="methodCode" xsi:type="const">Adyen\Payment\Model\Ui\AdyenBoletoConfigProvider::CODE</argument>
</arguments> </arguments>
</virtualType> </virtualType>
<virtualType name="AdyenPaymentPosConfig" type="Magento\Payment\Gateway\Config\Config">
<arguments>
<argument name="methodCode" xsi:type="const">Adyen\Payment\Model\Ui\AdyenPosConfigProvider::CODE</argument>
</arguments>
</virtualType>
<!-- Commands infrastructure --> <!-- Commands infrastructure -->
...@@ -234,6 +262,18 @@ ...@@ -234,6 +262,18 @@
</arguments> </arguments>
</virtualType> </virtualType>
<virtualType name="AdyenPaymentPosCommandPool" type="Magento\Payment\Gateway\Command\CommandPool">
<arguments>
<argument name="commands" xsi:type="array">
<item name="initialize" xsi:type="string">Adyen\Payment\Gateway\Command\PosCommand</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>
...@@ -552,6 +592,20 @@ ...@@ -552,6 +592,20 @@
</arguments> </arguments>
</virtualType> </virtualType>
<virtualType name="AdyenPaymentPosValidatorPool" type="Magento\Payment\Gateway\Validator\ValidatorPool">
<arguments>
<argument name="validators" xsi:type="array">
<item name="country" xsi:type="string">AdyenPosCountryValidator</item>
</argument>
</arguments>
</virtualType>
<!--FIXME: Config does not exists-->
<virtualType name="AdyenPosCountryValidator" type="Magento\Payment\Gateway\Validator\CountryValidator">
<arguments>
<argument name="config" xsi:type="object">Adyen\Payment\Gateway\Config\PosConfig</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">
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
<item name="adyen_hpp_config_provider" xsi:type="object">Adyen\Payment\Model\Ui\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_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> <item name="adyen_boleto_config_provider" xsi:type="object">Adyen\Payment\Model\Ui\AdyenBoletoConfigProvider</item>
<item name="adyen_pos_config_provider" xsi:type="object">Adyen\Payment\Model\Ui\AdyenPosConfigProvider</item>
</argument> </argument>
</arguments> </arguments>
</type> </type>
......
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