bookmark_borderEnable Editing of the Entry Payment Details

The payment details panel on the entry detail page is usually only displayed when the entry was processed by a payment add-on. The ability to edit the payment details on this panel is usually only available when the entry was processed by the PayPal Standard add-on and the current payment status is set to Processing or Pending.

For Gravity Forms 2.0 and newer you can use the Enable Gravity Forms Payment Details plugin.

The snippet below which works with Gravity Forms versions older than 2.0 will allow you to enable the display of the payment details panel on the entry detail page and allow editing of those details for entries which were not processed by a payment add-on.

class RW_GF_Edit_Payment_Details {

	public function __construct( $form_ids = array() ) {
		if ( ! empty( $form_ids ) ) {
			$this->_form_ids = $form_ids;
			add_action( 'gform_loaded', array( $this, 'init' ) );
		}
	}

	function init() {
		if ( ! property_exists( 'GFForms', 'version' ) || ! version_compare( GFForms::$version, '1.9', '>=' ) ) {
			return;
		}

		//add actions to allow the payment details to be modified
		add_action( 'gform_payment_status', array( $this, 'admin_edit_payment_status' ), 10, 3 );
		add_action( 'gform_payment_date', array( $this, 'admin_edit_payment_date' ), 10, 3 );
		add_action( 'gform_payment_transaction_id', array( $this, 'admin_edit_payment_transaction_id' ), 10, 3 );
		add_action( 'gform_payment_amount', array( $this, 'admin_edit_payment_amount' ), 10, 3 );
		add_action( 'gform_after_update_entry', array( $this, 'admin_update_payment' ), 10, 2 );
		add_action( 'gform_entries_first_column_actions', array( $this, 'maybe_set_payment_status' ), 10, 4 );

		add_filter( 'gform_enable_entry_info_payment_details', '__return_false' );
	}

	public function maybe_set_payment_status( $form_id, $field_id, $value, $entry ) {
		// payment details panel won't be displayed unless payment_status has a value
		// only set the payment status when the entry is listed on the entries list page
		// only set the payment status if its not already set and if it is the form we want
		if ( rgempty( 'payment_status', $entry ) && in_array( $form_id, $this->_form_ids ) ) {
			GFAPI::update_entry_property( $entry['id'], 'payment_status', 'Processing' );
		}
	}

	public function admin_edit_payment_status( $payment_status, $form, $entry ) {
		if ( $this->payment_details_editing_disabled( $entry ) ) {
			return $payment_status;
		}

		//create drop down for payment status
		$payment_string = '<select id="payment_status" name="payment_status">';
		$payment_string .= '<option value="' . $payment_status . '" selected>' . $payment_status . '</option>';
		$payment_string .= '<option value="Paid">Paid</option>';
		$payment_string .= '</select>';

		return $payment_string;
	}

	public function admin_edit_payment_date( $payment_date, $form, $entry ) {
		if ( $this->payment_details_editing_disabled( $entry ) ) {
			return $payment_date;
		}

		$payment_date = $entry['payment_date'];
		if ( empty( $payment_date ) ) {
			$payment_date = gmdate( 'y-m-d H:i:s' );
		}

		$input = '<input type="text" id="payment_date" name="payment_date" value="' . $payment_date . '">';

		return $input;
	}

	public function admin_edit_payment_transaction_id( $transaction_id, $form, $entry ) {
		if ( $this->payment_details_editing_disabled( $entry ) ) {
			return $transaction_id;
		}

		$input = '<input type="text" id="custom_transaction_id" name="custom_transaction_id" value="' . $transaction_id . '">';

		return $input;
	}

	public function admin_edit_payment_amount( $payment_amount, $form, $entry ) {
		if ( $this->payment_details_editing_disabled( $entry ) ) {
			return $payment_amount;
		}

		if ( empty( $payment_amount ) ) {
			$payment_amount = GFCommon::get_order_total( $form, $entry );
		}

		$input = '<input type="text" id="payment_amount" name="payment_amount" class="gform_currency" value="' . $payment_amount . '">';

		return $input;
	}

	public function admin_update_payment( $form, $entry_id ) {
		check_admin_referer( 'gforms_save_entry', 'gforms_save_entry' );

		//update payment information in admin, need to use this function so the lead data is updated before displayed in the sidebar info section
		$entry = GFFormsModel::get_lead( $entry_id );

		if ( $this->payment_details_editing_disabled( $entry, 'update' ) ) {
			return;
		}

		//get payment fields to update
		$payment_status = rgpost( 'payment_status' );
		//when updating, payment status may not be editable, if no value in post, set to lead payment status
		if ( empty( $payment_status ) ) {
			$payment_status = $entry['payment_status'];
		}

		$payment_amount      = GFCommon::to_number( rgpost( 'payment_amount' ) );
		$payment_transaction = rgpost( 'custom_transaction_id' );
		$payment_date        = rgpost( 'payment_date' );
		if ( empty( $payment_date ) ) {
			$payment_date = gmdate( 'y-m-d H:i:s' );
		} else {
			//format date entered by user
			$payment_date = date( 'Y-m-d H:i:s', strtotime( $payment_date ) );
		}

		global $current_user;
		$user_id   = 0;
		$user_name = 'System';
		if ( $current_user && $user_data = get_userdata( $current_user->ID ) ) {
			$user_id   = $current_user->ID;
			$user_name = $user_data->display_name;
		}

		$entry['payment_status'] = $payment_status;
		$entry['payment_amount'] = $payment_amount;
		$entry['payment_date']   = $payment_date;
		$entry['transaction_id'] = $payment_transaction;

		//update lead, add a note
		GFAPI::update_entry( $entry );
		GFFormsModel::add_note( $entry['id'], $user_id, $user_name, sprintf( __( 'Payment information was manually updated. Status: %s. Amount: %s. Transaction Id: %s. Date: %s', 'gravityformspaypal' ), $entry['payment_status'], GFCommon::to_money( $entry['payment_amount'], $entry['currency'] ), $payment_transaction, $entry['payment_date'] ) );
	}

	public function payment_details_editing_disabled( $entry, $action = 'edit' ) {
		$gateway = gform_get_meta( $entry['id'], 'payment_gateway' );

		if ( ! empty( $gateway ) ) {
			// Entry was processed by a payment add-on, don't allow editing.
			return true;
		}

		if ( rgar( $entry, 'payment_status' ) != 'Processing' ) {
			// Editing not allowed for this entry.
			return true;
		}

		if ( $action == 'edit' && rgpost( 'screen_mode' ) == 'edit' ) {
			// Editing is allowed for this entry.
			return false;
		}

		if ( $action == 'update' && rgpost( 'screen_mode' ) == 'view' && rgpost( 'action' ) == 'update' ) {
			// Updating the payment details for this entry is allowed.
			return false;
		}

		// In all other cases editing is not allowed.

		return true;
	}

}

// pass in an array of form ids you want to allow editing the payment details for
new RW_GF_Edit_Payment_Details( array( 11, 407, 48 ) );

The code snippet would go in your theme functions.php file or a custom functionality plugin.