function TransactionNotification($notificationCode) { ob_clean(); global $cookie; $credentials = new PagSeguroAccountCredentials(Configuration::get("PAGSEGURO_BUSINESS"), Configuration::get("PAGSEGURO_TOKEN")); try { $transaction = PagSeguroNotificationService::checkTransaction($credentials, $notificationCode); $id_transaction = $transaction->getCode(); $id_status = $transaction->getStatus()->getValue(); $order_state = Configuration::get("PAGSEGURO_STATUS_{$id_status}"); $orderState = new OrderState($order_state); $status = $orderState->name[$cookie->id_lang]; $id_order = Db::getInstance()->getValue("SELECT id_order FROM " . _DB_PREFIX_ . "pagseguro_order WHERE id_transaction = '{$id_transaction}'"); $order = new Order(intval($id_order)); /** ENVIO DO EMAIL * */ $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!"); } }
private static function transactionNotification($notificationCode) { try { return PagSeguroNotificationService::checkTransaction(self::getCredentials(), $notificationCode); } catch (PagSeguroServiceException $e) { die($e->getMessage()); } }
private static function transactionNotification($notificationCode) { $credentials = PagSeguroConfig::getAccountCredentials(); try { return PagSeguroNotificationService::checkTransaction($credentials, $notificationCode); } catch (PagSeguroServiceException $e) { die($e->getMessage()); } }
private function createTransaction() { $this->obj_transaction = PagSeguroNotificationService::checkTransaction($this->obj_credential, $this->notification_code); $transaction = $this->isNotNull($this->obj_transaction); if (strpos($this->obj_transaction->getReference(), Configuration::get('PAGSEGURO_ID')) === false) { throw new Exception("ID_PAGSEGURO_INCOMPATIVEL", 1); } $this->reference = $transaction ? (int) EncryptionIdPagSeguro::decrypt($this->obj_transaction->getReference()) : null; }
private static function authorizationNotification($notificationCode) { $credentials = PagSeguroConfig::getApplicationCredentials(); try { $authorization = PagSeguroNotificationService::checkAuthorization($credentials, $notificationCode); // Do something with $authorization } catch (PagSeguroServiceException $e) { die($e->getMessage()); } }
private static function preApprovalNotification($preApprovalCode) { $credentials = PagSeguroConfig::getAccountCredentials(); try { $preApproval = PagSeguroNotificationService::checkPreApproval($credentials, $preApprovalCode); // Do something with $preApproval } catch (PagSeguroServiceException $e) { die($e->getMessage()); } }
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; } }
private static function TransactionNotification($notificationCode) { /* * #### Crendencials ##### * Substitute the parameters below with your credentials (e-mail and token) * You can also get your credentails from a config file. See an example: * $credentials = PagSeguroConfig::getAccountCredentials(); */ $credentials = new PagSeguroAccountCredentials("*****@*****.**", "your_token_here"); try { $transaction = PagSeguroNotificationService::checkTransaction($credentials, $notificationCode); } catch (PagSeguroServiceException $e) { die($e->getMessage()); } }
private static function transactionNotification($notificationCode) { /* * #### Credentials ##### * Replace the parameters below with your credentials (e-mail and token) * You can also get your credentials from a config file. See an example: * $credentials = PagSeguroConfig::getAccountCredentials(); */ $credentials = new PagSeguroAccountCredentials("*****@*****.**", "E231B2C9BCC8474DA2E260B6C8CF60D3"); try { $transaction = PagSeguroNotificationService::checkTransaction($credentials, $notificationCode); // Do something with $transaction } catch (PagSeguroServiceException $e) { die($e->getMessage()); } }
public function getNotificacao() { $credentials = $this->logar(); /* Tipo de notifica��o recebida */ $type = $_POST['notificationType']; /* C�digo da notifica��o recebida */ $code = $_POST['notificationCode']; /* Verificando tipo de notifica��o recebida */ if ($type === 'transaction') { /* Obtendo o objeto PagSeguroTransaction a partir do c�digo de notifica��o */ $transaction = PagSeguroNotificationService::checkTransaction($credentials, $code); switch ($transaction->getStatus()) { case 1: $status = "Aguardando pagamento"; break; case 2: $status = "Em an�lise"; break; case 3: $status = "Paga"; break; case 4: $status = "Dispon�vel"; break; case 5: $status = "Em disputa"; break; case 6: $status = "Devolvida"; break; case 7: $status = "Canselada"; break; } return array('status' => $status, 'IdTransacao' => $transaction->getCode()); } }
public function getTransacao($codigo_notificacao) { $email = Configure::read('Pagseguro.email'); $token = Configure::read('Pagseguro.token'); $config = new \PagSeguroAccountCredentials($email, $token); return \PagSeguroNotificationService::checkTransaction($config, $codigo_notificacao); }
public function check($notificationCode) { try { $transaction = \PagSeguroNotificationService::checkTransaction(new \PagSeguroAccountCredentials($this->credentials['email'], $this->credentials['token']), $notificationCode); return ['code' => $transaction->getCode(), 'reference' => $transaction->getReference()]; } catch (\PagSeguroServiceException $e) { return $e->getMessage(); } }
/** * Create Transaction */ private function _createTransaction() { $this->objTransaction = PagSeguroNotificationService::checkTransaction($this->objCredential, $this->notificationCode); $this->reference = $this->objTransaction->getReference(); }
/** * Perform update by received PagSeguro notification * @param string $notificationCode */ private function _doUpdateByNotification($statuses, $notificationCode) { try { // getting credentials data $credentials = new PagSeguroAccountCredentials($this->payment_params->pagseguro_email, $this->payment_params->pagseguro_token); // getting transaction data object $transaction = PagSeguroNotificationService::checkTransaction($credentials, $notificationCode); // getting PagSeguro status number $statusPagSeguro = $transaction->getStatus()->getValue(); $array_status = array(0 => 'Initiated', 1 => 'Waiting payment', 2 => 'In analysis', 3 => 'Paid', 4 => 'Available', 5 => 'In dispute', 6 => 'refunded', 7 => 'cancelled'); // performing update status if (!PagSeguroHelper::isEmpty($statusPagSeguro) && (int) $statusPagSeguro == 3) { $orderClass = hikashop_get('class.order'); $dbOrder = $orderClass->get((int) $transaction->getReference()); $email = new stdClass(); $history = new stdClass(); $order_status = $this->payment_params->verified_status; $history->notified = 1; if ($dbOrder->order_status == $order_status) { return true; } $url = HIKASHOP_LIVE . 'administrator/index.php?option=com_hikashop&ctrl=order&task=edit&order_id=' . $dbOrder->order_id; $order_text = "\r\n" . JText::sprintf('NOTIFICATION_OF_ORDER_ON_WEBSITE', $dbOrder->order_number, HIKASHOP_LIVE); $order_text .= "\r\n" . str_replace('<br/>', "\r\n", JText::sprintf('ACCESS_ORDER_WITH_LINK', $url)); $mail_status = $statuses[$order_status]; $email->subject = JText::sprintf('PAYMENT_NOTIFICATION_FOR_ORDER', 'Pagseguro', $array_status[$statusPagSeguro], $dbOrder->order_number); $email->body = str_replace('<br/>', "\r\n", JText::sprintf('PAYMENT_NOTIFICATION_STATUS', 'Pagseguro', $array_status[$statusPagSeguro])) . ' ' . JText::sprintf('ORDER_STATUS_CHANGED', $mail_status) . "\r\n\r\n" . $order_text; $this->modifyOrder($dbOrder->order_id, $order_status, $history, $email); } elseif ((int) $statusPagSeguro == 7) { $orderClass = hikashop_get('class.order'); $dbOrder = $orderClass->get((int) $transaction->getReference()); $email = new stdClass(); $history = new stdClass(); $order_status = $this->payment_params->invalid_status; $history->notified = 0; if ($dbOrder->order_status == $order_status) { return true; } $url = HIKASHOP_LIVE . 'administrator/index.php?option=com_hikashop&ctrl=order&task=edit&order_id=' . $dbOrder->order_id; $order_text = "\r\n" . JText::sprintf('NOTIFICATION_OF_ORDER_ON_WEBSITE', $dbOrder->order_number, HIKASHOP_LIVE); $order_text .= "\r\n" . str_replace('<br/>', "\r\n", JText::sprintf('ACCESS_ORDER_WITH_LINK', $url)); $mail_status = $statuses[$order_status]; $email->subject = JText::sprintf('PAYMENT_NOTIFICATION_FOR_ORDER', 'Pagseguro', $array_status[$statusPagSeguro], $dbOrder->order_number); $email->body = str_replace('<br/>', "\r\n", JText::sprintf('PAYMENT_NOTIFICATION_STATUS', 'Pagseguro', $array_status[$statusPagSeguro])) . ' ' . JText::sprintf('ORDER_STATUS_CHANGED', $mail_status) . "\r\n\r\n" . $order_text; $this->modifyOrder($dbOrder->order_id, $order_status, $history, $email); } } catch (PagSeguroServiceException $e) { LogPagSeguro::error("Error trying get transaction [" . $e->getMessage() . "]"); } return true; }
/** * Perform update by received PagSeguro notification * @param string $notificationCode */ private function _doUpdateByNotification($notificationCode) { // getting configuration params data $paramsData = $this->_getParamsData(); try { // getting credentials data $credentials = new PagSeguroAccountCredentials($paramsData['pagseguro_email'], $paramsData['pagseguro_token']); // getting transaction data object $transaction = PagSeguroNotificationService::checkTransaction($credentials, $notificationCode); // getting PagSeguro status number $statusPagSeguro = $transaction->getStatus()->getValue(); // getting new order state $newStatus = $this->_getAssociatedStatus($paramsData, $statusPagSeguro); // getting status translation $statusTranslation = $this->_getStatusTranslation($statusPagSeguro); // performing update status if (!PagSeguroHelper::isEmpty($newStatus)) { $this->_updateOrderStatus($transaction->getReference(), $newStatus, $statusTranslation); } } catch (PagSeguroServiceException $e) { LogPagSeguro::error("Error trying get transaction [" . $e->getMessage() . "]"); } }
public static function checkAuthorization(PagSeguroCredentials $credentials, $notificationCode) { LogPagSeguro::info("PagSeguroNotificationService.CheckAuthorization(notificationCode={$notificationCode}) - begin"); $connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME); try { $connection = new PagSeguroHttpConnection(); $connection->get(self::buildAuthorizationNotificationUrl($connectionData, $notificationCode), $connectionData->getServiceTimeout(), $connectionData->getCharset()); $authorization = PagSeguroAuthorizationParser::readAuthorization($connection->getResponse()); self::$logService = "CheckAuthorization"; return self::searchReturn($connection, $authorization, $notificationCode); } catch (PagSeguroServiceException $err) { throw $err; } catch (Exception $err) { LogPagSeguro::error("Exception: " . $err->getMessage()); throw $err; } }
public function notification() { $this->load->library('email'); $this->email->mailtype = 'html'; $code = $this->input->post('notificationCode'); $type = $this->input->post('notificationType'); $support_subject = ''; $support_mesage = ''; try { $credentials = PagSeguroConfig::getAccountCredentials(); $response = PagSeguroNotificationService::checkTransaction($credentials, $code); $status = $response->getStatus()->getValue(); $billId = $response->getReference(); $items = $response->getItems(); if ($status == 3 || $status == 4) { $this->db->where(['id' => $billId]); $this->db->update('tb_billing_accounts', ['dt_payment' => date('Y-m-d H:i:s')]); $message = '<h3>Seu pagamento foi aceito</h3>'; $message = '<p>A compra dos seguintes items foi bem sucedida, boa viagem.<;p><ul>'; foreach ($items as $k => $item) { $message .= "<li>" . $item->getDescription() . ' - ' . $item->getAmount() . "</li>"; } $message .= '</ul>'; $clientMail = $response->getSender()->getEmail(); $this->email->from('*****@*****.**', 'Notificações Financeiras - Origami'); $this->email->to($clientMail); $this->email->subject('Confirmação de pagamento - Caravana Origami'); $this->email->message($message); $this->email->send(); } $support_subject = 'Notificação ' . $response->getReference() . ' - ' . $response->getStatus()->getTypeFromValue(); $support_message = '<h3>Notificação de Transação</h3><p>A seguinte transação foi atualizada</p>'; $support_message .= '<ul><li>Referência: ' . $response->getReference() . '</li>'; $support_message .= '<li>Status: ' . $response->getStatus()->getValue() . ' - ' . $response->getStatus()->getTypeFromValue() . '</li>'; $support_message .= '<li>Cliente: ' . $response->getSender()->getName() . ' - ' . $response->getSender()->getEmail() . '</li>'; foreach ($items as $k => $item) { $support_message .= "<li>" . $item->getDescription() . ' - ' . $item->getAmount() . "</li>"; } $support_message .= '</ul>'; } catch (PagSeguroServiceException $e) { $support_subject = "Falha no acompanhamento de uma cobrança"; $support_message = $e->getMessage(); } $this->email->from('*****@*****.**', 'Notificações Financeiras - Origami'); $this->email->to('*****@*****.**'); $this->email->subject($support_subject); $this->email->message($support_message); $this->email->send(); }
/** * Create Transaction */ private function _createTransaction() { $this->objTransaction = PagSeguroNotificationService::checkTransaction($this->objCredential, $this->notificationCode); $reference = $this->objTransaction->getReference(); $orderId = $this->_helper->getReferenceDecryptOrderID($reference); $this->reference = $orderId; }
$donateFlux = Flux::config('PagSeguroFlux'); $rate = Flux::config('rate'); $hercules = Flux::config('hercules'); $donateId = (int) $params->get('id'); $donateRef = trim($params->get('payment_id')); $sql = "SELECT * FROM {$server->loginDatabase}.{$donateTable} WHERE id = ? OR payment_id = ?"; $sth = $server->connection->getStatement($sql); $sth->execute(array($donateId, $donateRef)); $transaction = $sth->fetch(); if ($transaction->payment_code) { $transactionCredencial = new PagSeguroAccountCredentials(Flux::config('EmailPagSeguro'), Flux::config('TokenPagseguro')); $transactionPagseguro = PagSeguroTransactionSearchService::searchByCode($transactionCredencial, $transaction->payment_code); } else { if ($transaction->payment_notification_code) { $transactionCredencial = new PagSeguroAccountCredentials(Flux::config('EmailPagSeguro'), Flux::config('TokenPagseguro')); $transactionPagseguro = PagSeguroNotificationService::checkTransaction($transactionCredencial, $transaction->payment_notification_code); } } if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (count($_POST) && isset($_POST['transactionCode'])) { $transactionCode = str_replace(' ', '', strtoupper($_POST['transactionCode'])); if (!preg_match('/^[A-Z 0-9]{8}[-]?[A-Z 0-9]{4}[-]?[A-Z 0-9]{4}[-]?[A-Z 0-9]{4}[-]?[A-Z 0-9]{12}$/', $transactionCode)) { $errorMessage = sprintf('Formato do código de transação incorreto! O formato deve ser: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX.'); } else { $transactionCredencial = new PagSeguroAccountCredentials(Flux::config('EmailPagSeguro'), Flux::config('TokenPagseguro')); $transactionPagseguro = PagSeguroTransactionSearchService::searchByCode($transactionCredencial, $transactionCode); $donateStatus = $transactionPagseguro->getStatus()->getValue(); $donateRef = $transactionPagseguro->getReference(); $sql = "SELECT * FROM {$server->loginDatabase}.{$donateTable} WHERE payment_id = ?"; $sth = $server->connection->getStatement($sql); $sth->execute(array($donateRef));
// se receber uma mensagem por POST, identifica se é uma notificação do pagseguro, // se for, redireciona para seu devido lugar error_reporting(-1); ini_set('display_errors', 'On'); ini_set("log_errors", 1); ini_set("error_log", "logs/erro.log"); // recebemos uma notificação do PagSeguro // importa a biblioteca do PagSeguro require '../PagSeguroLibrary/PagSeguroLibrary.php'; /* Tipo de notificação recebida */ $tipoNotificacao = $_POST['notificationType']; /* Código da notificação recebida */ $codigoNotificacao = $_POST['notificationCode']; $credenciais = PagSeguroConfig::getAccountCredentials(); if ($tipoNotificacao === 'transaction') { $transacao = PagSeguroNotificationService::checkTransaction($credenciais, $codigoNotificacao); $statusPag = $transacao->getStatus(); //se existe uma transacao valida, redireciona if ($statusPag->getValue() == 3) { $referencia = $transacao->getReference(); $codigoTipo = mb_substr($referencia, 0, 1); // se a referencia possuir um dos códigos do sistema novo, envia ao sistema novo if ($codigoTipo === "M" || $codigoTipo == "A") { //header("Location:./notificacoes_pagseguro.php",true,307); ?> <form action='./notificacao_pagseguro.php' method='post' name='frm'> <?php foreach ($_POST as $parametro => $valor) { echo "<input type='hidden' name='" . htmlentities($parametro) . "' value='" . htmlentities($valor) . "'>";
/** * Create Transaction */ private function _createTransaction() { $this->obj_transaction = PagSeguroNotificationService::checkTransaction($this->obj_credential, $this->notification_code); $this->reference = $this->_isNotNull($this->obj_transaction) ? (int) $this->obj_transaction->getReference() : null; }
private function transactionNotification($notificationCode) { $credentials = $this->obterCredenciaisPagSeguro(); try { $transaction = PagSeguroNotificationService::checkTransaction($credentials, $notificationCode); } catch (PagSeguroServiceException $e) { die($e->getMessage()); } return $transaction; }
/** * Create Transaction */ private function createTransaction() { $this->obj_transaction = PagSeguroNotificationService::checkTransaction($this->obj_credentials, $this->notification_code); $this->reference = str_replace('WC-', '', $this->obj_transaction->getReference()); }
/** * Request a list of PagSeguraTransaction by notificationCode * @param String $transactionCode * @return PagSeguroTransactionSearchResult */ public function getNotification($transactionCode) { return $this->notificationService->checkTransaction($this->credentials, $transactionCode); }
/** * 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; } }
public static function getTransacaoNotificacao(Integracao $integracao, $notificationCode) { try { // Incluir PagSeguro include_once PLUGINPATH . '/vendor/PagSeguro/PagSeguroLibrary.php'; // Obter a transação // Verificar situação $credentials = new PagSeguroAccountCredentials($integracao->client, $integracao->token); $transacao = \PagSeguroNotificationService::checkTransaction($credentials, $notificationCode); // PagSeguroTransactionSearchService::searchByCode($credentials, $notificationCode); } catch (PagSeguroServiceException $e) { throw new Exception($e->getMessage()); } return $transacao; }
/** * TransactionNotification * * Recupera a transação através de uma notificação * @access private * @param unknown_type $notificationCode * @return Ambigous <a, NULL, PagSeguroTransaction> */ private static function TransactionNotification($notificationCode) { $CI =& get_instance(); $credentials = new PagSeguroAccountCredentials($CI->config->item('pagseguroAccount'), $CI->config->item('pagseguroToken')); try { $transaction = PagSeguroNotificationService::checkTransaction($credentials, $notificationCode); } catch (PagSeguroServiceException $e) { die($e->getMessage()); } return $transaction; }
require_once Flux::config('PagSeguroLib'); $donateTable = Flux::config('FluxTables.DonateTable'); $tableBan = Flux::config('FluxTables.AccountBanTable'); $donatePromo = Flux::config('Promotion'); $initPromo = Flux::config('InitPromo'); $donateVar = Flux::config('PagSeguroVar'); $donateFlux = Flux::config('PagSeguroFlux'); $rate = Flux::config('rate'); $hercules = Flux::config('hercules'); if (count($_POST) && isset($_POST['notificationCode'])) { $notificationCode = str_replace(' ', '', strtoupper($_POST['notificationCode'])); if (!preg_match('/^[A-Z 0-9]{6}[-]?[A-Z 0-9]{12}[-]?[A-Z 0-9]{12}[-]?[A-Z 0-9]{6}$/', $notificationCode)) { $errorMessage = sprintf('Formato do código de notificação incorreto! O formato deve ser: XXXXXX-XXXXXXXXXXXX-XXXXXXXXXXXX-XXXXXX.'); } else { $transactionCredencial = new PagSeguroAccountCredentials(Flux::config('EmailPagSeguro'), Flux::config('TokenPagseguro')); $transaction = PagSeguroNotificationService::checkTransaction($transactionCredencial, $notificationCode); $donateStatus = $transaction->getStatus()->getValue(); $donateRef = $transaction->getReference(); $transactionCode = $transaction->getCode(); $sql = "SELECT * FROM {$server->loginDatabase}.{$donateTable} WHERE payment_id = ?"; $sth = $server->connection->getStatement($sql); $sth->execute(array($donateRef)); $donate = $sth->fetch(); $account = $donate->account_id; $donateVal = $donate->payment; $status = $donate->payment_status_pagseguro; if ($donateStatus == $status) { exit; } switch ($donateStatus) { case 1:
/** * Obtém o status de uma notificação no PagSeguro * * @param string $notificationCode * @return boolean * @since 1.0 */ private function obterDadosDeNotificacao($notificationCode) { try { $this->dadosTransacao = $transaction = PagSeguroNotificationService::checkTransaction($this->credenciais, $notificationCode); if ($this->dadosTransacao) { return true; } } catch (PagSeguroServiceException $e) { echo $e->getMessage(); exit; } return false; }
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.'); } }