Skip to content

Commit

Permalink
Merge pull request #441 from Adyen/develop
Browse files Browse the repository at this point in the history
Release 4.0.3
  • Loading branch information
Aleffio authored May 3, 2019
2 parents ecd01eb + 5b82076 commit dc96f65
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 36 deletions.
62 changes: 36 additions & 26 deletions Block/Redirect/Redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,9 @@ public function getFormUrl()
if ($this->getPaymentMethodSelectionOnAdyen()) {
$url = 'https://test.adyen.com/hpp/select.shtml';
} else {
if ($this->_adyenHelper->isPaymentMethodOpenInvoiceMethod(
$this->_order->getPayment()->getAdditionalInformation('brand_code')
) || $this->_adyenHelper->isPaymentMethodMolpayMethod(
$this->_order->getPayment()->getAdditionalInformation('brand_code')
)
if ($this->_adyenHelper->doesPaymentMethodSkipDetails(
$this->_order->getPayment()->getAdditionalInformation('brand_code')
)
) {
$url = "https://test.adyen.com/hpp/skipDetails.shtml";
} else {
Expand All @@ -148,11 +146,9 @@ public function getFormUrl()
if ($this->getPaymentMethodSelectionOnAdyen()) {
$url = 'https://live.adyen.com/hpp/select.shtml';
} else {
if ($this->_adyenHelper->isPaymentMethodOpenInvoiceMethod(
$this->_order->getPayment()->getAdditionalInformation('brand_code')
) || $this->_adyenHelper->isPaymentMethodMolpayMethod(
$this->_order->getPayment()->getAdditionalInformation('brand_code')
)
if ($this->_adyenHelper->doesPaymentMethodSkipDetails(
$this->_order->getPayment()->getAdditionalInformation('brand_code')
)
) {
$url = "https://live.adyen.com/hpp/skipDetails.shtml";
} else {
Expand Down Expand Up @@ -335,16 +331,21 @@ protected function setBillingAddressData($formFields)

$formFields['shopper.lastName'] = trim($billingAddress->getLastname());
$formFields['shopper.telephoneNumber'] = trim($billingAddress->getTelephone());
$street = $this->_adyenHelper->getStreet($billingAddress);

if (isset($street['name']) && $street['name'] != "") {
$formFields['billingAddress.street'] = $street['name'];
}
if ($this->_adyenHelper->isSeparateHouseNumberRequired($billingAddress->getCountryId())) {
$street = $this->_adyenHelper->getStreet($billingAddress);

if (isset($street['name']) && $street['name'] != "") {
$formFields['billingAddress.street'] = $street['name'];
}

if (isset($street['house_number']) && $street['house_number'] != "") {
$formFields['billingAddress.houseNumberOrName'] = $street['house_number'];
if (isset($street['house_number']) && $street['house_number'] != "") {
$formFields['billingAddress.houseNumberOrName'] = $street['house_number'];
} else {
$formFields['billingAddress.houseNumberOrName'] = "NA";
}
} else {
$formFields['billingAddress.houseNumberOrName'] = "NA";
$formFields['billingAddress.street'] = implode(" ", $billingAddress->getStreet());
}

if (trim($billingAddress->getCity()) == "") {
Expand Down Expand Up @@ -384,18 +385,23 @@ protected function setShippingAddressData($formFields)
$shippingAddress = $this->_order->getShippingAddress();

if ($shippingAddress) {
$street = $this->_adyenHelper->getStreet($shippingAddress);
if ($this->_adyenHelper->isSeparateHouseNumberRequired($shippingAddress->getCountryId())) {
$street = $this->_adyenHelper->getStreet($shippingAddress);

if (isset($street['name']) && $street['name'] != "") {
$formFields['deliveryAddress.street'] = $street['name'];
}
if (isset($street['name']) && $street['name'] != "") {
$formFields['deliveryAddress.street'] = $street['name'];
}

if (isset($street['house_number']) && $street['house_number'] != "") {
$formFields['deliveryAddress.houseNumberOrName'] = $street['house_number'];
if (isset($street['house_number']) && $street['house_number'] != "") {
$formFields['deliveryAddress.houseNumberOrName'] = $street['house_number'];
} else {
$formFields['deliveryAddress.houseNumberOrName'] = "NA";
}
} else {
$formFields['deliveryAddress.houseNumberOrName'] = "NA";
$formFields['deliveryAddress.street'] = implode(" ", $shippingAddress->getStreet());
}


if (trim($shippingAddress->getCity()) == "") {
$formFields['deliveryAddress.city'] = "NA";
} else {
Expand All @@ -420,6 +426,7 @@ protected function setShippingAddressData($formFields)
$formFields['deliveryAddress.country'] = trim($shippingAddress->getCountryId());
}
}

return $formFields;
}

Expand All @@ -433,6 +440,7 @@ protected function setOpenInvoiceData($formFields)
$currency = $this->_order->getOrderCurrencyCode();

foreach ($this->_order->getAllVisibleItems() as $item) {
/** @var $item \Magento\Sales\Model\Order\Item */
++$count;
$numberOfItems = (int)$item->getQtyOrdered();

Expand All @@ -446,7 +454,8 @@ protected function setOpenInvoiceData($formFields)
$item->getPriceInclTax(),
$item->getTaxPercent(),
$numberOfItems,
$this->_order->getPayment()
$this->_order->getPayment(),
$item->getId()
);
}

Expand All @@ -469,7 +478,8 @@ protected function setOpenInvoiceData($formFields)
$itemVatAmount,
$itemVatPercentage,
$numberOfItems,
$this->_order->getPayment()
$this->_order->getPayment(),
"discount"
);
}

Expand Down
3 changes: 2 additions & 1 deletion Gateway/Request/CaptureDataBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ protected function getOpenInvoiceData($payment)
$invoiceItem->getPriceInclTax(),
$invoiceItem->getTaxPercent(),
$numberOfItems,
$payment
$payment,
$invoiceItem->getId()
);
}

Expand Down
3 changes: 2 additions & 1 deletion Gateway/Request/RefundDataBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ protected function getOpenInvoiceData($payment)
$refundItem->getPriceInclTax(),
$refundItem->getTaxPercent(),
$numberOfItems,
$payment
$payment,
$refundItem->getId()
);
}

Expand Down
3 changes: 2 additions & 1 deletion Gateway/Validator/InstallmentValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ public function validate(array $validationSubject)
$fails = [];
$payment = $validationSubject['payment'];
$quote = $this->session->getQuote();
if ($quote) {
$installmentsEnabled = $this->adyenHelper->getAdyenCcConfigData('enable_installments');
if ($quote && $installmentsEnabled) {
$grandTotal = $quote->getGrandTotal();
$installmentsAvailable = $this->adyenHelper->getAdyenCcConfigData('installments');
$installmentSelected = $payment->getAdditionalInformation('number_of_installments');
Expand Down
66 changes: 61 additions & 5 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,38 @@ public function isPaymentMethodMolpayMethod($paymentMethod)
return false;
}

/**
* @param $paymentMethod
* @return bool
*/
public function isPaymentMethodOneyMethod($paymentMethod)
{
if (strpos($paymentMethod, 'facilypay_') !== false) {
return true;
}

return false;
}

/**
* @param $paymentMethod
* @return bool
*/
public function doesPaymentMethodSkipDetails($paymentMethod)
{
if ($this->isPaymentMethodOpenInvoiceMethod($paymentMethod) ||
$this->isPaymentMethodMolpayMethod($paymentMethod) ||
$this->isPaymentMethodOneyMethod($paymentMethod)
) {
return true;
}

return false;
}

/**
* @return mixed
*/
public function getRatePayId()
{
return $this->getAdyenHppConfigData("ratepay_id");
Expand Down Expand Up @@ -1099,6 +1131,7 @@ public function getUnprocessedNotifications()
* @param $taxPercent
* @param $numberOfItems
* @param $payment
* @param null $itemId
* @return mixed
*/
public function createOpenInvoiceLineItem(
Expand All @@ -1111,7 +1144,8 @@ public function createOpenInvoiceLineItem(
$priceInclTax,
$taxPercent,
$numberOfItems,
$payment
$payment,
$itemId = null
) {
$description = str_replace("\n", '', trim($name));
$itemAmount = $this->formatAmount($price, $currency);
Expand All @@ -1135,7 +1169,8 @@ public function createOpenInvoiceLineItem(
$itemVatAmount,
$itemVatPercentage,
$numberOfItems,
$payment
$payment,
$itemId
);
}

Expand Down Expand Up @@ -1187,7 +1222,8 @@ public function createOpenInvoiceLineShipping(
$itemVatAmount,
$itemVatPercentage,
$numberOfItems,
$payment
$payment,
"shipping"
);
}

Expand Down Expand Up @@ -1222,7 +1258,8 @@ public function getItemVatAmount(
* @param $itemVatPercentage
* @param $numberOfItems
* @param $payment
* @return
* @param null|int $itemId optional
* @return mixed
*/
public function getOpenInvoiceLineData(
$formFields,
Expand All @@ -1233,9 +1270,16 @@ public function getOpenInvoiceLineData(
$itemVatAmount,
$itemVatPercentage,
$numberOfItems,
$payment
$payment,
$itemId = null
) {
$linename = "line" . $count;

// item id is optional
if ($itemId) {
$formFields['openinvoicedata.' . $linename . '.itemId'] = $itemId;
}

$formFields['openinvoicedata.' . $linename . '.currencyCode'] = $currencyCode;
$formFields['openinvoicedata.' . $linename . '.description'] = $description;
$formFields['openinvoicedata.' . $linename . '.itemAmount'] = $itemAmount;
Expand Down Expand Up @@ -1607,4 +1651,16 @@ public function isCreditCardVaultEnabled($storeId = null)
return $this->getAdyenCcVaultConfigDataFlag('active', $storeId);
}

/**
* Checks if the house number needs to be sent to the Adyen API separately or as it is in the street field
*
* @param $country
* @return bool
*/
public function isSeparateHouseNumberRequired($country)
{
$countryList = ["nl", "de", "se", "no", "at", "fi", "dk"];

return in_array(strtolower($country), $countryList);
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "adyen/module-payment",
"description": "Official Magento2 Plugin to connect to Payment Service Provider Adyen.",
"type": "magento2-module",
"version": "4.0.2",
"version": "4.0.3",
"license": [
"OSL-3.0",
"AFL-3.0"
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">

<module name="Adyen_Payment" setup_version="4.0.2">
<module name="Adyen_Payment" setup_version="4.0.3">
<sequence>
<module name="Magento_Sales"/>
<module name="Magento_Quote"/>
Expand Down

0 comments on commit dc96f65

Please sign in to comment.