Redsys’ premium plugin, which you can find at WooCommerce.com, incorporates a proprietary API that you can use from any other WordPress plugin or theme. This makes life easier for developers and gives them tools to express their ideas based on the premium Plugin and Redsys.
The magic function created, is WCRed() and through it you can get a lot of information, and that will increase in new versions.
WCRed()->get_order( $order_id );
Used to get $order
WCRed()->get_ds_error();
Returns an Array() with all the DS errors and what they are.
WCRed()->get_ds_response();
Returns an Array() with all the DS response codes and what they are.
WCRed()->get_msg_error();
Returns an Array() with all the msg errors and what they are.
WCRed()->is_ds_error( $error_code = null );
The error must be passed, and returns true or false depending on whether it is a DS error or not.
WCRed()->is_ds_response( $error_code = null );
The message must be passed, and returns true or false depending on whether it is a DS response or not.
WCRed()->is_msg_error( $error_code = null );
The message must be passed, and returns true or false depending on whether it is a msg error or not.
WCRed()->get_msg_error_by_code( $error_code = null );
The message must be passed, and returns what it means if it is an msg error. If not, it returns false.
WCRed()->get_error_by_code( $error_code = null );
Must pass the DS error, and returns what it means if it is a DS error. If not, it returns false.
WCRed()->get_response_by_code( $error_code = null );
The DS response must be passed, and returns what it means if it is a DS message. If not, it returns false.
WCRed()->is_redsys_error( $error_code = null );
Passes the error or response, and returns true or false depending on whether it is a Redsys error or not.
WCRed()->get_error( $error_code = null );
Passes the DS error, the msg error or the DS response, and returns what it means. You don’t have to specify what it is. If it’s nothing like the above, return false.
WCRed()->get_error_type( $error_code = null );
Passes the error, and returns the type that is:
- ds_error
- ds_response
- msg_error
WCRed()->get_currencies();
Returns an array() with all Redsys currencies and their codes.
WCRed()->allowed_currencies();
Returns an array() with all allowed Redsys currencies. Just because they are allowed does not mean they are active in the terminal.
WCRed()->get_redsys_languages();
Returns an array with the languages and yes code. The languages are not code, that is, for example in the Array() there are Spanish, English – English, Catalan, French – French, and each one related to its code in Redsys.
WCRed()->get_redsys_wp_languages();
Returns an Array() with all WordPress language codes, related to the code at Redsys.
WCRed()->get_orders_type();
Returns an Array() with the different Redsys payment methods possible through the plugin.
WCRed()->get_lang_code( $lang = 'en' );
Pass the language code, and return the code of this in Redsys. You can pass both standardized code (es, fr, en, etc), and WordPress code (es_ES, ca, en_US, en, en_GB).
If the language does not exist in Redsys, it will always return “2”, which is the code for English.
WCRed()->order_exist( $order_id );
Passes the order ID, and tells you if the order exists returns true or false.
WCRed()->post_exist( $post_id );
Passes the ID of the $POST, and tells you if it exists. Note, it can be any Post, Post Type or Custom Post Type, it just tells you if it exists.
WCRed()->is_redsys_order( $order_id, $type = null );
You can pass a parameter, or two. If you only pass the first parameter (the order ID), it will tell you if the order was placed through Redsys in any of the payment methods that the plugin adds by returning true or false. If you pass the second parameter, it will respond true or false, depending on whether the payment was made through this specific type of payment.
The possible values for $type are:
- redsys
- masterpass
- redsysbank
- bizumredsys
- iupay
- on the premises
- redsyspreauthorizations
WCRed()->get_gateway( $order_id );
The order ID is passed to you, and you return the gateway ID with which it was paid. If the order ID does not exist, it returns false.
WCRed()->get_order_date( $order_id );
Passes the order ID, and returns the date paid for at Redsys. If no date, or no payment on Redsys, return false.
WCRed()->get_order_hour( $order_id );
Passes the order ID, and returns the Redsys payment time. If no time, or no Redsys payment, return false.
WCRed()->get_order_auth( $order_id );
Passes the order ID, and returns the Redsys payment authentication code. If no code, or no Redsys payment, return false.
WCRed()->get_status_pending();
Returns an Array() with the possible pending payment statuses added by the Redsys and WooCommerce plugin
apply_filters( 'redsys_status_pending', $status );
This filter within WCRed()->get_status_pending () serves to easily add more states if needed and the function WCRed( )->get_status_pending () returns the correct pending states.
WCRed()->get_pending( $order_id );
passes you the order ID and tells you whether it’s paid or not.
WCRed()->get_redsys_option( $option, $gateway );
You must pass the option you want to know, and the gateway ID (whatever). It returns the value of the option.
WCRed()->is_gateway_enabled( $gateway );
Passes the gateway ID, and returns true or false depending on whether it exists and is enabled or not.
WCRed()->check_if_token_is_valid( $token_id );
Checks if a token with the ID $token_id is valid (checks card expiration date). If valid, returns “true”, if invalid (expiration date), deletes it and returns false.
WCRed()->get_redsys_users_token();
Returns the Redsys token of the user identified on the site.
WCRed()->get_users_token_bulk( $user_id );
Returns a user’s token for their ID. The value $user_id must be passed to it.
WCRed()->prepare_order_number( $order_id );
Prepares the order number to be sent to Redsys.
WCRed()->clean_order_number( $order_number );
Converts the order number sent to Redsys into the WooCommerce number.
WCRed()->redsys_amount_format( $total );
Converts the total to be paid in Redsys format.
WCRed()->set_txnid( $token_num, $redsys_txnid );
Save the TXNID code. You must pass the token you want to relate it to and the TXNID.
WCRed()->get_txnid( $token_num );
Retrieve the TXNID code, the token we want to retrieve it from must be passed to it.