/** * Controller Action */ public function execute() { $request = $this->getRequest(); $this->coreHelper->log("Custom Received notification", self::LOG_NAME, $request->getParams()); $dataId = $request->getParam('data_id'); $type = $request->getParam('type'); if (!empty($dataId) && $type == 'payment') { $response = $this->coreModel->getPaymentV1($dataId); $this->coreHelper->log("Return payment", self::LOG_NAME, $response); if ($response['status'] == 200 || $response['status'] == 201) { $payment = $response['response']; $payment = $this->coreHelper->setPayerInfo($payment); $this->coreHelper->log("Update Order", self::LOG_NAME); $this->coreModel->updateOrder($payment); $setStatusResponse = $this->coreModel->setStatusOrder($payment); $this->getResponse()->setBody($setStatusResponse['text']); $this->getResponse()->setHttpResponseCode($setStatusResponse['code']); $this->coreHelper->log("Http code", self::LOG_NAME, $this->getResponse()->getHttpResponseCode()); return; } } $this->coreHelper->log("Payment not found", self::LOG_NAME, $request->getParams()); $this->getResponse()->getBody("Payment not found"); $this->getResponse()->setHttpResponseCode(\MercadoPago\Core\Helper\Response::HTTP_NOT_FOUND); $this->coreHelper->log("Http code", self::LOG_NAME, $this->getResponse()->getHttpResponseCode()); }
/** * Controller Action */ public function execute() { $request = $this->getRequest(); //notification received $this->coreHelper->log("Standard Received notification", self::LOG_NAME, $request->getParams()); $shipmentData = ''; $merchantOrder = ''; $id = $request->getParam('id'); $topic = $request->getParam('topic'); if ($this->_emptyParams($id, $topic)) { $this->coreHelper->log("Merchant Order not found", self::LOG_NAME, $request->getParams()); $this->getResponse()->setBody("Merchant Order not found"); $this->getResponse()->setHttpResponseCode(\MercadoPago\Core\Helper\Response::HTTP_NOT_FOUND); return; } if ($topic == 'merchant_order') { $response = $this->coreModel->getMerchantOrder($id); $this->coreHelper->log("Return merchant_order", self::LOG_NAME, $response); if (!$this->_isValidResponse($response)) { $this->_responseLog(); return; } $merchantOrder = $response['response']; if (count($merchantOrder['payments']) == 0) { $this->_responseLog(); return; } $data = $this->_getDataPayments($merchantOrder); $statusFinal = $this->_getStatusFinal($data['status'], $merchantOrder); $shipmentData = $this->_getShipmentsArray($merchantOrder); } elseif ($topic == 'payment') { $data = $this->_getFormattedPaymentData($id); $statusFinal = $data['status']; } else { $this->_responseLog(); return; } $this->coreHelper->log("Update Order", self::LOG_NAME); $this->coreHelper->setStatusUpdated($data); $this->coreModel->updateOrder($data); if ($this->_shipmentExists($shipmentData, $merchantOrder)) { $this->_eventManager->dispatch('mercadopago_standard_notification_before_set_status', ['shipmentData' => $shipmentData, 'orderId' => $merchantOrder['external_reference']]); } if ($statusFinal != false) { $data['status_final'] = $statusFinal; $this->coreHelper->log("Received Payment data", self::LOG_NAME, $data); $setStatusResponse = $this->coreModel->setStatusOrder($data); $this->getResponse()->setBody($setStatusResponse['text']); $this->getResponse()->setHttpResponseCode($setStatusResponse['code']); } else { $this->getResponse()->setBody("Status not final"); $this->getResponse()->setHttpResponseCode(\MercadoPago\Core\Helper\Response::HTTP_OK); } if ($this->_shipmentExists($shipmentData, $merchantOrder)) { $this->_eventManager->dispatch('mercadopago_standard_notification_received', ['payment' => $data, 'merchant_order' => $merchantOrder]); } $this->_responseLog(); }