ExpressCheckout needs to return to your site so you can get the details of the transaction, the only way to do the whole transaction inside the paypal would be to put a simple payment button, but if you want to get transaction details and already display for the customer, you should follow the paypal tutorial;
In the return URL you must perform two more steps to complete the transaction:
When setting up the return URL in your paypal account settings, when a client is sent back to your site, next to the URL will be passed two GETs the token and PayerID
With these two information you can get the details of the transaction with the following code:
$user = 'email da api de produção';
$pswd = 'sua senha de produção';
$signature = 'suas credenciais de produção';
$paypalURL = 'https://www.paypal.com/cgi-bin/webscr';
$urlCurl = 'https://api-3t.paypal.com/nvp';
/*obtem o status da transação getExpressDetails*/
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_URL, $urlCurl);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query(array(
'USER' => $user,
'PWD' => $pwd,
'SIGNATURE' => $assinatura,
'SUBJECT' => 'seu email',
'METHOD' => 'GetExpressCheckoutDetails',
'VERSION' => 108.0,
'TOKEN' => $token
)));
$response = curl_exec($curl);
curl_close($curl);
$nvp = array();
if (preg_match_all('/(?<name>[^\=]+)\=(?<value>[^&]+)&?/', $response, $matches)) {
foreach ($matches['name'] as $offset => $name) {
$detalhes[$name] = $nvp[$name] = urldecode($matches['value'][$offset]);
}
Once you've done this you can give print_r
to $detalhes
and you'll see all transaction details, and then you can now complete the transaction with DoExpressCheckout
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_URL, $urlCurl);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query(array(
'USER' => $user,
'PWD' => $pwd,
'SIGNATURE' => $assinatura,
'SUBJECT' => 'seu-email',
'METHOD' => 'DoExpressCheckoutPayment',
'VERSION' => '108',
'LOCALECODE' => 'pt_BR',
'TOKEN' => $token,
'PAYERID'=> $payerid,
'NOTIFYURL' => 'sua-url-para-notificação.com',
'PAYMENTREQUEST_0_PAYMENTACTION' = 'SALE', //venda
'PAYMENTREQUEST_0_CURRENCYCODE' => 'BRL', //diz a moeda
'PAYMENTREQUEST_0_ITEMAMT' => '22.00' //valor da soma dos produtos
'L_PAYMENTREQUEST_0_NAME0' = 'nome do produto'
'L_PAYMENTREQUEST_0_DESC0' => 'descrição do produto'
'L_PAYMENTREQUEST_0_AMT0=“22.00” //valor do produto
'L_PAYMENTREQUEST_0_QTY0=”1” //quantidade de produtos
'PAYMENTREQUEST_0_SHIPTONAME' => 'José Silva',
'PAYMENTREQUEST_0_SHIPTOSTREET' => 'Rua, 123',
'PAYMENTREQUEST_0_SHIPTOSTREET2' => 'Centro',
'PAYMENTREQUEST_0_SHIPTOCITY' => 'Sao Paulo',
'PAYMENTREQUEST_0_SHIPTOSTATE' => 'São Paulo',
'PAYMENTREQUEST_0_SHIPTOZIP' => '098765-432',
'PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE' => 'BR',
)));
$response = curl_exec($curl);
curl_close($curl);
$cnvp = array();
if (preg_match_all('/(?<name>[^\=]+)\=(?<value>[^&]+)&?/', $response, $matches)) {
foreach ($matches['name'] as $offset => $name) {
$doExpress[$name] = $cnvp[$name] = urldecode($matches['value'][$offset]);
}
Once this is done, $doExpress["ACK"]
should return whether the transaction succeeded or not, from print_r
to $doExpress
.
I did not get to test the code if it's okay, test anything, let me know.