Skip to content

Commit

Permalink
Merge pull request #72 from mollie/2.x-backport
Browse files Browse the repository at this point in the history
Backport for version 1.5 and 2.x
  • Loading branch information
QualityWorks-Dev authored Oct 12, 2017
2 parents 70b63ad + 045facb commit 973a7fd
Show file tree
Hide file tree
Showing 20 changed files with 1,225 additions and 176 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

# Changelog #

#### Changes in release 8.2.0
+ New features are now available for OpenCart 1.5 and 2.x!
+ Fix a bug where a payment method would not always be displayed correctly in the order email when using payment images.
+ Minor issues solved.

#### Changes in release 8.1.0
+ Added 6 new payment methods (Gift cards)!
+ fashioncheque
Expand Down
270 changes: 161 additions & 109 deletions admin/controller/extension/payment/mollie/base.php

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion admin/language/dutch/extension/payment/mollie.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@
$_['entry_payment_method'] = "Betaalmethode";
$_['entry_activate'] = "Activeren";
$_['entry_sort_order'] = "Sorteervolgorde";
$_['entry_status'] = "Status";
$_['entry_api_key'] = "API-sleutel";
$_['entry_description'] = "Omschrijving";
$_['entry_show_icons'] = "Toon icoontjes";
Expand Down
1 change: 0 additions & 1 deletion admin/language/en-gb/extension/payment/mollie.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@
$_['entry_payment_method'] = "Payment method";
$_['entry_activate'] = "Activate";
$_['entry_sort_order'] = "Sort order";
$_['entry_status'] = "Status";
$_['entry_api_key'] = "API key";
$_['entry_description'] = "Description";
$_['entry_show_icons'] = "Show icons";
Expand Down
1 change: 0 additions & 1 deletion admin/language/english/extension/payment/mollie.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@
$_['entry_payment_method'] = "Payment method";
$_['entry_activate'] = "Activate";
$_['entry_sort_order'] = "Sort order";
$_['entry_status'] = "Status";
$_['entry_api_key'] = "API key";
$_['entry_description'] = "Description";
$_['entry_show_icons'] = "Show icons";
Expand Down
1 change: 0 additions & 1 deletion admin/language/fr-fr/extension/payment/mollie.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@
$_['entry_payment_method'] = "Procédé de paiement";
$_['entry_activate'] = "Activate";
$_['entry_sort_order'] = "Ordre de triage";
$_['entry_status'] = "État";
$_['entry_api_key'] = "Clé API";
$_['entry_description'] = "Description";
$_['entry_show_icons'] = "Afficher des icônes";
Expand Down
1 change: 0 additions & 1 deletion admin/language/french/extension/payment/mollie.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@
$_['entry_payment_method'] = "Procédé de paiement";
$_['entry_activate'] = "Activate";
$_['entry_sort_order'] = "Ordre de triage";
$_['entry_status'] = "État";
$_['entry_api_key'] = "Clé API";
$_['entry_description'] = "Description";
$_['entry_show_icons'] = "Afficher des icônes";
Expand Down
1 change: 0 additions & 1 deletion admin/language/nl-nl/extension/payment/mollie.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@
$_['entry_payment_method'] = "Betaalmethode";
$_['entry_activate'] = "Activeren";
$_['entry_sort_order'] = "Sorteervolgorde";
$_['entry_status'] = "Status";
$_['entry_api_key'] = "API-sleutel";
$_['entry_description'] = "Omschrijving";
$_['entry_show_icons'] = "Toon icoontjes";
Expand Down
376 changes: 376 additions & 0 deletions admin/view/template/extension/payment/mollie.tpl

Large diffs are not rendered by default.

16 changes: 1 addition & 15 deletions admin/view/template/extension/payment/mollie.twig
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<button type="button" class="close" data-dismiss="alert">&times;
</button>
</div>
{% elseif stores[shop.id].payment_mollie_api_key|length %}
{% elseif stores[shop.id].payment_mollie_api_key|length <= 0 %}
<div class="alert alert-info alert-dismissable">
<i class="fa fa-info-circle"></i>
<i>{{ shop.name }}: </i> {{ help_view_profile }}
Expand Down Expand Up @@ -244,20 +244,6 @@
<p class="form-control-static">{{ entry_version }}</p>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">{{ entry_status }}</label>
<div class="col-sm-10">
<p class="form-control-static">
{% if entry_mstatus is iterable %}
{% for file in entry_mstatus %}
{{ error_file_missing }}: "{{ file }}"
{% endfor %}
{% else %}
{{ entry_mstatus }}
{% endif %}
</p>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">{{ entry_comm_status }}</label>
<div class="col-sm-10">
Expand Down
373 changes: 373 additions & 0 deletions admin/view/template/extension/payment/mollie_1.tpl

Large diffs are not rendered by default.

84 changes: 63 additions & 21 deletions catalog/controller/extension/payment/mollie/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public function index()
$data['set_issuer_url'] = $this->url->link("extension/payment/mollie_" . static::MODULE_NAME . "/set_issuer", "", "SSL");

// Return HTML output - it will get appended to confirm.tpl.
return $this->renderTemplate("mollie_checkout_form", $data, array(), false);
return $this->renderTemplate('mollie_checkout_form', $data, array(), false);
}

/**
Expand Down Expand Up @@ -164,13 +164,10 @@ public function payment()
$amount = $this->currency->convert($order['total'], $this->config->get("config_currency"), "EUR");

$amount = round($amount, 2);
$description = str_replace("%", $order['order_id'], html_entity_decode($this->config->get("payment_mollie_ideal_description"), ENT_QUOTES, "UTF-8"));
$description = str_replace("%", $order['order_id'], html_entity_decode($this->config->get(MollieHelper::getModuleCode() . "_ideal_description"), ENT_QUOTES, "UTF-8"));
$return_url = $this->url->link("extension/payment/mollie_" . static::MODULE_NAME . "/callback&order_id=" . $order['order_id'], "", "SSL");
$issuer = $this->getIssuer();

list ($language, $country) = explode('-', $this->session->data['language']);
$locale = strtolower($language) . '_' . strtoupper($country);

try {
$data = array(
"amount" => $amount,
Expand All @@ -180,7 +177,6 @@ public function payment()
"metadata" => array("order_id" => $order['order_id']),
"method" => static::MODULE_NAME,
"issuer" => $issuer,
"locale" => $locale,

/*
* This data is sent along for credit card payments / fraud checks. You can remove this but you will
Expand All @@ -198,6 +194,12 @@ public function payment()
"shippingPostal" => $order['shipping_postcode'] ? $order['shipping_postcode'] : $order['payment_postcode'],
"shippingCountry" => $order['shipping_iso_code_2'] ? $order['shipping_iso_code_2'] : $order['payment_iso_code_2'],
);

if (strstr($this->session->data['language'], '-')) {
list ($language, $country) = explode('-', $this->session->data['language']);
$data['locale'] = strtolower($language) . '_' . strtoupper($country);
}

$payment = $api->payments->create($data);
} catch (Mollie_Api_Exception $e) {
$this->showErrorPage($e->getMessage());
Expand All @@ -207,7 +209,7 @@ public function payment()

// Some payment methods can't be cancelled. They need an initial order status.
if ($this->startAsPending()) {
$this->addOrderHistory($order, $this->config->get("payment_mollie_ideal_pending_status_id"), $this->language->get("text_redirected"), false);
$this->addOrderHistory($order, $this->config->get(MollieHelper::getModuleCode() . "_ideal_pending_status_id"), $this->language->get("text_redirected"), false);
}

$model->setPayment($order['order_id'], $payment->id);
Expand Down Expand Up @@ -237,6 +239,7 @@ public function webhook()
return;
}

$moduleCode = MollieHelper::getModuleCode();
$payment_id = $this->request->post['id'];
$this->writeToMollieLog("Received webhook for payment_id " . $payment_id);

Expand All @@ -257,14 +260,14 @@ public function webhook()
}

// Only process the status if the order is stateless or in 'pending' status.
if (!empty($order['order_status_id']) && $order['order_status_id'] != $this->config->get("payment_mollie_ideal_pending_status_id")) {
if (!empty($order['order_status_id']) && $order['order_status_id'] != $this->config->get($moduleCode . "_ideal_pending_status_id")) {
$this->writeToMollieLog("The order was already processed before (order status ID: " . intval($order['order_status_id']) . ")");
return;
}

// Order paid ('processed').
if ($payment->isPaid()) {
$new_status_id = intval($this->config->get("payment_mollie_ideal_processing_status_id"));
$new_status_id = intval($this->config->get($moduleCode . "_ideal_processing_status_id"));

if (!$new_status_id) {
$this->writeToMollieLog("The payment has been received. No 'processing' status ID is configured, so the order status could not be updated.", true);
Expand All @@ -277,7 +280,7 @@ public function webhook()

// Order cancelled.
if ($payment->status == Mollie_API_Object_Payment::STATUS_CANCELLED) {
$new_status_id = intval($this->config->get("payment_mollie_ideal_canceled_status_id"));
$new_status_id = intval($this->config->get($moduleCode . "_ideal_canceled_status_id"));

if (!$new_status_id) {
$this->writeToMollieLog("The payment was cancelled. No 'cancelled' status ID is configured, so the order status could not be updated.", true);
Expand All @@ -290,7 +293,7 @@ public function webhook()

// Order expired.
if ($payment->status == Mollie_API_Object_Payment::STATUS_EXPIRED) {
$new_status_id = intval($this->config->get("payment_mollie_ideal_expired_status_id"));
$new_status_id = intval($this->config->get($moduleCode . "_ideal_expired_status_id"));

if (!$new_status_id) {
$this->writeToMollieLog("The payment expired. No 'expired' status ID is configured, so the order status could not be updated.", true);
Expand All @@ -302,7 +305,7 @@ public function webhook()
}

// Otherwise, order failed.
$new_status_id = intval($this->config->get("payment_mollie_ideal_failed_status_id"));
$new_status_id = intval($this->config->get($moduleCode . "_ideal_failed_status_id"));

if (!$new_status_id) {
$this->writeToMollieLog("The payment failed. No 'failed' status ID is configured, so the order status could not be updated.", true);
Expand Down Expand Up @@ -354,7 +357,7 @@ protected function getIssuer()
*/
public function callback()
{

$moduleCode = MollieHelper::getModuleCode();
$order_id = $this->getOrderID();

if ($order_id === false) {
Expand Down Expand Up @@ -403,7 +406,7 @@ public function callback()
}

// Show a 'transaction failed' page if we couldn't find the order or if the payment failed.
$failed_status_id = $this->config->get("payment_mollie_ideal_failed_status_id");
$failed_status_id = $this->config->get($moduleCode . "_ideal_failed_status_id");

if (!$order || ($failed_status_id && $order['order_status_id'] == $failed_status_id)) {
return $this->showReturnPage(
Expand All @@ -413,7 +416,7 @@ public function callback()
}

// If the order status is 'processing' (i.e. 'paid'), redirect to OpenCart's default 'success' page.
if ($order["order_status_id"] == $this->config->get("payment_mollie_ideal_processing_status_id")) {
if ($order["order_status_id"] == $this->config->get($moduleCode . "_ideal_processing_status_id")) {
if ($this->cart) {
$this->cart->clear();
}
Expand All @@ -424,7 +427,7 @@ public function callback()
}

// If the status is 'pending' (i.e. a bank transfer), the report is not delivered yet.
if ($order['order_status_id'] == $this->config->get("payment_mollie_ideal_pending_status_id")) {
if ($order['order_status_id'] == $this->config->get($moduleCode . "_ideal_pending_status_id")) {
if ($this->cart) {
$this->cart->clear();
}
Expand All @@ -438,7 +441,7 @@ public function callback()
}

// The status is probably 'cancelled'. Allow the admin to redirect their customers back to the shopping cart directly in these cases.
if (!(bool)$this->config->get("payment_mollie_show_order_canceled_page")) {
if (!(bool)$this->config->get($moduleCode . "_show_order_canceled_page")) {
$this->redirect($this->url->link("checkout/checkout", "", "SSL"));
}

Expand Down Expand Up @@ -562,7 +565,15 @@ protected function getAdminDirectory()
*/
protected function addOrderHistory($order, $order_status_id, $comment = "", $notify = false)
{
$this->model_checkout_order->addOrderHistory($order['order_id'], $order_status_id, $comment, $notify);
if (MollieHelper::isOpenCart2x()) {
$this->model_checkout_order->addOrderHistory($order['order_id'], $order_status_id, $comment, $notify);
} else {
if (empty($order['order_status_id'])) {
$this->model_checkout_order->confirm($order['order_id'], $order_status_id, $comment, $notify);
} else {
$this->model_checkout_order->update($order['order_id'], $order_status_id, $comment, $notify);
}
}
}

/**
Expand All @@ -576,11 +587,42 @@ protected function addOrderHistory($order, $order_status_id, $comment = "", $not
*/
protected function renderTemplate($template, $data, $common_children = array(), $echo = true)
{
foreach ($common_children as $child) {
$data[$child] = $this->load->controller("common/" . $child);
if (!MollieHelper::isOpenCart3x()) {
$template .= '.tpl';
}

if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/payment/' . $template)) {
$template = $this->config->get('config_template') . '/template/payment/' . $template;
} else if (file_exists(DIR_TEMPLATE . 'default/template/payment/' . $template)) {
$template = 'default/template/payment/' . $template;
} else {
$template = 'extension/payment/' . $template;
}

$html = $this->load->view('extension/payment/' . $template, $data);
if (MollieHelper::isOpenCart2x()) {
foreach ($common_children as $child) {
$data[$child] = $this->load->controller("common/" . $child);
}

$html = $this->load->view($template, $data);
} else {
$this->template = $template;
$this->children = array();

foreach ($data as $field => $value) {
$this->data[$field] = $value;
}

foreach($common_children as $child) {
if ($child === 'column_left') {
continue;
}

$this->children[] = "common/" . $child;
}

$html = $this->render();
}

if ($echo) {
return $this->response->setOutput($html);
Expand Down
43 changes: 39 additions & 4 deletions catalog/controller/extension/payment/mollie/helper.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<?php
class MollieHelper
{
// Plugin only for Opencart >= 3.0
const PLUGIN_VERSION = "8.1.0";
const PLUGIN_VERSION = "8.2.0";

// All available modules. These should correspond to the Mollie_API_Object_Method constants.
const MODULE_NAME_BANKTRANSFER = "banktransfer";
Expand Down Expand Up @@ -60,7 +59,7 @@ public static function getAPIClient ($config)

$mollie = new Mollie_API_Client;

$mollie->setApiKey($config->get('payment_mollie_api_key'));
$mollie->setApiKey($config->get(self::getModuleCode() . '_api_key'));

$mollie->addVersionString("OpenCart/" . VERSION);
$mollie->addVersionString("MollieOpenCart/" . self::PLUGIN_VERSION);
Expand All @@ -84,7 +83,7 @@ public static function getAPIClientAdmin ($config)

$mollie = new Mollie_API_Client;

$mollie->setApiKey(isset($config['payment_mollie_api_key']) ? $config['payment_mollie_api_key'] : null);
$mollie->setApiKey(isset($config[self::getModuleCode() . '_api_key']) ? $config[self::getModuleCode() . '_api_key'] : null);

$mollie->addVersionString("OpenCart/" . VERSION);
$mollie->addVersionString("MollieOpenCart/" . self::PLUGIN_VERSION);
Expand All @@ -105,4 +104,40 @@ public static function getAPIClientForKey($key = null)

return $mollie;
}

/**
* @return string
*/
public static function getModuleCode()
{
if (self::isOpenCart3x()) {
return 'payment_mollie';
}

return 'mollie';
}

/**
* @return bool
*/
public static function isOpenCart3x()
{
return version_compare(VERSION, '3.0.0', '>=');
}

/**
* @return bool
*/
public static function isOpenCart23x()
{
return version_compare(VERSION, '2.3.0', '>=');
}

/**
* @return bool
*/
public static function isOpenCart2x()
{
return version_compare(VERSION, '2', '>=');
}
}
Loading

0 comments on commit 973a7fd

Please sign in to comment.