Created
July 9, 2012 18:17
-
-
Save djalmaaraujo/3078002 to your computer and use it in GitHub Desktop.
Controller::Pagseguro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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