rcp_create_payment

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/
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”).
transaction_type (string) – Type of transaction (new/renewal/downgrade/upgrade)
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 );

Have more questions?

Submit a request