Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to integrate Paypal IPN for recurring payments?

I have been using Micah Carrick's PAYPAL IPN class till now for

web_accept

but now one of the Client wants to integrate the Recurring method into it.I tried using the same stuff but unfortunately was not so successful this time. I am trying to connect to the Paypal recurring method.Following is the code by which I trying to get to it;

$paypalObj = new paypal_class();

$itemName = "My Product";
$itemNumber = $itemName . " - Premium ($amount$)";

$paypalObj->paypal_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';// testing paypal url
//$paypalObj->paypal_url = 'https://www.paypal.com/cgi-bin/webscr';// Live paypal url

$paypalObj->add_field('cmd','_xclick-subscriptions');
$paypalObj->add_field('txn_type', "recurring_payment");
$paypalObj->add_field('product_name', "My Product Subscription - Monthly( $$amount )");
$paypalObj->add_field('desc', "My Product Subscription - Monthly( $$amount )");

$paypalObj->add_field('business', "[email protected]");

$paypalObj->add_field('return', "http://".$serverName . "/buy-now.php");
$paypalObj->add_field('cancel_return', "http://".$serverName. "/return.php?action=cancel");
$paypalObj->add_field('notify_url', "http://" . $serverName . "/return.php?action=ipn");

$paypalObj->add_field('src', "1");
$paypalObj->add_field('sra', "1");
$paypalObj->add_field('a3', "$amount");
$paypalObj->add_field('t3', "M");
$paypalObj->add_field('p3', "1");
//$paypalObj->add_field('no_note', "1");
$paypalObj->add_field('currency_code', "USD");

$paypalObj->add_field('first_name', $firstName);
$paypalObj->add_field('last_name', $lastName);

$paypalObj->submit_paypal_post();   

Code lets me to redirect to the Paypal sandbox(As I am still testing),but when I login onto Paypal sandbox it throws me this Error :

The link you have used to enter the PayPal system is invalid. Please review the link and try again.

like image 965
Nishant Shrivastava Avatar asked Oct 28 '10 17:10

Nishant Shrivastava


People also ask

Can you set up PayPal for recurring payments?

Log in to your PayPal Business or Premier account at www.paypal.com. Click Tools > All Tools at the top of the page, and then select Recurring Payments from the Tools page. The Recurring payments dashboard opens.

How do I setup a PayPal IPN?

Click the settings icon at the top of your PayPal account page and then click Account Settings. On the Notifications page, click the Update link for the Instant payment notifications item. Click Choose IPN Settings to specify your listener's URL and activate the listener.

Does PayPal do recurring invoices?

While there is no monthly fee associated with PayPal's recurring payments, there are limitations on a regular PayPal recurring invoicing plan: Customers must have a PayPal account to pay you. No automatic billing options. No option for installment plans.


1 Answers

I just figured out what was the problem behind my code.I just rewrote the code with some other Variables and it just worked fine.

$paypalObj = new paypal_class();


$customData = $firstName . ":";
$customData .= $lastName . ":";
$customData .= $emailId ;
$itemName = "MY_PRODUCT";
$itemNumber = $itemName . " - Premium ($amount$)";

$paypalObj->paypal_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';// testing paypal url


$paypalObj->add_field('cmd','_xclick-subscriptions');
$paypalObj->add_field('business','MY_MECHANT_ACCOUNT');
$paypalObj->add_field('item_name',$itemName);
$paypalObj->add_field('item_number',$itemNumber);
$paypalObj->add_field('return', "http://" . $serverName . "/buy-now.php");
$paypalObj->add_field('cancel_return', "http://".$serverName. "/buy-now.php?action=cancel");
$paypalObj->add_field('notify_url', "http://" . $serverName . "/buy-now.php?action=ipn");
$paypalObj->add_field('no_note','1');
$paypalObj->add_field('currency_code','USD');
$paypalObj->add_field('custom',$customData);
$paypalObj->add_field('a3', "$amount");
$paypalObj->add_field('t3', "M");
$paypalObj->add_field('p3', "1");
$paypalObj->add_field('src', "1");
$paypalObj->add_field('sra', "1");

$paypalObj->submit_paypal_post();
like image 172
Nishant Shrivastava Avatar answered Oct 16 '22 12:10

Nishant Shrivastava