Skip to content

Commit

Permalink
Merge branch 'hotfix/2.4.11'
Browse files Browse the repository at this point in the history
  • Loading branch information
nabil509 committed Nov 2, 2020
2 parents 316b552 + cad5008 commit c8761f4
Show file tree
Hide file tree
Showing 168 changed files with 315 additions and 213 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function _prepareToRender()
$this->addColumn(
'first',
[
'label' => __('1st payment'),
'label' => __('1st installment'),
'style' => 'width: 70px;'
]
);
Expand Down
4 changes: 2 additions & 2 deletions Block/Adminhtml/System/Config/Form/Field/NotifyUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public function render(\Magento\Framework\Data\Form\Element\AbstractElement $ele
$element->setValue($notifyUrl);

$warnImg = $this->getViewFileUrl('Lyranetwork_Payzen::images/warn.png');
$comment = '<img src="' . $warnImg . '" style="vertical-align: top; padding-right: 5px;"/>';
$comment .= '<span style="color: red; font-weight: bold; display: inline-block; width: 88%;">'
$comment = '<img src="' . $warnImg . '" style="vertical-align: middle; padding-right: 5px; height: 30px;"/>';
$comment .= '<span style="color: red; font-weight: bold; display: inline-block; width: 88%; vertical-align: middle;">'
. $element->getComment() . '</span>';
$element->setComment($comment);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ protected function _toHtml()
$column = $this->getColumn();

$codeInputName = str_replace($this->getColumnName(), 'code', $this->getInputName());
$html = '<input type="text" value="<%- code %>" name="' . $codeInputName . '" style="width: 0px; visibility: hidden;">';
$html = '<input type="hidden" value="<%- code %>" name="' . $codeInputName . '">';

$html .= '<div';
$html .= ' class="' . ($column['class'] ? $column['class'] : 'input-text') . '"';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ protected function _toHtml()
$column = $this->getColumn();

$html = '<select name="' . $this->getInputName() . '"';
$html .= ' class="' . ($column['class'] ? $column['class'] : 'input-text' . '"');
$html .= ' class="' . ($column['class'] ? $column['class'] : 'input-text') . '"';
$html .= $column['style'] ? ' style="' . $column['style'] . '"' : '';
$html .= '>';

foreach ($this->getOptions() as $code => $name) {
$html .= '<option value="' . $code . '"<% if (' . $this->getColumnName() . ' == "' . $code . '") { %> selected="selected"<% } %>>' . __($name) . '</option>';
$html .= '<option value="' . $code . '"<% if (typeof ' . $this->getColumnName() . ' != "undefined" && '
. $this->getColumnName() . ' == "' . $code . '") { %> selected="selected"<% } %>>' . __($name) . '</option>';
}

$html .= '</select>';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ protected function _toHtml()

$html .= '/>';

$src = $store->getBaseUrl(UrlInterface::URL_TYPE_MEDIA) . 'payzen/images/cc/<%- logo %>?' . time();
$image = '<% if (typeof logo != "undefined" && logo) { %><%- logo %><% } else { %><%- code.toLowerCase() %>.png<% } %>';
$src = $store->getBaseUrl(UrlInterface::URL_TYPE_MEDIA) . "payzen/images/cc/$image?" . time();
$html .= '<img style="margin-left: 10px; vertical-align: middle; height: 18px;" alt="<%- code %>" src="' . $src . '" title="<%- name %>" >';

$html .= '</div>';
Expand Down
23 changes: 10 additions & 13 deletions Block/Payment/Info.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,8 @@ public function getPaymentDetailsHtml($backend = true)
}

$html .= '<b>' . __('Expiration Date') . ': </b>' . $expiry;
}

$html .= '<br />';

$html .= '<b>' . __('3DS Authentication') . ': </b>';
if ($payment->getCcSecureVerify()) {
$html .= __('YES');
$html .= '<br />';
$html .= '<b>' . __('3DS Certificate') . ': </b>' . $payment->getCcSecureVerify();
} else {
$html .= __('NO');
$html .= '<hr />';
}

return $html;
Expand All @@ -151,14 +142,18 @@ public function getMultiPaymentDetailsHtml($backend = true)
$sequenceNumber = substr($item->getTxnId(), strpos($item->getTxnId(), '-') + 1);

$html .= '<b>' . __('Sequence Number') . ': </b>' . $sequenceNumber;
$html .= '<br />';

$info = $item->getAdditionalInformation(\Magento\Sales\Model\Order\Payment\Transaction::RAW_DETAILS);
foreach ($info as $key => $value) {
if (! $backend && in_array($key, ['Card Number', 'Expiration Date'])) {
continue;
}

if (! $value) {
continue;
}

$html .= '<br />';
$html .= '<b>' . __($key) . ': </b>' . $value;

if ($backend && ($key === 'Means of payment') && isset($userChoice[$sequenceNumber])) {
Expand All @@ -168,11 +163,13 @@ public function getMultiPaymentDetailsHtml($backend = true)
$html .= ' ' . __('(default card brand used)');
}
}

$html .= '<br />';
}
}

if ($backend) {
$html .= '<hr />';
}

return $html;
}

Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2.4.11: 2020-11-02:
- [embedded] Bug fix: Display 3DS result for REST API payments.
- Bug fix: Do not re-create invoice if it already exists.
- Some minor fixes relative to configuration screen.

2.4.10: 2020-10-06:
- [fullcb] Bug fix: Error when trying to pay with Full CB if payment options selection is disabled.
- Update payment means list.
Expand Down
2 changes: 1 addition & 1 deletion Controller/Adminhtml/Payment/Check.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function execute()

$case = $this->checkProcessor->execute($order, $response);
return $this->renderResponse($response->getOutputForGateway($case));
} catch (ResponseException $e) {
} catch (\Lyranetwork\Payzen\Model\ResponseException $e) {
return $this->renderResponse($e->getMessage());
}
}
Expand Down
3 changes: 1 addition & 2 deletions Controller/Adminhtml/Payment/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
namespace Lyranetwork\Payzen\Controller\Adminhtml\Payment;

use Lyranetwork\Payzen\Helper\Payment;
use Lyranetwork\Payzen\Model\ResponseException;

class Response extends \Magento\Backend\App\Action
{
Expand Down Expand Up @@ -53,7 +52,7 @@ public function execute()
$result = $this->responseProcessor->execute($order, $response);

return $this->redirectResponse($order, $result['case'], $result['warn']);
} catch (ResponseException $e) {
} catch (\Lyranetwork\Payzen\Model\ResponseException $e) {
$this->dataHelper->log($e->getMessage(), \Psr\Log\LogLevel::ERROR);
return $this->redirectError($order);
}
Expand Down
3 changes: 3 additions & 0 deletions Controller/Adminhtml/System/Config/Reset.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public function __construct(

public function execute()
{
// Clear all messages in session.
$this->messageManager->getMessages(true);

// Retrieve write connection.
$connection = $this->resourceConfig->getConnection();

Expand Down
4 changes: 1 addition & 3 deletions Controller/Payment/Check.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
*/
namespace Lyranetwork\Payzen\Controller\Payment;

use Lyranetwork\Payzen\Model\ResponseException;

class Check extends \Magento\Framework\App\Action\Action
{
/**
Expand Down Expand Up @@ -57,7 +55,7 @@ public function execute()

$case = $this->checkProcessor->execute($order, $response);
return $this->renderResponse($response->getOutputForGateway($case));
} catch (ResponseException $e) {
} catch (\Lyranetwork\Payzen\Model\ResponseException $e) {
return $this->renderResponse($e->getMessage());
}
}
Expand Down
3 changes: 1 addition & 2 deletions Controller/Payment/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
namespace Lyranetwork\Payzen\Controller\Payment;

use Lyranetwork\Payzen\Helper\Payment;
use Lyranetwork\Payzen\Model\ResponseException;

class Response extends \Magento\Framework\App\Action\Action
{
Expand Down Expand Up @@ -74,7 +73,7 @@ public function execute()
$result = $this->responseProcessor->execute($order, $response);

return $this->redirectResponse($order, $result['case'], $result['warn']);
} catch (ResponseException $e) {
} catch (\Lyranetwork\Payzen\Model\ResponseException $e) {
$this->dataHelper->log($e->getMessage(), \Psr\Log\LogLevel::ERROR);
return $this->redirectError($order);
}
Expand Down
74 changes: 63 additions & 11 deletions Helper/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,22 @@ public function updatePaymentInfo(\Magento\Sales\Model\Order $order, \Lyranetwor
$order->getPayment()->setAdditionalInformation(\Lyranetwork\Payzen\Helper\Payment::REST_ERROR_MESSAGE, $restErrorMsg);
}

// 3DS authentication result.
$threedsCavv = '';
$threedsStatus = '';
$threedsAuthType = '';
if ($status = $response->get('threeds_status')) {
$threedsStatus = $this->getThreedsStatus($status);
$threedsCavv = $response->get('threeds_cavv');
$threedsAuthType = $response->get('threeds_auth_type');
}

// Save payment infos to sales_flat_order_payment.
$order->getPayment()
->setCcSecureVerify($threedsCavv)
->setAdditionalInformation('threeds_status', $threedsStatus)
->setAdditionalInformation('threeds_auth_type', $threedsAuthType);


if ($response->isCancelledPayment()) {
// No more data to save.
Expand Down Expand Up @@ -296,7 +312,7 @@ public function updatePaymentInfo(\Magento\Sales\Model\Order $order, \Lyranetwor
// Set is_fraud_detected flag.
$order->getPayment()->setIsFraudDetected($response->isSuspectedFraud());

if ($response->get('card_brand') == 'MULTI') { // Multi brand.
if ($response->get('card_brand') === 'MULTI') { // Multi brand.
$data = json_decode($response->get('payment_seq'));
$transactions = $data->{'transactions'};

Expand Down Expand Up @@ -342,18 +358,11 @@ public function updatePaymentInfo(\Magento\Sales\Model\Order $order, \Lyranetwor

$order->getPayment()->setAdditionalInformation(\Lyranetwork\Payzen\Helper\Payment::BRAND_USER_CHOICE, $userChoice);
} else {
// 3DS authentication result.
$threedsCavv = '';
if (in_array($response->get('threeds_status'), array('Y', 'YES'))) {
$threedsCavv = $response->get('threeds_cavv');
}

// Save payment infos to sales_flat_order_payment.
$order->getPayment()
->setCcExpMonth($response->get('expiry_month'))
->setCcExpYear($response->get('expiry_year'))
->setCcNumberEnc($response->get('card_number'))
->setCcSecureVerify($threedsCavv);
->setCcNumberEnc($response->get('card_number'));

// Save transaction details to sales_payment_transaction.
$expiry = '';
Expand Down Expand Up @@ -438,7 +447,9 @@ public function updatePaymentInfo(\Magento\Sales\Model\Order $order, \Lyranetwor
'Means of payment' => $response->get('card_brand'),
'Card Number' => $response->get('card_number'),
'Expiration Date' => $expiry,
'3DS Certificate' => $threedsCavv
'3DS Authentication' => $threedsStatus,
'3DS Certificate' => $threedsCavv,
'Authentication Type' => $threedsAuthType
];

$this->addTransaction($order->getPayment(), $transactionType, $transactionId, $additionalInfo);
Expand Down Expand Up @@ -479,7 +490,9 @@ public function updatePaymentInfo(\Magento\Sales\Model\Order $order, \Lyranetwor
'Means of payment' => $response->get('card_brand'),
'Card Number' => $response->get('card_number'),
'Expiration Date' => $expiry,
'3DS Certificate' => $threedsCavv
'3DS Authentication' => $threedsStatus,
'3DS Certificate' => $threedsCavv,
'Authentication Type' => $threedsAuthType
];

$this->addTransaction($order->getPayment(), $transactionType, $transactionId, $additionalInfo);
Expand All @@ -492,6 +505,26 @@ public function updatePaymentInfo(\Magento\Sales\Model\Order $order, \Lyranetwor
->setSkipTransactionCreation(true);
}

private function getThreedsStatus($status)
{
switch ($status) {
case 'Y':
return 'SUCCESS';

case 'N':
return 'FAILED';

case 'U':
return 'UNAVAILABLE';

case 'A':
return 'ATTEMPT';

default :
return $status;
}
}

public function saveIdentifier(
\Magento\Sales\Model\Order $order,
\Lyranetwork\Payzen\Model\Api\PayzenResponse $response
Expand Down Expand Up @@ -614,6 +647,25 @@ public function createInvoice(\Magento\Sales\Model\Order $order)
return;
}

// Check if an invoice already exists for this order.
if ($order->hasInvoices()) {
$alreadyInvoiced = false;
$transId = $order->getPayment()->getLastTransId();

$invoices = $order->getInvoiceCollection();
foreach ($invoices as $invoice) {
if ($invoice->getTransactionId() === $transId) {
$alreadyInvoiced = true;
break;
}
}

if ($alreadyInvoiced) {
$this->dataHelper->log("Invoice already exists for order #{$order->getIncrementId()} with transaction ID #{$transId}.");
return;
}
}

$this->dataHelper->log("Creating invoice for order #{$order->getIncrementId()}.");

// Convert order to invoice.
Expand Down
2 changes: 1 addition & 1 deletion Helper/Payment/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function getPaymentMethods()

$methods[$code] = [
'model' => $config['value'],
'title' => $payzenMultiTitle . " ($count)",
'title' => "$payzenMultiTitle ($count)",
'group' => 'payzen'
];
}
Expand Down
16 changes: 12 additions & 4 deletions Helper/Rest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,18 @@ public function convertRestResult($answer)
$response['vads_auth_result'] = $this->getProperty($authorizationResponse, 'authorizationResult');
}

if (($threeDSResponse = $this->getProperty($cardDetails, 'threeDSResponse'))
&& ($authenticationResultData = $this->getProperty($threeDSResponse, 'authenticationResultData'))) {
$response['vads_threeds_cavv'] = $this->getProperty($authenticationResultData, 'cavv');
$response['vads_threeds_status'] = $this->getProperty($authenticationResultData, 'status');
if (($authenticationResponse = self::getProperty($cardDetails, 'authenticationResponse'))
&& ($value = self::getProperty($authenticationResponse, 'value'))) {
$response['vads_threeds_status'] = self::getProperty($value, 'status');
$response['vads_threeds_auth_type'] = self::getProperty($value, 'authenticationType');
if ($authenticationValue = self::getProperty($value, 'authenticationValue')) {
$response['vads_threeds_cavv'] = self::getProperty($authenticationValue, 'value');
}
} elseif (($threeDSResponse = self::getProperty($cardDetails, 'threeDSResponse'))
&& ($authenticationResultData = self::getProperty($threeDSResponse, 'authenticationResultData'))) {
$response['vads_threeds_cavv'] = self::getProperty($authenticationResultData, 'cavv');
$response['vads_threeds_status'] = self::getProperty($authenticationResultData, 'status');
$response['vads_threeds_auth_type'] = self::getProperty($authenticationResultData, 'threeds_auth_type');
}
}

Expand Down
2 changes: 1 addition & 1 deletion Model/Api/Ws/AuthenticationRequestData.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* PayZen V2-Payment Module version 2.4.10 for Magento 2.x. Support contact : [email protected].
* PayZen V2-Payment Module version 2.4.11 for Magento 2.x. Support contact : [email protected].
*
* @category Payment
* @package Payzen
Expand Down
2 changes: 1 addition & 1 deletion Model/Api/Ws/AuthenticationResultData.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* PayZen V2-Payment Module version 2.4.10 for Magento 2.x. Support contact : [email protected].
* PayZen V2-Payment Module version 2.4.11 for Magento 2.x. Support contact : [email protected].
*
* @category Payment
* @package Payzen
Expand Down
2 changes: 1 addition & 1 deletion Model/Api/Ws/AuthorizationResponse.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* PayZen V2-Payment Module version 2.4.10 for Magento 2.x. Support contact : [email protected].
* PayZen V2-Payment Module version 2.4.11 for Magento 2.x. Support contact : [email protected].
*
* @category Payment
* @package Payzen
Expand Down
2 changes: 1 addition & 1 deletion Model/Api/Ws/BillingDetailsRequest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* PayZen V2-Payment Module version 2.4.10 for Magento 2.x. Support contact : [email protected].
* PayZen V2-Payment Module version 2.4.11 for Magento 2.x. Support contact : [email protected].
*
* @category Payment
* @package Payzen
Expand Down
2 changes: 1 addition & 1 deletion Model/Api/Ws/BillingDetailsResponse.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* PayZen V2-Payment Module version 2.4.10 for Magento 2.x. Support contact : [email protected].
* PayZen V2-Payment Module version 2.4.11 for Magento 2.x. Support contact : [email protected].
*
* @category Payment
* @package Payzen
Expand Down
2 changes: 1 addition & 1 deletion Model/Api/Ws/CancelCapturedPayment.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* PayZen V2-Payment Module version 2.4.10 for Magento 2.x. Support contact : [email protected].
* PayZen V2-Payment Module version 2.4.11 for Magento 2.x. Support contact : [email protected].
*
* @category Payment
* @package Payzen
Expand Down
Loading

0 comments on commit c8761f4

Please sign in to comment.