Skip to content

Commit

Permalink
Merge pull request #4 from sreekesefingent/prestashop_simplify_2_4_3
Browse files Browse the repository at this point in the history
Implemented a feature to enable or disable debug logging. All communication data is encrypted and stored in a log file and Added void details to the order page
  • Loading branch information
jineshpv authored Oct 4, 2024
2 parents 9316a00 + 2a1f6c9 commit 7de1adb
Show file tree
Hide file tree
Showing 14 changed files with 401 additions and 91 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Changelog
All notable changes to this project will be documented in this file.

## [2.4.3] - 2024-10-04
### Added
- Implemented a feature to enable or disable debug logging. All communication data is encrypted and stored in a log file.
- Added void details to the order page.

## [2.4.2] - 2024-08-23
### Added
- Customer details are populated in transaction details in Simplify Gateway.
Expand Down
33 changes: 20 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ Version v2.4.1
Version v2.4.2
- Customer details are populated in transaction details in Simplify Gateway.

Version v2.4.3
- Implemented a feature to enable or disable debug logging. All communication data is encrypted and stored in a log file.
- Added void details to the order page.

## Installation
1. Make a backup of your site before applying new mods etc.
2. Download the .zip file of the latest release of the extension from https://github.com/simplifycom/simplify-prestashop-module/releases/latest
Expand All @@ -73,16 +77,19 @@ Version v2.4.2
Please proceed with the following actions to configure the payment method:

1. Log in to your PrestaShop administration application.
2. Go to Modules > Module Manager
3. Scroll down until you find the 'Mastercard Payment Gateway Services - Simplify' extension, and click on the Configure button
4. Enter your public and private API keys into the appropriate fields for the Live and Test mode. For information on your API keys go to https://www.simplify.com/commerce/docs/misc/index. NOTE: When working with Hosted Payments, you'll need to establish and activate an API key pair designed for Hosted Payments.
5. Select the Enable Payment Method to 'Yes'.
6. Enter a Payment Method Title. This will be the name shown to your users on the checkout form.
7. Choose between Payment and Authorize in Transaction Mode.
8. Choose between Embedded Payment Form and Modal Payment Window in the Hosted Checkout Method.
9. Map the Successful and Declined status to suit your workflow. This does not affect the Simplify Commerce configuration.
10. If you use multiple Payment Providers you can use Sort Order to configure how they're shown on the checkout form.
11. Don't forget to Enable the extension to activate it.
2. Navigate to Modules > Module Manager.
3. Locate the ‘Mastercard Payment Gateway Services – Simplify’ extension and click on the Configure button.
4. Enter your public and private API keys into the appropriate fields for the Live and Test mode. Refer to https://www.simplify.com/commerce/docs/misc/index for details on obtaining API keys. NOTE: When using Hosted Payments, ensure to activate an API key pair specifically for Hosted Payments.
5. Select the Enable Payment Method to ‘Yes’.
6. Save Customer Details: Enable customers to save their card details securely on Simplify servers for future transactions.
7. Provide a Payment Method Title, which will be displayed to users during checkout.
8. Choose between Payment and Authorize in Transaction Mode.
9. Select between Embedded Payment Form and Modal Payment Window in the Hosted Payment Method.
10. Map the Successful and Declined status to suit your workflow. This does not affect the Simplify Commerce configuration.
11. If multiple Payment Providers are used, adjust the Sort Order to determine their display sequence on the checkout form.
12. Option to choose Button color: Please select your preferred color from the options provided.
13. Enable/Disable the option to log data into ./var/logs/mastercard_simplify.log. All communications with the Simplify Mastercard Gateway are securely encrypted. You can also download the decrypted log file directly from the plugin configuration page.
14. Remember to enable the extension to activate the changes.

![Configuration](docs/images/configuration.png "Configuration")

Expand Down Expand Up @@ -122,11 +129,11 @@ To capture the order, go to the order details page and click the "Capture Paymen

![Capture](docs/images/capture.png "Capture")

### Reverse Authorization
### Void Authorization

Reverse Authorization is used to cancel the order if the merchant finds any fraud/suspect in that order.
Void Authorization is used to cancel the order if the merchant finds any fraud/suspect in that order.

![Reverse Authorization](docs/images/reverse-authorization.png "Reverse Authorization")
![Void Authorization](docs/images/void-authorization.png "Void Authorization")

### Refund / Partial Refund Transactions

Expand Down
2 changes: 1 addition & 1 deletion composer.json
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Mastercard Payment Gateway Services - Simplify",
"homepage": "https://github.com/Mastercard-Gateway/simplify-prestashop-module",
"license": "Apache-2.0",
"version": "2.4.2",
"version": "2.4.3",
"authors": [
{
"name": "Mastercard",
Expand Down
20 changes: 18 additions & 2 deletions controllers/admin/AdminSimplifyController.php
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright (c) 2019-2023 Mastercard
* Copyright (c) 2019-2024 Mastercard
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -79,6 +79,8 @@ protected function captureAction($order)
'amount' => $auth->amount
]);

$this->module->logMessage("Capture payment details: " . $payment);

if($payment->declineReason === "AUTHORIZATION_EXPIRED"){
$comment = "System error : Authorization expired for this order";
$this->insertCapture($payment,$orderId,$comment);
Expand Down Expand Up @@ -147,7 +149,7 @@ protected function voidAction($order)

$auth = Simplify_Authorization::findAuthorization($txnId);
$auth->deleteAuthorization();

$this->module->logMessage("Void details: " . $auth);
$this->updateOrder(
$auth->id,
$order
Expand All @@ -166,6 +168,15 @@ protected function updateOrder($paymentId, $order)
if ($payment->reversed === true) {

$newStatus = Configuration::get('PS_OS_CANCELED');
$data = array(
'order_id' => $order->id,
'transcation_id' => $payment->id,
'amount' => $payment->amount / 100,
'date_created' => $payment->transactionData->date,
);
if (!Db::getInstance()->insert('simplify_void_table', $data)) {
throw new Exception('Error inserting Void data into the database.');
}
}

if ($payment->captured === true) {
Expand Down Expand Up @@ -247,6 +258,8 @@ public function PartialRefundAction()
'payment' => $valueToUse,
]);

$this->module->logMessage("Partial refund details: " . $refund);

if($refund->paymentStatus === "APPROVED"){
$comment = "Transaction Successful";
// Insert the refund details into the database
Expand Down Expand Up @@ -349,6 +362,9 @@ public function FullRefundAction()
'amount' => $amount,
'payment' => $valueToUse,
]);

$this->module->logMessage("Full refund details: " . $refund);

if($refund->paymentStatus === "APPROVED"){
$comment = "Transaction Successful";
// Insert the refund details into the database
Expand Down
Binary file modified docs/images/capture.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/configuration.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/images/reverse-authorization.png
Binary file not shown.
Binary file added docs/images/void-authorization.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
111 changes: 111 additions & 0 deletions simplify-api-logger.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<?php
/**
* Copyright (c) 2023-2026 Mastercard
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

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

/**
* Main class of the Mastercard Simplify Api Logger
*
* This class handles logging for the Mastercard Simplify API. It is responsible for recording API request and response data,
* as well as any errors or relevant information that may be useful for debugging or monitoring API interactions.
*/
class Mastercard_Simplify_Api_Logger {
protected $cipher;
protected $cipher_algo;
protected $filename;

public function __construct( $hash ) {
$this->cipher_algo = "AES-256-CBC";
$this->cipher = $hash;
$this->filename = _PS_ROOT_DIR_ . '/var/logs/mastercard_simplify.log';
}

/**
* Encrypt the log message.
*/
public function encrypt_log( $message ) {
$iv_len = openssl_cipher_iv_length( $this->cipher_algo );
$iv = openssl_random_pseudo_bytes( $iv_len );
$cipher_text = openssl_encrypt( $message, $this->cipher_algo, $this->cipher, 0, $iv );
$cipher_text_iv = base64_encode( $iv . $cipher_text );
return $cipher_text_iv;
}

/**
* Encrypts and writes a log message to a secure log file.
*
* @param string $message The log message to be encrypted and stored.
*/
public function write_encrypted_log( $message ) {
$encrypted_message = $this->encrypt_log( $message, $this->cipher );
file_put_contents( $this->filename, $encrypted_message . PHP_EOL, FILE_APPEND );
}


/**
* Decrypt the log message.
*/
public function decrypt_log( $cipher_text_iv ) {
$iv_len = openssl_cipher_iv_length( $this->cipher_algo );
$cipher_text_iv = base64_decode( $cipher_text_iv );
$iv = substr( $cipher_text_iv, 0, $iv_len );
$cipher_text = substr( $cipher_text_iv, $iv_len );
$original_plaintext = openssl_decrypt( $cipher_text, $this->cipher_algo, $this->cipher, $options = 0, $iv );

return $original_plaintext;
}

/**
* Read and decrypt log entries.
*/
public function read_decrypted_log() {
$decrypted_log_data = [];
$log_file_path = _PS_ROOT_DIR_ . '/var/logs/mastercard_simplify.log';

// Check if the log file exists
if (file_exists($log_file_path)) {
// Read log file into an array where each element is a line in the file
$log_entries = file($log_file_path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);

// Iterate through log entries
foreach ($log_entries as $cipher_text) {
// Decrypt each log entry
$decrypted_message = $this->decrypt_log($cipher_text);
$decrypted_log_data[] = $decrypted_message . PHP_EOL; // Add newline after each decrypted message
}

// If there are decrypted messages, convert array to string
if (!empty($decrypted_log_data)) {
$decrypted_log_data = implode('', $decrypted_log_data); // Convert array to string
} else {
$decrypted_log_data = ''; // If no data, make it an empty string
}
} else {
$decrypted_log_data = 'Log file not found.';
}

// Output the decrypted log data
header('Content-Type: text/plain');
header('Content-Disposition: attachment; filename="mastercard_simplify.log"');
header('Content-Length: ' . strlen($decrypted_log_data)); // Calculate length of the string
echo $decrypted_log_data;
}

}
Loading

0 comments on commit 7de1adb

Please sign in to comment.