Suganya Rajasekar
Suganya Rajasekar

Reputation: 684

How to get the post values in success after completing payment in paypal

I follow simple code of PHP for paypal integration

Here is my code,

<form action="<?php echo $paypal_url; ?>" method="post">
        <input type="hidden" name="business" value="<?php echo $paypal_id; ?>">

        <input type="hidden" name="cmd" value="_xclick">

        <input type="hidden" name="item_name" value="<?php echo $row['name']; ?>">
        <input type="hidden" name="item_number" value="<?php echo $row['id']; ?>">
        <input type="hidden" name="amount" value="<?php echo $row['price']; ?>">
        <input type="hidden" name="currency_code" value="USD">

        <input type='hidden' name='cancel_return' value='http://localhost/paypal_integration_php/cancel.php'>
        <input type='hidden' name='return' value='http://localhost/paypal_integration_php/success.php'>

        <input type="image" name="submit" border="0"
        src="https://www.paypalobjects.com/en_US/i/btn/btn_buynow_LG.gif" alt="PayPal - The safer, easier way to pay online">
        <img alt="" border="0" width="1" height="1" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" >

    </form>

And, This is Success.php

<?php
include 'db_config.php';

$item_number = $_REQUEST['item_number']; 
$txn_id = $_REQUEST['tx'];
$payment_gross = $_REQUEST['amount'];
$currency_code = $_REQUEST['currency_code'];
$payment_status = $_REQUEST['st'];
?>

But when returning to my success file I got error like this, enter image description here

I'm not clear with the IPN and PDT concepts clearlry..

Upvotes: 2

Views: 1921

Answers (2)

kerv
kerv

Reputation: 315

I am not completely sure about this, but i believe PDT is responding with GET parameters. So check the url when you go back and it might look something like:

xxxxx.com/?TX=XXXX&AMOUNT=XXXX etc

if that is the case then your variables should be

$txn_id = $_GET['TX'];
$amount = $_GET['AMOUNT'];

etc with all the details in the url.

If you are using IPN however, I would recommend doing a var_dump or print_r on the $_POST to see what kind of data you are receiving from paypal. and then you will be able to add them to the variables. for example:

$item_name = $_POST['whatever post data you got from paypal'];

Upvotes: 2

Jomon Antony
Jomon Antony

Reputation: 258

Try this

$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'];

IPN Docs

Upvotes: 3

Related Questions