user4815703
user4815703

Reputation:

How to Call Custom variable from paypal IPN?

So i have setup my button using php to send a custom variable:

    $vars = array(
            'cmd' => '_s-xclick',
            'hosted_button_id' => 'xxxxxxxxx',
            'custom' => $lastId,
    );

    header('Location: https://www.sandbox.paypal.com/cgi-bin/webscr?' . http_build_query($vars));

What i am trying to do here is send the Last Inserted Row id via Paypal to my paypal IPN. Then use the id to modify the record depending on the payment status.

So in paypal IPN i will be looking up the table record based on $lastid. eg:

$sql = "SELECT x FROM table WHERE id = a";

a is the custom variable that should come back from paypal.

Upvotes: 1

Views: 73

Answers (2)

user4842787
user4842787

Reputation: 133

If you need to send more than one variable in custom you can use implode() and explode() to retrieve back.

To send:

$lastId = '1';
$lastDate = $insertDate;

$myCustomArr = array($lastId, $lastDate);
$myCustom = implode(',', $myCustomStrArr);

To get back:

if(isset($_POST['custom'])){
   $custom = $_POST['custom'];
   $customArr = explode(',', $custom);
   $lastId = $customArr[0];
   $lastDate = $customArr[1];
}

Upvotes: 0

Drew Angell
Drew Angell

Reputation: 26056

IPN sends an HTTP POST of the data to your script, so you would parse it just like a basic form post. So if you want to add the custom variable to your SQL query you would do something like this.

$lastId = isset($_POST['custom']) ? $_POST['custom'] : '';
$sql = "SELECT x FROM table WHERE id = '" . $lastId . "'";

Upvotes: 0

Related Questions