How to get confirmation of sale after uploading cart?

billPP
Contributor
Contributor

I'm trying to set up a fairly simple system for sales. I'm using Apache and PHP using local servers for development, but the system will run on a commercial web server (one.com) when I am convinced it will work.

 

I have set up my own sales cart, and can upload it to the Paypal sandbox, but I can't see how to get confirmation of the sale back to my server, so that I can reset my cart. I can't set up any fancy API stuff, as that is not supported by the web server,

but I know how to handle PHP and so on. I don't need any fancy authorisation - the email notification from Paypal is quite adequate for our very limited sales.

 

I hope some kind person can point me in the right direction.

 

Many thanks

 

Bill

Login to Me Too
3 REPLIES 3

ShippingDoneCom
Contributor
Contributor

We use PayPal's IPN for what you are talking about.  Basically you set up a listener script in php (see code posted below) on your server.  Then when a sale is made, paypal calls that script and it does what you program it to do, such as email you or add info to a database.

 

Here is PayPal's generic php listener script which is a good place to start.

<?php
// read the post from PayPal system and add 'cmd'
$req = 'cmd=' . urlencode('_notify-validate');
 
foreach ($_POST as $key => $value) {
	$value = urlencode(stripslashes($value));
	$req .= "&$key=$value";
}
 
 
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.paypal.com/cgi-bin/webscr');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Host: www.paypal.com'));
$res = curl_exec($ch);
curl_close($ch);
 
 
// 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 (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
}
?>

 As you can see you will need CURL for php installed on your server.  If the host your planning on using doesn't offer that there are plenty that do.

Login to Me Too

billPP
Contributor
Contributor

Thanks for that. I will have to think about how to test this out. I'm currently developing on

my home system which isn't visible via DNS. I don't want to upload my code to the real server

until I'm prestty sure I know what I'm doing. I think I see how to proceed....

 

Many thanks again.

 

Login to Me Too

billPP
Contributor
Contributor

I've set up some test pages on my personal web server, using the sandbox to handle the calls.

I've turned on AUTO_REPLY, and include notify_url, shopping_url and return in the

submitted form, but sandbox doesn't take any notice of these and leaves me in the

Paypal pages.

 

My scripts for the callbacks are just minimal bits of HTML initially, I assumed that one

of them would get invoked and display on my browser. Is my thinking wrong?

 

Many thanks

 

Bill

Login to Me Too

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.