Recurring Payment Using NVP api in paypal

https://developer.paypal.com/docs/classic/api/merchant/TransactionSearch_API_Operation_NVP/

https://developer.paypal.com/docs/classic/api/merchant/GetTransactionDetails_API_Operation_NVP/

https://developer.paypal.com/docs/classic/express-checkout/ht_searchRetrieveTransactionData-curl-etc/

========================================================================================

 

Setexpresscheckout.php
<?php
$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, 'https://api-3t.sandbox.paypal.com/nvp');
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query(array(
    'USER' => 'usuario_da_api',
    'PWD' => '123123123123',
    'SIGNATURE' => 'assinatura.da.api',
 
    'METHOD' => 'SetExpressCheckout',
    'VERSION' => '108',
    'LOCALECODE' => 'pt_BR',
 
    'PAYMENTREQUEST_0_AMT' => 100,
    'PAYMENTREQUEST_0_CURRENCYCODE' => 'BRL',
    'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale',
    'PAYMENTREQUEST_0_ITEMAMT' => 100,
 
    'L_PAYMENTREQUEST_0_NAME0' => 'Exemplo',
    'L_PAYMENTREQUEST_0_DESC0' => 'Assinatura de exemplo',
    'L_PAYMENTREQUEST_0_QTY0' => 1,
    'L_PAYMENTREQUEST_0_AMT0' => 100,

    'L_BILLINGTYPE0' => 'RecurringPayments',
    'L_BILLINGAGREEMENTDESCRIPTION0' => 'Exemplo',
 
    'CANCELURL' => 'http://localhost/cancel.html',
    'RETURNURL' => 'http://localhost/sucesso.html'
)));
 
$response =    curl_exec($curl);
 
curl_close($curl);
 
$nvp = array();
 
if (preg_match_all('/(?<name>[^\=]+)\=(?<value>[^&]+)&?/', $response, $matches)) {
    foreach ($matches['name'] as $offset => $name) {
        $nvp[$name] = urldecode($matches['value'][$offset]);
    }
}

if (isset($nvp['ACK']) && $nvp['ACK'] == 'Success') {
    $query = array(
        'cmd'    => '_express-checkout',
        'token'  => $nvp['TOKEN']
    );

    $redirectURL = sprintf('https://www.sandbox.paypal.com/cgi-bin/webscr?%s', http_build_query($query));

    header('Location: ' . $redirectURL);
} else {
    //Opz, alguma coisa deu errada.
    //Verifique os logs de erro para depuração.
} 

CreatingRecurringProfile.php
<?php
$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, 'https://api-3t.sandbox.paypal.com/nvp');
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query(array(
    'USER' => 'usuario_da_api',
    'PWD' => '1234123424',
    'SIGNATURE' => 'assinatura.da.api',
 
    'METHOD' => 'CreateRecurringPaymentsProfile',
    'VERSION' => '108',
    'LOCALECODE' => 'pt_BR',
 
    'TOKEN' => 'EC-0A9774676H705661Y',
    'PayerID' => '5KWXTCEDXPFQS',
 
    'PROFILESTARTDATE' => '2012-10-08T16:00:00Z',
    'DESC' => 'Exemplo',
    'BILLINGPERIOD' => 'Month',
    'BILLINGFREQUENCY' => '1',
    'AMT' => 100,
    'CURRENCYCODE' => 'BRL',
    'COUNTRYCODE' => 'BR',
    'MAXFAILEDPAYMENTS' => 3
)));
 
$response =    curl_exec($curl);
 
curl_close($curl);
 
$nvp = array();
 
if (preg_match_all('/(?<name>[^\=]+)\=(?<value>[^&]+)&?/', $response, $matches)) {
    foreach ($matches['name'] as $offset => $name) {
        $nvp[$name] = urldecode($matches['value'][$offset]);
    }
}
 
print_r($nvp);

Payment History Details:
<?php 
$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, 'https://api-3t.sandbox.paypal.com/nvp');
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query(array(
 'USER' => 'usuario_da_api',
 'PWD' => '1234123424',
 'SIGNATURE' => 'assinatura.da.api',
 
 'METHOD' => 'TransactionSearch', 
 'STARTDATE' => $gmt_date,
 'VERSION' => '123', 
 //'PROFILEID' => 'I-TWCJ1V9W5JSF'
 'PROFILEID' => $select_for_date['subscription_id']
 //ID I-17PGXW29RBXR
)));
 
$response = curl_exec($curl);
 
curl_close($curl);
 
$nvp = array();
 
if (preg_match_all('/(?<name>[^\=]+)\=(?<value>[^&]+)&?/', $response, $matches)) {
 foreach ($matches['name'] as $offset => $name) {
 $nvp[$name] = urldecode($matches['value'][$offset]);
 }
}
echo "<pre>"; 
print_r($nvp);

?>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s