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 216266c3 authored by attilak's avatar attilak

Fix new klarna integration for checkout api

Format line item tax percentage
Remove the check in the Result.php for merchantReference, because it is
not required anymore
Add locale code to payments code
parent d0930801
...@@ -173,9 +173,12 @@ class Result extends \Magento\Framework\App\Action\Action ...@@ -173,9 +173,12 @@ class Result extends \Magento\Framework\App\Action\Action
$response = $this->validatePayloadAndReturnResponse($response); $response = $this->validatePayloadAndReturnResponse($response);
} }
$incrementId = null;
if (!empty($response['merchantReference'])) {
$incrementId = $response['merchantReference']; $incrementId = $response['merchantReference'];
}
if ($incrementId) {
$order = $this->_getOrder($incrementId); $order = $this->_getOrder($incrementId);
if ($order->getId()) { if ($order->getId()) {
$this->_eventManager->dispatch('adyen_payment_process_resulturl_before', [ $this->_eventManager->dispatch('adyen_payment_process_resulturl_before', [
...@@ -198,11 +201,7 @@ class Result extends \Magento\Framework\App\Action\Action ...@@ -198,11 +201,7 @@ class Result extends \Magento\Framework\App\Action\Action
__('Order does not exists with increment_id: %1', $incrementId) __('Order does not exists with increment_id: %1', $incrementId)
); );
} }
} else {
throw new \Magento\Framework\Exception\LocalizedException(
__('Empty merchantReference')
);
}
return $result; return $result;
} }
...@@ -348,11 +347,16 @@ class Result extends \Magento\Framework\App\Action\Action ...@@ -348,11 +347,16 @@ class Result extends \Magento\Framework\App\Action\Action
* @param $incrementId * @param $incrementId
* @return \Magento\Sales\Model\Order * @return \Magento\Sales\Model\Order
*/ */
protected function _getOrder($incrementId) protected function _getOrder($incrementId = null)
{ {
if (!$this->_order) { if (!$this->_order) {
if (!is_null($incrementId)) {
$this->_order = $this->_orderFactory->create()->loadByIncrementId($incrementId); $this->_order = $this->_orderFactory->create()->loadByIncrementId($incrementId);
} else {
$this->_order = $this->_session->getLastRealOrder();
}
} }
return $this->_order; return $this->_order;
} }
...@@ -368,11 +372,13 @@ class Result extends \Magento\Framework\App\Action\Action ...@@ -368,11 +372,13 @@ class Result extends \Magento\Framework\App\Action\Action
$client = $this->_adyenHelper->initializeAdyenClient($this->storeManager->getStore()->getId()); $client = $this->_adyenHelper->initializeAdyenClient($this->storeManager->getStore()->getId());
$service = $this->_adyenHelper->createAdyenCheckoutService($client); $service = $this->_adyenHelper->createAdyenCheckoutService($client);
$request = array( $request = [];
"details" => array(
"payload" => $response["payload"] if (!empty($this->_session->getLastRealOrder()->getPayment()->getAdditionalInformation("paymentData"))) {
) $request['paymentData'] = $this->_session->getLastRealOrder()->getPayment()->getAdditionalInformation("paymentData");
); }
$request["details"] = $response;
try { try {
$response = $service->paymentsDetails($request); $response = $service->paymentsDetails($request);
......
...@@ -228,6 +228,7 @@ class CheckoutDataBuilder implements BuilderInterface ...@@ -228,6 +228,7 @@ class CheckoutDataBuilder implements BuilderInterface
$formattedPriceExcludingTax = $this->adyenHelper->formatAmount($priceExcludingTax, $currency); $formattedPriceExcludingTax = $this->adyenHelper->formatAmount($priceExcludingTax, $currency);
$formattedTaxAmount = $this->adyenHelper->formatAmount($item->getTaxAmount(), $currency); $formattedTaxAmount = $this->adyenHelper->formatAmount($item->getTaxAmount(), $currency);
$formattedTaxPercentage = $item->getTaxPercent() * 100;
$formFields['lineItems'][] = [ $formFields['lineItems'][] = [
'id' => $item->getId(), 'id' => $item->getId(),
...@@ -237,7 +238,7 @@ class CheckoutDataBuilder implements BuilderInterface ...@@ -237,7 +238,7 @@ class CheckoutDataBuilder implements BuilderInterface
'description' => $item->getName(), 'description' => $item->getName(),
'quantity' => $item->getQty(), 'quantity' => $item->getQty(),
'taxCategory' => $item->getProduct()->getAttributeText('tax_class_id'), 'taxCategory' => $item->getProduct()->getAttributeText('tax_class_id'),
'taxPercentage' => $item->getTaxPercent() 'taxPercentage' => $formattedTaxPercentage
]; ];
} }
...@@ -272,13 +273,19 @@ class CheckoutDataBuilder implements BuilderInterface ...@@ -272,13 +273,19 @@ class CheckoutDataBuilder implements BuilderInterface
$taxClassId = $this->taxConfig->getShippingTaxClass($this->storeManager->getStore()->getId()); $taxClassId = $this->taxConfig->getShippingTaxClass($this->storeManager->getStore()->getId());
$formattedTaxPercentage = 0;
if ($priceExcludingTax !== 0) {
$formattedTaxPercentage = $this->quote->getShippingAddress()->getShippingTaxAmount() / $priceExcludingTax * 100 * 100;
}
$formFields['lineItems'][] = [ $formFields['lineItems'][] = [
'itemId' => 'shippingCost', 'itemId' => 'shippingCost',
'amountExcludingTax' => $formattedPriceExcludingTax, 'amountExcludingTax' => $formattedPriceExcludingTax,
'taxAmount' => $formattedTaxAmount, 'taxAmount' => $formattedTaxAmount,
'description' => $order->getShippingDescription(), 'description' => $order->getShippingDescription(),
'quantity' => 1, 'quantity' => 1,
'taxPercentage' => $this->quote->getShippingAddress()->getShippingTaxAmount() 'taxPercentage' => $formattedTaxPercentage
]; ];
} }
......
...@@ -111,6 +111,11 @@ class CustomerDataBuilder implements BuilderInterface ...@@ -111,6 +111,11 @@ class CustomerDataBuilder implements BuilderInterface
if ($countryId = $billingAddress->getCountryId()) { if ($countryId = $billingAddress->getCountryId()) {
$result['countryCode'] = $countryId; $result['countryCode'] = $countryId;
} }
if ($shopperLocale = $this->adyenHelper->getCurrentLocaleCode($order->getStoreId())) {
$result['shopperLocale'] = $shopperLocale;
}
} }
return $result; return $result;
......
...@@ -118,6 +118,16 @@ class Data extends AbstractHelper ...@@ -118,6 +118,16 @@ class Data extends AbstractHelper
*/ */
private $agreementResourceModel; private $agreementResourceModel;
/**
* @var \Magento\Framework\Locale\ResolverInterface
*/
private $localeResolver;
/**
* @var \Magento\Framework\App\Config\ScopeConfigInterface
*/
private $config;
/** /**
* Data constructor. * Data constructor.
* @param \Magento\Framework\App\Helper\Context $context * @param \Magento\Framework\App\Helper\Context $context
...@@ -155,7 +165,9 @@ class Data extends AbstractHelper ...@@ -155,7 +165,9 @@ class Data extends AbstractHelper
\Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Framework\App\CacheInterface $cache, \Magento\Framework\App\CacheInterface $cache,
\Adyen\Payment\Model\Billing\AgreementFactory $billingAgreementFactory, \Adyen\Payment\Model\Billing\AgreementFactory $billingAgreementFactory,
\Adyen\Payment\Model\ResourceModel\Billing\Agreement $agreementResourceModel \Adyen\Payment\Model\ResourceModel\Billing\Agreement $agreementResourceModel,
\Magento\Framework\Locale\ResolverInterface $localeResolver,
\Magento\Framework\App\Config\ScopeConfigInterface $config
) { ) {
parent::__construct($context); parent::__construct($context);
$this->_encryptor = $encryptor; $this->_encryptor = $encryptor;
...@@ -174,6 +186,8 @@ class Data extends AbstractHelper ...@@ -174,6 +186,8 @@ class Data extends AbstractHelper
$this->cache = $cache; $this->cache = $cache;
$this->billingAgreementFactory = $billingAgreementFactory; $this->billingAgreementFactory = $billingAgreementFactory;
$this->agreementResourceModel = $agreementResourceModel; $this->agreementResourceModel = $agreementResourceModel;
$this->localeResolver = $localeResolver;
$this->config = $config;
} }
/** /**
...@@ -1701,4 +1715,30 @@ class Data extends AbstractHelper ...@@ -1701,4 +1715,30 @@ class Data extends AbstractHelper
$timeStamp = new \DateTime($date); $timeStamp = new \DateTime($date);
return $timeStamp->format($format); return $timeStamp->format($format);
} }
/**
* @param int $storeId
* @return mixed|string
*/
public function getCurrentLocaleCode($storeId)
{
$localeCode = $this->getAdyenAbstractConfigData('shopper_locale', $storeId);
if ($localeCode != "") {
return $localeCode;
}
$locale = $this->localeResolver->getLocale();
if ($locale) {
return $locale;
}
// should have the value if not fall back to default
$localeCode = $this->config->getValue(
\Magento\Directory\Helper\Data::XML_PATH_DEFAULT_LOCALE,
\Magento\Store\Model\ScopeInterface::SCOPE_STORES,
$store->getCode()
);
return $localeCode;
}
} }
\ No newline at end of file
...@@ -198,7 +198,7 @@ class PaymentMethods extends AbstractHelper ...@@ -198,7 +198,7 @@ class PaymentMethods extends AbstractHelper
), ),
], ],
"shopperReference" => $this->getCurrentShopperReference(), "shopperReference" => $this->getCurrentShopperReference(),
"shopperLocale" => $this->getCurrentLocaleCode($store) "shopperLocale" => $this->adyenHelper->getCurrentLocaleCode($store->getId())
]; ];
$billingAddress = $this->getQuote()->getBillingAddress(); $billingAddress = $this->getQuote()->getBillingAddress();
...@@ -325,32 +325,6 @@ class PaymentMethods extends AbstractHelper ...@@ -325,32 +325,6 @@ class PaymentMethods extends AbstractHelper
return ""; return "";
} }
/**
* @param $store
* @return mixed|string
*/
protected function getCurrentLocaleCode($store)
{
$localeCode = $this->adyenHelper->getAdyenAbstractConfigData('shopper_locale', $store->getId());
if ($localeCode != "") {
return $localeCode;
}
$locale = $this->localeResolver->getLocale();
if ($locale) {
return $locale;
}
// should have the value if not fall back to default
$localeCode = $this->config->getValue(
\Magento\Directory\Helper\Data::XML_PATH_DEFAULT_LOCALE,
\Magento\Store\Model\ScopeInterface::SCOPE_STORES,
$store->getCode()
);
return $localeCode;
}
/** /**
* @var array * @var array
*/ */
......
...@@ -412,6 +412,11 @@ define( ...@@ -412,6 +412,11 @@ define(
*/ */
result.renderKlarnaComponent = function () { result.renderKlarnaComponent = function () {
/* The new Klarna integration doesn't return details and the component does not handle it */
if (!value.details) {
return;
}
var klarnaNode = document.getElementById('klarnaContainer'); var klarnaNode = document.getElementById('klarnaContainer');
var klarna = self.checkoutComponent.create('klarna', { var klarna = self.checkoutComponent.create('klarna', {
......
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