示例#1
0
 protected function completed()
 {
     $this->myView = new OrderCompletedView();
     $this->myModel = new OrderModel();
     // TODO: Verificar se THIS->ID esta preenchido
     // Pesquisa na base interna e na base do PagSeguro
     $this->myView->data = $this->myModel->selectForDetail($this->id);
     $transactionSummary = SearchTransactionsByReference::main($this->id);
     // TODO: Verificar se transaction summary foi preenchido
     // Atualiza o status caso o pagamento tenha sido efetuado
     if ($transactionSummary && $transactionSummary->getStatus()->getValue() == 1 && $this->myView->data->status == 1) {
         $this->myView->data->status = Config::read('order.status')['waiting'];
         $this->myModel->update($this->myView->data);
     } else {
         header("location: " . Config::read('page.url.homepage'));
     }
     // $this->data->getCode()
     // $this->data->getGrossAmount()
     // $this->data->getStatus()->getValue()
 }
             */
            // seller authentication
            $credentials = new PagSeguroAccountCredentials("*****@*****.**", "E231B2C9BCC8474DA2E260B6C8CF60D3");
            $credentials = PagSeguroConfig::getAccountCredentials();
            // application authentication
            //$credentials = PagSeguroConfig::getApplicationCredentials();
            //$credentials->setAuthorizationCode("E231B2C9BCC8474DA2E260B6C8CF60D3");
            $result = PagSeguroTransactionSearchService::searchByReference($credentials, $reference, $initialDate, $finalDate, $pageNumber, $maxPageResults);
            self::printResult($result, $initialDate, $finalDate);
        } catch (PagSeguroServiceException $e) {
            die($e->getMessage());
        }
    }
    public static function printResult(PagSeguroTransactionSearchResult $result, $initialDate, $finalDate)
    {
        $finalDate = $finalDate ? $finalDate : 'now';
        echo "<h2>Search transactions by Reference</h2>";
        echo "<h3>{$initialDate} to {$finalDate}</h3>";
        $transactions = $result->getTransactions();
        if (is_array($transactions) && count($transactions) > 0) {
            foreach ($transactions as $key => $transactionSummary) {
                echo "Code: " . $transactionSummary->getCode() . "<br>";
                echo "Reference: " . $transactionSummary->getReference() . "<br>";
                echo "amount: " . $transactionSummary->getGrossAmount() . "<br>";
                echo "<hr>";
            }
        }
    }
}
SearchTransactionsByReference::main();