Named Constants and Utility Functions
The Payment Plugin SDK provides some utility PHP functions that ease plugin development. It also provides some useful named constants.
Named Constants
The following extract shows how the Payment Plugin SDK implemented some named constants, which can be used by any plugin:
define('DEFAULT_LANG', 'en');
define('STATUS' , 'STATUS' );
define('NEXT_TRANSACTION_GAP', 'NEXT_TRANSACTION_GAP');
define('ADD_NEW_METHOD' , 'ADD_NEW_METHOD' );
define('TRANSACTION_DETAILS' , 'TRANSACTION_DETAILS' );
define('REDIRECT_HASH' , 'REDIRECT_HASH' );
define('TEXT' , 'TEXT' );
define('MODAL_FORM' , 'MODAL_FORM' );
define('NOTIFY_RESPONSE' , 'NOTIFY_RESPONSE' );
define('STATUS_APPROVED', 'APPROVED');
define('STATUS_FRAUD' , 'FRAUD' );
define('STATUS_DECLINED', 'DECLINED');
define('STATUS_PENDING' , 'PENDING' );
define('STATUS_AUTHCALL', 'AUTHCALL');
define('STATUS_ERROR' , 'ERROR' );
define('STATUS_REFUNDED', 'REFUNDED');
define('STATUS_3DSECURE', '3DSECURE');
define('STATUS_REDIRECT', 'REDIRECT');
define('STATUS_MODAL' , 'MODAL' );
define('PAYMETHOD_STATUS_OK', 'OK');
define('PAYMETHOD_STATUS_PENDING' , 'PENDING' );
Utility functions
pa_localized_string
function pa_localized_string($string, $variables = null, $null_if_no_key = false);
Description
This function returns a localized string.
When a plug-in function is invoked, the language is detected and the .string
file related to that language is loaded from the i18n
folder. This method makes it easy to retrieve a translation value based on the key associated with it.
By default, this method returns $string
if there is no $string
key. $null_if_no_key
must be set to true
if null
must be returned instead.
Input parameters
Param name | Description | Type |
---|---|---|
$string
|
The key for a localization string. | string |
$variables
|
(Optional) An associative array that contains a set of key-value pairs. The key is a template argument for replacement in a localizing string and the value (without the percent symbol) is a string that template will be replaced with. |
array |
$null_if_no_key
|
(Optional) Returns null if the $string does not exist. |
boolean |
Output parameters
There are three possible outputs:
- The translate value related to the
$string
key. $string
, if$string
key is not present.null
, if the$string
key is not present and$null_if_no_key
istrue
.
pa_log
function pa_log ($message);
Description
This function writes a message to the log file at /var/log/httpd/payment-sdk.log
Input parameters
Param name | Description | Type |
---|---|---|
$message
|
A string, array or object to be written to the log. |
mixed |
Output parameters
None.
pa_array_to_xmlstr
function pa_array_to_xmlstr ($array);
Description
This function converts an array to a string that contains data in the XML format.
Input parameters
Param name | Description | Type |
---|---|---|
$array
|
An array to be converted. |
array |
Output parameters
A string that contains data in the XML format.
pa_xml_to_array
function pa_xml_to_array ($xmlstr);
Description
This function converts a string containing XML data to an array.
Input parameters
Param name | Description | Type |
---|---|---|
$xmlstr
|
A string to be converted. |
string |
Output parameters
An array containing converted data.