Using Gravity Forms ‘gform_post_payment_completed’ PHP filter

The gform_post_payment_completed Gravity Forms action triggers when a payment has been completed through the form.

Usage

add_action('gform_post_payment_completed', 'my_function', 10, 2);

Parameters

  • $entry (Entry Object) – The entry object that was created.
  • $action (array) – The action that occurred. Contains details such as the amount, what occurred, and the transaction ID. For example:
$action = array(
  'type'             => '',
  'amount'           => '',
  'transaction_type' => '',
  'transaction_id'   => '',
  'subscription_id'  => '',
  'entry_id'         => '',
  'payment_status'   => '',
  'note'             => '',
);

More information

See Gravity Forms Docs: gform_post_payment_completed

Examples

Send a confirmation email after payment

function send_confirmation_email($entry, $action) {
  // Send email to the user
  wp_mail($entry['3'], 'Payment Confirmation', 'Thank you for your payment!');

}
add_action('gform_post_payment_completed', 'send_confirmation_email', 10, 2);

Update user role after payment

function update_user_role_after_payment($entry, $action) {
  // Get the user ID from the entry object
  $user_id = $entry['created_by'];

  // Update the user role to 'premium_member'
  $user = new WP_User($user_id);
  $user->set_role('premium_member');
}
add_action('gform_post_payment_completed', 'update_user_role_after_payment', 10, 2);

Log payment data

function log_payment_data($entry, $action) {
  // Log the transaction ID and amount
  error_log('Transaction ID: ' . $action['transaction_id'] . ' Amount: ' . $action['amount']);
}
add_action('gform_post_payment_completed', 'log_payment_data', 10, 2);

Add a note to the entry

function add_payment_note($entry, $action) {
  // Add a note to the entry with the transaction ID
  GFFormsModel::add_note($entry['id'], 0, 'Payment', 'Transaction ID: ' . $action['transaction_id']);
}
add_action('gform_post_payment_completed', 'add_payment_note', 10, 2);

Send payment data to an external API

function send_payment_to_api($entry, $action) {
  // Prepare data for the API
  $data = array(
    'transaction_id' => $action['transaction_id'],
    'amount'         => $action['amount'],
    'email'          => $entry['3'],
  );

  // Send data to the external API
  $response = wp_remote_post('https://example.com/api/endpoint', array(
    'body' => $data
  ));
}
add_action('gform_post_payment_completed', 'send_payment_to_api', 10, 2);