I believe you’re using the v2
, as you did not inform as configured, I will only assume the answer as to documentation
In PHP we should call the class PagSeguroPaymentRequest
$paymentRequest = new PagSeguroPaymentRequest();
To add an item or more:
$paymentRequest->addItem('0001', 'Notebook', 1, 2430.00);
$paymentRequest->addItem('0002', 'Mochila', 1, 150.99);
Informing the buyer’s address as well as freight type:
$sedexCode = PagSeguroShippingType::getCodeByType('SEDEX');
$paymentRequest->setShippingType($sedexCode);
$paymentRequest->setShippingAddress(
'01452002',
'Av. Brig. Faria Lima',
'1384',
'apto. 114',
'Jardim Paulistano',
'São Paulo',
'SP',
'BRA'
);
If you already have the buyer’s details, you can inform them to facilitate the payment flow. This way they will not need to inform them again.
$paymentRequest->setSender(
'João Comprador',
'[email protected]',
'11',
'56273440',
'CPF',
'156.009.442-76'
);
Defining the currency to be used in the payment.
$paymentRequest->setCurrency("BRL");
Defining additional information, which can be used by your system after the payment flow in Pagseguro, I believe the problem can be here.
// Referenciando a transação do PagSeguro em seu sistema
$paymentRequest->setReference("REF123");
// URL para onde o comprador será redirecionado (GET) após o fluxo de pagamento
$paymentRequest->setRedirectUrl("https://exemplo.com/obrigado.php");
// URL para onde serão enviadas notificações (POST) indicando alterações no status da transação
$paymentRequest->addParameter('notificationURL', 'http://www.lojamodelo.com.br/nas');
It is possible to add parameters/information in the checkout request that, although already implemented in the API, are not yet available as methods in the library.
$paymentRequest->addParameter('senderBornDate', '07/05/1981');
Finally you must register the request in the Pagseguro system. The return of the Register method, by default, will be the URL that should be used to redirect the buyer to the payment screen in Pagseguro.
The way to redirect the buyer to make the payment on Pagseguro after the return of the call to the Register method depends on the implementation of your system.
try {
$credentials = PagSeguroConfig::getAccountCredentials();
$checkoutUrl = $paymentRequest->register($credentials);
} catch (PagSeguroServiceException $e) {
die($e->getMessage());
}
At this point we should use the $checkoutUrl
, should look something like:
try {
$credentials = PagSeguroConfig::getAccountCredentials();
$checkoutUrl = $paymentRequest->register($credentials);
echo '<h2>Criando requisição de pagamento</h2>',
'<p>URL do pagamento: <strong>', $checkoutUrl,'</strong></p>',
'<p>',
//Mostra link para pagamento
'<a title="URL do pagamento" href="', $checkoutUrl,'">',
'Ir para URL do pagamento.</a></p>';
} catch (PagSeguroServiceException $e) {
die($e->getMessage());
}
If the use of PagSeguroConfig::getAccountCredentials
not working is probably because there is something wrong with the data from Pagseguroconfig.php, but you can try "manually" to check the situation:
$credentials = new PagSeguroAccountCredentials("[email protected]",
"E231B2C9BCC8474DA2E260B6C8CF60D3");
$url = $paymentRequest->register($credentials);
E231B2C9BCC8474DA2E260B6C8CF60D3
is the authorization code, you can also set it on PagSeguroConfig::getAccountCredentials
, as described in the examples, thus:
$credentials->setAuthorizationCode("E231B2C9BCC8474DA2E260B6C8CF60D3");
Some of the other problems (error 403) that occur may be due to missing "token" from pagesecure file, configure the file and preferably add the actual path to a log file.
Start configuration normally on Pagseguroconfig.php:
$PagSeguroConfig = array();
$PagSeguroConfig['environment'] = "production"; // production ou sandbox
$PagSeguroConfig['credentials'] = array();
$PagSeguroConfig['credentials']['email'] = "your_pagseguro_email";
This may be the point that needs to be corrected, it is necessary to token
of production the appId
and the appKey
:
$PagSeguroConfig['credentials']['token']['production'] = "Token de produçao do pagseguro";
$PagSeguroConfig['credentials']['token']['sandbox'] = "Token do sandbox";
$PagSeguroConfig['credentials']['appId']['production'] = "Seu ID de produção";
$PagSeguroConfig['credentials']['appId']['sandbox'] = "Seu ID de produção";
$PagSeguroConfig['credentials']['appKey']['production'] = "Sua chave de aplicativo para o ambiente de produção";
$PagSeguroConfig['credentials']['appKey']['sandbox'] = "Sua chave de aplicativo para o ambiente sandbox";
Configure the log to get details, maybe it helps to find the problem define true
in $PagSeguroConfig['log']['active'] = true;
and the actual path of a file in $PagSeguroConfig['log']['fileLocation']
, for example:
$PagSeguroConfig['log']['fileLocation'] = '/home/user/www/pagseguro/log.txt';
It should look something like:
$PagSeguroConfig['log'] = array();
$PagSeguroConfig['log']['active'] = true;
$PagSeguroConfig['log']['fileLocation'] = '/home/user/www/pagseguro/log.txt';
The mistake TypeError: this.callback is undefined
may have occurred because of (2) Bloqueado carregamento de conteúdo ativo mesclado
, but I don’t know exactly at what point this problem occurs (whether it is on your site or when it is already on the pagseguro page).
To download the API for PHP go to:
Tip: after downloading access folder source/examples, has all the examples needed for integration via PHP, it might be useful
If someone wants to go deeper into the problems of the log, I can indicate the page where I sell my products(and there where he buys too).
– Ale