Jump to content

PayPal IPN Help Please


jbwebdesign

Recommended Posts

Hello, I have a question.....

 

I am working on a script that requires PayPal IPN.....

I am trying to code up a subscription based website and for some reason when i test the IPN in the Sandbox Test Site under "Test Tools" for IPN, the script doesn't seem to work if it's in the VERIFIED section.

 

The Script only works when i have the Data above the following lines instead of inside of the "VERIFIED".....

 

Does this mean that my script would be coded incorrectly?

 

Shouldn't the script be working inside of the code below instead of outside?

 

<?php 
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

}
?>

 

 

 

Here is the entire IPN script....

 

<?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'];
$txn_type = $_POST['txn_type'];
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];

//-------Lets Begin Here..............
//item name will be the Authorization Mobile Number
//item number will be the Rep ID


/* $_POST['subscr_date'] = Transaction-specific	Start date or cancellation date depending on whether transaction is "subscr_signup" or "subscr_cancel"*/
/*
  "subscr_signup"	 This Instant Payment Notification is for a subscription sign-up.
  "subscr_cancel"	 This Instant Payment Notification is for a subscription cancellation.
  "subscr_modify"	 This Instant Payment Notification is for a subscription modification.
  "subscr_failed"	 This Instant Payment Notification is for a subscription payment failure.
  "subscr_payment" This Instant Payment Notification is for a subscription payment.
  "subscr_eot"     This Instant Payment Notification is for a subscription's end of term.
*/
switch($txn_type)
{
	case 'subscr_signup':
	//New Subscription....
	//lets connect to the database and activate the mobile line
	//this is a test below
               mail("info@affordablewebdev.com","Testing IPN","$txn_type","From: info@affordablewebdev.com");
	break;

	case 'subscr_cancel':
	//Subscription Has Been Canceled
	//Lets connect to the database and De-Activate the mobile line

	break;

	case 'subscr_modify':
	//----N/A-----
	break;

	case 'subscr_failed':
	//Subscription Payment Failed, Lets Connect to the database and De-Activate the mobile line

	break;

	case 'subscr_payment':
	//Subscription Payment Success....
	//Lets Connect to the database and log our payment details for this rep

	break;

	case 'subscr_eot':
	//----N/A-----
	break;
}

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

}

?>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...