Skip to content

Commit

Permalink
[BOT] Migrate hotfix 1.11.4 to GitHub.
Browse files Browse the repository at this point in the history
  • Loading branch information
nabil509 committed Nov 6, 2020
1 parent e1e0906 commit 9f002db
Show file tree
Hide file tree
Showing 170 changed files with 419 additions and 295 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
1.11.4, 2020-11-06:
- [embedded] Bug fix: Force redirection when there is an error in payment form token creation.
- [embedded] Bug fix: Display 3DS results for REST API payments.
- [embedded] Bug fix: Empty cart to avoid double payments with REST API.
- [embedded] Bug fix: Embedded payment fields not correctly displayed since the last gateway JS library delivery.
- Bug fix: Do not re-create invoice if it already exists.
- Some minor fixes relative to plugin configuration update.

1.11.3, 2020-10-14:
- [oney] Do not display payment installments for buyer.
- Update payment means list.

1.11.2, 2020-08-19:
- [embedded] Bug fix: Do not cancel orders in status "Fraud suspected" when new IPN calls are made.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ protected function _getAllCategories()
protected function _toHtml()
{
$script = '<script type="text/javascript">
//<![CDATA[
document.observe("dom:loaded", function() {
$$("select.payzen_list_payzen_category").each(function(elt) {
var value = elt.readAttribute("currentvalue");
Expand All @@ -143,7 +142,6 @@ protected function _toHtml()

$script .= '
});
//]]>
</script>';

return parent::_toHtml() . "\n" . $script;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ protected function _toHtml()
if ($this->getElement()->getCanUseWebsiteValue() || $this->getElement()->getCanUseDefaultValue()) {
$script .= '
<script type="text/javascript">
//<![CDATA[
document.observe("dom:loaded", function() {';

if ($this->getElement()->getDisabled()) {
Expand All @@ -93,7 +92,6 @@ protected function _toHtml()
);
});
});
//]]>
</script>';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ public function yesno()
protected function _toHtml()
{
$script = '<script type="text/javascript">
//<![CDATA[
document.observe("dom:loaded", function() {
$$("select.payzen_list_means, select.payzen_list_validation_mode, select.payzen_list_cart_data").each(function(elt) {
var value = elt.readAttribute("currentvalue") || elt.readAttribute("defaultvalue");
Expand All @@ -171,7 +170,6 @@ protected function _toHtml()
}
});
});
//]]>
</script>';

return parent::_toHtml() . "\n" . $script;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ protected function _getAllShippingMethods()
protected function _toHtml()
{
$script = '<script type="text/javascript">
//<![CDATA[
document.observe("dom:loaded", function() {
$$(
"select.payzen_list_type",
Expand Down Expand Up @@ -232,7 +231,6 @@ protected function _toHtml()
}
});
});
//]]>
</script>';

return parent::_toHtml() . "\n" . $script;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,13 @@ private function _getScript(Varien_Data_Form_Element_Abstract $element)

$script = '';
$script .= '<script type="text/javascript">
// <![CDATA[
function payzenSubSectionToggle() {';

foreach ($fields as $field) {
$script .= ' $("' . $prefix . $field . '").toggle();' . "\n";
}

$script .= ' }
//]]>
</script>';

return $script;
Expand Down
2 changes: 1 addition & 1 deletion app/code/community/Lyranetwork/Payzen/Block/Info.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function getTransactionInfoHtml($front = false)

$html = '';

$frontInfos = array('Transaction Type', 'Amount', 'Transaction ID', 'Transaction UUID', 'Means of Payment', '3DS Authentication');
$frontInfos = array('Transaction Type', 'Amount', 'Transaction ID', 'Transaction UUID', 'Means of Payment');

foreach ($collection as $item) {
$html .= '<hr />';
Expand Down
3 changes: 2 additions & 1 deletion app/code/community/Lyranetwork/Payzen/Block/Review.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ protected function _isIframeMode()
protected function _isRestMode()
{
$check = ($this->_getMethodInstance() instanceof Lyranetwork_Payzen_Model_Payment_Standard)
&& $this->_getMethodInstance()->getConfigData('card_info_mode') == '4';
&& ($this->_getMethodInstance()->getConfigData('card_info_mode') == '4')
&& $this->_getMethodInstance()->getFormToken(false);

return $check;
}
Expand Down
10 changes: 4 additions & 6 deletions app/code/community/Lyranetwork/Payzen/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@

class Lyranetwork_Payzen_Helper_Data extends Mage_Core_Helper_Abstract
{

/**
*
* @var array a global var to easily enable/disable features
*/
public static $pluginFeatures = array(
Expand Down Expand Up @@ -90,8 +88,8 @@ public function getConfigGroupTitle($group)
{
// Get group title.
$config = Mage::getModel('core/config_base');
$config->loadFile(Mage::getConfig()->getModuleDir('etc', 'Lyranetwork_Payzen').DS.'system.xml');
$node = $config->getNode('sections/payment/groups/'.$group);
$config->loadFile(Mage::getConfig()->getModuleDir('etc', 'Lyranetwork_Payzen') . DS . 'system.xml');
$node = $config->getNode('sections/payment/groups/' . $group);

return Mage::helper('payzen')->__((string) $node->label);
}
Expand Down Expand Up @@ -207,7 +205,7 @@ public function getReviewState()
if (defined('Mage_Sales_Model_Order::STATE_PAYMENT_REVIEW')) {
return Mage_Sales_Model_Order::STATE_PAYMENT_REVIEW;
} else {
// For magento 1.4.0.x
// For magento 1.4.0.x.
return 'payment_review';
}
}
Expand Down Expand Up @@ -247,7 +245,7 @@ public function log($message, $level = null)
$currentMethod = $this->_getCallerMethod();

$log = '';
$log .= 'PayZen '. $this->getCommonConfigData('plugin_version');
$log .= 'PayZen ' . $this->getCommonConfigData('plugin_version');
$log .= ' - ' . $currentMethod;
$log .= ' : ' . $message;

Expand Down
119 changes: 85 additions & 34 deletions app/code/community/Lyranetwork/Payzen/Helper/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public function doPaymentForm($controller)
// Clear quote data.
$controller->getCheckout()->setQuoteId(null);
$controller->getCheckout()->setLastSuccessQuoteId(null);
$controller->getCheckout()->unsPayzenForceRedirection();

// Inactivate quote.
$quote = Mage::getModel('sales/quote')->load($order->getQuoteId());
Expand Down Expand Up @@ -160,7 +161,7 @@ public function doPaymentReturn($controller)
// Display success page.
$controller->redirectResponse($order, self::SUCCESS, true /* IPN URL warn in TEST mode */);
} else {
$this->_getHelper()->log("Payment for order #{$order->getIncrementId()} has failed.");
$this->_getHelper()->log("Payment for order #{$order->getIncrementId()} has been refused/cancelled.");

// Cancel order.
$this->_cancelOrder($order, $response);
Expand Down Expand Up @@ -197,10 +198,9 @@ public function doPaymentReturn($controller)
$controller->redirectResponse($order, $case);
} else {
// This is an error case, the client returns with an error but the payment already has been accepted.
$this->_getHelper()->log(
"Order #{$order->getIncrementId()} has been validated but we receive a payment error code!",
Zend_Log::ERR
);
$msg = "Invalid payment result received for already saved order #{$order->getIncrementId()}.";
$msg .= " Payment result : {$response->getTransStatus()}, Order status : {$order->getStatus()}.";
$this->_getHelper()->log($msg, Zend_Log::ERR);
$controller->redirectError($order);
}
}
Expand Down Expand Up @@ -272,7 +272,7 @@ public function doPaymentCheck($controller)
}
} else {
$this->_getHelper()->log(
"Payment for order #{$order->getIncrementId()} has been invalidated by notification URL."
"Payment for order #{$order->getIncrementId()} has been refused/cancelled by notification URL."
);

// Cancel order.
Expand Down Expand Up @@ -351,10 +351,9 @@ public function doPaymentCheck($controller)
$controller->getResponse()->setBody($response->getOutputForPlatform('payment_ko_already_done'));
} else {
// This is an error case, the client returns with an error but the payment already has been accepted.
$this->_getHelper()->log(
"Order #{$order->getIncrementId()} has been validated but we receive a payment error code!",
Zend_Log::ERR
);
$msg = "Invalid payment result received for already saved order #{$order->getIncrementId()}.";
$msg .= " Payment result : {$response->getTransStatus()}, Order status : {$order->getStatus()}.";
$this->_getHelper()->log($msg, Zend_Log::ERR);
$controller->getResponse()->setBody($response->getOutputForPlatform('payment_ko_on_order_ok'));
}
}
Expand Down Expand Up @@ -422,7 +421,7 @@ public function doPaymentRestReturn($controller)

$quote->setIsActive(false)->save();

$this->_getHelper()->log("Request authenticated for quote #{$quote->getId()}.");
$this->_getHelper()->log("Request authenticated for quote #{$quote->getId()}, reserved order ID: #{$quote->getReservedOrderId()}.");

$order = Mage::getModel('sales/order');
$order->loadByIncrementId($quote->getReservedOrderId());
Expand Down Expand Up @@ -457,7 +456,7 @@ public function doPaymentRestReturn($controller)
// Display success page.
$controller->redirectResponse($order, self::SUCCESS, true /* IPN URL warn in TEST mode */);
} else {
$this->_getHelper()->log("Payment for order #{$order->getIncrementId()} has failed.");
$this->_getHelper()->log("Payment for order #{$order->getIncrementId()} has been refused/cancelled.");

// Cancel order.
$this->_cancelOrder($order, $response);
Expand Down Expand Up @@ -491,10 +490,9 @@ public function doPaymentRestReturn($controller)
$controller->redirectResponse($order, $case);
} else {
// This is an error case, the client returns with an error but the payment already has been accepted.
$this->_getHelper()->log(
"Order #{$order->getIncrementId()} has been validated but we receive a payment error code!",
Zend_Log::ERR
);
$msg = "Invalid payment result received for already saved order #{$order->getIncrementId()}.";
$msg .= " Payment result : {$response->getTransStatus()}, Order status : {$order->getStatus()}.";
$this->_getHelper()->log($msg, Zend_Log::ERR);
$controller->redirectError($order);
}
}
Expand Down Expand Up @@ -554,8 +552,9 @@ public function doPaymentRestCheck($controller)

// Case of failure when retries are enabled, do nothing before last attempt.
if (! $response->isAcceptedPayment() && ($answer['orderCycle'] !== 'CLOSED')) {
$this->_getHelper()->log("Payment is not accepted but buyer can try to re-order. Do not create order at this time. Quote ID: #{$quoteId},
reserved order ID: #{$quote->getReservedOrderId()}.");
$msg = 'Payment is not accepted but buyer can try to re-order. Do not create order at this time.';
$msg .= " Quote ID: #{$quoteId}, reserved order ID: #{$quote->getReservedOrderId()}.";
$this->_getHelper()->log($msg);
$controller->getResponse()->setBody($response->getOutputForPlatform('payment_ko_bis'));
return;
}
Expand Down Expand Up @@ -609,7 +608,7 @@ public function doPaymentRestCheck($controller)
}
} else {
$this->_getHelper()->log(
"Payment for order #{$order->getIncrementId()} has been invalidated by notification URL."
"Payment for order #{$order->getIncrementId()} has been refused/cancelled by notification URL."
);

// Cancel order.
Expand Down Expand Up @@ -640,10 +639,9 @@ public function doPaymentRestCheck($controller)
$controller->getResponse()->setBody($response->getOutputForPlatform('payment_ko_already_done'));
} else {
// This is an error case, the client returns with an error but the payment already has been accepted.
$this->_getHelper()->log(
"Order #{$order->getIncrementId()} has been validated but we receive a payment error code!",
Zend_Log::ERR
);
$msg = "Invalid payment result received for already saved order #{$order->getIncrementId()}.";
$msg .= " Payment result : {$response->getTransStatus()}, Order status : {$order->getStatus()}.";
$this->_getHelper()->log($msg, Zend_Log::ERR);
$controller->getResponse()->setBody($response->getOutputForPlatform('payment_ko_on_order_ok'));
}
}
Expand Down Expand Up @@ -730,6 +728,22 @@ public function updatePaymentInfo(Mage_Sales_Model_Order $order, $response)
->setAdditionalInformation(self::ALL_RESULTS, serialize($response->getAllResults()))
->setAdditionalInformation(self::TRANS_UUID, $response->get('trans_uuid'));

// 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.
return;
Expand Down Expand Up @@ -796,17 +810,11 @@ public function updatePaymentInfo(Mage_Sales_Model_Order $order, $response)
}
}
} 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'))
$order->getPayment()
->setCcExpMonth($response->get('expiry_month'))
->setCcExpYear($response->get('expiry_year'))
->setCcNumberEnc($response->get('card_number'))
->setCcSecureVerify($threedsCavv);
->setCcNumberEnc($response->get('card_number'));

// Format card expiration data.
$expiry = '';
Expand Down Expand Up @@ -887,7 +895,9 @@ public function updatePaymentInfo(Mage_Sales_Model_Order $order, $response)
'Means of Payment' => $response->get('card_brand'),
'Card Number' => $response->get('card_number'),
'Expiration Date' => $expiry,
'3DS Authentication' => $threedsCavv
'3DS Authentication' => $threedsStatus,
'3DS Certificate' => $threedsCavv,
'Authentication Type' => $threedsAuthType
);

if ($transactionType) {
Expand Down Expand Up @@ -925,7 +935,9 @@ public function updatePaymentInfo(Mage_Sales_Model_Order $order, $response)
'Means of Payment' => $response->get('card_brand'),
'Card Number' => $response->get('card_number'),
'Expiration Date' => $expiry,
'3DS Authentication' => $threedsCavv
'3DS Authentication' => $threedsStatus,
'3DS Certificate' => $threedsCavv,
'Authentication Type' => $threedsAuthType
);

if ($transactionType) {
Expand All @@ -938,6 +950,26 @@ public function updatePaymentInfo(Mage_Sales_Model_Order $order, $response)
$order->getPayment()->setTransactionId(null)->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;
}
}

private function _saveIdentifier(Mage_Sales_Model_Order $order, Lyranetwork_Payzen_Model_Api_Response $response)
{
if (! $order->getCustomerId()) {
Expand Down Expand Up @@ -1038,6 +1070,25 @@ public function createInvoice(Mage_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->_getHelper()->log("Invoice already exists for order #{$order->getIncrementId()} with transaction ID #{$transId}.");
return;
}
}

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

// Convert order to invoice.
Expand Down
Loading

0 comments on commit 9f002db

Please sign in to comment.