PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Check Payment Status & Pay Later

  1. I am looking to have a user fill out a form, with a predetermined price, and then be sent a link to the PayPal pay screen. Once they receive the link they can choose to pay when they can. Or they can pay when they are directed towards the paypal screen on form submit. So if they don't want to pay then, they can use the link in their email.

    So far this seems to be working for me. What I need to do next is check if the user has paid or not with the gform_post_payment_status hook. I want to loop through all of the entries of my form, check if they have paid within 24hours of their submission, if not, delete them, if they have then they are fine.

    Is this possible?

    I am trying to use this for an RSVP form so it will auto delete people if they don't pay the $5 holding fee for the event.

    Posted 9 years ago on Sunday September 30, 2012 | Permalink
  2. Sounds like you will need to set up a function which will delete submissions that do not have a payment after 24 hours. I don't think you want to run the job every 24 hours, since you could have an entry sitting there for 47:59 (if the entry was made right after your cron job runs, then when the next cron job runs, it's less than 24 hrs old, so it is not deleted until the next run.)

    You could write some code, using that gform_post_payment_status hook, and hook it to a function which is called whenever someone visits your site (so, in effect, it is checking for old entries with every page load. That might not be ideal. You could run it on a schedule with regular cron if your host supports that, or WP Cron.

    So, that's the approach I think. What question do you have about the code to loop through the entries and checking payment status?

    Posted 9 years ago on Sunday September 30, 2012 | Permalink
  3. Well, I have figured the part out about getting the payment status for each entry. I am using the following for that:

    function retrieve_guests_payment($entry) {
    	 $entries =  RGFormsModel::get_leads(1, '', 'DESC', '', '0', '99999999');
    	 foreach ($entries as $entry){
    	 	if($entry['payment_status'] == 'Pending'){
    	 		// delete entry
    	 	}
    	 }

    Just not sure how to roll this into anything else for deleting an entry. Is there a hook to delete an entry? I found gform_delete_lead but not sure how that really works, because it seems like that is only fired when someone is being deleted. Not a hook to actually delete something.

    Posted 9 years ago on Monday October 1, 2012 | Permalink
  4. Okay, I looked around a little more and came up with this. It is probably doing too much work this way, so it can probably be streamlined. This loops through my entries, and finds people with the Payment Status of "Processing" and then completely deletes them.

    function my_remove_entries( $entry, $form ) {
    
    	global $wpdb;
    
    	// Get all Entries for our form ID 1
    	$entries =  RGFormsModel::get_leads(1, '', 'DESC', '', '0', '99999999');
    	foreach ($entries as $entry){
    
    		// Check to see if the User has paid or not
    		if($entry['payment_status'] == 'Processing'){
    
    			// Get our Leads
    			$lead_id                = $entry['id'];
    			$lead_table             = RGFormsModel::get_lead_table_name();
    			$lead_notes_table       = RGFormsModel::get_lead_notes_table_name();
    			$lead_detail_table      = RGFormsModel::get_lead_details_table_name();
    			$lead_detail_long_table = RGFormsModel::get_lead_details_long_table_name();
    
    			// Delete from detail long
    			$sql = $wpdb->prepare( " DELETE FROM $lead_detail_long_table
    									WHERE lead_detail_id IN(
    									SELECT id FROM $lead_detail_table WHERE lead_id=%d
    									)", $lead_id );
    			$wpdb->query( $sql );
    
    			// Delete from lead details
    			$sql = $wpdb->prepare( "DELETE FROM $lead_detail_table WHERE lead_id=%d", $lead_id );
    			$wpdb->query( $sql );
    
    			// Delete from lead notes
    			$sql = $wpdb->prepare( "DELETE FROM $lead_notes_table WHERE lead_id=%d", $lead_id );
    			$wpdb->query( $sql );
    
    			// Delete from lead
    			$sql = $wpdb->prepare( "DELETE FROM $lead_table WHERE id=%d", $lead_id );
    			$wpdb->query( $sql );
    
    		}
    	}
    	// Message. Take this out later.
    	echo 'deleted users!';
    
    }

    I have the function being fired on page load in my header.php file. The only piece missing is whether the entry is 24 hours old or not. That's where I am stuck....

    Posted 9 years ago on Monday October 1, 2012 | Permalink
  5. I'm going to close your other topic and continue the discussion here.

    Posted 9 years ago on Monday October 1, 2012 | Permalink
  6. Okay, I am on to something here... I am using this function to check every entry and let me know if 1 day has passed since they have signed up. I will work on rolling this into the delete function that I posted above. I will get back to you shortly on it.

    function gf_published_entry_time( $entry, $form ) {
    
    	// Get all Entries for our form ID 1
    	$entries =  RGFormsModel::get_leads(1, '', 'DESC', '', '0', '99999999');
    	foreach ($entries as $entry){
    
    		$time = strtotime($entry['date_created']);
    		$one_day_ago = strtotime('-1 day');
    
    		if( $time > $one_day_ago ) {
    		    // it's sooner than one day ago
    		    $time_left = $time - $one_day_ago;
    		    $days_left = floor($time_left / 86400); // 86400 = seconds per day
    		    $hours_left = floor(($time_left - $days_left * 86400) / 3600); // 3600 = seconds per hour
    		    echo "Still $days_left day(s), $hours_left hour(s) to go.";
    		} else {
    			echo 'It has been longer than one day!';
    		}
    
    	}
    
    }
    Posted 9 years ago on Monday October 1, 2012 | Permalink
  7. In this line:

    [php]
    if($entry['payment_status'] == 'Processing'){

    you need to say something like:

    [php]
    if(($entry['payment_status'] == 'Processing') && (strtotime("$entry['date_created'] +24 hour") <= time())){

    I tested the function but did not verify the logic in all cases. Please be sure it is checking for entries older than 24 hours.

    Posted 9 years ago on Monday October 1, 2012 | Permalink
  8. Sorry, I was working on my solution and posted after you posted your code. I did not look at your approach at all, but I think it's similar.

    Posted 9 years ago on Monday October 1, 2012 | Permalink
  9. Tried adding in your statement. It breaks my site if I add it in like so:

    function gf_published_entry_time( $entry, $form ) {
    
    	// Get all Entries for our form ID 1
    	$entries =  RGFormsModel::get_leads(1, '', 'DESC', '', '0', '99999999');
    	foreach ($entries as $entry){
    
    		if(
    			($entry['payment_status'] == 'Processing') &&
    			(strtotime("$entry['date_created'] +24 hour") <= time())
    		){
    			echo 'Created On: '.$entry['date_created'];
    		} else {
    			// Delete Appropriate Entries
    			echo 'Delete';
    		}
    
    	}
    
    }
    Posted 9 years ago on Tuesday October 2, 2012 | Permalink
  10. However, this does not break the site. I am just not sure the logic is correct on this.. My brain is a little scrambled right now. It seems to delete the entry regardless of the time parameters within our conditional statement...

    I have gf_published_entry_time() in my header.php file to it is triggered on page load.

    function gf_published_entry_time( $entry, $form ) {
    
    	// Get all Entries for our form ID 1
    	$entries =  RGFormsModel::get_leads(1, '', 'DESC', '', '0', '99999999');
    	foreach ($entries as $entry){
    
    		// Created on
    		$time = strtotime($entry['date_created']);
    		// Time on Day Ago
    		$one_day_ago = strtotime('-24 hour');
    
    		if(
    			$entry['payment_status'] == 'Processing' &&
    			$time <= $one_day_ago
    		){
    			// it's sooner than one day ago
    			$time_left = $time - $one_day_ago;
    			$days_left = floor($time_left / 86400); // 86400 = seconds per day
    			$hours_left = floor(($time_left - $days_left * 86400) / 3600); // 3600 = seconds per hour
    			echo 'Created On: '.$entry['date_created'];
    			echo " Still $days_left day(s), $hours_left hour(s) to go until it is past due.<br/>";
    		} else {
    			// Delete Appropriate Entries
    			my_remove_entries();
    		}
    
    	}
    
    }
    Posted 9 years ago on Tuesday October 2, 2012 | Permalink
  11. Okay, I believe I have solved this issue. The code is here: http://pastebin.com/t2UXwzSW

    This checks all of my entries that have been posted, if they are +24hours from created day & their payment status is Processing, they will be deleted. I am using the function in the header.php file, so it gets fired and checks on page load. In this function I have it displaying a list of entries and it shows a countdown until they will be deleted... I will most likely use this in the backend of my site later on.

    Is there a way to make this happen without it being triggered on page load? Because lets say 25 hours goes by and no one goes to the site.. An entry will still be in the database for that extra hour, correct?

    Posted 9 years ago on Tuesday October 2, 2012 | Permalink
  12. David Peralty

    Maybe somehow hooking it into WP Cron? http://codex.wordpress.org/Function_Reference/wp_cron

    Posted 9 years ago on Tuesday October 2, 2012 | Permalink
  13. @David Peralty Genius! I will look into that and let you know how it goes.

    Posted 9 years ago on Tuesday October 2, 2012 | Permalink
  14. bluantinoo
    Member

    Hi all, very nice post! i have a similar situation, except that the price for my product is not predetermined.
    So I should build the Paypal button/link based on each entry total price before sending it to user email.
    Anyone has some suggestion on how it could be achieved?

    Posted 9 years ago on Wednesday October 17, 2012 | Permalink
  15. @bluantinoo - please begin a new topic for your issue and we will address it there. Please clearly explain what you would like to do when you create your topic. You can include a link to this topic if you like. Thank you.

    Posted 9 years ago on Thursday October 18, 2012 | Permalink