Skip to content

Commit

Permalink
Merge branch 'release/2.24.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
hipaybot committed Dec 6, 2024
2 parents e042ffe + 5d1daa7 commit 65d7a3f
Show file tree
Hide file tree
Showing 23 changed files with 1,587 additions and 1,351 deletions.
29 changes: 17 additions & 12 deletions .github/workflows/slack-message.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,24 @@ jobs:
]
};
tickets.forEach((ticket) => {
ticket = ticket.toUpperCase();
payload.blocks[2].elements[0].elements.push({
"type": "rich_text_section",
"elements": [
{
"type": "link",
"url": "https://${{ vars.JIRA_DOMAIN }}/browse/" + ticket,
"text": ticket
}
]
if(tickets.length) {
tickets.forEach((ticket) => {
ticket = ticket.toUpperCase();
payload.blocks[2].elements[0].elements.push({
"type": "rich_text_section",
"elements": [
{
"type": "link",
"url": "https://${{ vars.JIRA_DOMAIN }}/browse/" + ticket,
"text": ticket
}
]
});
});
});
} else {
payload.blocks.splice(2, 1);
payload.blocks.splice(1, 1);
}
console.log("payload", payload);
Expand Down
4 changes: 3 additions & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ get-jira-tickets:
}
const mergeRequests = await gitlabResponse.json();
const tickets = [];
let tickets = [];
mergeRequests.forEach((mr) => {
const matches = mr.source_branch.match(/EC-\d+/);
Expand All @@ -276,6 +276,8 @@ get-jira-tickets:
}
});
tickets = [...new Set(tickets)];
console.log("tickets", tickets);
const payload = {
Expand Down
4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"trailingComma": "none",
"singleQuote": true
}
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 2.24.0

- **Add**: Added dynamic Min/Max functionality for Alma payment method
- **Fix**: Fixed max retry waiting notification using max retry custom field value

## 2.23.0

- **Add**: Added Klarna payment method
Expand Down
37 changes: 37 additions & 0 deletions src/hipay_enterprise/classes/apiCaller/ApiCaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
require_once(dirname(__FILE__) . '/../apiFormatter/Request/HostedPaymentFormatter.php');
require_once(dirname(__FILE__) . '/../apiFormatter/Request/DirectPostFormatter.php');
require_once(dirname(__FILE__) . '/../apiFormatter/Request/MaintenanceFormatter.php');
require_once(dirname(__FILE__) . '/../apiFormatter/Request/AvailablePaymentProductFormatter.php');
require_once(dirname(__FILE__) . '/../exceptions/GatewayException.php');
require_once(dirname(__FILE__) . '/../helper/HipayMaintenanceData.php');
require_once(dirname(__FILE__) . '/../helper/dbquery/HipayDBUtils.php');
Expand Down Expand Up @@ -225,6 +226,42 @@ public static function requestMaintenance($moduleInstance, $params, $eci = null)
}
}

/**
* return available Payment Product
*
* @param $moduleInstance
* @param $params
* @return array|\HiPay\Fullservice\Gateway\Model\AvailablePaymentProduct[]|string
* @throws GatewayException
*/
public static function getAvailablePaymentProduct($moduleInstance, $params)
{
try {
// HiPay Gateway
$gatewayClient = ApiCaller::createGatewayClient($moduleInstance, false);

//Set data to send to the API
$availablePaymentProductFormatter = new AvailablePaymentProductFormatter($moduleInstance, $params);

$paymentProduct = $availablePaymentProductFormatter->generate();
$moduleInstance->getLogs()->logRequest($paymentProduct, 'AvailablePaymentProduct');
$availablePaymentProduct = $gatewayClient->requestAvailablePaymentProduct($paymentProduct);

return $availablePaymentProduct;
} catch (Exception $e) {
$moduleInstance->getLogs()->logException($e);
throw new GatewayException(
Context::getContext(),
$moduleInstance,
'An error occured during request availablePaymentProduct. Please Retry later. Reason [' .
$e->getMessage() .
']',
$e->getCode(),
null
);
}
}

/**
* create gateway client from config and client provider
* @param type $moduleInstance
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php
/**
* HiPay Enterprise SDK Prestashop
*
* 2017 HiPay
*
* NOTICE OF LICENSE
*
* @author HiPay <[email protected]>
* @copyright 2017 HiPay
* @license https://github.com/hipay/hipay-enterprise-sdk-prestashop/blob/master/LICENSE.md
*/

require_once(dirname(__FILE__) . '/CommonRequestFormatterAbstract.php');
require_once(dirname(__FILE__) . '/../../../lib/vendor/autoload.php');

/**
*
* Available payment product formatter
*
* @author HiPay <[email protected]>
* @copyright Copyright (c) 2017 - HiPay
* @license https://github.com/hipay/hipay-enterprise-sdk-prestashop/blob/master/LICENSE.md
* @link https://github.com/hipay/hipay-enterprise-sdk-prestashop
*/
class AvailablePaymentProductFormatter extends CommonRequestFormatterAbstract
{
public function __construct($moduleInstance, $params, $cart = false)
{
parent::__construct($moduleInstance, $cart);
$this->params = $params;
}

/**
* generate request data before API call
* @return \HiPay\Fullservice\Gateway\Request\Info\AvailablePaymentProductRequest
*/
public function generate()
{
$paymentProduct = new \HiPay\Fullservice\Gateway\Request\Info\AvailablePaymentProductRequest();

$this->mapRequest($paymentProduct);

return $paymentProduct;
}

/**
* map prestashop Payment Product to request fields (Available Payment Product)
* @param type $paymentProduct
*/
protected function mapRequest(&$paymentProduct)
{
parent::mapRequest($paymentProduct);
$paymentProduct->payment_product = $this->params["payment_product"];
$paymentProduct->with_options = $this->params["with_options"];
}
}

This file was deleted.

53 changes: 50 additions & 3 deletions src/hipay_enterprise/classes/helper/HipayHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,8 @@ public static function getAdminUrl()
{
if (_PS_VERSION_ < '1.7' && _PS_VERSION_ >= '1.6') {
$admin = explode(DIRECTORY_SEPARATOR, _PS_ADMIN_DIR_);
$adminFolder = array_pop(array_slice($admin, -1));
$lastElement = array_slice($admin, -1);
$adminFolder = array_pop($lastElement);
$adminUrl = _PS_BASE_URL_.__PS_BASE_URI__.$adminFolder.'/';
} else {
$adminUrl = '';
Expand Down Expand Up @@ -552,8 +553,7 @@ public static function getActivatedPaymentByCountryAndCurrency(
if ($settings['activated'] &&
(empty($settings['countries']) || in_array($country->iso_code, $settings['countries'])) &&
(empty($settings['currencies']) || in_array($currency->iso_code, $settings['currencies'])) &&
$orderTotal >= $settings['minAmount']['EUR'] &&
($orderTotal <= $settings['maxAmount']['EUR'] || !$settings['maxAmount']['EUR']) &&
self::isOrderTotalWithinLimits($module, $orderTotal, $settings) &&
(empty($settings['minPrestashopVersion']) || ($settings['minPrestashopVersion'] <= _PS_VERSION_))
) {
if ('local_payment' == $paymentMethodType) {
Expand Down Expand Up @@ -882,4 +882,51 @@ public static function isHipayOrder($module, $order)
{
return $order->module === $module->name;
}

/**
* Check if the order total is within the allowed limits for a payment method.
*
* @param Hipay_enterprise $module The HiPay module instance
* @param float $orderTotal The total amount of the order
* @param array $settings An array containing payment method settings
* @return bool True if the order total is within limits, false otherwise
* @throws Exception If there's an error in API communication for Alma products
*/
public static function isOrderTotalWithinLimits($module, $orderTotal, $settings)
{
// Check for Alma products
if (isset($settings["productCode"]) && stripos($settings["productCode"], 'alma') !== false) {
try {
$availablePaymentProducts = ApiCaller::getAvailablePaymentProduct($module, [
'payment_product' => $settings["productCode"],
'with_options' => true
]);

foreach ($availablePaymentProducts as $product) {
if ($product->getCode() === $settings["productCode"]) {
$options = $product->getOptions();
$installments = substr($product->getCode(), -2, 1);
$minKey = "basketAmountMin{$installments}x";
$maxKey = "basketAmountMax{$installments}x";

if (isset($options[$minKey], $options[$maxKey])) {
return $orderTotal >= (float)$options[$minKey] && $orderTotal <= (float)$options[$maxKey];
}
}
}

return false;
} catch (Exception $e) {
$module->getLogs()->logError("Error fetching Alma payment product: " . $e->getMessage());
throw $e;
}
}

// For non-Alma products
$minAmount = $settings['minAmount']['EUR'] ?? 0;
$maxAmount = $settings['maxAmount']['EUR'] ?? false;

$hasUpperLimit = $maxAmount && $maxAmount > 0;
return $orderTotal >= $minAmount && (!$hasUpperLimit || $orderTotal <= $maxAmount);
}
}
4 changes: 2 additions & 2 deletions src/hipay_enterprise/classes/helper/HipayNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public function dispatchWaitingNotifications()

$notifications = $this->dbMaintenance->getWaitingNotificationsAndUpdateStatus(
NotificationStatus::IN_PROGRESS,
Configuration::get('HIPAY_NOTIFICATION_THRESHOLD')
$this->configHipay['account']['global']['notification_max_retry'] ?? 50
);

$totalError = 0;
Expand Down Expand Up @@ -823,7 +823,7 @@ private function createOrderSlip($order, $transaction)

OrderSlip::create(
$order,
[$product],
[$product]
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/hipay_enterprise/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
"hipay/hipay-fullservice-sdk-php": "^2.19.1",
"symfony/polyfill-php80": "<=1.18.1"
},
"version": "2.23.0"
"version": "2.24.0"
}
2 changes: 1 addition & 1 deletion src/hipay_enterprise/controllers/front/redirectlocal.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function initContent()
&& $this->module->hipayConfigTool->getLocalPayment()[$method]["handleHpayment"]
&& $this->module->hipayConfigTool->getPaymentGlobal()['operating_mode']['APIMode'] === ApiMode::HOSTED_PAGE
)
|| ($this->module::isPaypalV2($method, $this->module->hipayConfigTool))
|| ($this->module::isPaypalV2($method, $this->module))
) {
$mode = ApiMode::HOSTED_PAGE;
}
Expand Down
Loading

0 comments on commit 65d7a3f

Please sign in to comment.