From 92d3d4bfcc5cb60d2c4d42640b2c504849c63d14 Mon Sep 17 00:00:00 2001 From: Pradeep Date: Mon, 14 Jan 2019 10:46:55 +0530 Subject: [PATCH 1/5] COMDEVNL-1696 -- Added update button text --- admin/language/de-de/payment/mollie.php | 3 +++ admin/language/dutch/payment/mollie.php | 3 +++ admin/language/en-gb/payment/mollie.php | 3 +++ admin/language/english/payment/mollie.php | 3 +++ admin/language/es-es/payment/mollie.php | 3 +++ admin/language/fr-fr/payment/mollie.php | 3 +++ admin/language/french/payment/mollie.php | 3 +++ admin/language/german/payment/mollie.php | 3 +++ admin/language/nl-nl/payment/mollie.php | 3 +++ admin/language/spanish/payment/mollie.php | 3 +++ 10 files changed, 30 insertions(+) diff --git a/admin/language/de-de/payment/mollie.php b/admin/language/de-de/payment/mollie.php index e11186f4..f278a656 100644 --- a/admin/language/de-de/payment/mollie.php +++ b/admin/language/de-de/payment/mollie.php @@ -134,3 +134,6 @@ $_['text_create_shipment_on_status'] = "Legen Sie eine Sendung an, wenn Sie den Auftrag auf diesen Status setzen"; $_['text_create_shipment_on_order_complete'] = "Erstellen Sie eine Sendung, nachdem Sie den Status zum Bestellen der Bestellung festgelegt haben"; $_['entry_create_shipment_on_order_complete'] = "Erstellen Sie den Versand nach Abschluss der Bestellung"; + +//Button +$_['button_update'] = "Aktualisieren"; diff --git a/admin/language/dutch/payment/mollie.php b/admin/language/dutch/payment/mollie.php index 7eba1abc..f0e24344 100644 --- a/admin/language/dutch/payment/mollie.php +++ b/admin/language/dutch/payment/mollie.php @@ -134,3 +134,6 @@ $_['text_create_shipment_on_status'] = "Maak verzending bij het plaatsen van de bestelling naar deze status"; $_['text_create_shipment_on_order_complete'] = "Maak verzending bij het plaatsen van bestelling om de volledige status te bestellen"; $_['entry_create_shipment_on_order_complete'] = "Maak verzending bij bestelling compleet"; + +//Button +$_['button_update'] = "Bijwerken"; diff --git a/admin/language/en-gb/payment/mollie.php b/admin/language/en-gb/payment/mollie.php index 25e23650..770dee08 100644 --- a/admin/language/en-gb/payment/mollie.php +++ b/admin/language/en-gb/payment/mollie.php @@ -134,3 +134,6 @@ $_['text_create_shipment_on_status'] = "Create shipment upon setting order to this status"; $_['text_create_shipment_on_order_complete'] = "Create shipment upon setting order to order complete status"; $_['entry_create_shipment_on_order_complete'] = "Create shipment upon order complete"; + +//Button +$_['button_update'] = "Update"; diff --git a/admin/language/english/payment/mollie.php b/admin/language/english/payment/mollie.php index 25e23650..770dee08 100644 --- a/admin/language/english/payment/mollie.php +++ b/admin/language/english/payment/mollie.php @@ -134,3 +134,6 @@ $_['text_create_shipment_on_status'] = "Create shipment upon setting order to this status"; $_['text_create_shipment_on_order_complete'] = "Create shipment upon setting order to order complete status"; $_['entry_create_shipment_on_order_complete'] = "Create shipment upon order complete"; + +//Button +$_['button_update'] = "Update"; diff --git a/admin/language/es-es/payment/mollie.php b/admin/language/es-es/payment/mollie.php index 7003956d..9e4e24f5 100644 --- a/admin/language/es-es/payment/mollie.php +++ b/admin/language/es-es/payment/mollie.php @@ -136,3 +136,6 @@ $_['text_create_shipment_on_status'] = "Crear envío al establecer orden a este estado"; $_['text_create_shipment_on_order_complete'] = "Crear envío al establecer orden para ordenar estado completo"; $_['entry_create_shipment_on_order_complete'] = "Crear envío al completar el pedido"; + +//Button +$_['button_update'] = "Actualizar"; diff --git a/admin/language/fr-fr/payment/mollie.php b/admin/language/fr-fr/payment/mollie.php index 3c710443..dc6800c7 100644 --- a/admin/language/fr-fr/payment/mollie.php +++ b/admin/language/fr-fr/payment/mollie.php @@ -133,3 +133,6 @@ $_['text_create_shipment_on_status'] = "Créer un envoi lors du réglage de la commande à ce statut"; $_['text_create_shipment_on_order_complete'] = "Créer une expédition lors du paramétrage de la commande pour passer à la commande"; $_['entry_create_shipment_on_order_complete'] = "Créer une expédition à la fin de la commande"; + +//Button +$_['button_update'] = "Mettre à jour"; diff --git a/admin/language/french/payment/mollie.php b/admin/language/french/payment/mollie.php index 3c710443..dc6800c7 100644 --- a/admin/language/french/payment/mollie.php +++ b/admin/language/french/payment/mollie.php @@ -133,3 +133,6 @@ $_['text_create_shipment_on_status'] = "Créer un envoi lors du réglage de la commande à ce statut"; $_['text_create_shipment_on_order_complete'] = "Créer une expédition lors du paramétrage de la commande pour passer à la commande"; $_['entry_create_shipment_on_order_complete'] = "Créer une expédition à la fin de la commande"; + +//Button +$_['button_update'] = "Mettre à jour"; diff --git a/admin/language/german/payment/mollie.php b/admin/language/german/payment/mollie.php index 746ce3de..5f158c1a 100644 --- a/admin/language/german/payment/mollie.php +++ b/admin/language/german/payment/mollie.php @@ -135,3 +135,6 @@ $_['text_create_shipment_on_status'] = "Legen Sie eine Sendung an, wenn Sie den Auftrag auf diesen Status setzen"; $_['text_create_shipment_on_order_complete'] = "Erstellen Sie eine Sendung, nachdem Sie den Status zum Bestellen der Bestellung festgelegt haben"; $_['entry_create_shipment_on_order_complete'] = "Erstellen Sie den Versand nach Abschluss der Bestellung"; + +//Button +$_['button_update'] = "Aktualisieren"; diff --git a/admin/language/nl-nl/payment/mollie.php b/admin/language/nl-nl/payment/mollie.php index 92f7c6bc..2477b7a6 100644 --- a/admin/language/nl-nl/payment/mollie.php +++ b/admin/language/nl-nl/payment/mollie.php @@ -134,3 +134,6 @@ $_['text_create_shipment_on_status'] = "Maak verzending bij het plaatsen van de bestelling naar deze status"; $_['text_create_shipment_on_order_complete'] = "Maak verzending bij het plaatsen van bestelling om de volledige status te bestellen"; $_['entry_create_shipment_on_order_complete'] = "Maak verzending bij bestelling compleet"; + +//Button +$_['button_update'] = "Bijwerken"; diff --git a/admin/language/spanish/payment/mollie.php b/admin/language/spanish/payment/mollie.php index 264ac47b..f406c298 100644 --- a/admin/language/spanish/payment/mollie.php +++ b/admin/language/spanish/payment/mollie.php @@ -135,3 +135,6 @@ $_['text_create_shipment_on_status'] = "Crear envío al establecer orden a este estado"; $_['text_create_shipment_on_order_complete'] = "Crear envío al establecer orden para ordenar estado completo"; $_['entry_create_shipment_on_order_complete'] = "Crear envío al completar el pedido"; + +//Button +$_['button_update'] = "Actualizar"; From 7feb8b9399d7fb79eaef1f8729bfed2948d18aba Mon Sep 17 00:00:00 2001 From: Pradeep Date: Mon, 14 Jan 2019 13:52:58 +0530 Subject: [PATCH 2/5] COMDEVNL-1697 -- Updated cleanup function --- admin/controller/payment/mollie/base.php | 42 ++++++++++++++++-------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/admin/controller/payment/mollie/base.php b/admin/controller/payment/mollie/base.php index 8cde85ba..048bdec8 100644 --- a/admin/controller/payment/mollie/base.php +++ b/admin/controller/payment/mollie/base.php @@ -155,26 +155,42 @@ public function cleanUp() $catalogControllerDir = DIR_CATALOG . 'controller/'; $catalogModelDir = DIR_CATALOG . 'model/'; - if(file_exists($adminControllerDir . 'extension/payment/mistercash.php')) { - unlink($adminControllerDir . 'extension/payment/mistercash.php'); - $languageFiles = glob($adminLanguageDir .'*/extension/payment/mistercash.php'); - foreach($languageFiles as $file) { + if(file_exists($adminControllerDir . 'extension/payment/mollie_mistercash.php')) { + unlink($adminControllerDir . 'extension/payment/mollie_mistercash.php'); + } + + $languageFiles = glob($adminLanguageDir .'*/extension/payment/mollie_mistercash.php'); + foreach($languageFiles as $file) { + if(file_exists($file)) { unlink($file); } + } + + if(file_exists($catalogControllerDir .'extension/payment/mollie_mistercash.php')) { + unlink($catalogControllerDir .'extension/payment/mollie_mistercash.php'); + } - unlink($catalogControllerDir .'extension/payment/mistercash.php'); - unlink($catalogModelDir .'extension/payment/mistercash.php'); + if(file_exists($catalogModelDir .'extension/payment/mollie_mistercash.php')) { + unlink($catalogModelDir .'extension/payment/mollie_mistercash.php'); } - if(file_exists($adminControllerDir . 'payment/mistercash.php')) { - unlink($adminControllerDir . 'payment/mistercash.php'); - $languageFiles = glob($adminLanguageDir .'*/payment/mistercash.php'); - foreach($languageFiles as $file) { + if(file_exists($adminControllerDir . 'payment/mollie_mistercash.php')) { + unlink($adminControllerDir . 'payment/mollie_mistercash.php'); + } + + $languageFiles = glob($adminLanguageDir .'*/payment/mollie_mistercash.php'); + foreach($languageFiles as $file) { + if(file_exists($file)) { unlink($file); } + } + + if(file_exists($catalogControllerDir .'payment/mollie_mistercash.php')) { + unlink($catalogControllerDir .'payment/mollie_mistercash.php'); + } - unlink($catalogControllerDir .'payment/mistercash.php'); - unlink($catalogModelDir .'payment/mistercash.php'); + if(file_exists($catalogModelDir .'payment/mollie_mistercash.php')) { + unlink($catalogModelDir .'payment/mollie_mistercash.php'); } if (MollieHelper::isOpenCart3x()) { @@ -291,7 +307,7 @@ public function index () } $adminControllerDir = DIR_APPLICATION . 'controller/'; - if(file_exists($adminControllerDir . 'extension/payment/mistercash.php') || file_exists($adminControllerDir . 'payment/mistercash.php')) { + if(file_exists($adminControllerDir . 'extension/payment/mollie_mistercash.php') || file_exists($adminControllerDir . 'payment/mollie_mistercash.php')) { $this->cleanUp(); } From 9bddca1ca6e5022a88d63a2c8b3641e9ccc5d39e Mon Sep 17 00:00:00 2001 From: Pradeep Date: Tue, 15 Jan 2019 13:18:29 +0530 Subject: [PATCH 3/5] COMDEVNL-1682 -- Fixed rounding differences --- catalog/controller/payment/mollie/base.php | 42 +++++++++++++--------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/catalog/controller/payment/mollie/base.php b/catalog/controller/payment/mollie/base.php index f9fec87b..6f970b42 100644 --- a/catalog/controller/payment/mollie/base.php +++ b/catalog/controller/payment/mollie/base.php @@ -421,25 +421,35 @@ public function payment() //Check for rounding off issue $orderTotal = number_format($amount, 2, '.', ''); - $productTotal = 0; - $shippingTotal = 0; - $couponTotal = 0; - $productTotalArray = array(); - foreach($orderProducts as $orderProduct) { - $total = $orderProduct['total'] + ($orderProduct['tax'] * $orderProduct['quantity']); - $productTotalArray[] = $this->convertCurrency($total); - } - $productTotal = number_format(array_sum($productTotalArray), 2, '.', ''); + // This is the old way of checking rounding off issue. + // $productTotal = 0; + // $shippingTotal = 0; + // $couponTotal = 0; - if(isset($costWithTax)) { - $shippingTotal = number_format($this->convertCurrency($costWithTax), 2, '.', ''); - } - if(isset($unitPriceWithTax)) { - $couponTotal = number_format($this->convertCurrency($unitPriceWithTax), 2, '.', ''); - } + // $productTotalArray = array(); + // foreach($orderProducts as $orderProduct) { + // $total = $orderProduct['total'] + ($orderProduct['tax'] * $orderProduct['quantity']); + // $productTotalArray[] = $this->convertCurrency($total); + // } + // $productTotal = number_format(array_sum($productTotalArray), 2, '.', ''); - $orderLineTotal = number_format($productTotal + $shippingTotal + $couponTotal, 2, '.', ''); + // if(isset($costWithTax)) { + // $shippingTotal = number_format($this->convertCurrency($costWithTax), 2, '.', ''); + // } + // if(isset($unitPriceWithTax)) { + // $couponTotal = number_format($this->convertCurrency($unitPriceWithTax), 2, '.', ''); + // } + + // $orderLineTotal = number_format($productTotal + $shippingTotal + $couponTotal, 2, '.', ''); + + // Check for rounding off issue in a general way (for all possible totals) + + $orderLineTotal = 0; + + foreach($lines as $line) { + $orderLineTotal += $line['totalAmount']['value']; + } if(($orderTotal > $orderLineTotal) && (number_format(($orderTotal - $orderLineTotal), 2, '.', '') == 0.01)) { $lineForDiscount[] = array( From 44d24221fb2c6ca26cab1093fbc06840696deed9 Mon Sep 17 00:00:00 2001 From: Pradeep Date: Wed, 16 Jan 2019 09:41:42 +0530 Subject: [PATCH 4/5] Removed commented out code --- catalog/controller/payment/mollie/base.php | 26 +--------------------- 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/catalog/controller/payment/mollie/base.php b/catalog/controller/payment/mollie/base.php index 6f970b42..b9a643d1 100644 --- a/catalog/controller/payment/mollie/base.php +++ b/catalog/controller/payment/mollie/base.php @@ -419,32 +419,8 @@ public function payment() $lines = array_merge($lines, $otherTotals); } - //Check for rounding off issue + //Check for rounding off issue in a general way (for all possible totals) $orderTotal = number_format($amount, 2, '.', ''); - - // This is the old way of checking rounding off issue. - // $productTotal = 0; - // $shippingTotal = 0; - // $couponTotal = 0; - - // $productTotalArray = array(); - // foreach($orderProducts as $orderProduct) { - // $total = $orderProduct['total'] + ($orderProduct['tax'] * $orderProduct['quantity']); - // $productTotalArray[] = $this->convertCurrency($total); - // } - // $productTotal = number_format(array_sum($productTotalArray), 2, '.', ''); - - // if(isset($costWithTax)) { - // $shippingTotal = number_format($this->convertCurrency($costWithTax), 2, '.', ''); - // } - // if(isset($unitPriceWithTax)) { - // $couponTotal = number_format($this->convertCurrency($unitPriceWithTax), 2, '.', ''); - // } - - // $orderLineTotal = number_format($productTotal + $shippingTotal + $couponTotal, 2, '.', ''); - - // Check for rounding off issue in a general way (for all possible totals) - $orderLineTotal = 0; foreach($lines as $line) { From b81cf4f76dccd3c211a40c5174003be23c848217 Mon Sep 17 00:00:00 2001 From: Pradeep Date: Wed, 16 Jan 2019 13:22:38 +0530 Subject: [PATCH 5/5] COMDEVNL-1711 -- Added webhook for payments --- catalog/controller/payment/mollie/base.php | 98 +++++++++++++++++++++- 1 file changed, 95 insertions(+), 3 deletions(-) diff --git a/catalog/controller/payment/mollie/base.php b/catalog/controller/payment/mollie/base.php index f9fec87b..a2e0e01c 100644 --- a/catalog/controller/payment/mollie/base.php +++ b/catalog/controller/payment/mollie/base.php @@ -239,7 +239,10 @@ public function payment() "method" => static::MODULE_NAME, ); - $data['payment'] = ["issuer" => $this->formatText($issuer)]; + $data['payment'] = array( + "issuer" => $this->formatText($issuer), + "webhookUrl" => $this->getWebhookUrl() + ); //Order line data $orderProducts = $this->getOrderProducts($order['order_id']); @@ -567,8 +570,97 @@ public function webhook() return; } + // Check webhook for order/payment + $id = $this->request->post['id']; + $temp = explode('_', $id); + $idPrefix = $temp[0]; + if($idPrefix == 'ord') { + $this->webhookForOrder($id); + } else { + $this->webhookForPayment($id); + } + + } + + private function webhookForPayment($payment_id) { + + $moduleCode = MollieHelper::getModuleCode(); + + $this->writeToMollieLog("Received webhook for payment_id " . $payment_id); + + $molliePayment = $this->getAPIClient()->payments->get($payment_id); + + $mollieOrderId = $molliePayment->orderId; + + $mollieOrder = $this->getAPIClient()->orders->get($mollieOrderId); + + // Load essentials + Util::load()->model("checkout/order"); + $this->getModuleModel(); + Util::load()->language("payment/mollie"); + + //Get order_id of this transaction from db + $order = $this->model_checkout_order->getOrder($mollieOrder->metadata->order_id); + + if (empty($order)) { + header("HTTP/1.0 404 Not Found"); + echo "Could not find order."; + return; + } + + if($order['order_status_id'] != 0) { + return; + } + + // 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($moduleCode . "_ideal_pending_status_id")) { + $this->writeToMollieLog("The order was already processed before (order status ID: " . intval($order['order_status_id']) . ")"); + return; + } + + // Payment cancelled. + if ($molliePayment->status == PaymentStatus::STATUS_CANCELED) { + $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); + return; + } + $this->addOrderHistory($order, $new_status_id, $this->language->get("response_cancelled"), false); + $this->writeToMollieLog("The payment was cancelled and the order was moved to the 'cancelled' status (new status ID: {$new_status_id}).", true); + return; + } + + // Payment expired. + if ($molliePayment->status == PaymentStatus::STATUS_EXPIRED) { + $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); + return; + } + $this->addOrderHistory($order, $new_status_id, $this->language->get("response_expired"), false); + $this->writeToMollieLog("The payment expired and the order was moved to the 'expired' status (new status ID: {$new_status_id}).", true); + return; + } + + // Otherwise, payment failed. + $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); + return; + } + $this->addOrderHistory($order, $new_status_id, $this->language->get("response_unknown"), false); + $this->writeToMollieLog("The payment failed for an unknown reason and the order was moved to the 'failed' status (new status ID: {$new_status_id}).", true); + return; + + } + + private function webhookForOrder($order_id) { + $moduleCode = MollieHelper::getModuleCode(); - $order_id = $this->request->post['id']; + $this->writeToMollieLog("Received webhook for order_id " . $order_id); $mollieOrder = $this->getAPIClient()->orders->get($order_id); @@ -624,7 +716,7 @@ public function webhook() } // Order expired. - if ($mollieOrder->status == PaymentStatus::STATUS_CANCELED) { + if ($mollieOrder->status == PaymentStatus::STATUS_EXPIRED) { $new_status_id = intval($this->config->get($moduleCode . "_ideal_expired_status_id")); if (!$new_status_id) {