Skip to content

Commit

Permalink
Merge pull request #153 from margud/3.5.3
Browse files Browse the repository at this point in the history
3.5.3
  • Loading branch information
margud authored Feb 7, 2020
2 parents 76804bc + 4c99a4a commit 30cc612
Show file tree
Hide file tree
Showing 28 changed files with 317 additions and 227 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ package-lock.json
build/
prestashop/
.codecept.phar
/translations/
1 change: 1 addition & 0 deletions controllers/front/ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function postProcess()
foreach ($errorMessages as $errorMessage) {
if (strpos($errorMessage, 'mollieMessage=') === 0) {
$errorMessage = str_replace('mollieMessage=', '', $errorMessage);
$errorMessage = str_replace('_', ' ', $errorMessage);
$this->context->smarty->assign(array(
'errorMessage' => $errorMessage

Expand Down
42 changes: 2 additions & 40 deletions controllers/front/payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,44 +88,6 @@ public function initContent()
}
$issuer = Tools::getValue('issuer') ?: null;

// If no issuer was set yet and the issuer list has its own page, show issuer list here
if (!$issuer
&& Configuration::get(Mollie::MOLLIE_ISSUERS) === Mollie::ISSUERS_OWN_PAGE
&& $method === \Mollie\Api\Types\PaymentMethod::IDEAL
) {
$tplData = array();
try {
$issuers = $this->module->getIssuerList();
} catch (\Mollie\Api\Exceptions\ApiException $e) {
$this->setTemplate('error.tpl');
$this->errors[] = Configuration::get(Mollie::MOLLIE_DISPLAY_ERRORS)
? $e->getMessage()
: $this->module->l('An error occurred while initializing your payment. Please contact our customer support.', 'payment');
return;
} catch (PrestaShopException $e) {
$this->setTemplate('error.tpl');
$this->errors[] = Configuration::get(Mollie::MOLLIE_DISPLAY_ERRORS)
? $e->getMessage()
: $this->module->l('An error occurred while initializing your payment. Please contact our customer support.', 'payment');
return;
}
$tplData['issuers'] = isset($issuers[\Mollie\Api\Types\PaymentMethod::IDEAL]) ? $issuers[\Mollie\Api\Types\PaymentMethod::IDEAL] : array();
if (!empty($tplData['issuers'])) {
$tplData['msg_bankselect'] = $this->module->lang['Select your bank:'];
$tplData['msg_ok'] = $this->module->lang['OK'];
$tplData['msg_return'] = $this->module->lang['Different payment method'];
$tplData['link'] = $this->context->link;
$tplData['cartAmount'] = (int) ($this->context->cart->getOrderTotal(true) * 100);
$tplData['qrAlign'] = 'center';
$tplData['publicPath'] = __PS_BASE_URI__.'modules/'.basename(__FILE__, '.php').'/views/js/dist/';
$this->context->controller->addJS(Mollie::getWebpackChunks('app'));
$this->context->smarty->assign($tplData);
$this->setTemplate('mollie_issuers.tpl');

return;
}
}

$originalAmount = $cart->getOrderTotal(
true,
Cart::BOTH
Expand Down Expand Up @@ -251,7 +213,7 @@ public function initContent()
'step' => 1,
]
);
$this->errors[] = $this->l('Failed to validate order');
$this->errors[] = $this->l('Failed to validate order', 'payment');
$this->redirectWithNotifications($redirectLink);
}
}
Expand Down Expand Up @@ -319,7 +281,7 @@ protected function createPayment($data)
$payment = $this->module->api->payments->create($data);
}
} catch (Exception $e) {
throw new ApiException();
throw new ApiException($e->getMessage());
}
return $payment;
}
Expand Down
75 changes: 24 additions & 51 deletions controllers/front/return.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,55 +131,7 @@ public function initContent()
) {
$data['msg_details'] = $this->module->lang('We have not received a definite payment status. You will be notified as soon as we receive a confirmation of the bank/merchant.');
} else {
switch ($data['mollie_info']['bank_status']) {
case 'created':
$data['wait'] = true;
break;
case \Mollie\Api\Types\PaymentStatus::STATUS_OPEN:
$data['wait'] = true;
break;
case \Mollie\Api\Types\PaymentStatus::STATUS_PENDING:
$data['wait'] = true;
break;
case \Mollie\Api\Types\PaymentStatus::STATUS_FAILED:
Tools::redirect($this->context->link->getPagelink('order', true, null, array('step' => 3)));
break;
case \Mollie\Api\Types\PaymentStatus::STATUS_CANCELED:
Tools::redirect($this->context->link->getPagelink('order', true, null, array('step' => 3)));
break;
case \Mollie\Api\Types\PaymentStatus::STATUS_EXPIRED:
$data['msg_details'] = $this->module->lang('Unfortunately your payment was expired.');
break;
case \Mollie\Api\Types\PaymentStatus::STATUS_PAID:
case \Mollie\Api\Types\PaymentStatus::STATUS_AUTHORIZED:
// Validate the Order
if (isset($cart) && Validate::isLoadedObject($cart)) {
Tools::redirect(
$this->context->link->getPageLink(
'order-confirmation',
true,
null,
array(
'id_cart' => (int) $cart->id,
'id_module' => (int) $this->module->id,
'id_order' => (int) version_compare(_PS_VERSION_, '1.7.1.0', '>=')
? Order::getIdByCartId((int) $cart->id)
: Order::getOrderByCartId((int) $cart->id),
'key' => $cart->secure_key,
)
)
);
}

$data['msg_details'] = $this->module->lang('Thank you. Your order has been received.');
break;
default:
$data['msg_details'] = $this->module->lang('The transaction has an unexpected status.');
if (Configuration::get(Mollie::MOLLIE_DEBUG_LOG) == Mollie::DEBUG_LOG_ERRORS) {
Logger::addLog(__METHOD__.'said: The transaction has an unexpected status ('.$data['mollie_info']['bank_status'].')', Mollie::WARNING);
}
break;
}
$data['wait'] = true;
}
} else {
// Not allowed? Don't make query but redirect.
Expand Down Expand Up @@ -312,20 +264,41 @@ protected function processGetStatus()
$_GET['module'] = $this->module->name;
}
$webhookController = new MollieWebhookModuleFrontController();

if (Tools::substr($transactionId, 0, 3) === 'ord') {
$apiPayment = $webhookController->processTransaction($this->module->api->orders->get($transactionId, array('embed' => 'payments')));
} else {
$apiPayment = $webhookController->processTransaction($this->module->api->payments->get($transactionId));
}

if (!isset($apiPayment->status)) {
$status = static::DONE;
$href = $this->context->link->getPagelink('order', true, null, array('step' => 3));
$tagMessage = str_replace(' ', '_', $apiPayment);
$href .= "#mollieMessage={$tagMessage}";

die(json_encode(array(
'success' => true,
'status' => $status,
'response' => json_encode($apiPayment),
'href' => $href
)));
}

switch ($apiPayment->status) {
case \Mollie\Api\Types\PaymentStatus::STATUS_EXPIRED:
case \Mollie\Api\Types\PaymentStatus::STATUS_FAILED:
case \Mollie\Api\Types\PaymentStatus::STATUS_CANCELED:
$status = static::DONE;
$href = $this->context->link->getPagelink('order', true, null, array('step' => 3));
$href .= isset($apiPayment->details->failureMessage) ?
"#mollieMessage={$apiPayment->details->failureMessage}" : '';
if (isset($apiPayment->details->failureMessage)) {
$tagMessage = str_replace(' ', '_', $apiPayment->details->failureMessage);
$href .= "#mollieMessage={$tagMessage}";
} else {
$message = $this->module->l('Payment was canceled', 'return');
$tagMessage = str_replace(' ', '_', $message);
$href .= "#mollieMessage={$tagMessage}";
}
die(json_encode(array(
'success' => true,
'status' => $status,
Expand Down
21 changes: 11 additions & 10 deletions controllers/front/webhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected function displayMaintenancePage()
public function initContent()
{
if (Configuration::get(Mollie::DEBUG_LOG_ALL)) {
Logger::addLog('Mollie incoming webhook: '.Tools::file_get_contents('php://input'));
PrestaShopLogger::addLog('Mollie incoming webhook: '.Tools::file_get_contents('php://input'));
}

die($this->executeWebhook());
Expand All @@ -98,8 +98,8 @@ public function initContent()
protected function executeWebhook()
{
if (Tools::getValue('testByMollie')) {
if (Configuration::get(Mollie::MOLLIE_DEBUG_LOG) == Mollie::DEBUG_LOG_ERRORS) {
Logger::addLog(__METHOD__.' said: Mollie webhook tester successfully communicated with the shop.', Mollie::NOTICE);
if (Configuration::get(Mollie::MOLLIE_DEBUG_LOG) >= Mollie::DEBUG_LOG_ERRORS) {
PrestaShopLogger::addLog(__METHOD__.' said: Mollie webhook tester successfully communicated with the shop.', Mollie::NOTICE);
}

return 'OK';
Expand Down Expand Up @@ -136,11 +136,11 @@ protected function executeWebhook()
public function processTransaction($transaction)
{
if (empty($transaction)) {
if (Configuration::get(Mollie::MOLLIE_DEBUG_LOG) == Mollie::DEBUG_LOG_ERRORS) {
Logger::addLog(__METHOD__.' said: Received webhook request without proper transaction ID.', Mollie::WARNING);
if (Configuration::get(Mollie::MOLLIE_DEBUG_LOG) >= Mollie::DEBUG_LOG_ERRORS) {
PrestaShopLogger::addLog(__METHOD__.' said: Received webhook request without proper transaction ID.', Mollie::WARNING);
}

return 'NO ID';
return $this->module->l('Transaction failed', 'webhook');
}

// Ensure that we are dealing with a Payment object, in case of transaction ID or Payment object w/ Order ID, convert
Expand Down Expand Up @@ -205,7 +205,7 @@ public function processTransaction($transaction)
}

if (!isset($apiPayment)) {
return 'NOT OK';
return $this->module->l('Transaction failed', 'webhook');
}

$psPayment = Mollie::getPaymentBy('transaction_id', $transaction->id);
Expand Down Expand Up @@ -270,15 +270,16 @@ public function processTransaction($transaction)
$this->saveOrderTransactionData($apiPayment->id, $apiPayment->method, $orderId);

if (!$this->savePaymentStatus($transaction->id, $apiPayment->status, $orderId)) {
if (Configuration::get(Mollie::MOLLIE_DEBUG_LOG) == Mollie::DEBUG_LOG_ERRORS) {
Logger::addLog(__METHOD__.' said: Could not save Mollie payment status for transaction "'.$transaction->id.'". Reason: '.Db::getInstance()->getMsgError(), Mollie::WARNING);
if (Configuration::get(Mollie::MOLLIE_DEBUG_LOG) >= Mollie::DEBUG_LOG_ERRORS) {
PrestaShopLogger::addLog(__METHOD__.' said: Could not save Mollie payment status for transaction "'.$transaction->id.'". Reason: '.Db::getInstance()->getMsgError(), Mollie::WARNING);
}
}

// Log successful webhook requests in extended log mode only
if (Configuration::get(Mollie::MOLLIE_DEBUG_LOG) == Mollie::DEBUG_LOG_ALL) {
Logger::addLog(__METHOD__.' said: Received webhook request for order '.(int) $orderId.' / transaction '.$transaction->id, Mollie::NOTICE);
PrestaShopLogger::addLog(__METHOD__.' said: Received webhook request for order '.(int) $orderId.' / transaction '.$transaction->id, Mollie::NOTICE);
}
Hook::exec('actionOrderStatusUpdate', array('newOrderStatus' => (int) $this->module->statuses[$apiPayment->status], 'id_order' => (int) $orderId));

return $apiPayment;
}
Expand Down
Loading

0 comments on commit 30cc612

Please sign in to comment.