Skip to content

Commit

Permalink
Merge pull request #214 from Adyen/develop
Browse files Browse the repository at this point in the history
Hotfix release 2.1.3
  • Loading branch information
rikterbeek authored Nov 16, 2017
2 parents 0146961 + 91682aa commit 798c644
Show file tree
Hide file tree
Showing 104 changed files with 382 additions and 230 deletions.
7 changes: 7 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
**Magento version**: x.y.z
**Plugin version**: x.y.z
**Description**
<!--
- please provide description of the issue. In case of bug report, please provide the necessary steps to reproduce.
- For merchant specific requests, please use https://support.adyen.com
-->
7 changes: 7 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
**Description**
<!-- Please provide a description of the changes proposed in the Pull Request -->

**Tested scenarios**
<!-- Description of tested scenarios -->

**Fixed issue**: <!-- #-prefixed issue number -->
123 changes: 62 additions & 61 deletions Block/Redirect/Redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ public function __construct(
\Adyen\Payment\Logger\AdyenLogger $adyenLogger,
\Magento\Tax\Model\Config $taxConfig,
\Magento\Tax\Model\Calculation $taxCalculation
) {
)
{
$this->_orderFactory = $orderFactory;
$this->_checkoutSession = $checkoutSession;
parent::__construct($context, $data);
Expand Down Expand Up @@ -127,11 +128,12 @@ public function getFormUrl()
} else {

if ($this->getPaymentMethodSelectionOnAdyen()) {
$url = 'https://test.adyen.com/hpp/select.shtml';
$url = 'https://test.adyen.com/hpp/select.shtml';
} else {
if ($this->_adyenHelper->isPaymentMethodOpenInvoiceMethod(
$this->_order->getPayment()->getAdditionalInformation('brand_code')
)) {
)
) {
$url = "https://test.adyen.com/hpp/skipDetails.shtml";
} else {
$url = "https://test.adyen.com/hpp/details.shtml";
Expand All @@ -144,11 +146,12 @@ public function getFormUrl()
$url = 'https://live.adyen.com/hpp/pay.shtml';
} else {
if ($this->getPaymentMethodSelectionOnAdyen()) {
$url = 'https://live.adyen.com/hpp/select.shtml';
$url = 'https://live.adyen.com/hpp/select.shtml';
} else {
if ($this->_adyenHelper->isPaymentMethodOpenInvoiceMethod(
$this->_order->getPayment()->getAdditionalInformation('brand_code')
)) {
)
) {
$url = "https://live.adyen.com/hpp/skipDetails.shtml";
} else {
$url = "https://live.adyen.com/hpp/details.shtml";
Expand All @@ -158,7 +161,7 @@ public function getFormUrl()
break;
}
}
} catch(Exception $e) {
} catch (Exception $e) {
// do nothing for now
throw($e);
}
Expand All @@ -183,56 +186,57 @@ public function getFormFields()
try {
if ($this->_order->getPayment()) {

$realOrderId = $this->_order->getRealOrderId();
$realOrderId = $this->_order->getRealOrderId();
$orderCurrencyCode = $this->_order->getOrderCurrencyCode();
$skinCode = trim($this->_adyenHelper->getAdyenHppConfigData('skin_code'));
$amount = $this->_adyenHelper->formatAmount(
$skinCode = trim($this->_adyenHelper->getAdyenHppConfigData('skin_code'));
$amount = $this->_adyenHelper->formatAmount(
$this->_order->getGrandTotal(), $orderCurrencyCode
);
$merchantAccount = trim($this->_adyenHelper->getAdyenAbstractConfigData('merchant_account'));
$shopperEmail = $this->_order->getCustomerEmail();
$customerId = $this->_order->getCustomerId();
$shopperIP = $this->_order->getRemoteIp();
$browserInfo = $_SERVER['HTTP_USER_AGENT'];
$deliveryDays = $this->_adyenHelper->getAdyenHppConfigData('delivery_days');
$shopperLocale = trim($this->_adyenHelper->getAdyenHppConfigData('shopper_locale'));
$shopperLocale = (!empty($shopperLocale)) ? $shopperLocale : $this->_resolver->getLocale();
$countryCode = trim($this->_adyenHelper->getAdyenHppConfigData('country_code'));
$countryCode = (!empty($countryCode)) ? $countryCode : false;
$merchantAccount = trim($this->_adyenHelper->getAdyenAbstractConfigData('merchant_account'));
$shopperEmail = $this->_order->getCustomerEmail();
$customerId = $this->_order->getCustomerId();
$shopperIP = $this->_order->getRemoteIp();
$browserInfo = $_SERVER['HTTP_USER_AGENT'];
$deliveryDays = $this->_adyenHelper->getAdyenHppConfigData('delivery_days');
$shopperLocale = trim($this->_adyenHelper->getAdyenHppConfigData('shopper_locale'));
$shopperLocale = (!empty($shopperLocale)) ? $shopperLocale : $this->_resolver->getLocale();
$countryCode = trim($this->_adyenHelper->getAdyenHppConfigData('country_code'));
$countryCode = (!empty($countryCode)) ? $countryCode : false;

// if directory lookup is enabled use the billingaddress as countrycode
if ($countryCode == false) {
if ($this->_order->getBillingAddress() &&
$this->_order->getBillingAddress()->getCountryId() != "") {
$this->_order->getBillingAddress()->getCountryId() != ""
) {
$countryCode = $this->_order->getBillingAddress()->getCountryId();
}
}

$formFields = [];

$formFields['merchantAccount'] = $merchantAccount;
$formFields['merchantAccount'] = $merchantAccount;
$formFields['merchantReference'] = $realOrderId;
$formFields['paymentAmount'] = (int)$amount;
$formFields['currencyCode'] = $orderCurrencyCode;
$formFields['shipBeforeDate'] = date(
$formFields['paymentAmount'] = (int)$amount;
$formFields['currencyCode'] = $orderCurrencyCode;
$formFields['shipBeforeDate'] = date(
"Y-m-d",
mktime(date("H"), date("i"), date("s"), date("m"), date("j") + $deliveryDays, date("Y"))
);
$formFields['skinCode'] = $skinCode;
$formFields['shopperLocale'] = $shopperLocale;
$formFields['countryCode'] = $countryCode;
$formFields['shopperIP'] = $shopperIP;
$formFields['browserInfo'] = $browserInfo;
$formFields['sessionValidity'] = date(
$formFields['skinCode'] = $skinCode;
$formFields['shopperLocale'] = $shopperLocale;
$formFields['countryCode'] = $countryCode;
$formFields['shopperIP'] = $shopperIP;
$formFields['browserInfo'] = $browserInfo;
$formFields['sessionValidity'] = date(
DATE_ATOM,
mktime(date("H") + 1, date("i"), date("s"), date("m"), date("j"), date("Y"))
);
$formFields['shopperEmail'] = $shopperEmail;
$formFields['shopperEmail'] = $shopperEmail;
// recurring
$recurringType = trim($this->_adyenHelper->getAdyenAbstractConfigData(
$recurringType = trim($this->_adyenHelper->getAdyenAbstractConfigData(
'recurring_type')
);
$brandCode = $this->_order->getPayment()->getAdditionalInformation(
$brandCode = $this->_order->getPayment()->getAdditionalInformation(
\Adyen\Payment\Observer\AdyenHppDataAssignObserver::BRAND_CODE
);

Expand All @@ -243,39 +247,37 @@ public function getFormFields()

if ($customerId > 0) {
$formFields['recurringContract'] = $recurringType;
$formFields['shopperReference'] = $customerId;
$formFields['shopperReference'] = $customerId;
} else {
// required for openinvoice payment methods use unique id
$uniqueReference = "guest_" . $realOrderId . "_" . $this->_order->getStoreId();
$formFields['shopperReference'] = $uniqueReference;
$uniqueReference = "guest_" . $realOrderId . "_" . $this->_order->getStoreId();
$formFields['shopperReference'] = $uniqueReference;
}

//blocked methods
$formFields['blockedMethods'] = "";
$formFields['blockedMethods'] = "";

$baseUrl = $this->_storeManager->getStore($this->getStore())
->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_LINK);

$formFields['resURL'] = $baseUrl . 'adyen/process/result';
$hmacKey = $this->_adyenHelper->getHmac();
$formFields['resURL'] = $baseUrl . 'adyen/process/result';
$hmacKey = $this->_adyenHelper->getHmac();


if ($brandCode) {
$formFields['brandCode'] = $brandCode;
$formFields['brandCode'] = $brandCode;
}

$issuerId = $this->_order->getPayment()->getAdditionalInformation("issuer_id");
if ($issuerId) {
$formFields['issuerId'] = $issuerId;
$formFields['issuerId'] = $issuerId;
}

$formFields = $this->setBillingAddressData($formFields);
$formFields = $this->setShippingAddressData($formFields);
$formFields = $this->setOpenInvoiceData($formFields);

$formFields['shopper.gender'] = $this->getGenderText($this->_order->getCustomerGender());


$dob = $this->_order->getCustomerDob();
if ($dob) {
$formFields['shopper.dateOfBirthDayOfMonth'] = trim($this->_getDate($dob, 'd'));
Expand All @@ -285,15 +287,19 @@ public function getFormFields()

// For klarna acceptPrivacyPolicy to skip HPP page
if ($brandCode == "klarna") {
$ssn = $this->_order->getPayment()->getAdditionalInformation('ssn');
if (!empty($ssn)) {
$formFields['shopper.socialSecurityNumber'] = $ssn;
}
// // needed for DE and AT
$formFields['klarna.acceptPrivacyPolicy'] = 'true';
$formFields['klarna.acceptPrivacyPolicy'] = 'true';
}

// OpenInvoice don't allow to edit billing and delivery items

if ($this->_adyenHelper->isPaymentMethodOpenInvoiceMethod($brandCode)) {
// don't allow editable shipping/delivery address
$formFields['billingAddressType'] = "1";
$formFields['billingAddressType'] = "1";
$formFields['deliveryAddressType'] = "1";

// make setting to make this optional
Expand All @@ -313,18 +319,14 @@ public function getFormFields()

$merchantSig = base64_encode(hash_hmac('sha256', $signData, pack("H*", $hmacKey), true));

$formFields['merchantSig'] = $merchantSig;
$formFields['merchantSig'] = $merchantSig;

$this->_adyenLogger->addAdyenDebug(print_r($formFields, true));
}

} catch(Exception $e) {
} catch (Exception $e) {
// do nothing for now
}

// echo "GENDER" . $this->_order->getCustomerGender();
//
// print_r($formFields);die();
return $formFields;
}

Expand All @@ -336,9 +338,7 @@ public function getFormFields()
protected function setBillingAddressData($formFields)
{
$billingAddress = $this->_order->getBillingAddress();

if ($billingAddress) {

$formFields['shopper.firstName'] = trim($billingAddress->getFirstname());
$middleName = trim($billingAddress->getMiddlename());
if ($middleName != "") {
Expand All @@ -347,7 +347,6 @@ 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'] != "") {
Expand Down Expand Up @@ -458,7 +457,7 @@ protected function setOpenInvoiceData($formFields)
$this->_adyenHelper->formatAmount(
$item->getPriceInclTax(),
$currency
) - $this->_adyenHelper->formatAmount(
) - $this->_adyenHelper->formatAmount(
$item->getPrice(),
$currency
) : $this->_adyenHelper->formatAmount($item->getTaxAmount(), $currency);
Expand All @@ -467,7 +466,7 @@ protected function setOpenInvoiceData($formFields)
// Calculate vat percentage
$itemVatPercentage = $this->_adyenHelper->getMinorUnitTaxPercent($item->getTaxPercent());

$numberOfItems = (int) $item->getQtyOrdered();
$numberOfItems = (int)$item->getQtyOrdered();

$formFields = $this->setOpenInvoiceLineData($formFields, $count, $currency, $description, $itemAmount,
$itemVatAmount, $itemVatPercentage, $numberOfItems);
Expand Down Expand Up @@ -515,7 +514,7 @@ protected function setOpenInvoiceData($formFields)
$itemVatAmount, $itemVatPercentage, $numberOfItems);
}

$formFields['openinvoicedata.refundDescription'] = "Refund / Correction for ".$formFields['merchantReference'];
$formFields['openinvoicedata.refundDescription'] = "Refund / Correction for " . $formFields['merchantReference'];
$formFields['openinvoicedata.numberOfLines'] = $count;

return $formFields;
Expand All @@ -534,9 +533,10 @@ protected function setOpenInvoiceData($formFields)
* @param $numberOfItems
*/
protected function setOpenInvoiceLineData($formFields, $count, $currencyCode, $description, $itemAmount,
$itemVatAmount, $itemVatPercentage, $numberOfItems
) {
$linename = "line".$count;
$itemVatAmount, $itemVatPercentage, $numberOfItems
)
{
$linename = "line" . $count;
$formFields['openinvoicedata.' . $linename . '.currencyCode'] = $currencyCode;
$formFields['openinvoicedata.' . $linename . '.description'] = $description;
$formFields['openinvoicedata.' . $linename . '.itemAmount'] = $itemAmount;
Expand All @@ -545,7 +545,8 @@ protected function setOpenInvoiceLineData($formFields, $count, $currencyCode, $d
$formFields['openinvoicedata.' . $linename . '.numberOfItems'] = $numberOfItems;

if ($this->_adyenHelper->isVatCategoryHigh($this->_order->getPayment()->getAdditionalInformation(
\Adyen\Payment\Observer\AdyenHppDataAssignObserver::BRAND_CODE))) {
\Adyen\Payment\Observer\AdyenHppDataAssignObserver::BRAND_CODE))
) {
$formFields['openinvoicedata.' . $linename . '.vatCategory'] = "High";
} else {
$formFields['openinvoicedata.' . $linename . '.vatCategory'] = "None";
Expand Down
25 changes: 11 additions & 14 deletions Gateway/Command/PayByMailCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use Magento\Payment\Gateway\Command;
use Magento\Payment\Gateway\CommandInterface;


class PayByMailCommand implements CommandInterface
{

Expand All @@ -34,11 +35,6 @@ class PayByMailCommand implements CommandInterface
*/
protected $_adyenHelper;

/**
* @var ResolverInterface
*/
protected $_resolver;

/**
* @var \Adyen\Payment\Logger\AdyenLogger
*/
Expand All @@ -53,11 +49,9 @@ class PayByMailCommand implements CommandInterface
*/
public function __construct(
\Adyen\Payment\Helper\Data $adyenHelper,
\Magento\Framework\Locale\ResolverInterface $resolver,
\Adyen\Payment\Logger\AdyenLogger $adyenLogger
) {
$this->_adyenHelper = $adyenHelper;
$this->_resolver = $resolver;
$this->_adyenLogger = $adyenLogger;
}
/**
Expand Down Expand Up @@ -134,25 +128,28 @@ protected function getFormFields($payment)

$realOrderId = $order->getRealOrderId();
$orderCurrencyCode = $order->getOrderCurrencyCode();
$storeId = $order->getStore()->getId();

// check if paybymail has it's own skin
$skinCode = trim($this->_adyenHelper->getAdyenPayByMailConfigData('skin_code'));
if ($skinCode == "") {
// use HPP skin and HMAC
$skinCode = $this->_adyenHelper->getAdyenHppConfigData('skin_code');
$hmacKey = $this->_adyenHelper->getHmac();
$shopperLocale = trim($this->_adyenHelper->getAdyenHppConfigData('shopper_locale', $storeId));
$countryCode = trim($this->_adyenHelper->getAdyenHppConfigData('country_code', $storeId));
} else {
// use pay_by_mail skin and hmac
$hmacKey = $this->_adyenHelper->getHmacPayByMail();
}

$amount = $this->_adyenHelper->formatAmount($order->getGrandTotal(), $orderCurrencyCode);
$merchantAccount = trim($this->_adyenHelper->getAdyenAbstractConfigData('merchant_account'));
$merchantAccount = trim($this->_adyenHelper->getAdyenAbstractConfigData('merchant_account', $storeId));
$shopperEmail = $order->getCustomerEmail();
$customerId = $order->getCustomerId();
$shopperLocale = trim($this->_adyenHelper->getAdyenHppConfigData('shopper_locale'));
$shopperLocale = (!empty($shopperLocale)) ? $shopperLocale : $this->_resolver->getLocale();
$countryCode = trim($this->_adyenHelper->getAdyenHppConfigData('country_code'));

// get locale from store
$shopperLocale = (!empty($shopperLocale)) ? $shopperLocale : $this->_adyenHelper->getStoreLocale($storeId);
$countryCode = (!empty($countryCode)) ? $countryCode : false;

// if directory lookup is enabled use the billingadress as countrycode
Expand All @@ -164,7 +161,7 @@ protected function getFormFields($payment)
}
}

$deliveryDays = $this->_adyenHelper->getAdyenHppConfigData('delivery_days');
$deliveryDays = $this->_adyenHelper->getAdyenHppConfigData('delivery_days', $storeId);
$deliveryDays = (!empty($deliveryDays)) ? $deliveryDays : 5;

$formFields = [];
Expand All @@ -184,9 +181,9 @@ protected function getFormFields($payment)

$formFields['shopperEmail'] = $shopperEmail;
// recurring
$recurringType = trim($this->_adyenHelper->getAdyenAbstractConfigData('recurring_type'));
$recurringType = trim($this->_adyenHelper->getAdyenAbstractConfigData('recurring_type', $storeId));

$sessionValidity = $this->_adyenHelper->getAdyenPayByMailConfigData('session_validity');
$sessionValidity = $this->_adyenHelper->getAdyenPayByMailConfigData('session_validity', $storeId);

if ($sessionValidity == "") {
$sessionValidity = 3;
Expand Down
Loading

0 comments on commit 798c644

Please sign in to comment.