RCP_Payments

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/
The RCP_Payments class is for interacting with the payments database table.
insert( $payment_data = array() )
Used for inserting a new payment into the database. The following $payment_data arguments are available:

subscription (string) – Name of the associated subscription level.

object_id (int) – ID of the associated item that was purchased (i.e. subscription level ID).

object_type (string) – Type of object that object_id is. The default is “subscription” to designate this payment is associated with a subscription.

date (string) – The date the payment was made in MySQL format. Omit this parameter to use the current time.

amount (float) – The amount the payment was for.

user_id (int) – ID of the user who made the payment.

payment_type (string) – Description of the type of payment, i.e. “Credit Card One Time”.

subscription_key (string) – Associated subscription key.

transaction_id (string) – Transaction ID from the payment gateway.

status (string) – Status of the payment: complete, pending, failed, refunded.

gateway (string) – Slug of the gateway that was used for this payment.

subtotal (float) – The base price of the payment before credits, fees, or discounts are applied. For a subscription level, this would be the base price of the subscription level.

credits (float) – Amount of credits applied to the purchase.

fees (float) – Signup fees applied to the purchase.

discount_amount (float) – The amount discounted off the purchase.

discount_code (string) – Discount code applied to the purchase.

Example:
$payments = new RCP_Payments();
$payments->insert( array(
‘subscription’ => ‘Silver’,
‘object_id’ => 3,
‘object_type’ => ‘subscription’,
‘amount’ => 15.50,
‘user_id’ => 3,
‘payment_type’ => ‘Credit Card One Time’,
‘transaction_id’ => ‘123456789’,
‘status’ => ‘complete’,
‘gateway’ => ‘stripe’,
‘subtotal’ => 20.00,
‘credits’ => 4.50
) );

update( $payment_id = 0, $payment_data = array() )
Used for updating a specific payment. Use the same $payment_data arguments as the insert() method.
get_payment( $payment_id = 0 )
Retrieves a specific payment from the database. Returns a database row object.
get_payment_by( $field = ‘id’, $value = ” )
Similar to get_payment() but allows you to get a payment by any database column. This is useful for getting a payment by its transaction ID. Example:
$payments = new RCP_Payments();
$payment = get_payment_by( ‘transaction_id’, ‘123456789’ );

get_payments( $args = array() )
This method is used for retrieving an array of payments based on arguments. For example, getting all payments for a specific user, or all payments for a specific subscription level.
Available arguments:

number (int) – Maximum number of results (default is 20).

offset (int) – Offset the results (default is 0).

subscription (string) – Name of a subscription level.

user_id (int) – ID of a user.

date (array) – Array of day/month/year values.

fields (string) – Column name(s) to return. Omit to return all columns.

status (string) – Name of a status to filter by.

s (string) – Search value. This will search the email, subscription key, subscription level, or transaction ID.

order (string) – DESC | ASC

orderby (string) – Column to order by.

Example:
$payments = new RCP_Payments();
$payment_results = $payments->get_payments( array(
‘number’ => 5,
‘user_id’ => get_current_user_id()
) );

delete( $payment_id )
Deletes a payment record by its ID number.
get_earnings( $args = array() )
Calculates the total earnings of all payments in the database. There are a few arguments that allow you to filter the results:

subscription (string) – Name of a subscription level.

user_id (int) – ID of a user.

date (array) – Array of day/month/year values.

Example:
$payments = new RCP_Payments();
$july_earnings = $payments->get_earnings( array(
‘date’ => array(
‘day’ => 01,
‘month’ => 07,
‘year’ => 2016
)
) );

Getting, setting, and deleting payment meta
Payments have a meta table, just like user meta or post meta. You can use the following methods to interact with the meta table: 

get_meta( $payment_id = 0, $meta_key = ”, $single = false ) – Get the meta value for a payment ID and key.
add_meta( $payment_id = 0, $meta_key = ”, $meta_value, $unique = false ) – Add meta data to a payment.
update_meta( $payment_id = 0, $meta_key = ”, $meta_value, $prev_value = ” ) – Update an existing meta value. If the field does not yet exist, it will be created.
delete_meta( $payment_id = 0, $meta_key = ”, $meta_value = ” ) – Deletes the matching meta for a payment.

Have more questions?

Submit a request