marcelofoxes

PAGSEGURO CODEIGNITER

May 27th, 2017
573
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.56 KB | None | 0 0
  1. <?php
  2. class PagSeguro extends CI_Controller {
  3.     #protected $allowed_http_methods = array('get', 'delete', 'post', 'put');
  4.    
  5.     public function __construct() {
  6.         parent::__construct();
  7.         header('Access-Control-Allow-Origin: *');
  8.     }
  9.    
  10.     public  function notify() {
  11.         PagSeguroLibrary::init();
  12.         $pagseguroConfig = PagSeguroConfig::init();
  13.        
  14.         $pagseguroConfig->setEnvironment('sandbox');
  15.         $pagseguroConfig->setData('credentials', 'email', '[email protected]');
  16.         $pagseguroConfig->setData('credentials', 'token', array("sandbox" => 'x'));
  17.         $pagseguroConfig->setData('credentials', 'appId', array("sandbox" => "x"));
  18.         $pagseguroConfig->setData('credentials', 'appKey', array("sandbox" => "x"));
  19.        
  20.         $credentials = PagSeguroConfig::getAccountCredentials(); // getApplicationCredentials()
  21.        
  22.         $code = $this->input->post("notificationCode");
  23.        
  24.         $response = PagSeguroNotificationService::checkTransaction(
  25.                 $credentials,
  26.                 $code
  27.         );
  28.        
  29.        
  30. //      'INITIATED' => 0,
  31. //      'WAITING_PAYMENT' => 1,
  32. //      'IN_ANALYSIS' => 2,
  33. //      'PAID' => 3,
  34. //      'AVAILABLE' => 4,
  35. //      'IN_DISPUTE' => 5,
  36. //      'REFUNDED' => 6,
  37. //      'CANCELLED' => 7,
  38. //      'SELLER_CHARGEBACK' => 8,
  39. //      'CONTESTATION' => 9
  40.         log_message('error', "Recebida notificaçao do pagseguro");
  41.         // pagamentos apenas
  42.         if ($response->getType()->getValue() == 1 && is_numeric($response->getReference())) {
  43. //          echo "<pre>";
  44. //          var_dump($response);
  45. //          echo "</pre>";
  46.            
  47.             $this->load->model("pagseguro_model");
  48.             $this->pagseguro_model->adicionarTransacaoUpdate($response);
  49.         }
  50.        
  51.        
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment