开发者

How do I add PayPal to my web app and expose additional functionality once payment has been made?

I am building a simple web app that will allow users to sign up and then use the web application. I want to add a payment mechanism after sign up but before the web app functionality can be used.

For example:

  1. User arrives at site and signs up
  2. PayPal payment options offered on page (payment for one-time use OR payment for unlimited annual use)
  3. After payment is successfully made, user profile in DB updated to "PAID" status
  4. Rest of page exposed with access to web app functionality

I would be OK if after step 3 a new page was loaded with the web app functionality, but the same page exposing the functionality (e.g. showing a div) would be a better UI in my opinion.

I have never integrated PayPal with a web app (PayPal buttons don't count!) and curious to know how to set this up given my web app is sportin开发者_开发技巧g a vanilla LAMP architecture.

Any help or pointers to guides or sample code would be greatly appreciated. Just as useful would be any pitfalls to watch out for as I go about this exercise.

Thanks.


PayPal offers a notification mechanism just for the purpose such as yours. The asynchronous IPN mechanism and synchronous PDT mechanism. IPN is better suited for backend tasks (in your case DB update. However, since you need to offer additional features to your user after payment is done PDT is probably better as it is real time

You have easy snippets for all main programming languages on www.x.com,

IPN: https://merchant.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/library_code_ipn_code_samples

PDT: https://merchant.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/library_code_ipn_code_samples

If you are really going to implement this, read about differences between IPN and PDT, they pass around same messages but the risks associated are different. Which one you need always depends on the context.


Any simple ajax tutorial will help you with this. The only thing you need to do is something like this:

premium.php

<?php
$query="SELECT 'user' FROM table ETC ETC ETC"; //the query to test if paid
$RESULT = MYSQL_QUERY( bla bla bla, $query);
if $RESULT ... = true
{
echo "<div> THE PREMIUM CONTENT</div>";
else
echo "<div> please pay to see the content </div>";
}
?>

Just call premium.php in the ajax code. Hope it helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜