I think you're using v2
, like you did not inform how it was configured, I will only assume the answer according 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 he will not have to inform them again.
$paymentRequest->setSender(
'João Comprador',
'[email protected]',
'11',
'56273440',
'CPF',
'156.009.442-76'
);
Defining the currency to be used for payment.
$paymentRequest->setCurrency("BRL");
Defining additional information that may be used by your system after the payment flow in PagSeguro, I believe the problem may 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 in the checkout request parameters / information 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 requisition 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 PayPal.
The way to perform buyer redirection to effect payment in PagSeguro after returning 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 $checkoutUrl
, 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 PagSeguroConfig::getAccountCredentials
does not work, then there is probably something wrong with the PagSeguroConfig.php data, 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 in PagSeguroConfig::getAccountCredentials
, as described in the examples, like this:
$credentials->setAuthorizationCode("E231B2C9BCC8474DA2E260B6C8CF60D3");
Some of the other problems (error 403) that occur can be due to the lack of the token of the paysurance file, configure the file and preferably add the actual path to a log file.
Start the configuration normally in 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 fixed, you need the% of production token
and appId
:
$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";
Set the log to get details, it may help to find the problem set appKey
to true
and the actual path of a file to $PagSeguroConfig['log']['active'] = true;
, for example:
$PagSeguroConfig['log']['fileLocation'] = '/home/user/www/pagseguro/log.txt';
Should be something like:
$PagSeguroConfig['log'] = array();
$PagSeguroConfig['log']['active'] = true;
$PagSeguroConfig['log']['fileLocation'] = '/home/user/www/pagseguro/log.txt';
The error $PagSeguroConfig['log']['fileLocation']
may have occurred because of TypeError: this.callback is undefined
, but I'm not sure exactly where this issue occurs (whether it's on your site or when you're already on the pay-
To download the API for PHP, go to:
link
Tip: After downloading the source / examples folder, all examples needed for integration via PHP,