Skip to content

Commit

Permalink
Merge pull request #300 from Adyen/develop
Browse files Browse the repository at this point in the history
Release 2.3.1
  • Loading branch information
lancergr authored Aug 10, 2018
2 parents 527ab73 + dee1944 commit d1635b1
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 38 deletions.
14 changes: 3 additions & 11 deletions Block/Redirect/Redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,6 @@ public function getFormFields()
->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_LINK);

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


if ($brandCode) {
$formFields['brandCode'] = $brandCode;
Expand Down Expand Up @@ -307,15 +305,9 @@ public function getFormFields()
$formFields['dfValue'] = $this->_order->getPayment()->getAdditionalInformation("df_value");
}

// Sort the array by key using SORT_STRING order
ksort($formFields, SORT_STRING);

// Generate the signing data string
$signData = implode(":", array_map([$this, 'escapeString'],
array_merge(array_keys($formFields), array_values($formFields))));

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

// Sign request using secret key
$hmacKey = $this->_adyenHelper->getHmac();
$merchantSig = \Adyen\Util\Util::calculateSha256Signature($hmacKey, $formFields);
$formFields['merchantSig'] = $merchantSig;

$this->_adyenLogger->addAdyenDebug(print_r($formFields, true));
Expand Down
5 changes: 3 additions & 2 deletions Controller/Process/Json.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function execute()

$notificationMode = isset($notificationItems['live']) ? $notificationItems['live'] : "";

if ($notificationMode != "" && $this->_validateNotificationMode($notificationMode)) {
if ($notificationMode !== "" && $this->_validateNotificationMode($notificationMode)) {
foreach ($notificationItems['notificationItems'] as $notificationItem) {


Expand Down Expand Up @@ -154,7 +154,8 @@ protected function _validateNotificationMode($notificationMode)
{
$mode = $this->_adyenHelper->getAdyenAbstractConfigData('demo_mode');

if (($mode == '1' && $notificationMode == "false") || ($mode == '0' && $notificationMode == 'true')) {
// Notification mode can be a string or a boolean
if (($mode == '1' && ($notificationMode == "false" || $notificationMode == false)) || ($mode == '0' && ($notificationMode == 'true' || $notificationMode == true))) {
return true;
}
return false;
Expand Down
12 changes: 3 additions & 9 deletions Controller/Process/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@ protected function _validateUpdateOrder($order, $response)
*/
protected function _authenticate($response) {

$hmacKey = $this->_adyenHelper->getHmac();
$merchantSigNotification = $response['merchantSig'];

// do it like this because $_GET is converting dot to underscore
Expand All @@ -297,14 +296,9 @@ protected function _authenticate($response) {
// do not include the merchantSig in the merchantSig calculation
unset($result['merchantSig']);

// Sort the array by key using SORT_STRING order
ksort($result, SORT_STRING);

// Generate the signing data string
$signData = implode(":", array_map([$this, 'escapeString'],
array_merge(array_keys($result), array_values($result))));

$merchantSig = base64_encode(hash_hmac('sha256', $signData, pack("H*", $hmacKey), true));
// Sign request using secret key
$hmacKey = $this->_adyenHelper->getHmac();
$merchantSig = \Adyen\Util\Util::calculateSha256Signature($hmacKey, $result);

if (strcmp($merchantSig, $merchantSigNotification) === 0) {
return true;
Expand Down
11 changes: 2 additions & 9 deletions Gateway/Command/PayByMailCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,15 +199,8 @@ protected function getFormFields($payment, $paymentAmount = false)
$formFields['shopperReference'] = $customerId;
}

// Sort the array by key using SORT_STRING order
ksort($formFields, SORT_STRING);

// Generate the signing data string
$signData = implode(":", array_map([$this, 'escapeString'],
array_merge(array_keys($formFields), array_values($formFields))));

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

// Sign request using secret key
$merchantSig = \Adyen\Util\Util::calculateSha256Signature($hmacKey, $formFields);
$formFields['merchantSig'] = $merchantSig;

$this->_adyenLogger->addAdyenDebug(print_r($formFields, true));
Expand Down
42 changes: 39 additions & 3 deletions Model/Cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@ class Cron
*/
protected $_areaList;

/**
* @var \Magento\Sales\Model\ResourceModel\Order\Status\CollectionFactory
*/
protected $_orderStatusCollection;

/**
* Cron constructor.
*
Expand All @@ -203,7 +208,9 @@ class Cron
* @param Api\PaymentRequest $paymentRequest
* @param Order\PaymentFactory $adyenOrderPaymentFactory
* @param ResourceModel\Order\Payment\CollectionFactory $adyenOrderPaymentCollectionFactory
* @param InvoiceFactory $adyenInvoiceFactory
* @param AreaList $areaList
* @param \Magento\Sales\Model\ResourceModel\Order\Status\CollectionFactory $orderStatusCollection
*/
public function __construct(
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
Expand All @@ -220,8 +227,10 @@ public function __construct(
\Adyen\Payment\Model\Order\PaymentFactory $adyenOrderPaymentFactory,
\Adyen\Payment\Model\ResourceModel\Order\Payment\CollectionFactory $adyenOrderPaymentCollectionFactory,
\Adyen\Payment\Model\InvoiceFactory $adyenInvoiceFactory,
AreaList $areaList
) {
AreaList $areaList,
\Magento\Sales\Model\ResourceModel\Order\Status\CollectionFactory $orderStatusCollection
)
{
$this->_scopeConfig = $scopeConfig;
$this->_adyenLogger = $adyenLogger;
$this->_notificationFactory = $notificationFactory;
Expand All @@ -237,6 +246,7 @@ public function __construct(
$this->_adyenOrderPaymentCollectionFactory = $adyenOrderPaymentCollectionFactory;
$this->_adyenInvoiceFactory = $adyenInvoiceFactory;
$this->_areaList = $areaList;
$this->_orderStatusCollection = $orderStatusCollection;
}

/**
Expand Down Expand Up @@ -645,6 +655,8 @@ protected function _updateOrderPaymentWithAdyenAttributes($additionalData)
$acquirerReference = (isset($additionalData['acquirerReference'])) ?
$additionalData['acquirerReference'] : "";
$authCode = (isset($additionalData['authCode'])) ? $additionalData['authCode'] : "";
$cardBin = (isset($additionalData['cardBin'])) ? $additionalData['cardBin'] : "";
$expiryDate = (isset($additionalData['expiryDate'])) ? $additionalData['expiryDate'] : "";
}

// if there is no server communication setup try to get last4 digits from reason field
Expand Down Expand Up @@ -685,6 +697,12 @@ protected function _updateOrderPaymentWithAdyenAttributes($additionalData)
if (isset($authCode) && $authCode != "") {
$this->_order->getPayment()->setAdditionalInformation('adyen_auth_code', $authCode);
}
if (!empty($cardBin)) {
$this->_order->getPayment()->setAdditionalInformation('adyen_card_bin', $cardBin);
}
if (!empty($expiryDate)) {
$this->_order->getPayment()->setAdditionalInformation('adyen_expiry_date', $expiryDate);
}
}

/**
Expand Down Expand Up @@ -1137,6 +1155,8 @@ private function _setPrePaymentAuthorized()
// only do this if status in configuration is set
if (!empty($status)) {
$this->_order->addStatusHistoryComment(__('Payment is authorised waiting for capture'), $status);
$this->_setState($status);

$this->_adyenLogger->addAdyenNotificationCronjob(
'Order status is changed to Pre-authorised status, status is ' . $status
);
Expand Down Expand Up @@ -1594,14 +1614,30 @@ protected function _setPaymentAuthorized($manualReviewComment = true, $createInv
$comment = "Adyen Payment is in Manual Review check the Adyen platform";
}
}

$status = (!empty($status)) ? $status : $this->_order->getStatus();
$this->_order->addStatusHistoryComment(__($comment), $status);
$this->_setState($status);

$this->_adyenLogger->addAdyenNotificationCronjob(
'Order status is changed to authorised status, status is ' . $status
);
}

/**
* Set State from Status
*/

protected function _setState($status)
{
$statusObject = $this->_orderStatusCollection->create()
->addFieldToFilter('main_table.status', $status)
->addFieldToFilter('state_table.is_default', true)
->joinStates()
->getFirstItem();

$this->_order->setState($statusObject->getState());
$this->_adyenLogger->addAdyenNotificationCronjob('State is changed to ' . $statusObject->getState());
}

/**
* Create shipment
Expand Down
17 changes: 15 additions & 2 deletions Test/Unit/Helper/DataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,22 @@ public function setUp()
$assetRepo = $this->getSimpleMock(\Magento\Framework\View\Asset\Repository::class);
$assetSource = $this->getSimpleMock(\Magento\Framework\View\Asset\Source::class);
$notificationFactory = $this->getSimpleMock(\Adyen\Payment\Model\ResourceModel\Notification\CollectionFactory::class);
$taxConfig = $this->getSimpleMock(\Magento\Tax\Model\Config::class);
$taxCalculation = $this->getSimpleMock(\Magento\Tax\Model\Calculation::class);

$this->dataHelper = new \Adyen\Payment\Helper\Data($context, $encryptor, $dataStorage, $country, $moduleList,
$billingAgreementCollectionFactory, $assetRepo, $assetSource, $notificationFactory);
$this->dataHelper = new \Adyen\Payment\Helper\Data(
$context,
$encryptor,
$dataStorage,
$country,
$moduleList,
$billingAgreementCollectionFactory,
$assetRepo,
$assetSource,
$notificationFactory,
$taxConfig,
$taxCalculation
);
}

public function testFormatAmount()
Expand Down
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": "2.3.0",
"version": "2.3.1",
"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="2.3.0">
<module name="Adyen_Payment" setup_version="2.3.1">
<sequence>
<module name="Magento_Sales"/>
<module name="Magento_Quote"/>
Expand Down

0 comments on commit d1635b1

Please sign in to comment.