Jump to content

PayPal's API


Kryptix

Recommended Posts

I've tried everything I know to try and get this to work but I'm still stuck. Is there anyone out there who could possibly help me over MSN/TeamViewer? It's really simple what I'm trying to do, user clicks a button on my site to pay a fixed payment of £4 and then they're redirected back. If it's confirmed that it's paid it edits the database. I just can't get the PayPal API to tell my script that it's successful. I can pay if anyone fancies helping me. :-\

 

Send me a PM if you're interested. I don't expect this for free as I really need a walk through. :(

Link to comment
Share on other sites

Which API are you using?  Are you using the UK payflow pro 4 api?  We have a number of Brits on the forum who might be able to help you if that's the case.  I'm not sure if that's required in the UK, but since you mentioned pounds, I thought it might be pertinent.

Link to comment
Share on other sites

I don't know what your database looks like, but here is a sample snippet I used on a website once.

 

 

I'm sure with a bit of tweaking, you can get it to work the way you want.  ;)

<?php		$req = 'cmd=_notify-validate';
	foreach ($_POST as $key => $value) {
		$value = urlencode(stripslashes($value));
		$req .= "&$key=$value";
	}
	$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);

	$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'];
	$invoice_id = $_POST['custom'];

	if (!$fp) {
		echo "error connecting to paypal";
	} else {
	fputs ($fp, $header . $req);
	while (!feof($fp)) {
	$res = fgets ($fp, 1024);
	if (strcmp ($res, "VERIFIED") == 0) {
		$this->db->query("INSERT INTO `transactions` (`iid`,`gateway`,`gateway_id`,`amount`,`status`,`timestamp`) VALUES ('".$invoice_id."','paypal','".$txn_id."','$payment_amount','verified','".time()."')");
		$this->db->query("UPDATE `invoices` SET `status` = 'paid' WHERE `iid` = '".$invoice_id."'");
	}
	else if (strcmp ($res, "INVALID") == 0) {
		$this->db->query("INSERT INTO `transactions` (`iid`,`gateway`,`gateway_id`,`amount`,`status`,`timestamp`) VALUES ('".$invoice_id."','paypal','".$txn_id."','$payment_amount','invalid','".time()."')");
	}
	}
	fclose ($fp);
	}
?>

Link to comment
Share on other sites

you need to use their IPN (Instant Payment Notification) option.

 

PayPal has a huge reservoir of Developer information/help on their site .. that be a good place to start as it would be the most up-to-date information out there (i would assume).  they also have developer forums i believe.

 

IPN is feature that paypal has where their system will send a POSTBACK to your site upon a successful or declined payment.

 

IPN works like this:

 

1. user clicks "Pay using PayPal", or something similar.

 

2. user is taken to PayPal payment page on paypal.com

 

3. user enters payment information and clicks to have payment processed.

 

4a. user's payment info is approved/successful, so paypal executes your IPN script (http://www.your-site.com/paypal/ipn.php) and your database is updated accordingly (as well as anything else you want your script to do).

 

4b. user's payment is declined by paypal.  IPN is executed and no changes are made to your db.

 

5. user is sent to confirmation page.

 

that's the jist of it.

Link to comment
Share on other sites

you need to use their IPN (Instant Payment Notification) option.

 

PayPal has a huge reservoir of Developer information/help on their site .. that be a good place to start as it would be the most up-to-date information out there (i would assume).  they also have developer forums i believe.

 

IPN is feature that paypal has where their system will send a POSTBACK to your site upon a successful or declined payment.

 

IPN works like this:

 

1. user clicks "Pay using PayPal", or something similar.

 

2. user is taken to PayPal payment page on paypal.com

 

3. user enters payment information and clicks to have payment processed.

 

4a. user's payment info is approved/successful, so paypal executes your IPN script (http://www.your-site.com/paypal/ipn.php) and your database is updated accordingly (as well as anything else you want your script to do).

 

4b. user's payment is declined by paypal.  IPN is executed and no changes are made to your db.

 

5. user is sent to confirmation page.

 

that's the jist of it.

I understand how it works but it's getting it working that I'm struggling with. Will the script above work?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.