Last active
May 7, 2019 21:24
-
-
Save kneipp/735cbff6af3c26e21b90be221ddd75c5 to your computer and use it in GitHub Desktop.
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 | |
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( | |
'[email protected]', | |
'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