I am trying to set up a way to change a custom field in an entry once an item has been purchased. I used the ipn_handler extension framework from here and have added a query to it but am stuck on how to retrieve the entry_id from the IPN and then call that id in the query.
Thanks for the help.
Bryan
Code I am using is here. Query is under “// do whatever you need to do here”
<?php
class Paypal_ipn_handler {
var $settings = array();
var $name = 'Paypal IPN Handler';
var $version = '1.0.0';
var $description = 'Perform actions based on paypal events';
var $settings_exist = 'n';
var $docs_url = '';//'http://expressionengine.com';
function Paypal_ipn_handler($settings = '') {
$this->settings = $settings;
}
function evaluate_response($data, $result) {
global $IN, $DSP, $LANG, $SESS, $PREFS, $OUT, $LOC, $FNS, $REGX, $LOG, $DB, $EXT;
# continue if $EXT->end_script is false
$EXT->end_script = FALSE;
$paypal_account = ( ! $PREFS->ini('sc_paypal_account')) ? $PREFS->ini('webmaster_email') : $PREFS->ini('sc_paypal_account');
// good to have a record of what was received for testing purposes
if($data->debug) {
$dfile = fopen("/path/to/debug_ipn.txt", "a+"); // <- permissions are important here… 777 is nice and safe
fwrite($dfile, "=============== " . date("F j, Y, g:i a") . " ===============\n");
fwrite($dfile, "Response: " . $result . "\n\n");
fwrite($dfile, "Data:\n" . print_r($data, true) . "\n\n");
fclose($dfile);
}
// do whatever you need to do here
$DB->query("UPDATE exp_weblogs_data SET my_column = 'Sale Pending' WHERE entry_id = '{ID PASSED BACK FROM PAYPAL'");
}
# activate this extension
function activate_extension() {
global $DB;
$DB->query($DB->insert_string('exp_extensions', array(
'extension_id' => '',
'class' => "Paypal_ipn_handler",
'method' => "evaluate_response",
'hook' => "simple_commerce_evaluate_ipn_response",
'settings' => "",
'priority' => 3,
'version' => $this->version,
'enabled' => "y"
)));
}
# update this extension
function update_extension($current='') {
global $DB;
if ($current == '' OR $current == $this->version)
{
return FALSE;
}
if ($current < '1.0.1')
{
// Update to next version 1.0.1
}
if ($current < '1.0.2')
{
// Update to next version 1.0.2
}
$DB->query("UPDATE exp_extensions SET version = '" .
$DB->escape_str($this->version) .
"' WHERE class = 'Paypal_ipn_handler'");
}
# disable this extension
function disable_extension() {
global $DB;
$DB->query("DELETE FROM exp_extensions WHERE class = 'Paypal_ipn_handler'");
}
}