Skip to content

Commit 898b6fb

Browse files
committed
Compatibility fixes for CE-Phoenix-2341-Frozen
Standard distribution - Error helper: - check if cookie is defined - destory cookie after read
1 parent 0222692 commit 898b6fb

File tree

98 files changed

+8267
-7
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+8267
-7
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ Released under the GPL V3 license: https://opensource.org/licenses/GPL-3.0
4646
```
4747
require_once('includes/modules/payment/paylike/errors.php');
4848
```
49-
Before 'require('includes/application_top.php');' line(__);
49+
Before 'require('includes/application_top.php');' line;
5050
5151
7.2.Add:
5252
```
5353
require_once('includes/modules/payment/paylike/validate.php');
5454
```
55-
After 'reset($HTTP_POST_VARS['configuration']);' line(__);
55+
After 'reset($HTTP_POST_VARS['configuration']);' line;
5656
57-
7.3.Replace 'tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value = '" . $value . "' where configuration_key = '" . $key . "'");' line(__) with:
57+
7.3.Replace 'tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value = '" . $value . "' where configuration_key = '" . $key . "'");' line with:
5858
```
5959
if(sizeof($errors) === 0 || array_search($key, $validation_keys) === FALSE){
6060
tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value = '" . $value . "' where configuration_key = '" . $key . "'");
@@ -67,13 +67,13 @@ Released under the GPL V3 license: https://opensource.org/licenses/GPL-3.0
6767
tep_redirect(tep_href_link(FILENAME_MODULES, 'set=' . $set . '&module=' . $HTTP_GET_VARS['module'] . '&action=edit'));
6868
}
6969
```
70-
Before 'tep_redirect(tep_href_link(FILENAME_MODULES, 'set=' . $set . '&module=' . $HTTP_GET_VARS['module']));' line(__);
70+
Before 'tep_redirect(tep_href_link(FILENAME_MODULES, 'set=' . $set . '&module=' . $HTTP_GET_VARS['module']));' line;
7171
7272
7.5.Add:
7373
```
7474
if(isset($errorHandler))$errorHandler->display();
7575
```
76-
After 'case 'edit':' line(__).
76+
After 'case 'edit':' line.
7777
8. Install the Paylike module from modules -> payment in the admin
7878
9. Insert the app key and your public key in the settings and enable the plugin
7979

README_CE-Phoenix-2341-Frozen.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# osCommerce plugin for Paylike
2+
3+
This plugin is *not* developed or maintained by Paylike but kindly made
4+
available by a user.
5+
6+
Released under the GPL V3 license: https://opensource.org/licenses/GPL-3.0
7+
8+
9+
## Supported osCommerce versions
10+
11+
*The plugin has been tested with osCommerce v.2.3.4.1 and osCommerce CE Phoenix
12+
13+
## Installation
14+
15+
Once you have installed osCommerce, follow these simple steps:
16+
1. Signup at [paylike.io](https://paylike.io) (it’s free)
17+
2. Create a live account
18+
3. Create an app key for your osCommerce website
19+
4. Upload the files in the `upload` folder to root of your osCommerce store.
20+
5. In: `includes/template_top.php` add:
21+
```
22+
<?php
23+
if ( basename( $PHP_SELF ) == 'checkout_confirmation.php' ) {
24+
?>
25+
<script src="https://sdk.paylike.io/3.js"></script>
26+
<script src= "includes/javascript/paylike.js"></script>
27+
<?php
28+
}
29+
?>
30+
```
31+
Anywhere betwen the `head` tags.
32+
6. In: `includes/.htaccess` add:
33+
```
34+
<FilesMatch "paylike\.php$">
35+
<IfModule mod_authz_core.c>
36+
Require all granted
37+
</IfModule>
38+
<IfModule !mod_authz_core.c>
39+
Allow from all
40+
</IfModule>
41+
</FilesMatch>
42+
```
43+
After the last line.
44+
7. In: `admin/modules.php`
45+
7.1.Add:
46+
```
47+
require_once('includes/modules/payment/paylike/errors.php');
48+
```
49+
Before 'require('includes/application_top.php');' line;
50+
51+
7.2.Add:
52+
```
53+
require_once('includes/modules/payment/paylike/validate.php');
54+
```
55+
After 'case 'save':' line;
56+
57+
7.3.Replace 'tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value = '" . $value . "' where configuration_key = '" . $key . "'");' line with:
58+
```
59+
if(sizeof($errors) === 0 || array_search($key, $validation_keys) === FALSE){
60+
tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value = '" . $value . "' where configuration_key = '" . $key . "'");
61+
}
62+
```
63+
64+
7.4.Add:
65+
```
66+
if(sizeof($errors)){
67+
tep_redirect(tep_href_link('modules.php', 'set=' . $set . '&module=' . $HTTP_GET_VARS['module'] . '&action=edit'));
68+
}
69+
```
70+
Before 'tep_redirect(tep_href_link('modules.php', 'set=' . $set . '&module=' . $_GET['module']));' line;
71+
72+
7.5.Add:
73+
```
74+
if(isset($errorHandler))$errorHandler->display();
75+
```
76+
After 'case 'edit':' line.
77+
8. Install the Paylike module from modules -> payment in the admin
78+
9. Insert the app key and your public key in the settings and enable the plugin
79+
80+
## Updating settings
81+
82+
Under the Paylike settings, you can:
83+
* Update the title that shows up in the payment popup
84+
* Add test/live keys
85+
* Set payment mode (test/live)
86+
* Change the capture type (Instant/Delayed)
87+
88+
## How to
89+
90+
1. Capture
91+
* In Instant mode, the orders are captured automatically
92+
* In delayed mode you can capture funds only from the paylike dashboard.
93+
2. Refund
94+
* To refund an order you can use the paylike dashboard.
95+
3. Void
96+
* To void an order you can use the paylike dashboard.

upload/admin/includes/modules/payment/paylike/helpers/Paylike_Errors.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function __construct()
1919
*/
2020
public function display()
2121
{
22-
if (sizeof($this->errors)) {
22+
if ($this->errors && sizeof($this->errors)) {
2323
echo '<div class="validation_error">';
2424
echo '<ul>';
2525
echo '<li>' . implode('</li><li>', $this->errors) . '</li>';
@@ -41,7 +41,10 @@ public function setCookieErrors($list)
4141
*/
4242
public function loadCookieErrors()
4343
{
44-
$this->errors = json_decode($_COOKIE[$this->cookieName], true);
44+
if(isset($_COOKIE[$this->cookieName])){
45+
$this->errors = json_decode($_COOKIE[$this->cookieName], true);
46+
setcookie($this->cookieName, '', time()-3600);
47+
}
4548
}
4649
}
4750
endif; /* End if class_exists. */
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "esparks/module-paylike",
3+
"description": "Paylike integration with payment gateway prestashop",
4+
"type": "prestashop-module",
5+
"version": "1.0.6",
6+
"license": [
7+
"GPL-3.0-or-later"
8+
],
9+
"authors": [
10+
{
11+
"name": "Ionut Calara",
12+
"email": "ionut.calara@gmail.com"
13+
}
14+
],
15+
"require": {
16+
"paylike/php-api": "^1.0.3"
17+
}
18+
}

upload_CE-Phoenix-2341-Frozen/admin/includes/modules/payment/paylike/composer.lock

Lines changed: 59 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
/* Initialize errors object */
3+
require_once('helpers/Paylike_Errors.php');
4+
$errorHandler = new PaylikeErrors();
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
/* Security class check */
3+
if (! class_exists('PaylikeErrors')) :
4+
/**
5+
* Helper class that handles errors via cookies
6+
*/
7+
class PaylikeErrors
8+
{
9+
public $errors = '';
10+
private $cookieName = 'validation_errors';
11+
12+
public function __construct()
13+
{
14+
/* Load current cookie value */
15+
$this->loadCookieErrors();
16+
}
17+
/**
18+
* Dispay errors as HTML list
19+
*/
20+
public function display()
21+
{
22+
if ($this->errors && sizeof($this->errors)) {
23+
echo '<div class="validation_error">';
24+
echo '<ul>';
25+
echo '<li>' . implode('</li><li>', $this->errors) . '</li>';
26+
echo '</ul></div>';
27+
}
28+
}
29+
/**
30+
* Set cookie with list of given values
31+
*
32+
* @param array $list - the list o errors to be stored
33+
*/
34+
public function setCookieErrors($list)
35+
{
36+
setcookie($this->cookieName, json_encode($list), time()+3600);
37+
}
38+
39+
/**
40+
* Read and store cookie value
41+
*/
42+
public function loadCookieErrors()
43+
{
44+
if(isset($_COOKIE[$this->cookieName])){
45+
$this->errors = json_decode($_COOKIE[$this->cookieName], true);
46+
setcookie($this->cookieName, '', time()-3600);
47+
}
48+
}
49+
}
50+
endif; /* End if class_exists. */
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
/* Security class check */
3+
if (! class_exists('PaylikeValidator')) :
4+
/**
5+
* Helper class that validates module keys via Paylike API
6+
*/
7+
class PaylikeValidator
8+
{
9+
public $validationPublicKeys = array('Live'=>array(),'Test'=>array());
10+
/**
11+
* Validate the App key.
12+
*
13+
* @param string $value - the value of the input.
14+
* @param string $mode - the transaction mode 'test' | 'live'.
15+
*
16+
* @return string - the error message
17+
*/
18+
public function validateAppKeyField($value, $mode)
19+
{
20+
/** Check if the key value is empty **/
21+
if (! $value) {
22+
return sprintf(ERROR_APP_KEY, $mode);
23+
}
24+
/** Load the client from API**/
25+
$paylikeClient = new \Paylike\Paylike($value);
26+
try {
27+
/** Load the identity from API**/
28+
$identity = $paylikeClient->apps()->fetch();
29+
} catch (\Paylike\Exception\ApiException $exception) {
30+
$this->logMessage(sprintf(ERROR_APP_KEY_INVALID, $mode));
31+
return sprintf(ERROR_APP_KEY_INVALID, $mode);
32+
}
33+
34+
try {
35+
/** Load the merchants public keys list corresponding for current identity **/
36+
$merchants = $paylikeClient->merchants()->find($identity['id']);
37+
if ($merchants) {
38+
foreach ($merchants as $merchant) {
39+
/** Check if the key mode is the same as the transaction mode **/
40+
if (($mode == 'Test' && $merchant['test']) || ($mode != 'Test' && !$merchant['test'])) {
41+
$this->validationPublicKeys[$mode][] = $merchant['key'];
42+
}
43+
}
44+
}
45+
} catch (\Paylike\Exception\ApiException $exception) {
46+
$this->logMessage(sprintf(ERROR_APP_KEY_INVALID, $mode));
47+
}
48+
/** Check if public keys array for the current mode is populated **/
49+
if (empty($this->validationPublicKeys[$mode])) {
50+
/** Generate the error based on the current mode **/
51+
$error = sprintf(ERROR_APP_KEY_INVALID_MODE, $mode, array_values(array_diff(array_keys($this->validationPublicKeys), array($mode)))[0]);
52+
$this->logMessage($error);
53+
return $error;
54+
}
55+
}
56+
57+
/**
58+
* Validate the Public key.
59+
*
60+
* @param string $value - the value of the input.
61+
* @param string $mode - the transaction mode 'test' | 'live'.
62+
*
63+
* @return string - the error message
64+
*/
65+
public function validatePublicKeyField($value, $mode)
66+
{
67+
/** Check if the key value is not empty **/
68+
if (! $value) {
69+
return sprintf(ERROR_PUBLIC_KEY, $mode);
70+
}
71+
/** Check if the local stored public keys array is empty OR the key is not in public keys list **/
72+
if (empty($this->validationPublicKeys[$mode]) || ! in_array($value, $this->validationPublicKeys[$mode])) {
73+
$error = sprintf(ERROR_PUBLIC_KEY_INVALID, $mode);
74+
$this->logMessage($error);
75+
return $error;
76+
}
77+
}
78+
79+
/**
80+
* log message to default logger
81+
*
82+
* @param string $message
83+
*
84+
*/
85+
public static function logMessage($message)
86+
{
87+
error_log('[Paylike] ' . $message);
88+
}
89+
}
90+
endif; /* End if class_exists. */
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.validation_error {
2+
background: pink;
3+
width: 100%;
4+
margin-bottom: 10px;
5+
}
6+
7+
.validation_error ul {
8+
padding: 0px 10px;
9+
display: inline-block;
10+
}
11+
12+
.validation_error ul li {
13+
list-style: none;
14+
padding: 0;
15+
}
16+
17+
*:disabled, .disabled {
18+
opacity: 0.4;
19+
pointer-events: none;
20+
}

0 commit comments

Comments
 (0)