Skip to content

Commit

Permalink
release: module update from ifthenpay/dev_prestashop_8 (ifthenpay/dev…
Browse files Browse the repository at this point in the history
  • Loading branch information
joaocouto-ifthenpay committed Apr 21, 2023
1 parent 3de1419 commit 6d0ca39
Show file tree
Hide file tree
Showing 26 changed files with 221 additions and 100 deletions.
2 changes: 1 addition & 1 deletion ifthenpay/classes/Admin/Payments/CCardAdminOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class CCardAdminOrder extends CCardBase implements AdminOrderInterface
{
public function setSmartyVariables($paymentInDatabase)
{
$this->smartyDefaultData->setIdPedido($this->paymentDataFromDb['requestId']);
$this->smartyDefaultData->setIdPedido($this->paymentDataFromDb['transaction_id']);
}

public function getAdminOrder()
Expand Down
2 changes: 1 addition & 1 deletion ifthenpay/classes/Admin/Payments/MbwayAdminOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class MbwayAdminOrder extends MbwayBase implements AdminOrderInterface
public function setSmartyVariables($paymentInDatabase)
{
$this->smartyDefaultData->setTelemovel($this->paymentDataFromDb['telemovel']);
$this->smartyDefaultData->setIdPedido($this->paymentDataFromDb['id_transacao']);
$this->smartyDefaultData->setIdPedido($this->paymentDataFromDb['transaction_id']);
}

public function getAdminOrder()
Expand Down
2 changes: 1 addition & 1 deletion ifthenpay/classes/Admin/Payments/PayshopAdminOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function setSmartyVariables($paymentInDatabase)
$this->smartyDefaultData->setValidade($this->paymentDataFromDb['validade'] !== '' ?
(new \DateTime($this->paymentDataFromDb['validade']))->format('d-m-Y') : ''
);
$this->smartyDefaultData->setIdPedido($this->paymentDataFromDb['id_transacao']);
$this->smartyDefaultData->setIdPedido($this->paymentDataFromDb['transaction_id']);
} else {
$this->smartyDefaultData->setReferencia($this->paymentGatewayResultData->referencia);
$this->smartyDefaultData->setValidade($this->paymentGatewayResultData->validade !== '' ?
Expand Down
4 changes: 2 additions & 2 deletions ifthenpay/classes/Base/Payments/CCardBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected function setGatewayBuilderData()

protected function saveToDatabase()
{
$this->paymentModel->requestId = $this->paymentGatewayResultData->idPedido;
$this->paymentModel->transaction_id = $this->paymentGatewayResultData->idPedido;
$this->paymentModel->order_id = $this->paymentDefaultData->order->id;
$this->paymentModel->status = 'pending';
$this->paymentModel->save();
Expand All @@ -71,7 +71,7 @@ protected function updateDatabase()
{
/*$this->setPaymentModel('ccard', $this->paymentDataFromDb['id_ifthenpay_ccard']);
$this->paymentModel->referencia = $this->paymentGatewayResultData->referencia;
$this->paymentModel->id_transacao = $this->paymentGatewayResultData->idPedido;
$this->paymentModel->transaction_id = $this->paymentGatewayResultData->idPedido;
$this->paymentModel->update();*/
}

Expand Down
4 changes: 2 additions & 2 deletions ifthenpay/classes/Base/Payments/MbwayBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ protected function setGatewayBuilderData()

protected function saveToDatabase()
{
$this->paymentModel->id_transacao = $this->paymentGatewayResultData->idPedido;
$this->paymentModel->transaction_id = $this->paymentGatewayResultData->idPedido;
$this->paymentModel->telemovel = $this->paymentGatewayResultData->telemovel;
$this->paymentModel->order_id = $this->paymentDefaultData->order->id;
$this->paymentModel->status = 'pending';
Expand All @@ -92,7 +92,7 @@ protected function saveToDatabase()
protected function updateDatabase()
{
$this->setPaymentModel('mbway', $this->paymentDataFromDb['id_ifthenpay_mbway']);
$this->paymentModel->id_transacao = $this->paymentGatewayResultData->idPedido;
$this->paymentModel->transaction_id = $this->paymentGatewayResultData->idPedido;
$this->paymentModel->update();
}

Expand Down
2 changes: 1 addition & 1 deletion ifthenpay/classes/Base/Payments/MultibancoBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected function saveToDatabase()
$this->paymentModel->entidade = $this->paymentGatewayResultData->entidade;
$this->paymentModel->referencia = $this->paymentGatewayResultData->referencia;
$this->paymentModel->order_id = $this->paymentDefaultData->order->id;
$this->paymentModel->request_id = isset($this->paymentGatewayResultData->idPedido) ? $this->paymentGatewayResultData->idPedido : null;
$this->paymentModel->transaction_id = isset($this->paymentGatewayResultData->idPedido) ? $this->paymentGatewayResultData->idPedido : null;
$this->paymentModel->validade = isset($this->paymentGatewayResultData->validade) ? $this->paymentGatewayResultData->validade : null;
$this->paymentModel->status = 'pending';
$this->paymentModel->save();
Expand Down
4 changes: 2 additions & 2 deletions ifthenpay/classes/Base/Payments/PayshopBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected function setGatewayBuilderData()

protected function saveToDatabase()
{
$this->paymentModel->id_transacao = $this->paymentGatewayResultData->idPedido;
$this->paymentModel->transaction_id = $this->paymentGatewayResultData->idPedido;
$this->paymentModel->referencia = $this->paymentGatewayResultData->referencia;
$this->paymentModel->validade = $this->paymentGatewayResultData->validade;
$this->paymentModel->order_id = $this->paymentDefaultData->order->id;
Expand All @@ -53,7 +53,7 @@ protected function updateDatabase()
{
$this->setPaymentModel('payshop', $this->paymentDataFromDb['id_ifthenpay_payshop']);
$this->paymentModel->referencia = $this->paymentGatewayResultData->referencia;
$this->paymentModel->id_transacao = $this->paymentGatewayResultData->idPedido;
$this->paymentModel->transaction_id = $this->paymentGatewayResultData->idPedido;
$this->paymentModel->update();
}

Expand Down
33 changes: 19 additions & 14 deletions ifthenpay/classes/Callback/CallbackOnline.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,37 +62,41 @@ public function process()
$customer = PrestashopModelFactory::buildCustomer((string) $cart->id_customer);
$this->setOrder();
$redirectUrl = \Context::getContext()->link->getPageLink('order-confirmation', true) .
'?id_cart=' . $this->request['cartId'] . '&id_module=' . (int)$ifthenpayModule->id . '&id_order=' . $this->order->id . '&key='.
$customer->secure_key . '&paymentOption=ccard';
'?id_cart=' . $this->request['cartId'] . '&id_module=' . (int)$ifthenpayModule->id . '&id_order=' . $this->order->id . '&key='.
$customer->secure_key . '&paymentOption=ccard';

if ($this->paymentData['status'] === 'pending') {
$paymentStatus = Status::getTokenStatus(
Token::decrypt($this->request['qn'])
);

if ($paymentStatus === 'success') {
if ($this->request['sk'] !== TokenExtra::encript(
$this->request['id'] . $this->request['amount'] . $this->request['requestId'], \Configuration::get('IFTHENPAY_CCARD_KEY'))) {
throw new \Exception($ifthenpayModule->l('Invalid security token', Utility::getClassName($this)));
$this->request['id'] . $this->request['amount'] . $this->request['requestId'],
\Configuration::get('IFTHENPAY_CCARD_KEY'
))) {
throw new \Exception($ifthenpayModule->l('Invalid security token', Utility::getClassName($this)));
}
$orderTotal = floatval(Utility::convertPriceToEuros($this->order));
$requestValor = floatval($this->request['amount']);

if (round($orderTotal, 2) !== round($requestValor, 2)) {
IfthenpayLogProcess::addLog('Payment value by credit card not valid - ' . print_r($_GET), IfthenpayLogProcess::ERROR, $this->order->id);
\Context::getContext()->controller[] = $ifthenpayModule->l('Payment by credit card not valid', Utility::getClassName($this));
\Context::getContext()->controller->redirectWithNotifications($redirectUrl);
}

$this->changeIfthenpayPaymentStatus('paid');
$this->changePrestashopOrderStatus(\Configuration::get('IFTHENPAY_' . \Tools::strtoupper($this->paymentMethod) . '_OS_CONFIRMED'));
IfthenpayLogProcess::addLog('Payment by credit card made with success', IfthenpayLogProcess::INFO, $this->order->id);
$this->redirectUser('success', $ifthenpayModule, $redirectUrl, $ifthenpayModule->l('Payment by credit card made with success', Utility::getClassName($this)));
} else if($paymentStatus === 'cancel') {
$this->changeIfthenpayPaymentStatus('cancel');
$this->changePrestashopOrderStatus(\Configuration::get('PS_OS_CANCELED'));
$msg = isset($this->$this->request['error'])
? ' id:' . $this->request['id'] . ' amount:' . $this->request['amount'] . ' requestId:' . $this->request['requestId'] . 'error: ' . json_encode($this->request['error'])
: 'error data not found';

IfthenpayLogProcess::addLog('Payment by credit card canceled by the client', IfthenpayLogProcess::INFO, $this->order->id);
$this->redirectUser('cancel', $ifthenpayModule, $redirectUrl, $ifthenpayModule->l('Payment by credit card canceled', Utility::getClassName($this)));

} else if ($paymentStatus === 'cancel') {
$this->changeIfthenpayPaymentStatus('cancel');
$this->changePrestashopOrderStatus(\Configuration::get('PS_OS_CANCELED'));
IfthenpayLogProcess::addLog('Payment by credit card canceled by the client', IfthenpayLogProcess::INFO, $this->order->id);
$this->redirectUser('cancel', $ifthenpayModule, $redirectUrl, $ifthenpayModule->l('Payment by credit card canceled', Utility::getClassName($this)));

} else {
$this->changeIfthenpayPaymentStatus('error');
$this->changePrestashopOrderStatus(\Configuration::get('PS_OS_ERROR'));
Expand All @@ -105,17 +109,18 @@ public function process()
}
$errorMsg = $errorMsg === '{}' ? 'error data not found' : $errorMsg;


IfthenpayLogProcess::addLog('Error processing credit card payment - ' . $errorMsg, IfthenpayLogProcess::INFO, $this->order->id);
$this->redirectUser('error', $ifthenpayModule, $redirectUrl, $ifthenpayModule->l('Error processing credit card payment', Utility::getClassName($this)));
}

} else if ($this->paymentData['status'] === 'cancel') {
$this->redirectUser('cancel', $ifthenpayModule, $redirectUrl, $ifthenpayModule->l('Order has already been canceled by the customer', Utility::getClassName($this)));
} else if ($this->paymentData['status'] === 'error') {
$this->redirectUser('error', $ifthenpayModule, $redirectUrl, $ifthenpayModule->l('Error processing credit card payment', Utility::getClassName($this)));
} else {
$this->redirectUser('error', $ifthenpayModule, $redirectUrl, $ifthenpayModule->l('Order has already been paid', Utility::getClassName($this)));
}

} catch (\Throwable $th) {
$this->changeIfthenpayPaymentStatus('error');
$this->changePrestashopOrderStatus(\Configuration::get('PS_OS_ERROR'));
Expand Down
6 changes: 3 additions & 3 deletions ifthenpay/classes/Callback/CallbackProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ protected function changeIfthenpayPaymentStatus($status)
{
$ifthenpayModel = IfthenpayModelFactory::build($this->paymentMethod, $this->paymentData['id_ifthenpay_' . $this->paymentMethod]);

//WORKAROUND: odd behaviour from prestashop model object, it loses the requestId of the order for Ccard, so there is a need to set it in the next two lines
if($this->paymentMethod == 'ccard' && isset($this->paymentData['requestId'])){
$ifthenpayModel->requestId = $this->paymentData['requestId'];
//WORKAROUND: odd behaviour from prestashop model object, it loses the transaction_id of the order for Ccard, so there is a need to set it in the next two lines
if($this->paymentMethod == 'ccard' && isset($this->paymentData['transaction_id'])){
$ifthenpayModel->transaction_id = $this->paymentData['transaction_id'];
}
$ifthenpayModel->status = $status;
$ifthenpayModel->update();
Expand Down
1 change: 0 additions & 1 deletion ifthenpay/classes/Callback/CallbackStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class CallbackStrategy
{
public function execute($request)
{
$request['type'] = 'offline';
if ($request['type'] === 'offline') {
return (new CallbackOffline())->setPaymentMethod($request['payment'])->setRequest($request)->process();
} else if ($request['type'] === 'online') {
Expand Down
14 changes: 7 additions & 7 deletions ifthenpay/classes/Config/IfthenpaySql.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,38 +43,38 @@ class IfthenpaySql implements InstallerInterface
`entidade` varchar(5) NOT NULL,
`referencia` varchar(9) NOT NULL,
`validade` varchar(16),
`request_id` varchar(50),
`transaction_id` varchar(50),
`order_id` int(11) NOT NULL,
`status` varchar(50) NOT NULL,
PRIMARY KEY (`id_ifthenpay_multibanco`),
INDEX `referencia` (`referencia`)
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8;',
'mbway' => 'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'ifthenpay_mbway` (
`id_ifthenpay_mbway` int(10) unsigned NOT NULL auto_increment,
`id_transacao` varchar(20) NOT NULL,
`transaction_id` varchar(20) NOT NULL,
`telemovel` varchar(20) NOT NULL,
`order_id` int(11) NOT NULL,
`status` varchar(50) NOT NULL,
PRIMARY KEY (`id_ifthenpay_mbway`),
INDEX `idTransacao` (`id_transacao`)
INDEX `transaction_id` (`transaction_id`)
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8;',
'payshop' => 'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'ifthenpay_payshop` (
`id_ifthenpay_payshop` int(10) unsigned NOT NULL auto_increment,
`id_transacao` varchar(20) NOT NULL,
`transaction_id` varchar(20) NOT NULL,
`referencia` varchar(13) NOT NULL,
`validade` varchar(8) NOT NULL,
`order_id` int(11) NOT NULL,
`status` varchar(50) NOT NULL,
PRIMARY KEY (`id_ifthenpay_payshop`),
INDEX `idTransacao` (`id_transacao`)
INDEX `transaction_id` (`transaction_id`)
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8;',
'ccard' => 'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'ifthenpay_ccard` (
`id_ifthenpay_ccard` int(10) unsigned NOT NULL auto_increment,
`requestId` varchar(50) NOT NULL,
`transaction_id` varchar(50) NOT NULL,
`order_id` int(11) NOT NULL,
`status` varchar(50) NOT NULL,
PRIMARY KEY (`id_ifthenpay_ccard`),
INDEX `requestId` (`requestId`)
INDEX `transaction_id` (`transaction_id`)
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8;',
];

Expand Down
4 changes: 2 additions & 2 deletions ifthenpay/classes/Log/IfthenpayLogProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@

class IfthenpayLogProcess
{
const ERROR = 'error';

const INFO = 'info';
const WARNING = 'warning';
const ERROR = 'error';

public static function addLog($message, $type, $orderId)
{
Expand Down
8 changes: 4 additions & 4 deletions ifthenpay/classes/Models/IfthenpayCCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class IfthenpayCCard extends \ObjectModel implements PaymentModelInterface
{
public $id;
public $id_ifthenpay_ccard;
public $id_transacao;
public $transaction_id;
public $referencia;
public $validade;
public $order_id;
Expand All @@ -47,7 +47,7 @@ class IfthenpayCCard extends \ObjectModel implements PaymentModelInterface
'multilang' => false,
'multishop' => true,
'fields' => [
'requestId' => [
'transaction_id' => [
'type' => self::TYPE_STRING,
'required' => true,
'validate' => 'isString',
Expand Down Expand Up @@ -87,10 +87,10 @@ public static function getByOrderId($orderId)
}
}

public static function getCCardByRequestId($requestId)
public static function getCCardByRequestId($transaction_id)
{
$rowOrder = \Db::getInstance()
->executeS('SELECT * FROM ' . _DB_PREFIX_ . self::$definition['table'] . ' WHERE (requestId = ' . '\'' . \pSQL((string) $requestId) . '\') ');
->executeS('SELECT * FROM ' . _DB_PREFIX_ . self::$definition['table'] . ' WHERE (transaction_id = ' . '\'' . \pSQL((string) $transaction_id) . '\') ');
if (is_array($rowOrder)) {
return $rowOrder[0];
} else {
Expand Down
8 changes: 4 additions & 4 deletions ifthenpay/classes/Models/IfthenpayMbway.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class IfthenpayMbway extends \ObjectModel implements PaymentModelInterface
{
public $id;
public $id_ifthenpay_mbway;
public $id_transacao;
public $transaction_id;
public $telemovel;
public $order_id;

Expand All @@ -46,7 +46,7 @@ class IfthenpayMbway extends \ObjectModel implements PaymentModelInterface
'multilang' => false,
'multishop' => true,
'fields' => [
'id_transacao' => [
'transaction_id' => [
'type' => self::TYPE_STRING,
'required' => true,
'validate' => 'isString',
Expand Down Expand Up @@ -92,10 +92,10 @@ public static function getByOrderId($orderId)
}
}

public static function getMbwayByIdTransacao($idTransacao)
public static function getMbwayByIdTransacao($transaction_id)
{
$rowOrder = \Db::getInstance()
->executeS('SELECT * FROM ' . _DB_PREFIX_ . self::$definition['table'] . ' WHERE (id_transacao = ' . '\'' . \pSQL($idTransacao) . '\') ');
->executeS('SELECT * FROM ' . _DB_PREFIX_ . self::$definition['table'] . ' WHERE (transaction_id = ' . '\'' . \pSQL($transaction_id) . '\') ');

if (is_array($rowOrder) && !empty($rowOrder)) {
return $rowOrder[0];
Expand Down
2 changes: 1 addition & 1 deletion ifthenpay/classes/Models/IfthenpayMultibanco.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class IfthenpayMultibanco extends \ObjectModel implements PaymentModelInterface
'validate' => 'isString',
'size' => 16
],
'request_id' => [
'transaction_id' => [
'type' => self::TYPE_STRING,
'required' => false,
'validate' => 'isString',
Expand Down
8 changes: 4 additions & 4 deletions ifthenpay/classes/Models/IfthenpayPayshop.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class IfthenpayPayshop extends \ObjectModel implements PaymentModelInterface
{
public $id;
public $id_ifthenpay_payshop;
public $id_transacao;
public $transaction_id;
public $referencia;
public $validade;
public $order_id;
Expand All @@ -47,7 +47,7 @@ class IfthenpayPayshop extends \ObjectModel implements PaymentModelInterface
'multilang' => false,
'multishop' => true,
'fields' => [
'id_transacao' => [
'transaction_id' => [
'type' => self::TYPE_STRING,
'required' => true,
'validate' => 'isString',
Expand Down Expand Up @@ -98,10 +98,10 @@ public static function getByOrderId($orderId)
}
}

public static function getPayshopByIdTransacao($idTransacao)
public static function getPayshopByIdTransacao($transaction_id)
{
$rowOrder = \Db::getInstance()
->executeS('SELECT * FROM ' . _DB_PREFIX_ . self::$definition['table'] . ' WHERE (id_transacao = ' . '\'' . \pSQL((string) $idTransacao) . '\') ');
->executeS('SELECT * FROM ' . _DB_PREFIX_ . self::$definition['table'] . ' WHERE (transaction_id = ' . '\'' . \pSQL((string) $transaction_id) . '\') ');
if (is_array($rowOrder)) {
return $rowOrder[0];
} else {
Expand Down
Loading

0 comments on commit 6d0ca39

Please sign in to comment.