Using Gravity Forms ‘gform_post_payment_callback’ PHP action

The gform_post_payment_callback action in Gravity Forms triggers right after the payment callback occurs when payments are processed.

Usage

add_action('gform_post_payment_callback', 'my_function', 10, 3);

Parameters

  • $entry: Entry object – The entry object that was created.
  • $action: array – The action that occurred. Contains information such as the amount, what occurred, and the transaction ID. See sample array structure below.
  • $result: mixed – The result of the payment, such as payment success or failure.

More information

See Gravity Forms Docs: gform_post_payment_callback

Examples

Send an email after successful payment

In this example, we will send an email to the admin after a successful payment.

function send_email_after_payment($entry, $action, $result) {
    if ($action['type'] == 'complete_payment') {
        $to = '[email protected]';
        $subject = 'Payment received';
        $message = 'A payment of ' . $action['amount'] . ' has been received. Transaction ID: ' . $action['transaction_id'];
        wp_mail($to, $subject, $message);
    }
}
add_action('gform_post_payment_callback', 'send_email_after_payment', 10, 3);

Add a note after payment failure

In this example, we will add a note to the entry after a payment failure.

function add_note_after_payment_failure($entry, $action, $result) {
    if ($action['type'] == 'fail_payment') {
        $note = 'Payment failed. Transaction ID: ' . $action['transaction_id'];
        GFFormsModel::add_note($entry['id'], $entry['form_id'], $entry['created_by'], $note);
    }
}
add_action('gform_post_payment_callback', 'add_note_after_payment_failure', 10, 3);

Update user meta after subscription cancellation

In this example, we will update the user meta after a subscription is cancelled.

function update_user_meta_after_subscription_cancellation($entry, $action, $result) {
    if ($action['type'] == 'cancel_subscription') {
        $user_id = $entry['created_by'];
        update_user_meta($user_id, 'subscription_status', 'Cancelled');
    }
}
add_action('gform_post_payment_callback', 'update_user_meta_after_subscription_cancellation', 10, 3);

Change entry status after pending payment

In this example, we will change the entry status to ‘Pending Payment’ after adding a pending payment.

function set_entry_status_to_pending_payment($entry, $action, $result) {
    if ($action['type'] == 'add_pending_payment') {
        GFAPI::update_entry_property($entry['id'], 'status', 'Pending Payment');
    }
}
add_action('gform_post_payment_callback', 'set_entry_status_to_pending_payment', 10, 3);