Nishant Shrivastava
Nishant Shrivastava

Reputation: 2119

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.

Upvotes: 13

Views: 4527

Answers (2)

Nishant Shrivastava
Nishant Shrivastava

Reputation: 2119

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();

Upvotes: 10

BrynJ
BrynJ

Reputation: 8382

I don't believe you should be setting txn_type - this is a value passed back by PayPal's IPN, not passed to it.

Upvotes: 0

Related Questions