Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ PrestaShop 1.6.x, 1.7.x and 8.x

# Changelog

## [5.0.1]
### Added
- Ensure the payment request does not fail in cases where `checkoutSession` is not returned or fails, particularly for older gateway API versions.

## [5.0.0]
### Added
- Add support for `checkoutSession` for reusable checkout sessions improving fraud detection and conversion.
- Support gateway form independent of the plugin/theme styling.

> **Note:** `checkoutSession` requires gateway version `20260311` or later.


## [4.0.2]
### Added
- Add support for Checkout Design v2.
Expand Down
15 changes: 12 additions & 3 deletions altapay.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct()
{
$this->name = 'altapay';
$this->tab = 'payments_gateways';
$this->version = '5.0.0';
$this->version = '5.0.1';
$this->author = 'AltaPay A/S';
$this->is_eu_compatible = 1;
$this->ps_versions_compliancy = ['min' => '1.6.0.1', 'max' => '8.2.3'];
Expand Down Expand Up @@ -3186,6 +3186,7 @@ public function createTransaction($savecard,
$results = false;
}

$sessionId = null;
try {
$sessionRequest = new API\PHP\Altapay\Api\Payments\CheckoutSession(getAuth());
$sessionRequest->setTerminals([$cgConf['terminal']])
Expand All @@ -3194,6 +3195,11 @@ public function createTransaction($savecard,
->setCurrency($cgConf['currency']);
$sessionResponse = $sessionRequest->call();
$sessionId = $sessionResponse->Session->Id;
} catch (\Exception $e) {
PrestaShopLogger::addLog($e->getMessage(), 2, $e->getCode(), $this->name, $this->id, true);
}

try {
$config = new API\PHP\Altapay\Request\Config();
$config->setCallbackOk($callback['callback_ok']);
$config->setCallbackFail($callback['callback_fail']);
Expand Down Expand Up @@ -3234,14 +3240,17 @@ public function createTransaction($savecard,
->setShopOrderId($requestShopOrderId)
->setAmount($requestAmount)
->setCurrency($cgConf['currency'])
->setSessionID($sessionId)
->setCustomerInfo($customer)
->setTransactionInfo($transactionInfo)
->setCookie($cgConf['cookie'])
->setFraudService(null)
->setOrderLines($requestOrderLines)
->setSaleReconciliationIdentifier(sha1(uniqid(time(), true)));

if ($sessionId) {
$request->setSessionID($sessionId);
}

if (!$isReservation) {
$request->setConfig($config)->setLanguage($cgConf['language']);
if (!$terminal->applepay) {
Expand Down Expand Up @@ -3292,7 +3301,7 @@ public function createTransaction($savecard,
$message = $e->getMessage();
}
} catch (API\PHP\Altapay\Exceptions\ClientException $e) {
$message = $e->getResponse()->getBody();
$message = (string) $e->getResponse()->getBody();
} catch (API\PHP\Altapay\Exceptions\ResponseHeaderException $e) {
$message = $e->getHeader()->ErrorMessage;
} catch (API\PHP\Altapay\Exceptions\ResponseMessageException $e) {
Expand Down
2 changes: 1 addition & 1 deletion config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<module>
<name>altapay</name>
<displayName><![CDATA[AltaPay for PrestaShop]]></displayName>
<version><![CDATA[5.0.0]]></version>
<version><![CDATA[5.0.1]]></version>
<description><![CDATA[AltaPay: Payments less complicated]]></description>
<author><![CDATA[AltaPay A/S]]></author>
<tab><![CDATA[payments_gateways]]></tab>
Expand Down
1 change: 1 addition & 0 deletions controllers/front/callbackformexternal.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public function postProcess()
'stylingclass' => $payment_style,
'amount' => $postData['amount'],
'shop_logo' => _PS_IMG_ . Configuration::get('PS_LOGO'),
'shop_name' => Configuration::get('PS_SHOP_NAME'),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We are pushing the shop name to the frontend, which potentially can do XSS if not sanitised.

Is the ShopName sanitised when being inserted in the configuration?

Or even better, maybe we should sanitise it now to ensure how it is stored does not open us for this vulnerability?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@emicha , here we are only reading the value from configuration and sending it to the template.

In PrestaShop, the standard approach is to escape at output depending on the context, which is already done here with {$shop_name|escape:'html').

views/templates/front/payment_form_independent.tpl

If we sanitize it in PHP here, it could cause issues like double escaping or problems in other contexts.

I agree it would be better to validate the shop name when it is saved in configuration, so it is safe everywhere.

]);
if (version_compare(_PS_VERSION_, $this->module::PS_17_MIN_VERSION, '>=')) {
$this->setTemplate('module:altapay/views/templates/front/payment_form_independent.tpl');
Expand Down
2 changes: 1 addition & 1 deletion helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
function transactionInfo($transactionInfo = [])
{
$pluginName = 'altapay';
$pluginVersion = '5.0.0';
$pluginVersion = '5.0.1';

// Transaction info
$transactionInfo['ecomPlatform'] = 'PrestaShop';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require('@cypress/xpath');

class Order

{
Expand Down Expand Up @@ -39,8 +37,6 @@ class Order
cy.contains(CC_TERMINAL_NAME).click({force: true})

cy.get('[id=creditCardNumberInput]').type('4111111111111111')
cy.get('#emonth').select('12')
cy.get('#eyear').select('2025')
cy.get('#cvcInput').type('123')
cy.get('#cardholderNameInput').type('testname')
cy.get('#pensioCreditCardPaymentSubmitButton').click().wait(4000)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require('@cypress/xpath');

class Order

{
Expand Down Expand Up @@ -47,8 +45,6 @@ class Order
cy.get('.condition-label > .js-terms').click()
cy.get('.ps-shown-by-js > .btn').click()
cy.get('[id=creditCardNumberInput]').type('4111111111111111')
cy.get('#emonth').select('12')
cy.get('#eyear').select('2025')
cy.get('#cvcInput').type('123')
cy.get('#cardholderNameInput').type('testname')
cy.get('#pensioCreditCardPaymentSubmitButton').click().wait(4000)
Expand Down Expand Up @@ -389,8 +385,6 @@ class Order
cy.get('#generate-payment-link-btn').click().wait(8000)
cy.get('a[href^="https://testgateway.pensio.com/eCommerce/API/requestForm?pid="]').click()
cy.get('[id=creditCardNumberInput]').type('4111111111111111')
cy.get('#emonth').select('12')
cy.get('#eyear').select('2025')
cy.get('#cvcInput').type('123')
cy.get('#cardholderNameInput').type('testname')
cy.get('#pensioCreditCardPaymentSubmitButton').click().wait(4000)
Expand Down
2 changes: 1 addition & 1 deletion views/templates/front/payment_form_independent.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@
<body class="{$stylingclass}">
<header class="header-minimal">
<div class="header-minimal-logo">
<img src="{$shop_logo}" alt="logo" class="header-logo-main-img">
<img src="{$shop_logo|escape:'html'}" alt="{$shop_name|escape:'html'}" class="header-logo-main-img">
</div>
</header>
<div class="content-wrapper">
Expand Down
Loading