Skip to content

Instantly share code, notes, and snippets.

@djalmaaraujo
Created July 9, 2012 18:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djalmaaraujo/3078002 to your computer and use it in GitHub Desktop.
Save djalmaaraujo/3078002 to your computer and use it in GitHub Desktop.
Controller::Pagseguro
<?php
require_once APP . "/lib/PagSeguroLibrary/PagSeguroLibrary.php";
class PagseguroController extends AppController {
public $uses = array();
/**
* Método da Lib do Pagseguro
* para repassar os dados da
* transação.
*
* @return void
* @author Djalma Araújo
*/
public function npi() {
$this->autoRender = false;
$code = (isset($_POST['notificationCode']) && trim($_POST['notificationCode']) !== "" ? trim($_POST['notificationCode']) : null);
$type = (isset($_POST['notificationType']) && trim($_POST['notificationType']) !== "" ? trim($_POST['notificationType']) : null);
$this->Log->save(array(
'text' => json_encode($this->data)
));
if ( $code && $type ) {
$notificationType = new PagSeguroNotificationType($type);
$strType = $notificationType->getTypeFromValue();
switch($strType) {
case 'TRANSACTION':
$this->TransactionNotification($code);
break;
default:
LogPagSeguro::error("Unknown notification type [".$notificationType->getValue()."]");
}
} else {
die('post not found');
}
}
/**
* Recebe os dados da notificação
* do Pagseguro.
*
* @param string $notificationCode
* @return void
* @author Djalma Araújo
*/
private function TransactionNotification($notificationCode) {
$this->autoRender = false;
$credentials = new PagSeguroAccountCredentials(Config::read('gateway.email'), Config::read('gateway.token'));
try {
$transaction = PagSeguroNotificationService::checkTransaction($credentials, $notificationCode);
$status = $transaction->getStatus()->getTypeFromValue();
$code = $transaction->getCode();
// DO SOMETHING
} catch (PagSeguroServiceException $e) {
die($e->getMessage());
}
}
public function test() {
$this->Billing->handleNotification(4);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment