Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
Adyen Magento2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Shared Libs
Adyen Magento2
Commits
ade2e9e7
Commit
ade2e9e7
authored
Jul 19, 2017
by
Rik ter Beek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #142 add discount and shipping costs into request
parent
488161ba
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
98 additions
and
21 deletions
+98
-21
Block/Redirect/Redirect.php
Block/Redirect/Redirect.php
+98
-21
No files found.
Block/Redirect/Redirect.php
View file @
ade2e9e7
...
...
@@ -58,6 +58,13 @@ class Redirect extends \Magento\Payment\Block\Form
*/
protected
$_adyenLogger
;
/**
* @var \Magento\Tax\Model\Config
*/
protected
$_taxConfig
;
protected
$_taxCalculation
;
/**
* Redirect constructor.
*
...
...
@@ -74,7 +81,9 @@ class Redirect extends \Magento\Payment\Block\Form
\Magento\Checkout\Model\Session
$checkoutSession
,
\Adyen\Payment\Helper\Data
$adyenHelper
,
\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
->
_checkoutSession
=
$checkoutSession
;
...
...
@@ -88,6 +97,8 @@ class Redirect extends \Magento\Payment\Block\Form
$incrementId
=
$this
->
_getCheckout
()
->
getLastRealOrderId
();
$this
->
_order
=
$this
->
_orderFactory
->
create
()
->
loadByIncrementId
(
$incrementId
);
}
$this
->
_taxConfig
=
$taxConfig
;
$this
->
_taxCalculation
=
$taxCalculation
;
}
...
...
@@ -306,6 +317,10 @@ class Redirect extends \Magento\Payment\Block\Form
}
catch
(
Exception
$e
)
{
// do nothing for now
}
// echo "GENDER" . $this->_order->getCustomerGender();
//
// print_r($formFields);die();
return
$formFields
;
}
...
...
@@ -430,15 +445,11 @@ class Redirect extends \Magento\Payment\Block\Form
foreach
(
$this
->
_order
->
getAllVisibleItems
()
as
$item
)
{
++
$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
)
?
$this
->
_adyenHelper
->
formatAmount
(
$item
->
getPriceInclTax
(),
...
...
@@ -447,23 +458,57 @@ class Redirect extends \Magento\Payment\Block\Form
$item
->
getPrice
(),
$currency
)
:
$this
->
_adyenHelper
->
formatAmount
(
$item
->
getTaxAmount
(),
$currency
);
// Calculate vat percentage
$percentageMinorUnits
=
$this
->
_adyenHelper
->
getMinorUnitTaxPercent
(
$item
->
getTaxPercent
());
$formFields
[
'openinvoicedata.'
.
$linename
.
'.itemVatPercentage'
]
=
$percentageMinorUnits
;
$formFields
[
'openinvoicedata.'
.
$linename
.
'.numberOfItems'
]
=
(
int
)
$item
->
getQtyOrdered
();
$itemVatPercentage
=
$this
->
_adyenHelper
->
getMinorUnitTaxPercent
(
$item
->
getTaxPercent
());
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"
;
}
$numberOfItems
=
(
int
)
$item
->
getQtyOrdered
();
if
(
$item
->
getSku
()
!=
""
)
{
$formFields
[
'openinvoicedata.'
.
$linename
.
'.itemId'
]
=
$item
->
getSku
();
}
$formFields
=
$this
->
setOpenInvoiceLineData
(
$formFields
,
$count
,
$currency
,
$description
,
$itemAmount
,
$itemVatAmount
,
$itemVatPercentage
,
$numberOfItems
);
}
// 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'
];
...
...
@@ -472,6 +517,38 @@ class Redirect extends \Magento\Payment\Block\Form
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
* @return string
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment