Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 3.0.0 #12

Closed
wants to merge 77 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
656e386
Initialize composer project
EmanueleCoppola Sep 28, 2024
31b7d00
Add atomic lock classes
EmanueleCoppola Sep 28, 2024
4987d85
Create LICENSE
EmanueleCoppola Sep 29, 2024
acb7d51
Update project name
EmanueleCoppola Sep 29, 2024
bd4d269
Improve licensing; keep only root LICENSE file
EmanueleCoppola Sep 29, 2024
f5627aa
Remove unneeded upgrade file
EmanueleCoppola Sep 29, 2024
c8fc6ab
Add PS environment checks
EmanueleCoppola Sep 29, 2024
407b6f7
Remove unused Satispay state
EmanueleCoppola Sep 29, 2024
1365e22
Bump to 2.5.0 and update description
EmanueleCoppola Sep 29, 2024
cda8180
Update .gitignore
EmanueleCoppola Sep 29, 2024
549ad36
Update index.php
EmanueleCoppola Sep 29, 2024
18f354e
Add basic callback health system
EmanueleCoppola Sep 30, 2024
aaf8575
Remove imported SDK
EmanueleCoppola Sep 30, 2024
4d8ae37
Update implementation for Carbon v2
EmanueleCoppola Sep 30, 2024
23848b0
Add base form class
EmanueleCoppola Sep 30, 2024
4542c50
Add CallbackHealth class
EmanueleCoppola Oct 1, 2024
b7d4140
Improve Form base class and add logging
EmanueleCoppola Oct 1, 2024
37f58ec
Rename CallbackHealth to CallbackHealthCheck
EmanueleCoppola Oct 1, 2024
996d3f1
Update ConfigForm
EmanueleCoppola Oct 1, 2024
01367d2
Minor index.php formatting
EmanueleCoppola Oct 1, 2024
489c629
Remove deprecated templates
EmanueleCoppola Oct 3, 2024
ca524e1
Add SatispayPayment model
EmanueleCoppola Oct 3, 2024
d6e71ba
Add index.php in classes
EmanueleCoppola Oct 3, 2024
44e36a4
Improve callback health check
EmanueleCoppola Oct 3, 2024
987794d
Rename model SatispayPayment to SatispayPendingPayment
EmanueleCoppola Oct 3, 2024
af0b2fa
Improve SatispayPendingPayment model efficiency
EmanueleCoppola Oct 10, 2024
8f839bb
Rewrite payment creation controller
EmanueleCoppola Oct 10, 2024
778ab09
Rewrite redirect handling
EmanueleCoppola Oct 10, 2024
970db64
Add Meal Voucher support
EmanueleCoppola Oct 10, 2024
3f2c692
Update config xmls
EmanueleCoppola Oct 10, 2024
ef41bfc
Remove CRON system
EmanueleCoppola Oct 10, 2024
d9ad3a9
Bump version and improve description
EmanueleCoppola Oct 10, 2024
cee0243
Improve callback edge case handling
EmanueleCoppola Oct 11, 2024
55ecd28
Improve redirect handling
EmanueleCoppola Oct 11, 2024
94f1908
Move acceptOrder logic to model
EmanueleCoppola Oct 11, 2024
06727c4
Add SatispayRefund model
EmanueleCoppola Oct 11, 2024
77cd10b
Fix double executed query
EmanueleCoppola Oct 14, 2024
758ad88
Use FQN for internal Prestashop dependencies
EmanueleCoppola Oct 14, 2024
332478c
Rename upgrade file to match new plugin version
EmanueleCoppola Oct 14, 2024
a7814d4
Improve phpdoc description and remove magic numbers from code
EmanueleCoppola Oct 14, 2024
c171b42
Update upgrade file
EmanueleCoppola Oct 15, 2024
d31fd16
Improve model data validation
EmanueleCoppola Oct 16, 2024
5c38f1a
Fix SatispayRefund ordering and add PS readable amount
EmanueleCoppola Oct 16, 2024
c5e22a9
Add base Satispay refund view
EmanueleCoppola Oct 16, 2024
cc74b35
Add refund support
EmanueleCoppola Oct 16, 2024
ba90073
Add callback health check system
EmanueleCoppola Oct 16, 2024
c91e453
Move payment icon
EmanueleCoppola Oct 16, 2024
a82449d
Add french language
EmanueleCoppola Oct 16, 2024
36d5a92
Add italian language
EmanueleCoppola Oct 16, 2024
8fd5120
Improve translations
EmanueleCoppola Oct 16, 2024
995bf26
Add french configuration
EmanueleCoppola Oct 16, 2024
7a14cd0
Fix translations
EmanueleCoppola Oct 16, 2024
95262db
Improve redirect logging
EmanueleCoppola Oct 16, 2024
148afc9
Update build script
EmanueleCoppola Oct 16, 2024
e912569
Update LICENSE
EmanueleCoppola Oct 16, 2024
7407e83
Minor boolean casting
EmanueleCoppola Oct 16, 2024
313fb17
Improve logging
EmanueleCoppola Oct 16, 2024
5f9ed26
Bump Satispay SDK version
EmanueleCoppola Oct 16, 2024
fed6c15
Add old cron file to prevent file not found error
EmanueleCoppola Oct 17, 2024
f7f4c53
Improve refunds deep linking
EmanueleCoppola Oct 17, 2024
1573596
Update translations
EmanueleCoppola Oct 17, 2024
4d14307
Add development docker setup
EmanueleCoppola Oct 24, 2024
18123ca
Improve refund flow
EmanueleCoppola Oct 24, 2024
678c3bb
Improve docker-compose.yml
EmanueleCoppola Oct 25, 2024
f16fa8b
Add missing index.php
EmanueleCoppola Oct 25, 2024
2ab6bac
Improve docker file
EmanueleCoppola Oct 25, 2024
46b88f1
Add development doc
EmanueleCoppola Oct 25, 2024
87d44b3
add: clean and run scripts
EmanueleCoppola Nov 18, 2024
7750728
add: Timeout constant
EmanueleCoppola Nov 28, 2024
daaa451
fix: Composer namespace capitalization
EmanueleCoppola Nov 29, 2024
e98c7a3
Disable maintenance page in callback controllers
EmanueleCoppola Dec 3, 2024
9f3b8db
add: Customizable payment duration
EmanueleCoppola Dec 3, 2024
8030f6b
fix: Payment duration handling
EmanueleCoppola Dec 3, 2024
875bfde
add: Translations
EmanueleCoppola Dec 3, 2024
56b6872
fix: Install queries and add constant
EmanueleCoppola Dec 3, 2024
bd70e93
update: Building and running scripts
EmanueleCoppola Dec 3, 2024
da84049
fix: Prestashop coding standard
EmanueleCoppola Dec 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.gitattributes export-ignore
.gitignore export-ignore

.git/ export-ignore
tmp export-ignore
docs/ export-ignore
scripts/ export-ignore
psdata/ export-ignore
14 changes: 13 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
/tmp
# OS
.DS_Store

# building
tmp/
satispay.zip

# Composer
vendor/
composer.lock

psdata/*
!psdata/.gitkeep
191 changes: 191 additions & 0 deletions Classes/CallbackHealthCheck.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
<?php

namespace Satispay\Prestashop\Classes;

if (!defined('_PS_VERSION_')) {
exit;
}

// Prestashop
use \Configuration;
use \Context;
use \PrestaShopLogger;

//
use Carbon\Carbon;
use \Satispay;
use \Exception;
use SatispayGBusiness\Payment;

/**
* Manages the health check process for Satispay callbacks in Prestashop.
*
* This class handles the creation, verification, and validation of callback
* health checks. It ensures that callbacks are functioning correctly by
* creating test payments and verifying their responses within a specified
* time frame.
*/
class CallbackHealthCheck
{
/**
* CallbackHealthCheck constants.
*
* If we don't receive an update within X minutes
* we consider the callback health failed.
* That's why we need these constants.
*
* @var string
*/
const PAYMENT_DURATION_SECONDS = 60;
const PAYMENT_TIMEOUT_DURATION_SECONDS = 10; // 10 more seconds are more than enough

// statuses
const STATUS_TODO = 'todo';
const STATUS_PENDING = 'pending';
const STATUS_SUCCESS = 'success';
const STATUS_FAIL = 'fail';

/**
* The Satispay module.
*
* @var Satispay
*/
protected $module;

/**
* The Satispay module context.
*
* @var Context
*/
protected $context;

/**
* The CallbackHealthCheck constructor.
*/
public function __construct($module)
{
/** @var Satispay $module */
$this->module = $module;

$this->context = Context::getContext();
}

/**
* Run the health check process for the Satispay callback.
*
* Generates a unique nonce, creates a payment to test the callback,
* and sets the status to pending. The callback URL contains the
* generated nonce and a payment ID.
*
* @return void
*/
public function run()
{
$nonce = substr(str_shuffle(str_repeat('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', 5)), 0, 12);
Configuration::updateValue(Satispay::SATIPAY_CALLBACK_HEALTH_NONCE, $nonce);

$this->module->log(get_class($this) . "@run starting with nonce {$nonce}");

try {
Payment::create([
'flow' => 'MATCH_CODE',
'currency' => 'EUR',
'amount_unit' => 1,
'external_code' => "Prestashop callback-health {$nonce}",
'callback_url' =>
urldecode(
$this
->context
->link
->getModuleLink(
$this->module->name,
'callback_health_check',
[
'nonce' => $nonce,
'payment_id' => '{uuid}',
],
true
)
),
'expiration_date' =>
Carbon::now()
->timezone('UTC')
->addSeconds(self::PAYMENT_DURATION_SECONDS)
->format("Y-m-d\TH:i:s.v\Z")
]);

Configuration::updateValue(Satispay::SATIPAY_CALLBACK_HEALTH_STATUS, self::STATUS_PENDING);

Configuration::updateValue(
Satispay::SATIPAY_CALLBACK_HEALTH_TIMESTAMP,
Carbon::now()
->timezone('UTC')
->getPreciseTimestamp(3)
);

$this->module->log(get_class($this) . "@run succeded with nonce {$nonce}");
} catch (Exception) {
// can be silent as it doesn't affect the module
$this->module->log(get_class($this) . "@run failed with nonce {$nonce}", PrestaShopLogger::LOG_SEVERITY_LEVEL_ERROR);
}
}

/**
* Verify the callback health status.
*
* Checks if the payment callback response was received within
* the expected time frame. If the response is overdue, sets the
* status to failed and clears the timestamp.
*
* @return void
*/
public function verify()
{
$timestamp = Configuration::get(Satispay::SATIPAY_CALLBACK_HEALTH_TIMESTAMP);

$this->module->log(get_class($this) . "@verify with timestamp {$timestamp}");

if (!$timestamp) {
return;
}

$timestamp = Carbon::createFromTimestampMs($timestamp);

if (
$timestamp
->addSeconds(
self::PAYMENT_DURATION_SECONDS + self::PAYMENT_TIMEOUT_DURATION_SECONDS
)
->lessThan(
Carbon::now()->timezone('UTC')
)
) {
Configuration::updateValue(Satispay::SATIPAY_CALLBACK_HEALTH_NONCE, null);
Configuration::updateValue(Satispay::SATIPAY_CALLBACK_HEALTH_STATUS, self::STATUS_FAIL);
Configuration::updateValue(Satispay::SATIPAY_CALLBACK_HEALTH_TIMESTAMP, null);
}
}

/**
* Validate the callback using a nonce.
*
* Compares the provided nonce with the stored nonce. If they match,
* updates the callback health status to success.
*
* @param string $nonce The nonce received in the callback.
*
* @return void
*/
public function validate($nonce)
{
$this->module->log(get_class($this) . "@validate with nonce {$nonce}");

$_nonce = Configuration::get(Satispay::SATIPAY_CALLBACK_HEALTH_NONCE);

if ($_nonce && $nonce === $_nonce) {
Configuration::updateValue(Satispay::SATIPAY_CALLBACK_HEALTH_NONCE, null);
Configuration::updateValue(Satispay::SATIPAY_CALLBACK_HEALTH_STATUS, self::STATUS_SUCCESS);
Configuration::updateValue(Satispay::SATIPAY_CALLBACK_HEALTH_TIMESTAMP, null);
}
}
}
Loading