GFPaymentAddOn redirect_url() not working

Hi,

I’m developing a payment method extension extending GFPaymentAddOn.

After sending the form I need to redirect to a URL.

I’m using the function redirect_url from the class GFPaymentAddOn but it doesn’t work now, It was working previously.

How could I solve it?

My Code sample:

public function redirect_url( $feed, $submission_data, $form, $entry ) {
//some code goes here
return $url; //I checked it by print URL it prints correct url
}

It also shows redirect message but not redirecting: https://prnt.sc/tycg8z

Checked error log and gravity from log too but nothing found.
Please help.

Thanks in advance.

Hi Kapil. Can you share any more of your code or your logging?

Here is complete log of Gravity Forms Core:
2020-08-13 4:15:33.931355 - DEBUG --> GFFormDisplay::process_form(): Starting to process form (#3) submission.
2020-08-13 4:15:33.932123 - DEBUG --> GFFormDisplay::process_form(): Source page number: 1. Target page number: 0.
2020-08-13 4:15:33.934160 - DEBUG --> GFCommon::is_spam_entry(): Is submission considered spam? No.
2020-08-13 4:15:33.934755 - DEBUG --> GFFormDisplay::process_form(): After validation. Is submission valid? Yes.
2020-08-13 4:15:33.934801 - DEBUG --> GFFormDisplay::process_form(): Submission is valid. Moving forward.
2020-08-13 4:15:33.934865 - DEBUG --> GFFormsModel::save_entry(): Saving entry.
2020-08-13 4:15:33.938703 - DEBUG --> GFFormsModel::save_entry(): Entry record created in the database. ID: 93.
2020-08-13 4:15:33.940409 - DEBUG --> GFFormsModel::save_entry(): Saving entry fields.
2020-08-13 4:15:33.940512 - DEBUG --> GFFormsModel::queue_save_input_value(): Queued field operation: Name(#1.2 - name).
2020-08-13 4:15:33.940562 - DEBUG --> GFFormsModel::queue_save_input_value(): Queued field operation: Name(#1.3 - name).
2020-08-13 4:15:33.940602 - DEBUG --> GFFormsModel::queue_save_input_value(): Queued field operation: Name(#1.4 - name).
2020-08-13 4:15:33.940639 - DEBUG --> GFFormsModel::queue_save_input_value(): Queued field operation: Name(#1.6 - name).
2020-08-13 4:15:33.940674 - DEBUG --> GFFormsModel::queue_save_input_value(): Queued field operation: Name(#1.8 - name).
2020-08-13 4:15:33.940728 - DEBUG --> GFFormsModel::queue_save_input_value(): Queued field operation: Email(#2 - email).
2020-08-13 4:15:33.940783 - DEBUG --> GFFormsModel::queue_save_input_value(): Queued field operation: Phone(#3 - phone).
2020-08-13 4:15:33.940834 - DEBUG --> GFFormsModel::queue_save_input_value(): Queued field operation: Product Name(#4.1 - product).
2020-08-13 4:15:33.940871 - DEBUG --> GFFormsModel::queue_save_input_value(): Queued field operation: Product Name(#4.2 - product).
2020-08-13 4:15:33.940907 - DEBUG --> GFFormsModel::queue_save_input_value(): Queued field operation: Product Name(#4.3 - product).
2020-08-13 4:15:33.944608 - DEBUG --> GFFormsModel::queue_save_input_value(): Queued field operation: Total(#5 - total).
2020-08-13 4:15:33.946722 - DEBUG --> GFFormsModel::save_entry(): Finished saving entry fields.
2020-08-13 4:15:35.226438 - DEBUG --> GF_Background_Process::dispatch(): Running for gf_feed_processor.
2020-08-13 4:15:35.227214 - DEBUG --> GF_Background_Process::dispatch(): Unable to dispatch tasks to Admin Ajax: Nothing left to process
2020-08-13 4:15:35.227314 - DEBUG --> GFFormsModel::create_post(): Starting.
2020-08-13 4:15:35.227399 - DEBUG --> GFFormsModel::create_post(): Stopping. The form doesn’t have any post fields.
2020-08-13 4:15:35.227452 - DEBUG --> GFAPI::send_notifications(): Gathering notifications for form_submission event for entry #93.
2020-08-13 4:15:35.227515 - DEBUG --> GFCommon::send_notifications(): Processing notifications for form_submission event for entry #93: Array
(
[0] => 5f2d2150936a1
)

(only active/applicable notifications are sent)
2020-08-13 4:15:35.227557 - DEBUG --> GFCommon::send_notifications(): Notification is inactive, not processing notification (#5f2d2150936a1 - Admin Notification) for entry #93.
2020-08-13 4:15:35.227618 - DEBUG --> GFFormDisplay::handle_confirmation(): Sending confirmation.
2020-08-13 4:15:35.227727 - DEBUG --> GFFormDisplay::handle_confirmation(): Executing functions hooked to gform_confirmation.
2020-08-13 4:15:35.227932 - DEBUG --> GFFormDisplay::handle_confirmation(): Confirmation => Redirecting you to the Secure Payment Page.

Here is complete log of my extension Gravity Forms Instamojo Standard Add-On:
2020-08-12 11:17:04.958151 - DEBUG --> GFFeedAddOn::maybe_process_feed(): Checking for feeds to process for entry #90 for gravityformsinstamojo.
2020-08-12 11:17:04.958235 - DEBUG --> GFFeedAddOn::maybe_process_feed(): Starting to process feed (#4 - Instamojo Feed 2) for entry #90 for gravityformsinstamojo
2020-08-12 11:17:04.958267 - DEBUG --> GFFeedAddOn::maybe_process_feed(): Marking entry #90 as fulfilled for gravityformsinstamojo
2020-08-12 11:40:27.089879 - DEBUG --> GFFeedAddOn::maybe_process_feed(): Checking for feeds to process for entry #91 for gravityformsinstamojo.
2020-08-12 11:40:27.089947 - DEBUG --> GFFeedAddOn::maybe_process_feed(): Starting to process feed (#4 - Instamojo Feed 2) for entry #91 for gravityformsinstamojo
2020-08-12 11:40:27.089977 - DEBUG --> GFFeedAddOn::maybe_process_feed(): Marking entry #91 as fulfilled for gravityformsinstamojo
2020-08-12 11:41:08.157398 - DEBUG --> GFFeedAddOn::maybe_process_feed(): Checking for feeds to process for entry #92 for gravityformsinstamojo.
2020-08-12 11:41:08.157473 - DEBUG --> GFFeedAddOn::maybe_process_feed(): Starting to process feed (#4 - Instamojo Feed 2) for entry #92 for gravityformsinstamojo
2020-08-12 11:41:08.157505 - DEBUG --> GFFeedAddOn::maybe_process_feed(): Marking entry #92 as fulfilled for gravityformsinstamojo

Code: https://drive.google.com/file/d/1BSFNx0ozumyJ00hElym_x5kWDL8JhiXF/view?usp=sharing

1 Like

Have you tried adding some logging statements to the redirect_url method to log the response from the post request? Based on the current log it would seem that request did not return the expected response so $url was set to an empty string by the else resulting in the forms configured confirmation message being used instead.

Hey Richard, I already mentioned I checked URL, It prints correctly.
I tried it with echo statement. And also tried with static URL too.

@chrishajer Any update on this?

Hi George. Can you please add some debugging statements to your code so that the logging goes to the add-on log, or Gravity Forms core log?

You can find information about custom logging statements in Gravity Forms here:

Added log in redirect_url function

public function redirect_url( $feed, $submission_data, $form, $entry ) {
		//Don't process redirect url if request is a Instamoj return
		if(!rgempty( 'gf_instamojo_return', $_GET ) ) {
			return false;
		}
		$meta=$feed['meta'];
		if(isset($meta['instamojoSandbox']) && !empty($meta['instamojoSandbox'])){
			$this->_instamojo_api_url = $this->_instamojo_sandbox_api_url;
		}
		//updating lead's payment_status to Processing
		$entry['payment_status']= 'Processing' ;
		$entry['payment_method']='instamojo';

		// get payment amount form the product url list  this should not be less than 10 RS
		$payment_amount = rgar( $submission_data, 'payment_amount' );

		//return after success 
		$return_url = $meta['instamojoReturnUrl'];//$this->return_url( $form['id'], $entry['id'] ) ; 

		//URL that will listen to notifications from Instamoj
		$webhook_callback_url = site_url() . '?page=gf_instamoj_webhook&ref='.$entry['id'] ;
        GFCommon::log_debug( '$webhook_callback_url => ' . $webhook_callback_url );
		$request  = new WP_Http();
		$meta=$feed['meta'];
		//add authentication to the insa mojo account
		$headers =['X-Api-Key'=>$meta['instamojoAPIKey'] ,'X-Auth-Token'=>$meta['instamojoAuthToken']];

        $first_name = $meta['billingInformation_firstName'];
        $last_name  = $meta['billingInformation_lastName'];
        $name       = $last_name ? $entry[ $first_name ].' '.$entry[ $last_name ]  : $entry[ $first_name ];
        $email      = $entry[ $meta['billingInformation_email'] ];
		$phone      = $entry[ $meta['billingInformation_phone'] ];
		$payload = Array(
		    'purpose' => $meta['instamojoPaymentPurposeDescription'],
		    'amount' => $payment_amount,
            'phone' => $phone,
		    'buyer_name' => $name,
		    'redirect_url' => $return_url,
            //'send_email' => true,
		    'webhook' => $webhook_callback_url,
            //'send_sms' => true,
            'email' => $email,
		    'allow_repeated_payments' => false
		);

		$response = $request->post($this->_instamojo_api_url , array(
			'sslverify' => false, 'ssl' => true,
			'headers'=>$headers, 'timeout' => 20,'body'=>$payload ) );

		GFCommon::log_debug( '$response => ' . $response );
		// try to parse josn 
		$body=json_decode(rgar( $response, 'body' ));
		if ( ! is_wp_error( $response ) && $body->success ) {
			$url=$body->payment_request->longurl;
		   GFCommon::log_debug( '$url => ' . $url );
		   	//update the entry status 
		   	$entry['transaction_id']=$body->payment_request->id;
			$entry['payment_amount']=$body->payment_request->amount;
			$entry['payment_date']=$body->payment_request->created_at;
			$action['payment_status']	= $body->payment_request->payment->status;
		} else {
		   //$this->log_debug( __METHOD__ . "(): Unableto find the payment  URL Instamoj: ".print_r(rgar( $response, 'body' ),true) );
		   $url='';
		}
		//update the entry 
		GFAPI::update_entry($entry);
		GFCommon::log_debug( '$url => ' . $url );
		return $url;

	}

Gravity Forms Core Log:
2020-09-03 10:01:40.800420 - DEBUG --> GFFormDisplay::process_form(): Starting to process form (#3) submission.
2020-09-03 10:01:40.801327 - DEBUG --> GFFormDisplay::process_form(): Source page number: 1. Target page number: 0.
2020-09-03 10:01:40.803226 - DEBUG --> GFCommon::is_spam_entry(): Is submission considered spam? No.
2020-09-03 10:01:40.803841 - DEBUG --> GFFormDisplay::process_form(): After validation. Is submission valid? Yes.
2020-09-03 10:01:40.803893 - DEBUG --> GFFormDisplay::process_form(): Submission is valid. Moving forward.
2020-09-03 10:01:40.803957 - DEBUG --> GFFormsModel::save_entry(): Saving entry.
2020-09-03 10:01:40.806345 - DEBUG --> GFFormsModel::save_entry(): Entry record created in the database. ID: 94.
2020-09-03 10:01:40.807209 - DEBUG --> GFFormsModel::save_entry(): Saving entry fields.
2020-09-03 10:01:40.807312 - DEBUG --> GFFormsModel::queue_save_input_value(): Queued field operation: Name(#1.2 - name).
2020-09-03 10:01:40.807363 - DEBUG --> GFFormsModel::queue_save_input_value(): Queued field operation: Name(#1.3 - name).
2020-09-03 10:01:40.807403 - DEBUG --> GFFormsModel::queue_save_input_value(): Queued field operation: Name(#1.4 - name).
2020-09-03 10:01:40.807440 - DEBUG --> GFFormsModel::queue_save_input_value(): Queued field operation: Name(#1.6 - name).
2020-09-03 10:01:40.807475 - DEBUG --> GFFormsModel::queue_save_input_value(): Queued field operation: Name(#1.8 - name).
2020-09-03 10:01:40.807528 - DEBUG --> GFFormsModel::queue_save_input_value(): Queued field operation: Email(#2 - email).
2020-09-03 10:01:40.807584 - DEBUG --> GFFormsModel::queue_save_input_value(): Queued field operation: Phone(#3 - phone).
2020-09-03 10:01:40.807635 - DEBUG --> GFFormsModel::queue_save_input_value(): Queued field operation: Product Name(#4.1 - product).
2020-09-03 10:01:40.807672 - DEBUG --> GFFormsModel::queue_save_input_value(): Queued field operation: Product Name(#4.2 - product).
2020-09-03 10:01:40.807707 - DEBUG --> GFFormsModel::queue_save_input_value(): Queued field operation: Product Name(#4.3 - product).
2020-09-03 10:01:40.813546 - DEBUG --> GFFormsModel::queue_save_input_value(): Queued field operation: Total(#5 - total).
2020-09-03 10:01:40.814618 - DEBUG --> GFFormsModel::save_entry(): Finished saving entry fields.
2020-09-03 10:01:40.821391 - DEBUG --> $webhook_callback_url => http://nishit.pugmarker.net?page=gf_instamoj_webhook&ref=94
2020-09-03 10:01:42.032330 - DEBUG --> $response => Array
2020-09-03 10:01:42.032424 - DEBUG --> $url => https://test.instamojo.com/@nishit_m/b0a790b1c3894fb39214f81f16ae18a4
2020-09-03 10:01:42.053971 - DEBUG --> $url => https://test.instamojo.com/@nishit_m/b0a790b1c3894fb39214f81f16ae18a4
2020-09-03 10:01:42.054121 - DEBUG --> GF_Background_Process::dispatch(): Running for gf_feed_processor.
2020-09-03 10:01:42.054757 - DEBUG --> GF_Background_Process::dispatch(): Unable to dispatch tasks to Admin Ajax: Nothing left to process
2020-09-03 10:01:42.054842 - DEBUG --> GFFormsModel::create_post(): Starting.
2020-09-03 10:01:42.054920 - DEBUG --> GFFormsModel::create_post(): Stopping. The form doesn’t have any post fields.
2020-09-03 10:01:42.054969 - DEBUG --> GFAPI::send_notifications(): Gathering notifications for form_submission event for entry #94.
2020-09-03 10:01:42.055083 - DEBUG --> GFCommon::send_notifications(): Processing notifications for form_submission event for entry #94: Array
(
[0] => 5f2d2150936a1
)

(only active/applicable notifications are sent)
2020-09-03 10:01:42.055133 - DEBUG --> GFCommon::send_notifications(): Notification is inactive, not processing notification (#5f2d2150936a1 - Admin Notification) for entry #94.
2020-09-03 10:01:42.055192 - DEBUG --> GFFormDisplay::handle_confirmation(): Sending confirmation.
2020-09-03 10:01:42.055291 - DEBUG --> GFFormDisplay::handle_confirmation(): Executing functions hooked to gform_confirmation.
2020-09-03 10:01:42.055417 - DEBUG --> GFFormDisplay::handle_confirmation(): Confirmation => Redirecting you to the Secure Payment Page.
2020-09-03 10:02:00.363224 - DEBUG --> GFCommon::post_to_manager(): endpoint: https://gravityapi.com/wp-content/plugins/gravitymanager/api.php?op=upgrade_message&key=b2f56d4a6c2db1ffaf69c50feea6aad5
2020-09-03 10:02:00.657926 - DEBUG --> GFCommon::log_remote_response(): code: 200; body:

Gravity Forms Instamojo Standard Add-On Log:

2020-09-03 10:01:40.814826 - DEBUG --> GFFeedAddOn::maybe_process_feed(): Checking for feeds to process for entry #94 for gravityformsinstamojo.
2020-09-03 10:01:40.814899 - DEBUG --> GFFeedAddOn::maybe_process_feed(): Starting to process feed (#4 - Instamojo Feed 2) for entry #94 for gravityformsinstamojo
2020-09-03 10:01:40.814929 - DEBUG --> GFFeedAddOn::maybe_process_feed(): Marking entry #94 as fulfilled for gravityformsinstamojo

@chrishajer Any update on this?