Talking about Monetize and Php.
When you want to sell something through the internet, PayPal is your best choice. Almost every website selling stuff or subscriptions use PayPal to manage its transactions.
While PayPal back-end allows users to fully manage their accounts, there are some features it still lacks.
Real world example: let’s say you are selling a digital good, such as the source code of your latest Flash game, or an ebook.
Since there is no shipment as the buyer will download it or receive it by email, he expects to get the book/game a few minutes after the payment.
That’s ok if you check your PayPal account every 10 minutes, manually sending emails to buyers, but once in a while you need to sleep… or have a shower… who will send your book then?
That’s why services like PayLoadz come into play, managing transactions and digital delivery for a monthly subscription and a per transition fee.
If you don’t want to use third part services, PayPal offers the Instant Payment Notification to automate your digital deliveries.
Instant Payment Notification (IPN) is PayPal’s message service that sends a notification when a transaction is affected. Once IPN is integrated, sellers can automate their back office so they don’t have to wait for payments to come in to trigger order fulfillment.
The process is simple: once you have a PayPal account, in your profile page click “Instant Payment Notification Preferences” under “Selling Preferences”, and you will be asked for an URL.
This is the URL of a page on your server which will act as a listener for PayPal payments.
Then, all you have to do is write your own listener based on the information you will find in the official docs. Wait, I forgot to tell you three things:
1) The script is wrong, it will give an error because there are missing curly brackets
2) The given address where to test the script is wrong, it’s not www.sandbox.paypal.com
anymore
3) The script (once corrected) won’t work on every server since relies on fsockopen
. In my opinion it would have been better to use cURL
So, this is the script I suggest to use:
$varvalue){
$email .= "$varname: $varvalue\n";
if(function_exists('get_magic_quotes_gpc') and get_magic_quotes_gpc()){
$varvalue = urlencode(stripslashes($varvalue));
}
else {
$value = urlencode($value);
}
$request .= "&$varname=$varvalue";
}
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,"https://www.sandbox.paypal.com/cgi-bin/webscr");
//curl_setopt($ch,CURLOPT_URL,"https://www.paypal.com");
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch,CURLOPT_POSTFIELDS,$request);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,false);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
$result = curl_exec($ch);
curl_close($ch);
switch($result){
case "VERIFIED":
// verified payment
break;
case "INVALID":
// invalid/fake payment
break;
default:
// any other case (such as no response, connection timeout...)
}
?>
Simply comment/uncomment lines 15-16 if you want to use it in sandbox or real mode.
Once the payment is VERIFIED
, you can send the email with the game/book/activation code to the email address you will find in POST[payer_email]
variable. You can find the complete list of passed variables at this page.
To test it, once you activated your IPN and installed the script on your web server, register as a PayPal developer, then test your IPN in the sandbox page.
In a few days, a fully working example on this site, with some deals at an extraordinary price.
Never miss an update! Subscribe, and I will bother you by email only when a new game or full source code comes out.