0
votes

I need to verify my IPN Message but it returning all time INVALID

MY IPN

cmd=_notify-validate&mc_gross=76.00&protection_eligibility=Ineligible&payer_id=5F68MJE8GYSFL&tax=0.00&payment_date=23%3A01%3A49%2BNov%2B04%2C%2B2016%2BPDT&payment_status=Completed&charset=UTF-8&first_name=Buyer%2BBrij&mc_fee=2.78¬ify_version=3.8&custom=&payer_status=verified&business=brij.mohan-softo-facilitator%40softobiz.com&quantity=1&payer_email=brij.mohan-softo-buyer%40softobiz.com&verify_sign=AFcWxV21C7fd0v3bYYYRCpSSRl31A2CY4u8sMD28t8rYIS1l.8kZv8Om&txn_id=2M448997GH018883K&payment_type=instant&last_name=Softobiz&receiver_email=brij.mohan-softo-facilitator%40softobiz.com&payment_fee=&receiver_id=UUEGZHZ6WXVCG&txn_type=web_accept&item_name=Hire%2BGuard&mc_currency=GBP&item_number=&residence_country=GB&test_ipn=1&handling_amount=0.00&transaction_subject=&payment_gross=&shipping=0.00&merchant_return_link=click%2Bhere&auth=AtmNfVa7oX-lTpjA7qqntT12AX085EG9DbyOgtWjgrr1Qm7nc3hfy442zorp44VGQ59KWCXZbifuNdzDp.A3n.w&form_charset=UTF-8

Then I checked IPN here

1.) https://www.sandbox.paypal.com/webscr

2.) My Account-> History -> IPN History -> Instant Payment Notification (IPN) details

here is IPN message below

 mc_gross=76.00&protection_eligibility=Ineligible&payer_id=5F68MJE8GYSFL&tax=0.00&payment_date=23:01:49 Nov 04, 2016 PDT&payment_status=Completed&charset=UTF-8&first_name=Buyer Brij&mc_fee=2.78&notify_version=3.8&custom=&payer_status=verified&[email protected]&quantity=1&verify_sign=A--8MSCLabuvN8L.-MHjxC9uypBtA5uyYRfhtvRLzxfTdTg29AzcboEl&[email protected]&txn_id=2M448997GH018883K&payment_type=instant&last_name=Softobiz&[email protected]&payment_fee=&receiver_id=UUEGZHZ6WXVCG&txn_type=web_accept&item_name=Hire Guard&mc_currency=GBP&item_number=&residence_country=GB&test_ipn=1&handling_amount=0.00&transaction_subject=&payment_gross=&shipping=0.00&ipn_track_id=3ab983572cde

I research on google and according to that all things seems fine except this point

Verify that your response to the test IPN message contains exactly the same variables and values as the test message and that they are in the same order as in the test message. Finally, verify that the original variables are preceded by a cmd=_notify-validate variable.

Prob is I am not able able to understand how i cam send ipn in same order and with same value so papal can verified my IPN . When I am comparing my ipn with original ipn then you will notice ¬ify_version=3.8 and in original ipn message notify_version=3.8

I am using this paypal IPN VERIFY CLASS

https://github.com/paypal/ipn-code-samples/tree/master/php

Here is my paypal form

<form name="myform" action="<?php echo $paypal_url;?>" method="post">
<input type="hidden" name="business" value="<?php echo $merchant_email;?>" />
<input type="hidden" name="notify_url" value="<?php echo $notify_url;?>" />
<input type="hidden" name="cancel_return" value="<?php echo $cancel_return;?>" />
<input type="hidden" name="return" value="<?php echo $success_return;?>" />
 <input type="hidden" name="user_id" value="<?php echo get_current_user_id(); ?>">
<input type="hidden" name="rm" value="2" />
<input type="hidden" name="lc" value="" />
<input type="hidden" name="no_shipping" value="1" />
<input type="hidden" name="no_note" value="1" />
<input type="hidden" name="currency_code" value="GBP" />
<input type="hidden" name="page_style" value="paypal" />
<input type="hidden" name="charset" value="UTF-8" />
<input type="hidden" name="item_name" value="Hire Guard" />
<input type="hidden" name="cbt" value="Back to FormGet" />
<input type="hidden" value="_xclick" name="cmd"/>
<input type="text" name="amount" value="<?php echo esc_attr($_POST['amount']); ?>" />
<input type="submit" class="button button-primary button-border-white submit-btn " value="Pay now" />
1

1 Answers

0
votes

This code snippest has been verified to be working. Make sure to switch it to live mode when ready. This is directly from PayPal's IPN documentation.

<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);


// Send an empty HTTP 200 OK response to acknowledge receipt of the notification
header('HTTP/1.1 200 OK');

// read the IPN notification from PayPal and add the 'cmd' parameter to the beginning of the acknowledgement you will send back
$req = 'cmd=_notify-validate';

// Loop through the notification name-value pairs
foreach ($_POST as $key => $value) {
    // Encode the values
    $value = urlencode(stripslashes($value));
    // Add the name-value pairs to the acknowledgement
    $req .= "&$key=$value";
}

// post back to PayPal system to validate
$header = "POST /cgi-bin/webscr HTTP/1.1\r\n";

// Set up other acknowledgement request headers
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";

// If testing on Sandbox use:
$header .= "Host: www.sandbox.paypal.com:443\r\n";
// For live servers use $header .= "Host: www.paypal.com:443\r\n";

// Open a socket for the acknowledgement request
// If testing on Sandbox use:
$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
// For live servers use $fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);

// Send the HTTP POST request back to PayPal for validation
fputs($fp, $header . $req);


//Do any commands with POST variables here, for ex:
echo $_POST['payment_status'];

?>