<?php require __DIR__ . '/../../vendor/autoload.php'; use Gerencianet\Exception\GerencianetException; use Gerencianet\Gerencianet; $file = file_get_contents(__DIR__ . '/../config.json'); $options = json_decode($file, true); $params = ['token' => 'token']; try { $api = new Gerencianet($options); $notification = $api->getNotification($params, []); print_r($notification); } catch (GerencianetException $e) { print_r($e->code); print_r($e->error); print_r($e->errorDescription); } catch (Exception $e) { print_r($e->getMessage()); }
public function callback() { if ($this->config->get('gerencianet_payment_notification_update')) { $this->load->model('checkout/order'); $this->load->model('extension/extension'); $options = $this->gerencianet_config_payment_api(); if (isset($this->request->post['notification'])) { $token = $this->request->post['notification']; } else { $token = ''; } if ($token) { $params = array('token' => $token); try { $api = new Gerencianet($options); $notification = $api->getNotification($params, array()); if ($notification['code'] == 200) { foreach ($notification['data'] as $notification_data) { $orderIdFromNotification = $notification_data['custom_id']; $orderStatusFromNotification = $notification_data['status']['current']; } $updateOrderHistory = false; switch ($orderStatusFromNotification) { case 'new': $order_status_id = $this->config->get('gerencianet_new_status_id'); $updateOrderHistory = false; break; case 'waiting': $order_status_id = $this->config->get('gerencianet_waiting_status_id'); $updateOrderHistory = false; break; case 'paid': $order_status_id = $this->config->get('gerencianet_paid_status_id'); $updateOrderHistory = true; break; case 'unpaid': $order_status_id = $this->config->get('gerencianet_unpaid_status_id'); $updateOrderHistory = true; break; case 'refunded': $order_status_id = $this->config->get('gerencianet_refunded_status_id'); $updateOrderHistory = true; break; case 'contested': $order_status_id = $this->config->get('gerencianet_contested_status_id'); $updateOrderHistory = true; break; case 'canceled': $order_status_id = $this->config->get('gerencianet_canceled_status_id'); $updateOrderHistory = true; break; } if ($updateOrderHistory) { if ($this->config->get('gerencianet_payment_notification_update_notify')) { $this->model_checkout_order->addOrderHistory(intval($orderIdFromNotification), intval($order_status_id), '', true); } else { $this->model_checkout_order->addOrderHistory(intval($orderIdFromNotification), intval($order_status_id), '', false); } } } } catch (GerencianetException $e) { $this->log->write('GERENCIANET :: NOTIFICATION: ' . $token); $this->log->write('GERENCIANET :: ERROR: ' . $e['errorDescription']); } catch (Exception $e) { $this->log->write('GERENCIANET :: NOTIFICATION: ' . $token); $this->log->write('GERENCIANET :: ERROR: ' . $e->getMessage()); } } } }