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 506825ca authored by Rik ter Beek's avatar Rik ter Beek Committed by GitHub

Merge pull request #144 from Adyen/develop-rik

Develop rik
parents 4737c28a cea55f4b
...@@ -58,6 +58,13 @@ class Redirect extends \Magento\Payment\Block\Form ...@@ -58,6 +58,13 @@ class Redirect extends \Magento\Payment\Block\Form
*/ */
protected $_adyenLogger; protected $_adyenLogger;
/**
* @var \Magento\Tax\Model\Config
*/
protected $_taxConfig;
protected $_taxCalculation;
/** /**
* Redirect constructor. * Redirect constructor.
* *
...@@ -74,7 +81,9 @@ class Redirect extends \Magento\Payment\Block\Form ...@@ -74,7 +81,9 @@ class Redirect extends \Magento\Payment\Block\Form
\Magento\Checkout\Model\Session $checkoutSession, \Magento\Checkout\Model\Session $checkoutSession,
\Adyen\Payment\Helper\Data $adyenHelper, \Adyen\Payment\Helper\Data $adyenHelper,
\Magento\Framework\Locale\ResolverInterface $resolver, \Magento\Framework\Locale\ResolverInterface $resolver,
\Adyen\Payment\Logger\AdyenLogger $adyenLogger \Adyen\Payment\Logger\AdyenLogger $adyenLogger,
\Magento\Tax\Model\Config $taxConfig,
\Magento\Tax\Model\Calculation $taxCalculation
) { ) {
$this->_orderFactory = $orderFactory; $this->_orderFactory = $orderFactory;
$this->_checkoutSession = $checkoutSession; $this->_checkoutSession = $checkoutSession;
...@@ -88,6 +97,8 @@ class Redirect extends \Magento\Payment\Block\Form ...@@ -88,6 +97,8 @@ class Redirect extends \Magento\Payment\Block\Form
$incrementId = $this->_getCheckout()->getLastRealOrderId(); $incrementId = $this->_getCheckout()->getLastRealOrderId();
$this->_order = $this->_orderFactory->create()->loadByIncrementId($incrementId); $this->_order = $this->_orderFactory->create()->loadByIncrementId($incrementId);
} }
$this->_taxConfig = $taxConfig;
$this->_taxCalculation = $taxCalculation;
} }
...@@ -286,7 +297,11 @@ class Redirect extends \Magento\Payment\Block\Form ...@@ -286,7 +297,11 @@ class Redirect extends \Magento\Payment\Block\Form
$formFields['deliveryAddressType'] = "1"; $formFields['deliveryAddressType'] = "1";
// make setting to make this optional // make setting to make this optional
$adyFields['shopperType'] = "1"; $formFields['shopperType'] = "1";
}
if ($this->_order->getPayment()->getAdditionalInformation("df_value") != "") {
$formFields['dfValue'] = $this->_order->getPayment()->getAdditionalInformation("df_value");
} }
// Sort the array by key using SORT_STRING order // Sort the array by key using SORT_STRING order
...@@ -306,6 +321,10 @@ class Redirect extends \Magento\Payment\Block\Form ...@@ -306,6 +321,10 @@ class Redirect extends \Magento\Payment\Block\Form
} catch(Exception $e) { } catch(Exception $e) {
// do nothing for now // do nothing for now
} }
// echo "GENDER" . $this->_order->getCustomerGender();
//
// print_r($formFields);die();
return $formFields; return $formFields;
} }
...@@ -430,15 +449,11 @@ class Redirect extends \Magento\Payment\Block\Form ...@@ -430,15 +449,11 @@ class Redirect extends \Magento\Payment\Block\Form
foreach ($this->_order->getAllVisibleItems() as $item) { foreach ($this->_order->getAllVisibleItems() as $item) {
++$count; ++$count;
$linename = "line".$count;
$formFields['openinvoicedata.' . $linename . '.currencyCode'] = $currency;
$formFields['openinvoicedata.' . $linename . '.description'] =
str_replace("\n", '', trim($item->getName()));
$formFields['openinvoicedata.' . $linename . '.itemAmount'] =
$this->_adyenHelper->formatAmount($item->getPrice(), $currency);
$formFields['openinvoicedata.' . $linename . '.itemVatAmount'] = $description = str_replace("\n", '', trim($item->getName()));
$itemAmount = $this->_adyenHelper->formatAmount($item->getPrice(), $currency);
$itemVatAmount =
($item->getTaxAmount() > 0 && $item->getPriceInclTax() > 0) ? ($item->getTaxAmount() > 0 && $item->getPriceInclTax() > 0) ?
$this->_adyenHelper->formatAmount( $this->_adyenHelper->formatAmount(
$item->getPriceInclTax(), $item->getPriceInclTax(),
...@@ -448,22 +463,56 @@ class Redirect extends \Magento\Payment\Block\Form ...@@ -448,22 +463,56 @@ class Redirect extends \Magento\Payment\Block\Form
$currency $currency
) : $this->_adyenHelper->formatAmount($item->getTaxAmount(), $currency); ) : $this->_adyenHelper->formatAmount($item->getTaxAmount(), $currency);
// Calculate vat percentage // Calculate vat percentage
$percentageMinorUnits = $this->_adyenHelper->getMinorUnitTaxPercent($item->getTaxPercent()); $itemVatPercentage = $this->_adyenHelper->getMinorUnitTaxPercent($item->getTaxPercent());
$formFields['openinvoicedata.' . $linename . '.itemVatPercentage'] = $percentageMinorUnits;
$formFields['openinvoicedata.' . $linename . '.numberOfItems'] = (int) $item->getQtyOrdered();
if ($this->_adyenHelper->isVatCategoryHigh($this->_order->getPayment()->getAdditionalInformation( $numberOfItems = (int) $item->getQtyOrdered();
\Adyen\Payment\Observer\AdyenHppDataAssignObserver::BRAND_CODE))) {
$formFields['openinvoicedata.' . $linename . '.vatCategory'] = "High"; $formFields = $this->setOpenInvoiceLineData($formFields, $count, $currency, $description, $itemAmount,
} else { $itemVatAmount, $itemVatPercentage, $numberOfItems);
$formFields['openinvoicedata.' . $linename . '.vatCategory'] = "None";
} }
if ($item->getSku() != "") {
$formFields['openinvoicedata.' . $linename . '.itemId'] = $item->getSku(); // Discount cost
if ($this->_order->getDiscountAmount() > 0 || $this->_order->getDiscountAmount() < 0) {
++$count;
$description = __('Total Discount');
$itemAmount = $this->_adyenHelper->formatAmount($this->_order->getDiscountAmount(), $currency);
$itemVatAmount = "0";
$itemVatPercentage = "0";
$numberOfItems = 1;
$formFields = $this->setOpenInvoiceLineData($formFields, $count, $currency, $description, $itemAmount,
$itemVatAmount, $itemVatPercentage, $numberOfItems);
} }
// Shipping cost
if ($this->_order->getShippingAmount() > 0 || $this->_order->getShippingTaxAmount() > 0) {
++$count;
$description = $this->_order->getShippingDescription();
$itemAmount = $this->_adyenHelper->formatAmount($this->_order->getShippingAmount(), $currency);
$itemVatAmount = $this->_adyenHelper->formatAmount($this->_order->getShippingTaxAmount(), $currency);
// Create RateRequest to calculate the Tax class rate for the shipping method
$rateRequest = $this->_taxCalculation->getRateRequest(
$this->_order->getShippingAddress(),
$this->_order->getBillingAddress(),
null,
$this->_order->getStoreId(), $this->_order->getCustomerId()
);
$taxClassId = $this->_taxConfig->getShippingTaxClass($this->_order->getStoreId());
$rateRequest->setProductClassId($taxClassId);
$rate = $this->_taxCalculation->getRate($rateRequest);
$itemVatPercentage = $this->_adyenHelper->getMinorUnitTaxPercent($rate);
$numberOfItems = 1;
$formFields = $this->setOpenInvoiceLineData($formFields, $count, $currency, $description, $itemAmount,
$itemVatAmount, $itemVatPercentage, $numberOfItems);
} }
$formFields['openinvoicedata.refundDescription'] = "Refund / Correction for ".$formFields['merchantReference']; $formFields['openinvoicedata.refundDescription'] = "Refund / Correction for ".$formFields['merchantReference'];
...@@ -472,6 +521,38 @@ class Redirect extends \Magento\Payment\Block\Form ...@@ -472,6 +521,38 @@ class Redirect extends \Magento\Payment\Block\Form
return $formFields; return $formFields;
} }
/**
* Set the openinvoice line
*
* @param $count
* @param $currencyCode
* @param $description
* @param $itemAmount
* @param $itemVatAmount
* @param $itemVatPercentage
* @param $numberOfItems
*/
protected function setOpenInvoiceLineData($formFields, $count, $currencyCode, $description, $itemAmount,
$itemVatAmount, $itemVatPercentage, $numberOfItems
) {
$linename = "line".$count;
$formFields['openinvoicedata.' . $linename . '.currencyCode'] = $currencyCode;
$formFields['openinvoicedata.' . $linename . '.description'] = $description;
$formFields['openinvoicedata.' . $linename . '.itemAmount'] = $itemAmount;
$formFields['openinvoicedata.' . $linename . '.itemVatAmount'] = $itemVatAmount;
$formFields['openinvoicedata.' . $linename . '.itemVatPercentage'] = $itemVatPercentage;
$formFields['openinvoicedata.' . $linename . '.numberOfItems'] = $numberOfItems;
if ($this->_adyenHelper->isVatCategoryHigh($this->_order->getPayment()->getAdditionalInformation(
\Adyen\Payment\Observer\AdyenHppDataAssignObserver::BRAND_CODE))) {
$formFields['openinvoicedata.' . $linename . '.vatCategory'] = "High";
} else {
$formFields['openinvoicedata.' . $linename . '.vatCategory'] = "None";
}
return $formFields;
}
/** /**
* @param $genderId * @param $genderId
* @return string * @return string
......
...@@ -36,6 +36,7 @@ class AdyenHppDataAssignObserver extends AbstractDataAssignObserver ...@@ -36,6 +36,7 @@ class AdyenHppDataAssignObserver extends AbstractDataAssignObserver
const GENDER = 'gender'; const GENDER = 'gender';
const DOB = 'dob'; const DOB = 'dob';
const TELEPHONE = 'telephone'; const TELEPHONE = 'telephone';
const DF_VALUE = 'df_value';
/** /**
...@@ -46,7 +47,8 @@ class AdyenHppDataAssignObserver extends AbstractDataAssignObserver ...@@ -46,7 +47,8 @@ class AdyenHppDataAssignObserver extends AbstractDataAssignObserver
self::ISSUER_ID, self::ISSUER_ID,
self::GENDER, self::GENDER,
self::DOB, self::DOB,
self::TELEPHONE self::TELEPHONE,
self::DF_VALUE
]; ];
/** /**
......
...@@ -6,7 +6,8 @@ ...@@ -6,7 +6,8 @@
/*global alert*/ /*global alert*/
var config = { var config = {
paths: { paths: {
'adyen/encrypt' : 'Adyen_Payment/js/view/payment/adyen.encrypt.min' 'adyen/encrypt' : 'Adyen_Payment/js/view/payment/adyen.encrypt.min',
'adyen/df' : 'https://live.adyen.com/hpp/js/df'
}, },
config: { config: {
mixins: { mixins: {
......
...@@ -35,12 +35,14 @@ define( ...@@ -35,12 +35,14 @@ define(
'Magento_Checkout/js/model/url-builder', 'Magento_Checkout/js/model/url-builder',
'Adyen_Payment/js/model/adyen-payment-service', 'Adyen_Payment/js/model/adyen-payment-service',
'Magento_Customer/js/model/customer', 'Magento_Customer/js/model/customer',
'Magento_Checkout/js/model/full-screen-loader' 'Magento_Checkout/js/model/full-screen-loader',
'adyen/df'
], ],
function (ko, $, Component, setPaymentMethodAction, selectPaymentMethodAction, quote, checkoutData, additionalValidators, storage, urlBuilder, adyenPaymentService, customer, fullScreenLoader) { function (ko, $, Component, setPaymentMethodAction, selectPaymentMethodAction, quote, checkoutData, additionalValidators, storage, urlBuilder, adyenPaymentService, customer, fullScreenLoader, deviceFingerprint) {
'use strict'; 'use strict';
var brandCode = ko.observable(null); var brandCode = ko.observable(null);
var paymentMethod = ko.observable(null); var paymentMethod = ko.observable(null);
var dfValue = ko.observable(null);
return Component.extend({ return Component.extend({
self: this, self: this,
...@@ -55,7 +57,8 @@ define( ...@@ -55,7 +57,8 @@ define(
'issuerId', 'issuerId',
'gender', 'gender',
'dob', 'dob',
'telephone' 'telephone',
'dfValue'
]); ]);
return this; return this;
}, },
...@@ -89,6 +92,12 @@ define( ...@@ -89,6 +92,12 @@ define(
).done( ).done(
function (response) { function (response) {
adyenPaymentService.setPaymentMethods(response); adyenPaymentService.setPaymentMethods(response);
// set device fingerprint value
dfSet('dfValue', 0);
// propagate this manually to knockoutjs otherwise it would not work
dfValue($('#dfValue').val());
fullScreenLoader.stopLoader(); fullScreenLoader.stopLoader();
} }
).fail(function(error) { ).fail(function(error) {
...@@ -114,7 +123,6 @@ define( ...@@ -114,7 +123,6 @@ define(
return self.validate(); return self.validate();
} }
if(value.brandCode == "ideal") { if(value.brandCode == "ideal") {
result.issuerIds = value.issuers; result.issuerIds = value.issuers;
result.issuerId = ko.observable(null); result.issuerId = ko.observable(null);
...@@ -155,17 +163,16 @@ define( ...@@ -155,17 +163,16 @@ define(
if (this.validate() && additionalValidators.validate()) { if (this.validate() && additionalValidators.validate()) {
var data = {}; var data = {};
data.method = self.method; data.method = self.method;
data.po_number = null;
var additionalData = {}; var additionalData = {};
additionalData.brand_code = self.value; additionalData.brand_code = self.value;
additionalData.df_value = dfValue();
if(brandCode() == "ideal") { if(brandCode() == "ideal") {
additionalData.issuer_id = this.issuerId(); additionalData.issuer_id = this.issuerId();
} else if(brandCode() == "klarna") { } else if(self.isPaymentMethodOpenInvoiceMethod()) {
additionalData.gender = this.gender(); additionalData.gender = this.gender();
additionalData.dob = this.dob(); additionalData.dob = this.dob();
additionalData.telephone = this.telephone(); additionalData.telephone = this.telephone();
...@@ -187,7 +194,7 @@ define( ...@@ -187,7 +194,7 @@ define(
"method": self.method, "method": self.method,
"po_number": null, "po_number": null,
"additional_data": { "additional_data": {
brand_code: self.value, brand_code: self.value
} }
}; };
......
...@@ -153,6 +153,20 @@ ...@@ -153,6 +153,20 @@
<!--/ko--> <!--/ko-->
<!--/ko--> <!--/ko-->
<input type="hidden" id="dfValue" name="payment[dfValue]" />
<script>
require([
"domReady!"
], function(){
// dfDo("dfValue");
dfSet('dfValue', 0);
});
</script>
<!-- ko if: (isPaymentMethodSelectionOnAdyen()) --> <!-- ko if: (isPaymentMethodSelectionOnAdyen()) -->
<div class="payment-method" data-bind="css: {'_active': (getCode() == isChecked())}"> <div class="payment-method" data-bind="css: {'_active': (getCode() == isChecked())}">
......
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