Skip to content

Merge Staging Into Main#26

Open
SalmanTwo wants to merge 24 commits intomainfrom
staging
Open

Merge Staging Into Main#26
SalmanTwo wants to merge 24 commits intomainfrom
staging

Conversation

@SalmanTwo
Copy link
Copy Markdown
Contributor

No description provided.

…rms-on-prestashop-plugin

Shabib/cet 926 eom style order terms on prestashop plugin
…load-in-prestashop-plugin

KNA-3211/feat: Enabling invoice upload and minor improvements
…presta-shop-and-improvements

KNA-3366/feat: Basic tests and general order logic improvements
@SalmanTwo SalmanTwo changed the title Staging Merge Staging Into Main Mar 16, 2026
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the Two Payment module for PrestaShop by implementing a provider-first checkout flow, which prioritizes Two's verification before local order creation, thereby eliminating phantom orders. It introduces critical security and data integrity measures, including cart snapshot validation and idempotency keys, alongside comprehensive improvements to tax and discount calculations for precise payload accuracy. The update also expands payment options with End-of-Month terms, refines user experience through better validation and error messaging, and integrates extensive AI development context and testing tools to ensure a robust and maintainable codebase.

Highlights

  • Provider-First Checkout Flow: Implemented a robust provider-first checkout process, ensuring local PrestaShop orders are only created after successful verification by the Two payment gateway, preventing phantom orders.
  • Enhanced Security & Idempotency: Introduced cart snapshot validation and idempotency keys for /v1/order creation, significantly reducing duplicate orders and improving data consistency. Callback authorization checks were also hardened.
  • AI Development Context: Added comprehensive AI context files (.ai/decisions.md, .ai/learnings.md, AGENTS.md, AI_CONTEXT.md, .cursor/rules/prestashop.mdc) to guide AI agents and developers on architectural decisions, learnings, and coding rules.
  • Improved Tax & Discount Accuracy: Refined tax rate calculations, discount attribution, and line-item modeling to ensure precise payload parity with PrestaShop totals, addressing rounding errors and VAT compliance.
  • Flexible Payment Terms: Introduced End-of-Month (EOM) payment terms alongside standard terms, providing more options for B2B customers and enhancing admin configuration.
  • Developer Tooling & Testing: Integrated composer.json and PHPUnit for a robust testing framework, along with a release packaging script, improving development workflow and code quality.
  • User Experience & Validation: Enhanced company search, phone validation, and error messaging in the checkout flow, providing clearer guidance to users and improving address data handling.
Changelog
  • .ai/decisions.md
    • Documented architectural decisions for AI agents.
  • .ai/learnings.md
    • Documented bug fixes and learnings for AI agents.
  • .cursor/rules/prestashop.mdc
    • Added AI development rules for non-Claude models.
  • .gitignore
    • Updated ignored files to include new AI-related directories and exclude IDE configurations.
  • AGENTS.md
    • Defined project-specific instructions and hard constraints for AI coding agents.
  • AI_CONTEXT.md
    • Provided a detailed AI agent operating manual for the module.
  • CHANGELOG.md
    • Updated with detailed entries for versions 2.4.0, 2.3.2, 2.3.1, and 2.3.0.
  • composer.json
    • Added development dependencies for PHPUnit.
  • config.xml
    • Updated module version to 2.4.0.
  • controllers/front/cancel.php
    • Refactored cancellation logic to support attempt tokens and added authorization checks.
  • controllers/front/confirmation.php
    • Implemented attempt token confirmation, cart snapshot validation, and merchant order ID synchronization.
  • controllers/front/orderintent.php
    • Improved error messages, company data fallbacks, rate limiting, and address ID resolution.
  • controllers/front/payment.php
    • Reworked payment processing for provider-first flow, including attempt persistence, cart snapshotting, and idempotency.
  • override/classes/form/CustomerAddressFormatter.php
    • Reworked to delegate to core formatter, added conditional fields, and adjusted field ordering.
  • package-release.sh
    • Added a script for creating clean ZIP releases.
  • phpunit.xml.dist
    • Added PHPUnit configuration file.
  • tests/CustomerAddressFormatterOverrideSpec.php
    • Added tests for CustomerAddressFormatter override.
  • tests/README.md
    • Documented the test suite and pre-commit checks.
  • tests/bootstrap.php
    • Added a bootstrap file for the test environment.
  • tests/integration/README.md
    • Documented real-engine integration matrix requirements.
  • translations/es.php
    • Added new Spanish translations for payment terms, plugin info, and various error messages.
  • upgrade/upgrade-2.3.0.php
    • Added upgrade script to introduce End-of-Month (EOM) payment terms.
  • upgrade/upgrade-2.3.1.php
    • Added upgrade script for tax calculation fixes and plugin info tab.
  • upgrade/upgrade-2.3.2.php
    • Added upgrade script for re-enabling invoice upload.
  • upgrade/upgrade-2.4.0.php
    • Added upgrade script to create the twopayment_attempt table and add new columns.
  • views/css/two.css
    • Added styles for admin payment terms badge and EOM badge.
  • views/js/modules/TwoCheckoutManager.js
    • Enhanced with internationalization, HTML escaping, improved company data handling, payment confirmation detection, and dynamic payment terms display.
  • views/js/modules/TwoCompanySearch.js
    • Implemented public API beforeSend hook and improved company input and address identifier synchronization.
  • views/js/modules/TwoFieldValidation.js
    • Updated the company field error message.
  • views/js/modules/TwoOrderIntent.js
    • Integrated internationalization, a public API beforeSend hook, refined company data resolution, and improved error message handling.
  • views/js/twopayment.js
    • Implemented a local jQuery fallback mechanism and updated the TwoCheckoutManager initialization logic.
  • views/templates/admin/configuration.tpl
    • Added a new plugin information tab and dynamic visibility logic for payment term options.
  • views/templates/hook/displayAdminOrderLeft.tpl
    • Updated to display End-of-Month payment terms and conditionally show invoice links.
  • views/templates/hook/displayAdminOrderTabContent.tpl
    • Updated to display End-of-Month payment terms and conditionally show invoice links.
  • views/templates/hook/displayOrderDetail.tpl
    • Updated to escape HTML output and add noopener noreferrer to external links.
  • views/templates/hook/displayPaymentReturn.tpl
    • Updated to escape HTML output and add noopener noreferrer to external links.
  • views/templates/hook/displayPaymentReturnBuyer.tpl
    • Updated to display End-of-Month payment terms.
  • views/templates/hook/paymentinfo.tpl
    • Updated to escape HTML output and dynamically adjust the payment terms description.
Ignored Files
  • Ignored by pattern: .github/workflows/** (1)
    • .github/workflows/tests.yml
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request merges a significant number of changes from staging to main, introducing major architectural improvements and numerous fixes. Key enhancements include a more robust provider-first checkout flow, idempotency keys for order creation, and cart snapshot validation to prevent inconsistencies. The changes also address security vulnerabilities by escaping output and preventing auth header leakage. Overall, the code quality is high. I have identified one potential issue in the legacy order cancellation logic that could lead to data inconsistency between PrestaShop and the payment provider.

Comment on lines +142 to +190
$orderpaymentdata = $this->module->getTwoOrderPaymentData($id_order);
if ($orderpaymentdata && isset($orderpaymentdata['two_order_id'])) {
$two_order_id = $orderpaymentdata['two_order_id'];

$cancel_response = $this->module->setTwoPaymentRequest('/v1/order/' . $two_order_id . '/cancel', [], 'POST');
$cancel_http_status = isset($cancel_response['http_status']) ? (int)$cancel_response['http_status'] : 0;

$response = $this->module->setTwoPaymentRequest('/v1/order/' . $two_order_id, [], 'GET');
$response_http_status = isset($response['http_status']) ? (int)$response['http_status'] : 0;
$provider_cancelled = $this->module->isTwoOrderCancelledResponse($response, $response_http_status);

if ($provider_cancelled) {
$resolved_terms = $this->module->resolveTwoPaymentTermsFromOrderResponse(
$response,
isset($orderpaymentdata['two_day_on_invoice']) ? (string)$orderpaymentdata['two_day_on_invoice'] : (string)$this->module->getSelectedPaymentTerm(),
isset($orderpaymentdata['two_payment_term_type']) ? $orderpaymentdata['two_payment_term_type'] : Configuration::get('PS_TWO_PAYMENT_TERM_TYPE')
);
$payment_data = array(
'two_order_id' => $response['id'],
'two_order_reference' => $response['merchant_reference'],
'two_order_state' => $response['state'],
'two_order_status' => $response['status'],
'two_day_on_invoice' => $resolved_terms['two_day_on_invoice'],
'two_invoice_url' => $response['invoice_url'],
'two_payment_term_type' => $resolved_terms['two_payment_term_type'],
);
$this->module->setTwoOrderPaymentData($order->id, $payment_data);
} else {
PrestaShopLogger::addLog(
'TwoPayment: Legacy cancel callback could not confirm CANCELLED provider state for order ' . (int)$order->id .
', Two order ' . $two_order_id .
', cancel_http=' . $cancel_http_status .
', fetch_http=' . $response_http_status .
', provider_state=' . (isset($response['state']) ? (string)$response['state'] : 'unknown'),
2
);
$message = sprintf($this->module->l('Could not update status to cancelled, please check with Two admin for id %s'), $two_order_id);
$this->errors[] = $message;
$this->redirectWithNotifications('index.php?controller=order');
}
}

$this->module->restoreDuplicateCart($order->id, $order->id_customer);
$this->module->changeOrderStatus($order->id, $this->getCancelledStatus());

$message = $this->module->l('Your order is cancelled.');
$this->errors[] = $message;
$this->redirectWithNotifications('index.php?controller=order');
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

In handleLegacyOrderCancel, if $orderpaymentdata is not found for the given id_order, the logic proceeds to line 184 and cancels the PrestaShop order locally without attempting to cancel the corresponding order on the Two provider's side. This can lead to data inconsistency between the two systems.

An order paid with Two should have this data. Its absence is an exceptional case. Instead of cancelling the local order, it would be safer to log a critical error and inform the user that the cancellation could not be fully processed.

Consider moving the local cancellation logic (lines 184-189) inside the if ($provider_cancelled) block to ensure it only happens after a confirmed provider-side cancellation. You should also add an else block to handle the case where $orderpaymentdata is missing.

@SalmanTwo SalmanTwo requested a review from brtkwr March 16, 2026 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant