rcp_create_payment

Runs when a new payment is created and inserted into the database.

Parameters:

  • $payment_id (int) - ID of the newly created payment.
  • $args (array) - Array of arguments used when creating the payment. Includes:
    • subscription (string) - Name of the associated subscription level.
    • object_id (int) - ID of the associated object type (usually the ID of the associated subscription level).
    • object_type (string) - Type of object (usually "subscription" to designate a subscription level).
    • date (string) - Date/time the payment was inserted, in MySQL format.
    • amount (float) - Final payment amount.
    • subtotal (float) - Base price of the subscription level, before any discounts/credits/fees are added.
    • credits (float) - Prorated credits applied towards the payment.
    • fees (float) - Fees applied towards the payment.
    • discount_amount (float) - Discount amount (from discount code) applied towards the payment.
    • discount_code (string) - Discount code used for the payment.
    • user_id (int) - ID of the associated user.
    • payment_type (string) - Type of payment (i.e. "Credit Card One Time").
    • subscription_key (string) - Subscription key.
    • transaction_id (string) - ID of the transaction with the payment gateway.
    • status (string) - Status of the payment (i.e. "complete", "pending", etc.).
    • gateway (string) - Slug of the payment gateway that was used for the payment.

Example:

/**
 * Send an email to the customer when a new manual payment is created.
 * 
 * @return void
 */
function ag_rcp_create_payment( $payment_id, $args ) {

    // If the gateway isn't "manual" - bail.
    if ( 'manual' != $args['gateway'] ) {
        return;
    }

    $user_info = get_userdata( $args['user_id'] );

    // Bail if user info can't be retrieved.
    if( ! $user_info ) {
        return;
    }

    // Setup the subject and message.
    $subject = __( 'Your payment is pending', 'rcp' );
    $message = __( 'Hello %name%, your payment for %subscription_name% is still pending. You can view your invoice here: https://yoursite.com/register/your-membership/', 'rcp' );

    // Setup the email class.
    $emails = new RCP_Emails;
    $emails->member_id = $args['user_id'];
    $emails->payment_id = $payment_id;

    // Send the email.
    $emails->send( $user_info->user_email, $subject, $message );

}

add_action( 'rcp_create_payment', 'ag_rcp_create_payment', 10, 2 );