Skip to content

Commit

Permalink
Merge branch 'release/1.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Alima Grine committed Nov 22, 2024
2 parents 4162b20 + d20740b commit aa613ea
Show file tree
Hide file tree
Showing 38 changed files with 3,589 additions and 271 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
1.1.0, 2024-11-22:
- Added compatibility with OpenMage and PHP latest versions.
- [technical] Enabled some features by plugin variant.
- Improve refund management.
- Update payment method default logo.
- Update list of supported payment means.
- Update list of supported currencies.
- Set return mode to POST by default.

1.0.0, 2021-07-13:
- Initial plugin version compatible with OpenMage 19 and 20.
2 changes: 1 addition & 1 deletion COPYING.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright © 2021 Lyra Network.
Copyright © 2021-2024 Lyra Network.

PayZen plugin for OpenMage is licensed under the
Open Software License version 3.0 that is bundled with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

use Lyranetwork\Payzen\Model\Api\Form\Api as PayzenApi;

/**
* Custom renderer for the contact us element.
*/
Expand All @@ -21,7 +23,7 @@ class Lyranetwork_Payzen_Block_Adminhtml_System_Config_Field_ContactUs extends M
*/
public function render(Varien_Data_Form_Element_Abstract $element)
{
$comment = Lyranetwork_Payzen_Model_Api_Api::formatSupportEmails('[email protected]');
$comment = PayzenApi::formatSupportEmails('[email protected]');
$element->setComment($comment);

return parent::render($element);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

use Lyranetwork\Payzen\Model\Api\Form\Api as PayzenApi;

/**
* Custom renderer for the multi payment options field.
*/
Expand Down Expand Up @@ -38,7 +40,7 @@ public function __construct()
)
);

$cards = Lyranetwork_Payzen_Model_Api_Api::getSupportedCardTypes();
$cards = PayzenApi::getSupportedCardTypes();
if (isset($cards['CB'])) {
// If CB is available, we allow contract override.
$this->addColumn(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

use Lyranetwork\Payzen\Model\Api\Form\Api as PayzenApi;

/**
* Custom renderer for the other payment means field.
*/
Expand All @@ -24,7 +26,7 @@ public function __construct()
)
);

$defaultCards = Lyranetwork_Payzen_Model_Api_Api::getSupportedCardTypes();
$defaultCards = PayzenApi::getSupportedCardTypes();
$addedCards = Mage::getModel('payzen/payment_other')->getAddedMeans();

$cards = array_merge ($defaultCards, $addedCards);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
/**
* Copyright © Lyra Network.
* This file is part of PayZen plugin for OpenMage. See COPYING.md for license details.
*
* @author Lyra Network (https://www.lyra.com/)
* @copyright Lyra Network
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

use Lyranetwork\Payzen\Model\Api\Form\Api as PayzenApi;

/**
* Custom renderer for the plugin documentation element.
*/
class Lyranetwork_Payzen_Block_Adminhtml_System_Config_Field_PluginDoc extends Mage_Adminhtml_Block_System_Config_Form_Field
{
/**
* Render field HTML.
*
* @param Varien_Data_Form_Element_Abstract $element
*
* @return string
*/
public function render(Varien_Data_Form_Element_Abstract $element)
{
// Get documentation links.
$languages = array(
'fr' => 'Français',
'en' => 'English',
'es' => 'Español',
'pt' => 'Português'
// Complete when other languages are managed.
);

$docs = "";
foreach (PayzenApi::getOnlineDocUri() as $lang => $docUri) {
$docs .= '<a style="margin-left: 10px; text-decoration: none; text-transform: uppercase;" href="' . $docUri . 'openmage/sitemap.html" target="_blank">' . $languages[$lang] . '</a>';
}

$element->setComment($docs);

return parent::render($element);
}
}
6 changes: 4 additions & 2 deletions app/code/community/Lyranetwork/Payzen/Block/Info.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

use Lyranetwork\Payzen\Model\Api\Form\Response as PayzenResponse;

class Lyranetwork_Payzen_Block_Info extends Mage_Payment_Block_Info
{
protected function _construct()
Expand Down Expand Up @@ -80,7 +82,7 @@ public function getResultDescription()
}

if ($key === 'result' && $allResults[$key] === '30') { // Append form error if any.
$label .= ' ' . Lyranetwork_Payzen_Model_Api_Response::extraMessage($allResults['extra_result']);
$label .= ' ' . PayzenResponse::extraMessage($allResults['extra_result']);
}

$labels[] = $label;
Expand All @@ -92,6 +94,6 @@ public function getResultDescription()
public function translate($code, $type, $appendCode = false)
{
$lang = strtolower(substr(Mage::app()->getLocale()->getLocaleCode(), 0, 2));
return Lyranetwork_Payzen_Model_Api_Response::translate($code, $type, $lang, $appendCode);
return PayzenResponse::translate($code, $type, $lang, $appendCode);
}
}
48 changes: 26 additions & 22 deletions app/code/community/Lyranetwork/Payzen/Helper/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

use Lyranetwork\Payzen\Model\Api\Form\Api as PayzenApi;
use Lyranetwork\Payzen\Model\Api\Rest\Api as PayzenRest;
use Lyranetwork\Payzen\Model\Api\Form\Response as PayzenResponse;

class Lyranetwork_Payzen_Helper_Payment extends Mage_Core_Helper_Abstract
{
const IDENTIFIER = 'payzen_identifier'; // Key to save if payment is by identifier.
Expand Down Expand Up @@ -108,7 +112,7 @@ public function doPaymentReturn($controller)
$storeId = $order->getStore()->getId();

// Load API response.
$response = new Lyranetwork_Payzen_Model_Api_Response(
$response = new PayzenResponse(
$request,
$this->_getHelper()->getCommonConfigData('ctx_mode', $storeId),
$this->_getHelper()->getCommonConfigData('key_test', $storeId),
Expand Down Expand Up @@ -227,7 +231,7 @@ public function doPaymentCheck($controller)
Mage::app()->init($storeId, 'store');

// Load API response.
$response = new Lyranetwork_Payzen_Model_Api_Response(
$response = new PayzenResponse(
$post,
$this->_getHelper()->getCommonConfigData('ctx_mode', $storeId),
$this->_getHelper()->getCommonConfigData('key_test', $storeId),
Expand Down Expand Up @@ -311,13 +315,13 @@ public function doPaymentCheck($controller)
$transactionId = $response->get('trans_id') . '-' . $response->get('sequence_number');

// Save paid amount.
$currency = Lyranetwork_Payzen_Model_Api_Api::findCurrencyByNumCode($response->get('currency'));
$currency = PayzenApi::findCurrencyByNumCode($response->get('currency'));
$amount = number_format($currency->convertAmountToFloat($response->get('amount')), $currency->getDecimals(), ',', ' ');

$amountDetail = $amount . ' ' . $currency->getAlpha3();

if ($response->get('effective_currency') && ($response->get('currency') !== $response->get('effective_currency'))) {
$effectiveCurrency = Lyranetwork_Payzen_Model_Api_Api::findCurrencyByNumCode($response->get('effective_currency'));
$effectiveCurrency = PayzenApi::findCurrencyByNumCode($response->get('effective_currency'));

$effectiveAmount = number_format(
$effectiveCurrency->convertAmountToFloat($response->get('effective_amount')),
Expand Down Expand Up @@ -390,8 +394,8 @@ public function doPaymentRestReturn($controller)
// Wrap payment result to use traditional order creation tunnel.
$data = $this->_getRestHelper()->convertRestResult($answer);

/** @var Lyranetwork_Payzen_Model_Api_Response $response */
$response = new Lyranetwork_Payzen_Model_Api_Response($data, null, null, null);
/** @var PayzenResponse $response */
$response = new PayzenResponse($data, null, null, null);

$quoteId = (int) $response->getExtInfo('quote_id'); // Quote ID is sent to platform as ext_info.
$quote = Mage::getModel('sales/quote');
Expand Down Expand Up @@ -530,7 +534,7 @@ public function doPaymentRestCheck($controller)

// Wrap payment result to use traditional order creation tunnel.
$data = $this->_getRestHelper()->convertRestResult($answer);
$response = new Lyranetwork_Payzen_Model_Api_Response($data, null, null, null);
$response = new PayzenResponse($data, null, null, null);

$quoteId = (int) $response->getExtInfo('quote_id'); // Quote ID is sent to platform as ext_info.
$quote = Mage::getModel('sales/quote');
Expand Down Expand Up @@ -678,7 +682,7 @@ public function deleteIdentifier($attribute, $maskedAttribute)
);

// Perform REST request to cancel identifier.
$client = new Lyranetwork_Payzen_Model_Api_Rest(
$client = new PayzenRest(
$this->_getHelper()->getCommonConfigData('rest_url'),
$this->_getHelper()->getCommonConfigData('site_id'),
$this->_getRestHelper()->getPassword()
Expand Down Expand Up @@ -729,7 +733,7 @@ private function deleteIdentifierAttribute($customer, $attribute, $maskedAttribu
$this->_getHelper()->log("Identifier for customer {$customer->getEmail()} successfully deleted.");
}

private function _isPaymentSuccessfullyProcessed(Lyranetwork_Payzen_Model_Api_Response $response)
private function _isPaymentSuccessfullyProcessed(PayzenResponse $response)
{
if ($response->isAcceptedPayment()) {
return true;
Expand All @@ -742,9 +746,9 @@ private function _isPaymentSuccessfullyProcessed(Lyranetwork_Payzen_Model_Api_Re
* Update order status and eventually create invoice.
*
* @param Mage_Sales_Model_Order $order
* @param Lyranetwork_Payzen_Model_Api_Response $response
* @param PayzenResponse $response
*/
protected function _registerOrder(Mage_Sales_Model_Order $order, Lyranetwork_Payzen_Model_Api_Response $response)
protected function _registerOrder(Mage_Sales_Model_Order $order, PayzenResponse $response)
{
$this->_getHelper()->log("Saving payment for order #{$order->getIncrementId()}.");

Expand Down Expand Up @@ -798,7 +802,7 @@ protected function _registerOrder(Mage_Sales_Model_Order $order, Lyranetwork_Pay
* Update order payment information.
*
* @param Mage_Sales_Model_Order $order
* @param Lyranetwork_Payzen_Model_Api_Response $response
* @param PayzenResponse $response
*/
public function updatePaymentInfo(Mage_Sales_Model_Order $order, $response)
{
Expand Down Expand Up @@ -853,7 +857,7 @@ public function updatePaymentInfo(Mage_Sales_Model_Order $order, $response)
// Set is_fraud_detected flag.
$order->getPayment()->setIsFraudDetected($response->isSuspectedFraud());

$currency = Lyranetwork_Payzen_Model_Api_Api::findCurrencyByNumCode($response->get('currency'));
$currency = PayzenApi::findCurrencyByNumCode($response->get('currency'));

if ($response->get('card_brand') === 'MULTI') { // Multi brand.
$data = Mage::helper('core')->jsonDecode($response->get('payment_seq'), Zend_Json::TYPE_OBJECT);
Expand Down Expand Up @@ -961,7 +965,7 @@ public function updatePaymentInfo(Mage_Sales_Model_Order $order, $response)
&& ($response->get('currency') !== $response->get('effective_currency'))
) {
// Effective amount.
$effectiveCurrency = Lyranetwork_Payzen_Model_Api_Api::findCurrencyByNumCode($response->get('effective_currency'));
$effectiveCurrency = PayzenApi::findCurrencyByNumCode($response->get('effective_currency'));

$effectiveAmount= number_format(
$effectiveCurrency->convertAmountToFloat((int) ($amount / $rate)),
Expand Down Expand Up @@ -1002,7 +1006,7 @@ public function updatePaymentInfo(Mage_Sales_Model_Order $order, $response)

if ($response->get('effective_currency') && ($response->get('currency') !== $response->get('effective_currency'))) {
// Effective amount.
$effectiveCurrency = Lyranetwork_Payzen_Model_Api_Api::findCurrencyByNumCode($response->get('effective_currency'));
$effectiveCurrency = PayzenApi::findCurrencyByNumCode($response->get('effective_currency'));

$effectiveAmount = number_format(
$effectiveCurrency->convertAmountToFloat($response->get('effective_amount')),
Expand Down Expand Up @@ -1059,7 +1063,7 @@ private function getThreedsStatus($status)
}
}

private function _saveIdentifier(Mage_Sales_Model_Order $order, Lyranetwork_Payzen_Model_Api_Response $response)
private function _saveIdentifier(Mage_Sales_Model_Order $order, PayzenResponse $response)
{
if (! $order->getCustomerId()) {
return;
Expand Down Expand Up @@ -1109,7 +1113,7 @@ private function _saveIdentifier(Mage_Sales_Model_Order $order, Lyranetwork_Payz
}
}

private function _saveSepaIdentifier(Mage_Sales_Model_Order $order, Lyranetwork_Payzen_Model_Api_Response $response)
private function _saveSepaIdentifier(Mage_Sales_Model_Order $order, PayzenResponse $response)
{
if (! $order->getCustomerId()) {
return;
Expand Down Expand Up @@ -1196,9 +1200,9 @@ public function createInvoice(Mage_Sales_Model_Order $order)
* Cancel order.
*
* @param Mage_Sales_Model_Order $order
* @param Lyranetwork_Payzen_Model_Api_Response $response
* @param PayzenResponse $response
*/
protected function _cancelOrder(Mage_Sales_Model_Order $order, Lyranetwork_Payzen_Model_Api_Response $response)
protected function _cancelOrder(Mage_Sales_Model_Order $order, PayzenResponse $response)
{
$this->_getHelper()->log("Canceling order #{$order->getIncrementId()}.");

Expand Down Expand Up @@ -1296,7 +1300,7 @@ public function addTransaction($payment, $type, $transactionId, $additionalInfo,
/**
* Get new order state and status according to the gateway response.
*
* @param Lyranetwork_Payzen_Model_Api_Response $response
* @param PayzenResponse $response
* @param Mage_Sales_Model_Order $order
* @param boolean $ignoreFraud
* @return Varien_Object
Expand Down Expand Up @@ -1369,8 +1373,8 @@ public function convertTxnType($payzenType)
$type = false;

$successStatuses = array_merge(
Lyranetwork_Payzen_Model_Api_Api::getSuccessStatuses(),
Lyranetwork_Payzen_Model_Api_Api::getPendingStatuses()
PayzenApi::getSuccessStatuses(),
PayzenApi::getPendingStatuses()
);

switch (true) {
Expand Down
Loading

0 comments on commit aa613ea

Please sign in to comment.