Ejemplo n.º 1
0
 public static function main()
 {
     $code = isset($_POST['notificationCode']) && trim($_POST['notificationCode']) !== "" ? trim($_POST['notificationCode']) : null;
     $type = isset($_POST['notificationType']) && trim($_POST['notificationType']) !== "" ? trim($_POST['notificationType']) : null;
     if ($code && $type) {
         $notificationType = new PagSeguroNotificationType($type);
         $strType = $notificationType->getTypeFromValue();
         switch ($strType) {
             case 'TRANSACTION':
                 self::transactionNotification($code);
                 break;
             case 'APPLICATION_AUTHORIZATION':
                 self::authorizationNotification($code);
                 break;
             case 'PRE_APPROVAL':
                 self::preApprovalNotification($code);
                 break;
             default:
                 LogPagSeguro::error("Unknown notification type [" . $notificationType->getValue() . "]");
         }
         self::printLog($strType);
     } else {
         LogPagSeguro::error("Invalid notification parameters.");
         self::printLog();
     }
 }
 function onPaymentNotification(&$statuses)
 {
     // adding PagSeguro API
     require_once 'PagSeguroLibrary/PagSeguroLibrary.php';
     // retrieving configurated default log info
     $filename = JPATH_BASE . '/logs/log_pagseguro.log';
     $this->_verifyFile($filename);
     PagSeguroConfig::activeLog($filename);
     $order_id = (int) $_REQUEST['invoice'];
     $dbOrder = $this->getOrder($order_id);
     $this->loadPaymentParams($dbOrder);
     if (empty($this->payment_params)) {
         return false;
     }
     $post = $_POST;
     if (!PagSeguroHelper::isNotificationEmpty($post)) {
         $notificationType = new PagSeguroNotificationType($post['notificationType']);
         $strType = $notificationType->getTypeFromValue();
         switch ($strType) {
             case 'TRANSACTION':
                 $this->_doUpdateByNotification($statuses, $post['notificationCode']);
                 break;
             default:
                 LogPagSeguro::error("Unknown notification type [" . $notificationType->getValue() . "]");
         }
     } else {
         LogPagSeguro::error("Invalid notification parameters.");
     }
     return true;
 }
Ejemplo n.º 3
0
 function validateIPN($data, $vars)
 {
     if (is_array($data)) {
         $code = $data['notificationCode'];
         $type = $data['notificationType'];
     } else {
         if (is_object($data)) {
             $code = $data->get('notificationCode');
             $type = $data->get('notificationType');
         }
     }
     if ($code && $type) {
         $notificationType = new PagSeguroNotificationType($type);
         $strType = $notificationType->getTypeFromValue();
         switch ($strType) {
             case 'TRANSACTION':
                 $credentials = new PagSeguroAccountCredentials($vars->sellar_email, $vars->token);
                 try {
                     $transaction = PagSeguroNotificationService::checkTransaction($credentials, $code);
                     $returndata['transaction_id'] = $transaction->getCode();
                     $returndata['payment_status'] = $transaction->getStatus()->getTypeFromValue();
                     $returndata['payment_statuscode'] = $transaction->getStatus()->getValue();
                     $returndata['order_id'] = $transaction->getReference();
                     $returndata['buyer_email'] = $transaction->getSender()->getEmail();
                     $returndata['payment_method'] = $transaction->getpaymentMethod()->gettype()->getTypeFromValue();
                     $returndata['total_paid_amt'] = $transaction->getgrossAmount();
                     $returndata['raw_data'] = json_encode($returndata);
                     return $returndata;
                 } catch (PagSeguroServiceException $e) {
                     $error = array();
                     $error['code'] = '';
                     //@TODO change these $data indexes afterwards
                     $error['desc'] = $e->getMessage();
                     return $error;
                 }
                 break;
             default:
                 $error = array();
                 $error['code'] = '';
                 //@TODO change these $data indexes afterwards
                 $error['desc'] = "Unknown notification type [" . $notificationType->getValue() . "]";
                 return $error;
                 break;
         }
     } else {
         $error = array();
         $error['code'] = '';
         //@TODO change these $data indexes afterwards
         $error['desc'] = 'Unknown notification type';
         return $error;
     }
 }
 /**
  * Inicia a consulta através de um código de notificação recebido
  * 
  * @param string $tipo
  * @param string $codigo
  * @return boolean
  * @since 1.0
  */
 public function obterDadosTransacao($tipo, $codigo)
 {
     $tipoNotificacao = new PagSeguroNotificationType($tipo);
     $strTipo = $tipoNotificacao->getTypeFromValue();
     try {
         if ($strTipo == 'TRANSACTION') {
             return $this->obterDadosDeNotificacao($codigo);
         }
     } catch (PagSeguroServiceException $e) {
         echo $e->getMessage();
         exit;
     }
     return false;
 }
Ejemplo n.º 5
0
 public static function getRetorno($code, $type)
 {
     $this->ci->log_message('error', $code . '|' . $type);
     if ($code && $type) {
         $notificationType = new PagSeguroNotificationType($type);
         $strType = $notificationType->getTypeFromValue();
         switch ($strType) {
             case 'TRANSACTION':
                 return self::transactionNotification($code);
                 break;
             default:
                 LogPagSeguro::error("Unknown notification type [" . $notificationType->getValue() . "]");
                 show_error('PagSeguroLibrary: Unknown notification type [' . $notificationType->getValue() . ']');
                 break;
         }
     } else {
         LogPagSeguro::error("Invalid notification parameters.");
         show_error('PagSeguroLibrary: Invalid notification parameters.');
     }
 }
 /**
  * NotificationListener
  *
  * Recebe as notificações do pagseguro sobre atualização de pagamento.
  * @access public
  * @return bool
  */
 public function NotificationListener()
 {
     $code = isset($_POST['notificationCode']) && trim($_POST['notificationCode']) !== "" ? trim($_POST['notificationCode']) : null;
     $type = isset($_POST['notificationType']) && trim($_POST['notificationType']) !== "" ? trim($_POST['notificationType']) : null;
     $transaction = false;
     if ($code && $type) {
         $notificationType = new PagSeguroNotificationType($type);
         $strType = $notificationType->getTypeFromValue();
         switch ($strType) {
             case 'TRANSACTION':
                 $transaction = self::TransactionNotification($code);
                 break;
             default:
                 LogPagSeguro::error("Unknown notification type [" . $notificationType->getValue() . "]");
         }
     } else {
         LogPagSeguro::error("Invalid notification parameters.");
         self::printLog();
     }
     if (is_object($transaction)) {
         self::setTransacaoPagseguro($transaction);
     }
     return TRUE;
 }
Ejemplo n.º 7
0
 /**
  * Listen for PagSeguro IPN
  *
  * PagSeguro instant payment notifications.
  *
  * @return   void
  * @since    1.0
  */
 function listen_for_pagseguro_ipn()
 {
     global $edd_options;
     // check for incoming order id
     $code = isset($_POST['notificationCode']) && trim($_POST['notificationCode']) !== "" ? trim($_POST['notificationCode']) : null;
     $type = isset($_POST['notificationType']) && trim($_POST['notificationType']) !== "" ? trim($_POST['notificationType']) : null;
     // check for the edd-listener in the URL request
     if (is_null($code) || is_null($type)) {
         return;
     }
     // debug notification
     if ($this->debug === true) {
         wp_mail(get_bloginfo('admin_email'), __('PagSeguro Gateway Debug 1: Incoming Notification'), var_export($_POST, true));
     }
     // get credentials
     $credentials = $this->get_credentials();
     // check credentials have been set
     if (is_null($credentials['email']) || is_null($credentials['token'])) {
         return;
     }
     // debug credentials
     if ($this->debug === true) {
         wp_mail(get_bloginfo('admin_email'), __('PagSeguro Gateway Debug 2: Credentials'), 'OK');
     }
     // require PagSeguro files
     $this->load_pagseguro_sdk();
     // verify classes exists
     if (!class_exists('PagSeguroNotificationType')) {
         return;
     }
     // debug sdk
     if ($this->debug === true) {
         wp_mail(get_bloginfo('admin_email'), __('PagSeguro Gateway Debug 3: SDK'), 'OK');
     }
     // get notification
     $notificationType = new PagSeguroNotificationType($type);
     $strType = $notificationType->getTypeFromValue();
     // debug type
     if ($this->debug === true) {
         wp_mail(get_bloginfo('admin_email'), __('PagSeguro Gateway Debug 4: Notification Type'), var_export($strType, true));
     }
     // try to verify the notification
     try {
         // generate credentials
         $credentials = new PagSeguroAccountCredentials($credentials['email'], $credentials['token']);
         // notification service
         $transaction = PagSeguroNotificationService::checkTransaction($credentials, $code);
         // debug check
         if ($this->debug === true) {
             wp_mail(get_bloginfo('admin_email'), __('PagSeguro Gateway Debug 5: Transaction Check'), 'OK');
         }
         // get both values
         $reference = $transaction->getReference();
         $status = $transaction->getStatus();
         // check there is an external reference
         if (isset($reference) && isset($status)) {
             // check for succesful status
             if ($status->getValue() == 3) {
                 // debug status
                 if ($this->debug === true) {
                     wp_mail(get_bloginfo('admin_email'), __('PagSeguro Gateway Debug 6: Status Check'), 'OK');
                 }
                 // update succesful payment
                 edd_update_payment_status($reference, 'publish');
             } else {
                 // debug status
                 if ($this->debug === true) {
                     wp_mail(get_bloginfo('admin_email'), __('PagSeguro Gateway Debug 6: Status Check'), 'ERROR');
                 }
             }
         } else {
             // debug reference/status error
             if ($this->debug === true) {
                 wp_mail(get_bloginfo('admin_email'), __('PagSeguro Gateway Debug 8: Reference/Status Check'), 'ERROR');
             }
         }
     } catch (Exception $e) {
         wp_mail(get_bloginfo('admin_email'), __('PagSeguro IPN Service Error', 'edd-pagseguro-gateway'), $e->getMessage());
         return;
     }
 }
Ejemplo n.º 8
0
 function plgVmOnPaymentNotification()
 {
     $post = $_POST;
     if (!PagSeguroHelper::isNotificationEmpty($post)) {
         $notificationType = new PagSeguroNotificationType($post['notificationType']);
         $strType = $notificationType->getTypeFromValue();
         switch ($strType) {
             case 'TRANSACTION':
                 $this->_doUpdateByNotification($post['notificationCode']);
                 break;
             default:
                 LogPagSeguro::error("Unknown notification type [" . $notificationType->getValue() . "]");
         }
     } else {
         LogPagSeguro::error("Invalid notification parameters.");
     }
 }
Ejemplo n.º 9
0
 public function callback()
 {
     require_once DIR_SYSTEM . 'library/PagSeguroLibrary/PagSeguroLibrary.php';
     $code = isset($_POST['notificationCode']) && trim($_POST['notificationCode']) != "" ? trim($_POST['notificationCode']) : null;
     $type = isset($_POST['notificationType']) && trim($_POST['notificationType']) != "" ? trim($_POST['notificationType']) : null;
     if ($code && $type) {
         $notificationType = new PagSeguroNotificationType($type);
         $strType = $notificationType->getTypeFromValue();
         switch ($strType) {
             case 'TRANSACTION':
                 $credentials = new PagSeguroAccountCredentials($this->config->get('pagseguro_email'), $this->config->get('pagseguro_token'));
                 try {
                     $transaction = PagSeguroNotificationService::checkTransaction($credentials, $code);
                     $transactionStatus = $transaction->getStatus();
                     $id_pedido = explode('_', $transaction->getReference());
                     $paymentMethod = $transaction->getPaymentMethod();
                     $parcelas = $transaction->getInstallmentCount();
                     $pagSeguroShipping = $transaction->getShipping();
                     $codigo_transacao = $transaction->getCode();
                     $this->load->model('checkout/order');
                     $order = $this->model_checkout_order->getOrder($id_pedido[0]);
                     // Obtendo o tipo de pagamento escolhido
                     $payment_code = $paymentMethod->getCode();
                     $comment = "Código da transação: " . $codigo_transacao . "\nTipo de pagamento: " . $payment_code->getTypeFromValue() . "\nParcelas: " . $parcelas . "\n";
                     // Obtendo o tipo e o valor do frete
                     $pagSeguroShippingType = $pagSeguroShipping->getType();
                     $valor_frete = $pagSeguroShipping->getCost();
                     // Valor 1: Pac, valor 2: Sedex, valor 3: não especificado ou cálculo não realizado pelo PagSeguro
                     if ($pagSeguroShippingType->getValue() != 3) {
                         $comment .= "\nTipo de frete escolhido no PagSeguro: " . $pagSeguroShippingType->getTypeFromValue() . "\nValor do frete: " . $this->currency->format($valor_frete, $order['currency_code'], false, false);
                     }
                     $update_status_alert = false;
                     if ($this->config->get('pagseguro_update_status_alert')) {
                         $update_status_alert = true;
                     }
                     switch ($transactionStatus->getTypeFromValue()) {
                         case 'WAITING_PAYMENT':
                             if ($order['order_status_id'] == '0') {
                                 $this->model_checkout_order->confirm($id_pedido[0], $this->config->get('pagseguro_order_aguardando_pagamento'), $comment);
                             } else {
                                 if ($order['order_status_id'] != $this->config->get('pagseguro_order_aguardando_pagamento')) {
                                     $this->model_checkout_order->update($id_pedido[0], $this->config->get('pagseguro_order_aguardando_pagamento'), $comment, $update_status_alert);
                                 }
                             }
                             break;
                         case 'IN_ANALYSIS':
                             if ($order['order_status_id'] != $this->config->get('pagseguro_order_analise')) {
                                 $this->model_checkout_order->update($id_pedido[0], $this->config->get('pagseguro_order_analise'), '', $update_status_alert);
                             }
                             break;
                         case 'PAID':
                             if ($order['order_status_id'] != $this->config->get('pagseguro_order_paga')) {
                                 $this->model_checkout_order->update($id_pedido[0], $this->config->get('pagseguro_order_paga'), $comment, $update_status_alert);
                             }
                             break;
                         case 'AVAILABLE':
                             //if($order['order_status_id'] != $this->config->get('pagseguro_order_disponivel')){
                             //	$this->model_checkout_order->update($id_pedido[0], $this->config->get('pagseguro_order_disponivel'), '', false);
                             //}
                             break;
                         case 'IN_DISPUTE':
                             if ($order['order_status_id'] != $this->config->get('pagseguro_order_disputa')) {
                                 $this->model_checkout_order->update($id_pedido[0], $this->config->get('pagseguro_order_disputa'), $comment, $update_status_alert);
                             }
                             break;
                         case 'REFUNDED':
                             if ($order['order_status_id'] != $this->config->get('pagseguro_order_devolvida')) {
                                 $this->model_checkout_order->update($id_pedido[0], $this->config->get('pagseguro_order_devolvida'), $comment, $update_status_alert);
                             }
                             break;
                         case 'CANCELLED':
                             if ($order['order_status_id'] != $this->config->get('pagseguro_order_cancelada')) {
                                 $this->model_checkout_order->update($id_pedido[0], $this->config->get('pagseguro_order_cancelada'), $comment, $update_status_alert);
                             }
                             break;
                     }
                 } catch (PagSeguroServiceException $e) {
                     $this->log->write('PagSeguro: ' . $e->getOneLineMessage());
                 }
                 break;
             default:
                 $this->log->write('PagSeguro: tipo de notificação desconhecido [' . $notificationType->getValue() . ']');
         }
     } else {
         $this->log->write('PagSeguro: Parâmetros de notificação retornado pelo PagSeguro são inválidos.');
     }
 }
	public function obterTransacao($fields) {
		$code = (isset($fields['notificationCode']) && trim($fields['notificationCode']) !== "" ?
            trim($fields['notificationCode']) : null);
        $type = (isset($fields['notificationType']) && trim($fields['notificationType']) !== "" ?
            trim($fields['notificationType']) : null);

        if ($code && $type) {
            $notificationType = new PagSeguroNotificationType($type);
            $strType = $notificationType->getTypeFromValue();

            switch ($strType) {
                case 'TRANSACTION':
                    $transaction = $this->transactionNotification($code);
                    break;
            }
            return $transaction;
        }
    }
Ejemplo n.º 11
0
 /**
  * Create Notification type
  */
 private function _createNotificationType()
 {
     $this->obj_notification_type = new PagSeguroNotificationType();
     $this->obj_notification_type->setByType("TRANSACTION");
 }
Ejemplo n.º 12
0
        $pagseguro = new pagseguro();
        $idCustomer = $order->id_customer;
        $idLang = $order->id_lang;
        $customer = new Customer(intval($idCustomer));
        $mailVars = array('{email}' => Configuration::get('PS_SHOP_EMAIL'), '{firstname}' => stripslashes($customer->firstname), '{lastname}' => stripslashes($customer->lastname), '{terceiro}' => stripslashes($pagseguro->displayName), '{id_order}' => stripslashes($pagseguro->currentOrder), '{status}' => stripslashes($status));
        $pagseguro->enviar($mailVars, 'pagseguro', $status, $pagseguro->displayName, $idCustomer, $idLang, $customer->email, 'modules/pagseguro/mails/');
        /** /ENVIO DO EMAIL * */
        $extraVars = array();
        $history = new OrderHistory();
        $history->id_order = intval($id_order);
        $history->changeIdOrderState(intval($order_state), intval($id_order));
        $history->addWithemail(true, $extraVars);
        die("Sucesso!");
    } catch (PagSeguroServiceException $e) {
        file_put_contents(dirname(__FILE__) . "/error.log", var_export($e, true));
        die("Error!");
    }
}
if ($code && $type) {
    $notificationType = new PagSeguroNotificationType($type);
    $strType = $notificationType->getTypeFromValue();
    switch ($strType) {
        case 'TRANSACTION':
            TransactionNotification($code);
            break;
        default:
            var_dump($strType);
            break;
    }
    //self::printLog($strType);
}