Skip to content

Commit

Permalink
Merge branch 'release/2.25.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
hipaybot committed Mar 6, 2025
2 parents 9b14f9c + fbe0d92 commit 8b3b02b
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 216 deletions.
95 changes: 8 additions & 87 deletions .github/workflows/slack-message.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,90 +27,11 @@ jobs:
env:
EVENT_CONTEXT: ${{ toJSON(github.event) }}
CONVERTED_TEXT: ${{ steps.convert.outputs.text }}
run: |
node <<EOF
const { tickets } = require('./artifact.json');
(async () => {
const project = "HiPay Enterprise SDK Prestashop";
const payload = {
channel: "${{ vars.SLACK_CHANNEL_ID }}",
blocks: [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*[NEW]* " + project + " - ${{ github.event.release.tag_name }}",
},
"accessory": {
"type": "button",
"text": {
"type": "plain_text",
"text": "Show release :rocket:",
"emoji": true
},
"url": "${{ github.event.release.html_url }}"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":clipboard: Tickets JIRA :"
}
},
{
"type": "rich_text",
"elements": [
{
"type": "rich_text_list",
"style": "bullet",
"elements": []
}
]
}
]
};
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);
try {
const slackResponse = await fetch("https://slack.com/api/chat.postMessage", {
method: "POST",
headers: {
"Authorization": "Bearer ${{ secrets.SLACK_API_TOKEN }}",
"Content-Type": "application/json"
},
body: JSON.stringify(payload)
});
if (!slackResponse.ok) {
const err = await slackResponse.json();
throw new Error("Failed to send message: " + JSON.stringify(err));
}
console.log("Message sent successfully !");
} catch (error) {
console.error("Request error", error.message);
}
})();
EOF
GITHUB_PROJECT_NAME: 'HiPay Enterprise SDK Prestashop'
GITHUB_RELEASE_TAG: ${{ github.event.release.tag_name }}
GITHUB_RELEASE_URL: ${{ github.event.release.html_url }}
JIRA_DOMAIN: ${{ vars.JIRA_DOMAIN }}
SLACK_CHANNEL_ID: ${{ vars.SLACK_CHANNEL_ID }}
SLACK_API_TOKEN: ${{ secrets.SLACK_API_TOKEN }}
run: |-
curl -s https://raw.githubusercontent.com/hipay/common-workflows/main/scripts/slack-message.js | node
112 changes: 5 additions & 107 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
image: $REGISTRY_CI/gitlab-ci-base:buster

workflow:
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
when: never
- when: always

stages:
- build-test
- test
Expand All @@ -17,6 +11,11 @@ stages:
variables:
GIT_DEPTH: 10

include:
- project: 'pi-ecommerce/cms/cms-template-ci'
ref: '1.0.0'
file: 'release.yaml'

#########################
#### TEMPLATE ####
########################
Expand Down Expand Up @@ -252,107 +251,6 @@ package:
when: never
- when: on_success

# Job to get JIRA tickets of the release
get-jira-tickets:
stage: release
image: node:latest
rules:
- if: $ONLY_DEPLOY
when: never
- if: $CI_COMMIT_TAG
script:
- |
node <<EOF
(async () => {
try {
const gitlabResponse = await fetch("${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/merge_requests?state=merged&target_branch=develop&milestone=${CI_COMMIT_TAG}", {
method: "GET",
headers: {
"Private-Token": "$GITLAB_API_TOKEN"
}
});
if (!gitlabResponse.ok) {
const err = await gitlabResponse.json();
throw new Error("Failed to send GitLab request: " + JSON.stringify(err));
}
const mergeRequests = await gitlabResponse.json();
let tickets = [];
mergeRequests.forEach((mr) => {
const matches = mr.source_branch.match(/EC-\d+/);
if(matches?.length) {
tickets.push(matches[0].toUpperCase());
}
});
tickets = [...new Set(tickets)];
console.log("tickets", tickets);
const payload = {
"event_type": "trigger-artifact-workflow",
"client_payload": {
"tickets": tickets
}
};
console.log("payload", JSON.stringify(payload));
const githubResponse = await fetch("https://api.github.com/repos/${GITHUB_ORGANIZATION}/${GITHUB_PROJECT}/dispatches", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer ${GITHUB_TOKEN}",
"User-Agent": "Node.js"
},
body: JSON.stringify(payload)
});
if (!githubResponse.ok) {
const err = await githubResponse.json();
throw new Error("Failed to send GitHub event: " + JSON.stringify(err));
}
} catch (error) {
throw new Error("Request error: " + error.message);
}
})();
EOF
# Release note job
release-job:
stage: release
image: registry.gitlab.com/gitlab-org/release-cli:latest
needs:
- get-jira-tickets
variables:
TEMP_CHANGELOG_FILE: 'release_changelog.txt'
rules:
- if: $ONLY_DEPLOY
when: never
- if: $CI_COMMIT_TAG
script:
- |
# Extract changelog part according to tag version
CHANGELOG=$(awk -v version="## $CI_COMMIT_TAG" '
$0 ~ version {printit=1; next}
printit && /^## / {exit}
printit {print}
' CHANGELOG.md)
{
echo "# CHANGE LOG"
echo "$CHANGELOG"
} > "$TEMP_CHANGELOG_FILE"
- cat "$TEMP_CHANGELOG_FILE"
release:
tag_name: $CI_COMMIT_TAG
name: Version $CI_COMMIT_TAG
description: '$TEMP_CHANGELOG_FILE'
milestones:
- $CI_COMMIT_TAG

build-prestashop16:
variables:
PS_VERSION: 16
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 2.25.1

- **Fix** : Remove "file_get_contents" for external URLs
- **Fix** : Fixed upgrade script from previous version `2.25.0`, thanks to [geoffrey-bedle](https://github.com/geoffrey-bedle) for issue [#90](https://github.com/hipay/hipay-enterprise-sdk-prestashop/issues/90)

## 2.25.0

- **Add** : Update OneClick payment
Expand Down
9 changes: 7 additions & 2 deletions bin/docker/images/prestashop/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,13 @@ EOF
#===================================#
# ADD CRON
#===================================#
#crontab -l | { cat; echo "*/5 * * * * php /var/www/html/modules/hipay_enterprise/cron.php > /var/log/cron.log"; } | crontab -
#service cron start
if [[ $PS_DOMAIN != "localhost"* ]]; then
crontab -l | {
cat
echo "*/5 * * * * /usr/local/bin/php /var/www/html/modules/hipay_enterprise/cron/handle-hipay-notifs.php >> /var/log/cron.log 2>&1"
} | crontab -
service cron start
fi
fi

if [ "$ENVIRONMENT" = "$ENV_DEVELOPMENT" ]; then
Expand Down
39 changes: 22 additions & 17 deletions src/hipay_enterprise/classes/helper/HipayUpdateNotif.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* HiPay Enterprise SDK Prestashop
*
Expand Down Expand Up @@ -82,25 +83,28 @@ public function __construct($module)
* PT1H => Interval of 1 hour
* https://www.php.net/manual/en/dateinterval.construct.php
*/
if(!$lastCall || $lastCall->add(new DateInterval("PT1H")) < $curdate ) {
// Headers to avoid 403 error from GitHub
$opts = [
'http' => [
'method' => 'GET',
'header' => [
'User-Agent: PHP'
]
]
];
if (!$lastCall || $lastCall->add(new DateInterval("PT1H")) < $curdate) {

$HIPAY_GITHUB_ACCESS_TOKEN = getenv('HIPAY_GITHUB_ACCESS_TOKEN');
$url = self::HIPAY_GITHUB_PRESTASHOP_LATEST;

$ch = curl_init($url);

// Headers to avoid 403 error from GitHub
$headers = ['User-agent: PHP'];
if ($HIPAY_GITHUB_ACCESS_TOKEN) {
$opts['http']['header'][] = 'Authorization: token ' . $HIPAY_GITHUB_ACCESS_TOKEN;
$headers[] = 'Authorization: token ' . $HIPAY_GITHUB_ACCESS_TOKEN;
}

$context = stream_context_create($opts);
$gitHubInfo = json_decode(file_get_contents(self::HIPAY_GITHUB_PRESTASHOP_LATEST, false, $context));
curl_setopt_array($ch, [
CURLOPT_HTTPHEADER => $headers,
CURLOPT_RETURNTRANSFER => true
]);

$response = curl_exec($ch);
curl_close($ch);
$gitHubInfo = json_decode($response);

// If call is successful, reading from call
if ($gitHubInfo) {
$this->newVersion = $gitHubInfo->tag_name;
Expand All @@ -121,15 +125,16 @@ public function __construct($module)
/**
* Reads the update info from saved configuration data
*/
public function readFromConf(){
public function readFromConf()
{
$lastResult = json_decode(Configuration::get('HIPAY_UPDATE_NOTIF_LAST_RESULT'));

// If conf exists, reading from it
if($lastResult) {
if ($lastResult) {
$this->newVersion = $lastResult->newVersion;
$this->readMeUrl = $lastResult->readMeUrl;
$this->downloadUrl = $lastResult->downloadUrl;
// If not, setting default data with values not showing the block
// If not, setting default data with values not showing the block
} else {
$this->newVersion = $this->version;
$this->readMeUrl = "#";
Expand Down Expand Up @@ -186,4 +191,4 @@ public function getDownloadUrl()
{
return $this->downloadUrl;
}
}
}
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.25.0"
"version": "2.25.1"
}
37 changes: 37 additions & 0 deletions src/hipay_enterprise/cron/handle-hipay-notifs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

require_once dirname(__DIR__, 3) . '/config/config.inc.php';

$moduleName = 'hipay_enterprise';
$module = Module::getInstanceByName($moduleName);
if (!$module || !$module->active) {
die('HiPay module disabled !' . PHP_EOL);
}

$config = $module->hipayConfigTool->getConfigHipay();

if (!$config['account']['global']['notification_cron']) {
die('HiPay CRON mode disabled !' . PHP_EOL);
}

$token = $config['account']['global']['notification_cron_token'];

$url = \Configuration::get('PS_SHOP_DOMAIN') . '/index.php?fc=module&module=' . $moduleName . '&controller=dispatch&token=' . $token;

$ch = curl_init($url);

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error = curl_error($ch);

curl_close($ch);

if ($error) {
error_log('Error cURL : ' . $error);
} else {
error_log('Request sent successfully ! Response (' . $httpCode . ') : ' . $response);
}

echo date('[Y-m-d H:i:s]') . ' - CRON job completed' . PHP_EOL;
2 changes: 1 addition & 1 deletion src/hipay_enterprise/hipay_enterprise.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function __construct()
{
$this->name = 'hipay_enterprise';
$this->tab = 'payments_gateways';
$this->version = '2.25.0';
$this->version = '2.25.1';
$this->module_key = 'c3c030302335d08603e8669a5210c744';
$this->ps_versions_compliancy = ['min' => '1.7.6', 'max' => _PS_VERSION_];
$this->currencies = true;
Expand Down
2 changes: 1 addition & 1 deletion src/hipay_enterprise/upgrade/Upgrade-2.25.0.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function upgrade_module_2_25_0($module)
try {

$sql = "
ALTER TABLE ps_hipay_cc_token
ALTER TABLE " . _DB_PREFIX_ . "hipay_cc_token
ADD UNIQUE (hp_id),
DROP PRIMARY KEY,
ADD PRIMARY KEY (customer_id, pan),
Expand Down

0 comments on commit 8b3b02b

Please sign in to comment.