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

Move open invoice to checkout

Put HPP redirect and Validate3d redirect (general handler) together
Put HPP into the authorize flow instead of the order flow
Show gender, date of birth and phone number for open invoice payment
methods all the time - remove the admin settings
Fix house number in the AddressBuilder
Add first name, last name and country code in the CustomerDataBuilder
parent bc071ac6
...@@ -112,29 +112,6 @@ class Redirect extends \Magento\Payment\Block\Form ...@@ -112,29 +112,6 @@ class Redirect extends \Magento\Payment\Block\Form
$this->_request = $context->getRequest(); $this->_request = $context->getRequest();
} }
/**
* Returns if the payment should follow the old HPP or the new Checkout flow
* - hpp will submit a form with all the additional information that the API requests\
* - checkout will redirect to a url without form submission
*
* @return bool
* @throws \Exception
*/
public function isCheckoutAPM() {
try {
if ($paymentObject = $this->_order->getPayment()) {
if ($paymentObject->getAdditionalInformation('CheckoutAPM')) {
return true;
}
}
} catch (Exception $e) {
// do nothing for now
throw($e);
}
return false;
}
/** /**
* @return mixed|string[] * @return mixed|string[]
* @throws AdyenException * @throws AdyenException
...@@ -178,6 +155,7 @@ class Redirect extends \Magento\Payment\Block\Form ...@@ -178,6 +155,7 @@ class Redirect extends \Magento\Payment\Block\Form
$url = ""; $url = "";
try { try {
if ($this->_order->getPayment()) { if ($this->_order->getPayment()) {
$paymentRoutine = $this->_adyenHelper->getAdyenHppConfigData('payment_routine');
switch ($this->_adyenHelper->isDemoMode()) { switch ($this->_adyenHelper->isDemoMode()) {
case true: case true:
......
...@@ -113,6 +113,11 @@ class CustomerDataBuilder implements BuilderInterface ...@@ -113,6 +113,11 @@ class CustomerDataBuilder implements BuilderInterface
} }
} }
$result['shopperName']['firstName'] = $order->getBillingAddress()->getFirstname();
$result['shopperName']['lastName'] = $order->getBillingAddress()->getLastname();
$result['countryCode'] = $billingAddress->getCountryId();
return $result; return $result;
} }
} }
...@@ -39,17 +39,41 @@ class HppAuthorizationDataBuilder implements BuilderInterface ...@@ -39,17 +39,41 @@ class HppAuthorizationDataBuilder implements BuilderInterface
private $storeManager; private $storeManager;
/** /**
* CcAuthorizationDataBuilder constructor. * @var \Magento\Checkout\Model\Session
*/
private $checkoutSession;
/**
* @var \Magento\Quote\Model\Quote
*/
private $quote;
/**
* @var \Magento\Tax\Model\Config
*/
protected $taxConfig;
/**
* HppAuthorizationDataBuilder constructor.
* *
* @param \Adyen\Payment\Helper\Data $adyenHelper * @param \Adyen\Payment\Helper\Data $adyenHelper
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Checkout\Model\Session $checkoutSession
* @param \Magento\Tax\Model\Config $taxConfig
*/ */
public function __construct( public function __construct(
\Adyen\Payment\Helper\Data $adyenHelper, \Adyen\Payment\Helper\Data $adyenHelper,
\Magento\Store\Model\StoreManagerInterface $storeManager \Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Checkout\Model\Session $checkoutSession,
\Magento\Tax\Model\Config $taxConfig
) )
{ {
$this->adyenHelper = $adyenHelper; $this->adyenHelper = $adyenHelper;
$this->storeManager = $storeManager; $this->storeManager = $storeManager;
$this->checkoutSession = $checkoutSession;
$this->quote = $checkoutSession->getQuote();
$this->taxConfig = $taxConfig;
} }
/** /**
...@@ -69,6 +93,9 @@ class HppAuthorizationDataBuilder implements BuilderInterface ...@@ -69,6 +93,9 @@ class HppAuthorizationDataBuilder implements BuilderInterface
$request['paymentMethod']['type'] = $payment->getAdditionalInformation(AdyenHppDataAssignObserver::BRAND_CODE); $request['paymentMethod']['type'] = $payment->getAdditionalInformation(AdyenHppDataAssignObserver::BRAND_CODE);
// Pass issuer id TODO in PW-875
$request['paymentMethod']['issuer'] = "";
$request['returnUrl'] = $this->storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_LINK) . 'adyen/process/result'; $request['returnUrl'] = $this->storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_LINK) . 'adyen/process/result';
// update customer based on additionalFields // update customer based on additionalFields
...@@ -76,16 +103,99 @@ class HppAuthorizationDataBuilder implements BuilderInterface ...@@ -76,16 +103,99 @@ class HppAuthorizationDataBuilder implements BuilderInterface
$order->setCustomerGender(\Adyen\Payment\Model\Gender::getMagentoGenderFromAdyenGender( $order->setCustomerGender(\Adyen\Payment\Model\Gender::getMagentoGenderFromAdyenGender(
$payment->getAdditionalInformation("gender")) $payment->getAdditionalInformation("gender"))
); );
$request['shopperName']['gender'] = $payment->getAdditionalInformation("gender");
} }
if ($payment->getAdditionalInformation("dob")) { if ($payment->getAdditionalInformation("dob")) {
$order->setCustomerDob($payment->getAdditionalInformation("dob")); $order->setCustomerDob($payment->getAdditionalInformation("dob"));
$request['dateOfBirth']= $this->adyenHelper->formatDate($payment->getAdditionalInformation("dob"), 'Y-m-d') ;
} }
if ($payment->getAdditionalInformation("telephone")) { if ($payment->getAdditionalInformation("telephone")) {
$order->getBillingAddress()->setTelephone($payment->getAdditionalInformation("telephone")); $order->getBillingAddress()->setTelephone($payment->getAdditionalInformation("telephone"));
$request['telephoneNumber']= $payment->getAdditionalInformation("telephone");
}
if ($this->adyenHelper->isPaymentMethodOpenInvoiceMethod(
$payment->getAdditionalInformation(AdyenHppDataAssignObserver::BRAND_CODE)
)) {
$openInvoiceFields = $this->getOpenInvoiceData($order);
$request = array_merge($request, $openInvoiceFields);
} }
return $request; return $request;
} }
/**
* @param $formFields
* @return mixed
*/
protected function getOpenInvoiceData($order)
{
$formFields = [
'lineItems' => []
];
$currency = $this->quote->getCurrency();
$discountAmount = 0;
foreach ($this->quote->getAllVisibleItems() as $item) {
$numberOfItems = (int)$item->getQtyOrdered();
// Summarize the discount amount item by item
$discountAmount += $item->getDiscountAmount();
$priceExcludingTax = $item->getPriceInclTax() - $item->getTaxAmount();
$formFields['lineItems'][] = [
'amountExcludingTax' => $priceExcludingTax,
'taxAmount' => $item->getTaxAmount(),
'description' => $item->getName(),
'id' => $item->getId(),
'quantity' => $item->getQty(),
'taxCategory' => $item->getProduct()->getAttributeText('tax_class_id'),
'taxPercentage' => $item->getTaxPercent()
];
}
// Discount cost
if ($discountAmount != 0) {
$description = __('Total Discount');
$itemAmount = $this->adyenHelper->formatAmount($discountAmount, $currency);
$itemVatAmount = "0";
$itemVatPercentage = "0";
$numberOfItems = 1;
$formFields['lineItems'][] = [
'amountExcludingTax' => $itemAmount,
'taxAmount' => $itemVatAmount,
'description' => $description,
'quantity' => $numberOfItems,
'taxCategory' => 'None',
'taxPercentage' => $itemVatPercentage
];
}
// Shipping cost
if ($this->quote->getShippingAddress()->getShippingAmount() > 0 || $this->quote->getShippingAddress()->getShippingTaxAmount() > 0) {
$priceExcludingTax = $this->quote->getShippingAddress()->getShippingAmount() - $this->quote->getShippingAddress()->getShippingTaxAmount();
$taxClassId = $this->taxConfig->getShippingTaxClass($this->storeManager->getStore()->getId());
$formFields['lineItems'][] = [
'amountExcludingTax' => $priceExcludingTax,
'taxAmount' => $this->quote->getShippingAddress()->getShippingTaxAmount(),
'description' => $order->getShippingDescription(),
'quantity' => 1,
'taxPercentage' => $this->quote->getShippingAddress()->getShippingTaxAmount()
];
}
return $formFields;
}
} }
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