Skip to content
Merged
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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ PrestaShop 1.6.x, 1.7.x and 8.x

# Changelog

## [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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Docs/Configuration/merchant_details.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 not shown.
68 changes: 53 additions & 15 deletions altapay.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ class ALTAPAY extends PaymentModule
private $api_error = '';

const ADMIN_SEND_PAYMENT_LINK_CONTROLLER = 'AltapaySendPaymentLink';
const PS_17_MIN_VERSION = '1.7.0.0'; //NOSONAR

public function __construct()
{
$this->name = 'altapay';
$this->tab = 'payments_gateways';
$this->version = '4.0.2';
$this->version = '5.0.0';
$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 @@ -466,11 +467,10 @@ public function install()
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8');
}

// Execute the query
$result = Db::getInstance()->getValue('SELECT COUNT(*) FROM ' . _DB_PREFIX_ . 'altapay_terminals');
// Check if the table contains data
if ($result == 0 && empty(Configuration::get('ALTAPAY_USERNAME'))) {
if (isAltapayTerminalTableEmpty() && empty(Configuration::get('ALTAPAY_USERNAME'))) {
Configuration::updateValue('enable_cc_style', 'checkout-cc');
Configuration::updateValue('payment_page_layout', 'default_layout');
}

if (!Db::getInstance()->getRow('SELECT * FROM INFORMATION_SCHEMA.COLUMNS
Expand Down Expand Up @@ -1760,6 +1760,28 @@ public function renderForm()
'name' => 'name',
],
],
[
'type' => 'select',
'label' => $this->l('Payment page layout'),
'desc' => $this->l('The default option follows the theme styling, while the custom option
displays the payment page independently of the theme styling.'),
'name' => 'payment_page_layout',
'required' => false,
'options' => [
'query' => [
[
'id_option' => 'default_layout',
'name' => 'Default',
],
[
'id_option' => 'checkout_independent',
'name' => 'Checkout Independent',
],
],
'id' => 'id_option',
'name' => 'name',
],
],
[
'type' => 'select',
'label' => $this->l('Authorized payments status'),
Expand Down Expand Up @@ -1882,6 +1904,7 @@ public function getConfigFieldsValues()
'AUTOCAPTURE_STATUSES[]' => Tools::getValue('AUTOCAPTURE_STATUSES',
unserialize(Configuration::get('AUTOCAPTURE_STATUSES'))),
'enable_cc_style' => Tools::getValue('enable_cc_style', Configuration::get('enable_cc_style')),
'payment_page_layout' => Tools::getValue('payment_page_layout', Configuration::get('payment_page_layout')),
'enable_fraud' => Tools::getValue('enable_fraud', Configuration::get('enable_fraud')),
'enable_release_refund' => Tools::getValue('enable_release_refund', Configuration::get('enable_release_refund')),
'authorized_payments_status' => Tools::getValue('authorized_payments_status', Configuration::get('authorized_payments_status')),
Expand Down Expand Up @@ -2019,6 +2042,9 @@ private function postProcess()
if (Tools::getValue('enable_cc_style') !== '') {
Configuration::updateValue('enable_cc_style', Tools::getValue('enable_cc_style'));
}
if (Tools::getValue('payment_page_layout') !== '') {
Configuration::updateValue('payment_page_layout', Tools::getValue('payment_page_layout'));
}
if (Tools::getValue('authorized_payments_status') !== '') {
Configuration::updateValue('authorized_payments_status', Tools::getValue('authorized_payments_status'));
}
Expand Down Expand Up @@ -3017,12 +3043,17 @@ public function createTransaction($savecard,
$cgConf['uniqueid'] = uniqid('PS');
$cgConf['terminal'] = $terminal->remote_name;
$cgConf['cookie'] = $_SERVER['HTTP_COOKIE'] ?? null;
$paymentPageLayout = Configuration::get('payment_page_layout');

$callback = [];
$callbackFormType = 'callbackform';
if ($paymentPageLayout === 'checkout_independent') {
$callbackFormType = 'callbackformexternal';
}
// Callbacks
$callback['callback_form'] = $this->context->link->getModuleLink(
$this->name,
'callbackform',
$callbackFormType,
[],
true,
$languageId,
Expand Down Expand Up @@ -3138,6 +3169,15 @@ public function createTransaction($savecard,
}

$type = $cgConf['payment_type'];
$requestShopOrderId = $cgConf['uniqueid'];
$requestAmount = $amount;
if (!empty($shopOrderId)) {
$requestShopOrderId = $shopOrderId;
$requestAmount = $remainingAmount;
$requestOrderLines = $this->orderAddedFromBackOffice($remainingAmount);
} else {
$requestOrderLines = $this->getOrderLines($cart);
}

if (!is_null($savecard) && $savecard != 0) {
$type = 'verifyCard';
Expand All @@ -3147,6 +3187,13 @@ public function createTransaction($savecard,
}

try {
$sessionRequest = new API\PHP\Altapay\Api\Payments\CheckoutSession(getAuth());
$sessionRequest->setTerminals([$cgConf['terminal']])
->setShopOrderId($requestShopOrderId)
->setAmount($requestAmount)
->setCurrency($cgConf['currency']);
$sessionResponse = $sessionRequest->call();
$sessionId = $sessionResponse->Session->Id;
$config = new API\PHP\Altapay\Request\Config();
$config->setCallbackOk($callback['callback_ok']);
$config->setCallbackFail($callback['callback_fail']);
Expand Down Expand Up @@ -3183,20 +3230,11 @@ public function createTransaction($savecard,
$request->setAgreement(['type' => 'recurring']);
}

$requestShopOrderId = $cgConf['uniqueid'];
$requestAmount = $amount;
if (!empty($shopOrderId)) {
$requestShopOrderId = $shopOrderId;
$requestAmount = $remainingAmount;
$requestOrderLines = $this->orderAddedFromBackOffice($remainingAmount);
} else {
$requestOrderLines = $this->getOrderLines($cart);
}

$request->setType($type)->setTerminal($cgConf['terminal'])
->setShopOrderId($requestShopOrderId)
->setAmount($requestAmount)
->setCurrency($cgConf['currency'])
->setSessionID($sessionId)
->setCustomerInfo($customer)
->setTransactionInfo($transactionInfo)
->setCookie($cgConf['cookie'])
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"require": {
"php": "^7.0",
"altapay/api-php": "^3.2",
"altapay/api-php": "^3.5.8",
"humbug/php-scoper": "0.13.9",
"nikic/php-parser": "4.x-dev",
"symfony/options-resolver": "^3.0",
Expand Down
Loading
Loading