myCRED_Transfer

Description

The Transfer object is used for creating new transfers, rendering the transfer form or just retreating information about a particular transfer.

Available since version 1.8

Interacting with Object

This is a utility object and it should not be accessed directly. Instead use one of the appropriate functions below:

Function Description
mycred_get_transfer Retrieves a specific, existing transfer based on the transfer ID.
mycred_new_transfer Attempts to process a transfer request. The request is first validated before it is executed (if now issues were found).
mycred_refund_transfer Attempts to refund a completed transfer.
mycred_transfer Returns a newly constructed myCRED_Transfer object. Should be used when you want to do multiple transfer related tasks or render a transfer form.

Object properties

Property Type Description
myCRED_Transfer Object (
public $transfer_id string The transfers unique transaction ID.
public $reference string The reference used for this transfer.
public $status string The transfers status.
public $sender_id int The numeric ID of the user that initiated the transfer.
public $recipient_id int The numeric ID of the user that is the recipient of this transfer.
public $point_type obj Holds the myCRED_Point_Type object used in this transfer.
public $transfer_amount int or float The original amount the sender requested to transfer to the recipient.
public $transfer_charge int or float The amount that was charged from the senders account for this transfer.
public $transfer_payout int or float The amount the transfer recipient received.
public $data array The transfer data array. This are used by some features to store additional information about the transfer. The transfer message is stored here.
public $message string The transfer message (if used).
public $settings array The transfer add-ons settings.
public $now int The current UNIX timestamp.
public $args array The arguments that is used for rendering the transfer form. Populated when rendering the transfer form.
public $request array The transfer request. Populated when making a new transfer request.
public $valid_request bool Indicates if a new transfer request is valid or not. Populated when a new transfer request is created.
public $transferable_types array An array of point type keys that a given user can transfer. Populated when a new transfer request is created.
public $balances array An associative array of point type keys and balances of the user making a transfer. Populated when a new transfer request is created.
public $limits array An array of limits that exists for each point type that is transferrable. Populated when a new transfer request is created.
public $minimum int or float The minimum amount a user must transfer. Populated when a new transfer request is created.
public $errors array Any errors that occur during a new transfer request or transfer process is stored in this array.
)

Object Methods

public function __construct( $transfer_id = false ) {
Description: Constructs the object.
Variable Type Required Description
$transfer_id string No A transfer ID unless a new transfer request is about to be made.
}
public function generate_new_transfer_id( $sender_id = 0, $recipient_id = 0 ) {
Description: Generates a new transfer ID based on the senders and recipients IDs.
Variable Type Required Description
$sender_id int Yes The numeric ID of the user sending the transfer.
$recipient_id int Yes The numeric ID of the recipient of the transfer.
}
public function get_transfer( $transfer_id = false ) {
Description: Retrieves a particular transfer from the database and populates the object. Returns FALSE if the transfer could not be found or the transfer ID value is invalid.
Variable Type Required Description
$transfer_id string or array Yes Either the transaction ID or if you have the two transfer log entries for the transfer, an array of this two log entries.
}
public function get_transfer_statuses() {
Description: Returns all possible transfer statuses. The default statuses are:
  • empty an empty status indicates the transfer is new.
  • incomplete Incomplete transfer. This indicates new transfers that has not yet been processed or if the request is invalid.
  • completed Completed transfer.
  • refunded Refunded transfer.
}
public function get_transfer_status() {
Description: Retrieves the transfer current status code.
}
public function display_transfer_status( $status = NULL ) {
Description: Translates a status code into a readable status description.
Variable Type Required Description
$status string No Option to render a different status then the status set in the object.
}
public function get_transfer_status() {
Description: Retrieves the transfer current status code.
}
public function new_instance( $request = array() ) {
Description: Creates a new transfer instance. Before a user can make a transfer, we need to setup an instance that tells myCRED what kind of transfer this is by setting a reference key, which point types that can be transferred along with limits and minimum requirement. Optionally this can also include what point amounts can be transferred and who the recipient is for the transfer. Once this instance is created, we can check if a user that wants to make a transfer can do so. This method should be used before rendering any transfer forms.
Variable Type Required Description
$request array No The transfer request array.
}
public function user_can_transfer_minimum() {
Description: Checks if the given user in the current instance can transfer the minimum amount we have set in our transfer settings.
}
public function get_transfer_limit() {
Description: Returns either FALSE if no transfer limit is set or a standard class of the limit setup based on your Transfer add-on settings.
}
public function get_transfer_limit_desc( $point_type = MYCRED_DEFAULT_TYPE_KEY ) {
Description: Converts any limit that exists for a particular point type into something readable. If no limit is set, the method will return "No Limit".
Variable Type Required Description
$point_type string No The point type key.
}
public function user_is_over_limit() {
Description: Checks if the user making a transfer is over their transfer limit for each point type that they can transfer. Returns either TRUE or FALSE.
}
public function is_valid_transfer_request( $request = array(), $posted = array() ) {
Description: Validates a new transfer request that was submitted by a transfer form.
Variable Type Required Description
$request array Yes The transfer request array.
$posted array Yes The content of the submitted transfer form.
}
public function new_transfer() {
Description: Processes a valid transfer request. This method should only be called after using is_valid_transfer_request() method or if we have validated the request ourselves. Returns FALSE if the transfer failed else a status array:
  • amount - The point amount that the sender was charged.
  • css - The CSS class selector for the point type that was transferred.
  • balance - The senders remaining balance after the transfer formatted.
  • zero - Indicates if the transfer has lead to the senders account to reach zero or below.
}
public function refund() {
Description: Attempts to refund the current transfer. Requires the transfer to be populated before this method is called. Returns TRUE on success else FALSE.
}
public function get_transfer_form( $args = array() ) {
Description: Returns a transfer form in a string format based on both the transfer instance we created and the arguments provided.
Variable Type Required Description
$args array Yes An array of arguments related to the form that we want to render. This includes:
  • button - The submit button label.
  • button_class - The submit buttons class.
  • show_balance - Indicates if a users balance should be shown in the form.
  • show_limit - Indicates if limits should be shown in the form.
  • placeholder - The placeholder text to use for the recipient field.
  • recipient_label - The recipient field label.
  • amount_label - The amount field label.
  • balance_label - The balance label.
  • message_label - The message field label.
}
public function get_transfer_recipient_field( $return = false ) {
Description: Renders the transfer recipient field.
Variable Type Required Description
$return bool No Indicates if the HTML code should be echoed or returned.
}
public function get_transfer_points_field( $return = false ) {
Description: Renders columns for the transfer amount and point type fields. This method will render columns based on which of these two fields is needed.
Variable Type Required Description
$return bool No Indicates if the HTML code should be echoed or returned.
}
public function get_transfer_amount_field( $return = false ) {
Description: Renders the transfer amount field.
Variable Type Required Description
$return bool No Indicates if the HTML code should be echoed or returned.
}
public function get_transfer_point_type_field( $return = false ) {
Description: Renders the point type selection field. Used only when more than one point type can be transferred.
Variable Type Required Description
$return bool No Indicates if the HTML code should be echoed or returned.
}
public function get_transfer_extra_fields( $return = false ) {
Description: Renders extra transfer information such as balances and limits (if used and set to show).
Variable Type Required Description
$return bool No Indicates if the HTML code should be echoed or returned.
}
public function get_error_message( $return = false ) {
Description: Renders any errors that a request has generated.
Variable Type Required Description
$return bool No Indicates if the HTML code should be echoed or returned.
}

Object Example

myCRED_Transfer Object
(
    [transfer_id] => 68bae8
    
    
        
            [1]
        
        
    

	 => transfer
    [status] => completed
    [sender_id] => 2
    [recipient_id] => 4
    [point_type] => myCRED_Point_Type Object
        (
            [cred_id] => mycred_default
            [singular] => Coin
            [plural] => Coins
            [prefix] => 
            [suffix] => co.
            [format] => Array
                (
                    [type] => bigint
                    [decimals] => 0
                    [separators] => Array
                        (
                            [decimal] => .
                            [thousand] => ,
                        )

                )

            [lowest_value] => 1
            [sql_format] => %d
        )

    [transfer_amount] => 80
    [transfer_charge] => 80
    [transfer_payout] => 80
    [data] => Array
        (
            [ref_type] => user
            [tid] => 68bae8
        )

    [message] => 
    [settings] => Array
        (
            [types] => Array
                (
                    [0] => mycred_default
                )

            [logs] => Array
                (
                    [sending] => Transfer of %plural% to %display_name%
                    [receiving] => Transfer of %plural% from %display_name%
                )

            [errors] => Array
                (
                    [low] => You do not have enough %plural% to send.
                    [over] => You have exceeded your %limit% transfer limit.
                )

            [templates] => Array
                (
                    [login] => 
                    [balance] => Your current balance is %balance%
                    [limit] => Your current %limit% transfer limit is %left%
                    [button] => Transfer
                )

            [autofill] => user_login
            [reload] => 1
            [message] => 0
            [limit] => Array
                (
                    [amount] => 0
                    [limit] => none
                )

        )

    [now] => 1507158010
    [args] => Array
        (
        )

    [request] => Array
        (
        )

    [valid_request] => 
    [transferable_types] => Array
        (
        )

    [balances] => Array
        (
        )

    [limits] => Array
        (
        )

    [minimum] => 0
    [errors] => Array
        (
        )

)