rcp_recurring_payment_failed

Note: This is part of the developer docs and is considered custom code.
Unfortunately, we cannot provide support for custom code at this time as we do not have the additional resources that would be necessary to provide support for custom code.

If you need assistance with this, please reach out to our list of consultants for further assistance:
https://codeable.io/developers/restrict-content-pro/
Triggers when an automatic renewal payment fails at the payment gateway.
Parameters:

$member (RCP_Member) – RCP_Member object, which extends the WP_User object.

$gateway (RCP_Payment_Gateway) – Payment gateway object.

Example:
Adds a note to the membership record when a recurring payment fails.
/**
* Add a note to the member when a recurring charge fails.
*
* @param RCP_Member $member
* @param RCP_Payment_Gateway $gateway
*
* @return void
*/
function rcp_add_recurring_payment_failure_note( $member, $gateway ) {

$membership = $gateway->membership;

$gateway_classes = wp_list_pluck( rcp_get_payment_gateways(), ‘class’ );
$gateway_name = array_search( get_class( $gateway ), $gateway_classes );

$note = sprintf( __( ‘Recurring charge failed in %s.’, ‘rcp’ ), ucwords( $gateway_name ) );

if ( ! empty( $gateway->webhook_event_id ) ) {
$note .= sprintf( __( ‘ Event ID: %s’, ‘rcp’ ), $gateway->webhook_event_id );
}

$membership->add_note( $note );

rcp_log( sprintf( ‘Recurring payment failed for membership #%d. Gateway: %s; Membership Level: %s; Expiration Date: %s’, $membership->get_id(), ucwords( $gateway_name ), $member->get_subscription_name(), $membership->get_expiration_date() ) );

}
add_action( ‘rcp_recurring_payment_failed’, ‘rcp_add_recurring_payment_failure_note’, 10, 2 );

Have more questions?

Submit a request