PHP Ferrari
PHP Ferrari

Reputation: 15656

Add custom hidden field in paypal form and get it on redirected page

I want to get user info (email) and paypal billing info (pricing, quantity) right after a successful paypal process (on redirected page) and then insert into mysql table.

I also used <input type="hidden" name="notify_url"> in buy now button and set it's value eg:

<form action="https://www.paypal.com/cgi-bin/webscr" method="post" id="lf2">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="xxxxx">
<input type="hidden" name="custom">
<input type="hidden" name="notify_url">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>

$notify_url='http://mysite.com/ipn/index.php?order_sld=123';

<script language="javascript">
document.getElementsByName('custom').value='123';
document.getElementsByName('notify_url').value='<?=$notify_url?>';

document.forms['lf2'].submit();
</script>

and my ipn/index.php script is:

function FetchOrder()
   {
   $array = array();

   $array['transactionID']=$_POST["txn_id"];
   $array['item']=$_POST["item_name"];
   $array['amount']=$_POST["mc_gross"];
   $array['currency']=$_POST["mc_currency"];
   $datefields=explode(" ",$_POST["payment_date"]);
   $array['time']=$datefields[0];
   $array['date']=str_replace(",","",$datefields[2])." ".$datefields[1]." ".$datefields[3];
   $array['timestamp']=strtotime($array['date']." ".$array['time']);
   $array['status']=$_POST["payment_status"];
   $array['firstname']=$_POST["first_name"];
   $array['lastname']=$_POST["last_name"];
   $array['email']=$_POST["payer_email"];
   $array['custom']=$_POST["option_selection1"];
   $array['sld']=$_POST["notify_url"];

    if ($array['transactionID'] AND $array['amount']) {
        return send_email($array);
    } else {
        return 0;
    }
}

/**
* Send email
*/
function send_email($array)
    {
    $to = "[email protected]";
    $email = "[email protected]";
    $name = "Sajid";

    $subject = "Testing Paypal IPN";

    $msg = "<table>
            <tr><td>Transaction ID: </td><td>".$array['transactionID']."</td></tr>
            <tr><td>Item: </td><td>".$array['item']."</td></tr>
            <tr><td>Amount: </td><td>".$array['amount']."</td></tr>
            <tr><td>Currency: </td><td>".$array['currency']."</td></tr>
            <tr><td>Time: </td><td>".$array['time']."</td></tr>
            <tr><td>Date: </td><td>".$array['date']."</td></tr>
            <tr><td>Timestamp: </td><td>".$array['timestamp']."</td></tr>
            <tr><td>Status: </td><td>".$array['status']."</td></tr>
            <tr><td>First Name: </td><td>".$array['firstname']."</td></tr>
            <tr><td>Last Name: </td><td>".$array['lastname']."</td></tr>
            <tr><td>Email: </td><td>".$array['email']."</td></tr>
            <tr><td>Custom: </td><td>".$array['custom']."</td></tr>
            <tr><td>SLD: </td><td>".$array['sld']."</td></tr>
            </table>";

    // To send HTML mail, the Content-type header must be set
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

    // Additional headers
    $headers .= "From: $name <$email>" . "\r\n";
    // Mail it to client.
    mail($to, $subject, $msg, $headers);
    return 1;
}
FetchOrder();

but mail only contains:

Transaction ID:     6BD19776WW7238524
Item:   
Amount:     12.00
Currency:   USD
Time:   04:04:21
Date:   05 Jan 2012
Timestamp:  1325761461
Status:     Completed
First Name:     ABC
Last Name:  XYZ
Email:  [email protected]
Custom:     
SLD:

Please guide whats going wrong...

Upvotes: 1

Views: 8895

Answers (1)

Nonym
Nonym

Reputation: 6299

Does this make any sense to you?

Get information from PayPal after a transaction

And... taken from the accepted answer:

http://www.ngcoders.com/php/selling-digital-goods-with-paypal-ipn-and-php

Credit goes to @JasonWilliams, of course.

Upvotes: 2

Related Questions