diff --git a/catalog/controller/payment/mollie/base.php b/catalog/controller/payment/mollie/base.php index 03502e70..98c032bf 100644 --- a/catalog/controller/payment/mollie/base.php +++ b/catalog/controller/payment/mollie/base.php @@ -582,12 +582,26 @@ private function webhookForPayment($payment_id) { // Load essentials Util::load()->model("checkout/order"); - $this->getModuleModel(); + $model = $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); + //Set transaction ID + $data = array(); + + if($molliePayment) { + $data = array( + 'payment_id' => $payment_id, + 'status' => $molliePayment->status + ); + } + + if(!empty($data)) { + $model->updatePayment($mollieOrder->metadata->order_id, $mollieOrderId, $data); + } + if (empty($order)) { header("HTTP/1.0 404 Not Found"); echo "Could not find order."; @@ -890,6 +904,14 @@ public function callback() if (($orderDetails->isPaid() || $orderDetails->isAuthorized()) && $order['order_status_id'] != $paid_status_id) { $this->addOrderHistory($order, $paid_status_id, $this->language->get("response_success"), true); $order['order_status_id'] = $paid_status_id; + } else if(!empty($orderDetails->_embedded->payments)) { + + $payment = $orderDetails->_embedded->payments[0]; + if (($payment->status == 'paid') && ($order['order_status_id'] != $paid_status_id)) { + $this->addOrderHistory($order, $paid_status_id, $this->language->get("response_success"), true); + $order['order_status_id'] = $paid_status_id; + } + } /* Check module module setting for shipment creation, diff --git a/catalog/model/payment/mollie/base.php b/catalog/model/payment/mollie/base.php index 74f3ccb4..db797822 100644 --- a/catalog/model/payment/mollie/base.php +++ b/catalog/model/payment/mollie/base.php @@ -188,17 +188,19 @@ public function setPayment($order_id, $mollie_order_id) * * @return bool */ - public function updatePayment($transaction_id, $payment_status, $consumer = NULL) + public function updatePayment($order_id, $mollie_order_id, $data, $consumer = NULL) { - if (!empty($transaction_id) && !empty($payment_status)) { + if (!empty($order_id) && !empty($mollie_order_id)) { $this->db->query( sprintf( "UPDATE `%smollie_payments` - SET `bank_status` = '%s' - WHERE `transaction_id` = '%s';", + SET `transaction_id` = '%s', `bank_status` = '%s' + WHERE `order_id` = '%s' AND `mollie_order_id` = '%s';", DB_PREFIX, - $this->db->escape($payment_status), - $this->db->escape($transaction_id) + $this->db->escape($data['payment_id']), + $this->db->escape($data['status']), + $this->db->escape($order_id), + $this->db->escape($mollie_order_id) ) );