Skip to content

Instantly share code, notes, and snippets.

@kneipp
Last active May 7, 2019 21:24
Show Gist options
  • Save kneipp/735cbff6af3c26e21b90be221ddd75c5 to your computer and use it in GitHub Desktop.
Save kneipp/735cbff6af3c26e21b90be221ddd75c5 to your computer and use it in GitHub Desktop.
<?php
use Doctrine\Common\Annotations\AnnotationRegistry;
use PHPSC\PagSeguro\Credentials;
//use PHPSC\PagSeguro\Environments\Production;
use PHPSC\PagSeguro\Environments\Sandbox;
use PHPSC\PagSeguro\Customer\Customer;
use PHPSC\PagSeguro\Items\Item;
use PHPSC\PagSeguro\Requests\Checkout\CheckoutService;
$autoloader = require __DIR__ . '/../../../../vendor/autoload.php';
AnnotationRegistry::registerLoader([$autoloader, 'loadClass']);
class Checkout extends TPage
{
/**
* Constructor method
* https://www.adianti.com.br/framework_files/tutor/index.php?class=SinglePageView
*/
public function __construct()
{
parent::__construct();
//new TMessage('info', 'teste');
$credentials = new Credentials(
'a@b.com',
'0000123123HASH',
new Sandbox()
);
try {
$service = new CheckoutService($credentials); // cria instância do serviço de pagamentos
$amount = 1.99;
$amount = number_format($amount, 2, '.', '');
$checkout = $service->createCheckoutBuilder()
->addItem(new Item(1, 'Cotação Online', $amount))
->getCheckout();
$response = $service->checkout($checkout);
$code = $response->getCode();
TPage::include_js('https://stc.sandbox.pagseguro.uol.com.br/pagseguro/api/v2/checkout/pagseguro.lightbox.js');
$script =new TElement('script');
$script->type = 'text/javascript';
$script->add('
<script>
$(function() {
PagSeguroLightbox({
code: "' . $code . '",
success : function(transactionCode) {
alert("success - " + transactionCode);
},
abort : function(transactionCode) {
//...
}
});
});
</script>
');
} catch (Exception $e) { // Caso ocorreu algum erro
new TMessage('error', $e->getMessage());
$this->onSolicitar($data);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment