I'm unable to redirect the url back to prefilled form after cashfree - gravity form payment failure
This is the code that I'm using for payment failure:
add_action( 'gform_cashfree_fail_payment', 'my_custom_cashfree_fail_payment_function', 10, 4 );
function my_custom_cashfree_fail_payment_function( $entry, $feed ) {
// Get the form object for the form ID used in the feed
$form = GFAPI::get_form( $feed['form_id'] );
$id2 = $entry['form_id'];
// Check if the $form variable is a WP_Error object
if ( is_wp_error( $form ) ) {
// Handle the error, for example:
error_log( 'Error getting form: ' . $form->get_error_message() );
wp_die( 'Error getting form: ' . $form->get_error_message() );
}
// Get the entry object for the failed payment
$entry = GFAPI::getentry( $entry['id'] );
// Create an array of field values to pre-fill in the form
$fields = array();
foreach ( $form['fields'] as $field ) {
if ( isset( $entry[ $field->id ] ) ) {
$fields[ 'input' . $field->id ] = $entry[ $field->id ];
}
}
// Get the URL of the form with the pre-filled fields
$form_url = add_query_arg( array( 'gf_token' => wp_create_nonce( 'gform_token' ),'gf_1' => json_encode( $fields ) ), get_permalink( $form['id2'] ) );
// Check if the $form_url variable is a WP_Error object
if ( is_wp_error( $form_url ) ) {
// Handle the error, for example:
error_log( 'Error creating form URL: ' . $form_url->get_error_message() );
wp_die( 'Error creating form URL: ' . $form_url->get_error_message() );
}
// Redirect the user to the pre-filled form URL
wp_redirect( $form_url );
}
The URL is generated however I receive error and URL doesn't redirect to the form that the user already submited.