• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 584
  • Last Modified:

PayPal IPN with subscription option

Hi,

I am developing a member site (PHP) where we will be taking subscription payments from users. For this, we are using PayPal - to which I am new to. Have set up the sandbox test accounts, and have set the IPN option and specifiied a url.

Now I want to test the IPN and set up tables in my database to save information each order/subscription.

Am finding the PayPal documentation is lacking, and have looked into various classes which can handle the IPN posts. All without success! I see there have been some posts here on the subject, but am still struggling.

If I am using a IPN script do I need to set the IPN url in the sandbox at all?

We would also need to deal with unsubscribes in any IPN script.

Many thanks,

Daisy
0
daisydoos
Asked:
daisydoos
  • 3
  • 2
2 Solutions
 
EMB01Commented:
To use the PayPal IPN, try following these steps:
1.) Use the code sample located at the following link (also attached):
http://www.paypal.com/cgi-bin/webscr?cmd=p/pdn/ipn-codesamples-pop-outside#php
2.) Modify the code to connect to your database and retrieve your variables.
3.) Utilize the following link's list of IPN variables; specifically, the "txn_type" variable as this will determine whether your product is a subscription or not:
https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_admin_IPNReference
4.) Update your database according to the information PayPal sends you via the IPN.

If you have any questions about these steps, let me know and I can help you in greater detail. This is the general process, however. Good luck!
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';
 
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
 
// post back to PayPal system to validate
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
 
// assign posted variables to local variables
$item_name = $_POST['item_name'];
$item_number = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$payment_amount = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];
 
if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
// check the payment_status is Completed
// check that txn_id has not been previously processed
// check that receiver_email is your Primary PayPal email
// check that payment_amount/payment_currency are correct
// process payment
}
else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation
}
}
fclose ($fp);
}

Open in new window

0
 
Ray PaseurCommented:
Daisy: You might want to check something carefully before you go too far down this path.  I looked into this about two years ago and it may have changed since that time, but I think I should mention it to you now anyway.  

At that time the ONLY way you could make a recurring subscription payment with PayPal was if you had a PayPal account - in other words, you could not subscribe with a credit card.  That was a deal-breaker for us, since we had many credit card clients but far fewer PayPal clients.

In the end, we chose to take a one-time payment and manage the requirement for recurring subscription payments ourselves, sending notes to remind clients of the need to renew the subscription.  It was a nuisance, but it was one of the key items in the decision tree.  

Good luck with it, ~Ray
0
 
daisydoosAuthor Commented:
Hi guys,

Many thanks for your comments - i have loads on but will let you know how I get on.

Ray - the option is there to pay by credit card in the sandbox with the subscription option - but I don't know yet if it does work. Will confirm this with them... if it doesn't, hope they will remove the link to pay by cc!

Cheers,

Daisy
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Ray PaseurCommented:
Hi, Daisy, and thanks for your post.  When you have a chance, please post a link to the example of subscription payment by credit card.  It would be VERY USEFUL to see this in action!

Many thanks, ~Ray
0
 
daisydoosAuthor Commented:
Hi Ray and EMB01,

I have got the IPN working - using the script provided by PayPal as a basis - discovered yesterday that the reason why there was no success when testing from the website in the sandbox, was due to the fact it was down for IPN testing! Great! Anyway, appreciate your help.  

Ray, when I spoke to them about this (subs by cc), was told that the user IS asked to provide a password when they use their card - effectively forcing them to create an account. Havent had a chance to test this out given the issues I've been describing. Not great I know, but for the time being it'll have to do.

Cheers,

Daisy
0
 
Ray PaseurCommented:
Thanks, Daisy!  Good luck with it, ~Ray
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now