I'm trying to integrate paypal standard with my Wordpress site and all was going well until I wanted to do one simple thing:
- The user submits a paypal payment
- Paypal posts the IPN to my server
- Post IPN Hook adds a user_meta
- If user reloads current page, it checks to see if previous user_meta is set to 1, if it is, displays "you have already purchased your ticket"
I thought this would be pretty straight forward, but if I add this to my functions.php
for the post IPN Hook :
add_filter("gform_paypal_post_ipn", "update_order_status", 10, 4);
function update_order_status($ipn_post, $entry, $config, $cancel){
// if the IPN was canceled, don't process
if($cancel)
return;
global $current_user;
get_currentuserinfo();
$currUID = $current_user->ID;
update_user_meta($currUID, 'eventRegistration', 1);
return;
}
Absolutely nothing happens. My thought is that since the IPN is bouncing from off-site, maybe the user ID isn't available? Or am I wrong here?
Figuring that I'm correct about the user ID not being avail, I was thinking of another way to grab the user ID. Since I'm using Gravity Forms with the PayPal addon, all forms submitted are stored in a database tables wp_rg_lead
& wp_rg_paypal_transaction
. Since every IPN posts a transaction id, I figured I could do a JOIN between the two tables using the transaction ID sent by paypal.
so I tried:
$txn_id = 'aRandomStringOfNumbersAndLetters'; // The transaction ID that paypal POSTs
$uid = $wpdb->get_col( $wpdb->prepare(
"
SELECT wp_rg_lead.created_by
FROM wp_rg_lead, wp_rg_paypal_transaction
WHERE wp_rg_lead.id = wp_rg_paypal_transaction.entry_id AND wp_rg_paypal_transaction.transaction_id = %s
",
$txn_id
) );
which returned the user ID associated with the transaction ID. I thought to myself, great! This will work!
However, if I try to combine all this in to my functions.php
nothing seems to work in its entirety.
This:
add_filter("gform_paypal_post_ipn", "update_order_status", 10, 4);
function update_order_status($ipn_post, $entry, $config, $cancel){
// if the IPN was canceled, don't process
if($cancel)
return;
$txn_id = $ipn_post["txn_id"]; // transaction ID POSTed by PayPal
$uid = $wpdb->get_col( $wpdb->prepare(
"
SELECT wp_rg_lead.created_by
FROM wp_rg_lead, wp_rg_paypal_transaction
WHERE wp_rg_lead.id = wp_rg_paypal_transaction.entry_id AND wp_rg_paypal_transaction.transaction_id = %s
",
$txn_id
) );
update_user_meta($uid[0], 'eventRegistration', 1)
return;
}
function update_order_status($ipn_post, $entry, $config, $cancel){
$txn_id = $ipn_post["txn_id"]; // transaction ID POSTed by PayPal
$uid = $wpdb->get_col( $wpdb->prepare(
"
SELECT wp_rg_lead.created_by
FROM wp_rg_lead, wp_rg_paypal_transaction
WHERE wp_rg_lead.id = wp_rg_paypal_transaction.entry_id AND wp_rg_paypal_transaction.transaction_id = %s
",
$txn_id
) );
update_user_meta($uid[0], 'eventRegistration', 1)
}
Produced nothing useful.
If I remove the SQL query and say change the update_user_meta to 1, 'eventRegistration', $txn_id
and submit a paypal request, the meta updates fine.
I'm kind of at a loss, I must be missing something.
Any help would be much appreciated!
Thanks!
Tre