Add REST handler for payment system sale.paysystem.handler.add
Scope:
pay_systemWho can execute the method: CRM administrator (permission "Allow to modify settings")
This method adds a REST handler for the payment system.
Method Parameters
Required parameters are marked with *
|
Name |
Description |
|
NAME* |
Name of the REST handler |
|
SORT |
Sorting. Default is |
|
CODE* |
Code of the REST handler. Must be unique among all handlers |
|
SETTINGS* |
Handler settings (detailed description provided below) |
SETTINGS Parameter
Required parameters are marked with *
Depending on the operating mode used, one of the following parameters must be present: FORM_DATA, CHECKOUT_DATA, IFRAME_DATA.
|
Name |
Description |
|
CODES* |
List of handler parameters. The keys are parameter codes ( Parameter values will be available to the administrator for filling in the settings of the created payment system. They can be specified when adding the payment system in the method sale.paysystem.add in the |
|
FORM_DATA |
Form settings when using the operating mode in form |
|
CHECKOUT_DATA |
Settings for the Checkout mode (creating an order on the service side and redirecting the customer to this page for payment) |
|
IFRAME_DATA |
Settings for the page displayed in the iframe on the seller's site on the payment page |
|
CLIENT_TYPE |
Type of customers with whom the handler can work. Available values:
Default value is |
|
CURRENCY |
List of currencies supported by the payment system. Default is empty |
CODES Parameter
|
Name |
Description |
|
NAME |
Name of the parameter |
|
DESCRIPTION |
Description of the parameter |
|
SORT |
Sorting |
|
GROUP |
Code of the group to which the parameter belongs |
|
DEFAULT |
Description of the default value (detailed description provided below) |
|
INPUT |
Object describing the input field. The structure of the object contains the
|
DEFAULT Parameter
|
Name |
Description |
|
PROVIDER_KEY |
Key of the provider from which the default value will be taken. Possible values of the key are provided below |
|
PROVIDER_VALUE |
Code of the value that will be taken from the provider. Possible values of the key are provided below |
Possible values for the PROVIDER_KEY
|
Name |
Description |
|
ORDER |
Order |
|
PROPERTY |
Invoice properties |
|
PAYMENT |
Payment |
|
USER |
User |
|
VALUE |
Arbitrary string value |
|
Y\N |
Checkbox |
Possible values for the PROVIDER_VALUE
|
Name |
Description |
|
ORDER |
|
|
PAYMENT |
|
|
USER |
|
Form Operating Mode
When adding a handler, the FORM_DATA parameter must be passed in the SETTINGS. This method is suitable if no information is required from the customer or only a small set of data needs to be requested.
Form fields are automatically displayed according to the design of the payment page.
Form data (the FIELDS values from FORM_DATA) will be sent to ACTION_URI. In addition to the data defined in FORM_DATA, two system keys will also be sent with the form:
|
Name |
Description |
|
BX_PAYSYSTEM_ID |
Identifier of the payment system through which the payment is made. Can be used to call the payment method sale.paysystem.pay.payment |
|
BX_RETURN_URL |
URL of the store's site to which the user will be redirected |
Parameters Passed When Adding a Handler in the FORM_DATA Array
Required parameters are marked with *
|
Name |
Description |
|
ACTION_URI* |
URL to which the form is sent |
|
METHOD |
HTTP method used when sending the form. Default is empty, in which case the GET method is used |
|
FIELDS |
Description of form fields (detailed description provided below) |
|
PARAMS |
Description of form fields. This parameter is deprecated; it is recommended to use the Represents a mapping between field names in the form ( Fields are added to the form as If both |
FIELDS Parameter
Required parameters are marked with *
Represents an array of descriptions of fields displayed in the form and sent to ACTION_URI. The key is the field code used as the field name in the form. The values are the field parameter objects.
|
Name |
Description |
|
CODE* |
If the value of the If an |
|
VISIBLE |
Whether the field is displayed in the form for input. Available values:
Default value is |
CODE Parameter
|
Name |
Description |
|
NAME |
Name of the field |
|
INPUT |
Description of the input field. Contains the
|
Code Examples
How to Use Examples in Documentation
curl -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{"NAME":"Handler.Rest FORM","CODE":"resthandlerform","SORT":100,"SETTINGS":{"CURRENCY":["USD"],"CLIENT_TYPE":"b2c","FORM_DATA":{"ACTION_URI":"http://example.com/payment_form.php","METHOD":"POST","FIELDS":{"phone":{"VISIBLE":"Y","CODE":{"NAME":"Phone number","TYPE":"STRING"}},"selection":{"VISIBLE":"Y","CODE":{"NAME":"Selection illusion","INPUT":{"TYPE":"Y/N"}}},"paymentId":{"CODE":"PAYMENT_ID","VISIBLE":"Y"},"serviceid":{"CODE":"REST_SERVICE_ID"}}},"CODES":{"REST_SERVICE_ID":{"NAME":"Store number","DESCRIPTION":"Store number","SORT":"100"},"REST_SERVICE_KEY":{"NAME":"Secret key","DESCRIPTION":"Secret key","SORT":"300"},"PAYMENT_ID":{"NAME":"Payment number","SORT":"400","GROUP":"PAYMENT","DEFAULT":{"PROVIDER_KEY":"PAYMENT","PROVIDER_VALUE":"ACCOUNT_NUMBER"}},"PAYMENT_SHOULD_PAY":{"NAME":"Payment amount","SORT":"600","GROUP":"PAYMENT","DEFAULT":{"PROVIDER_KEY":"PAYMENT","PROVIDER_VALUE":"SUM"}},"PS_CHANGE_STATUS_PAY":{"NAME":"Automatic payment status change","SORT":"700","INPUT":{"TYPE":"Y/N"}},"PAYMENT_BUYER_ID":{"NAME":"Customer code","SORT":"1000","GROUP":"PAYMENT","DEFAULT":{"PROVIDER_KEY":"ORDER","PROVIDER_VALUE":"USER_ID"}},"PS_WORK_MODE":{"NAME":"Payment system operating mode","SORT":"1100","INPUT":{"TYPE":"ENUM","OPTIONS":{"TEST":"Test","REGULAR":"Live"}}}}}' \
https://**put_your_bitrix24_address**/rest/**put_your_user_id_here**/**put_your_webhook_here**/sale.paysystem.handler.add
curl -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{"NAME":"Handler.Rest FORM","CODE":"resthandlerform","SORT":100,"SETTINGS":{"CURRENCY":["USD"],"CLIENT_TYPE":"b2c","FORM_DATA":{"ACTION_URI":"http://example.com/payment_form.php","METHOD":"POST","FIELDS":{"phone":{"VISIBLE":"Y","CODE":{"NAME":"Phone number","TYPE":"STRING"}},"selection":{"VISIBLE":"Y","CODE":{"NAME":"Selection illusion","INPUT":{"TYPE":"Y/N"}}},"paymentId":{"CODE":"PAYMENT_ID","VISIBLE":"Y"},"serviceid":{"CODE":"REST_SERVICE_ID"}}},"CODES":{"REST_SERVICE_ID":{"NAME":"Store number","DESCRIPTION":"Store number","SORT":"100"},"REST_SERVICE_KEY":{"NAME":"Secret key","DESCRIPTION":"Secret key","SORT":"300"},"PAYMENT_ID":{"NAME":"Payment number","SORT":"400","GROUP":"PAYMENT","DEFAULT":{"PROVIDER_KEY":"PAYMENT","PROVIDER_VALUE":"ACCOUNT_NUMBER"}},"PAYMENT_SHOULD_PAY":{"NAME":"Payment amount","SORT":"600","GROUP":"PAYMENT","DEFAULT":{"PROVIDER_KEY":"PAYMENT","PROVIDER_VALUE":"SUM"}},"PS_CHANGE_STATUS_PAY":{"NAME":"Automatic payment status change","SORT":"700","INPUT":{"TYPE":"Y/N"}},"PAYMENT_BUYER_ID":{"NAME":"Customer code","SORT":"1000","GROUP":"PAYMENT","DEFAULT":{"PROVIDER_KEY":"ORDER","PROVIDER_VALUE":"USER_ID"}},"PS_WORK_MODE":{"NAME":"Payment system operating mode","SORT":"1100","INPUT":{"TYPE":"ENUM","OPTIONS":{"TEST":"Test","REGULAR":"Live"}}}},"auth":"**put_access_token_here**"}' \
https://**put_your_bitrix24_address**/rest/sale.paysystem.handler.add
try
{
const response = await $b24.callMethod(
"sale.paysystem.handler.add",
{
"NAME": "Handler.Rest FORM",
"CODE": "resthandlerform",
"SORT": 100,
"SETTINGS": {
"CURRENCY": [
"USD"
],
"CLIENT_TYPE": "b2c",
"FORM_DATA": {
"ACTION_URI": "http://example.com/payment_form.php",
"METHOD": "POST",
"FIELDS": {
"phone": {
"VISIBLE": "Y",
"CODE": {
"NAME": "Phone number",
"TYPE": "STRING"
}
},
"selection": {
"VISIBLE": "Y",
"CODE": {
"NAME": "Selection illusion",
"INPUT": {
"TYPE": "Y/N"
}
}
},
"paymentId": {
"CODE": "PAYMENT_ID",
"VISIBLE": "Y"
},
"serviceid": {
"CODE": "REST_SERVICE_ID"
}
}
},
"CODES": {
"REST_SERVICE_ID": {
"NAME": "Store number",
"DESCRIPTION": "Store number",
"SORT": "100"
},
"REST_SERVICE_KEY": {
"NAME": "Secret key",
"DESCRIPTION": "Secret key",
"SORT": "300"
},
"PAYMENT_ID": {
"NAME": "Payment number",
"SORT": "400",
"GROUP": "PAYMENT",
"DEFAULT": {
"PROVIDER_KEY": "PAYMENT",
"PROVIDER_VALUE": "ACCOUNT_NUMBER"
}
},
"PAYMENT_SHOULD_PAY": {
"NAME": "Payment amount",
"SORT": "600",
"GROUP": "PAYMENT",
"DEFAULT": {
"PROVIDER_KEY": "PAYMENT",
"PROVIDER_VALUE": "SUM"
}
},
"PS_CHANGE_STATUS_PAY": {
"NAME": "Automatic payment status change",
"SORT": "700",
"INPUT": {
"TYPE": "Y/N"
}
},
"PAYMENT_BUYER_ID": {
"NAME": "Customer code",
"SORT": "1000",
"GROUP": "PAYMENT",
"DEFAULT": {
"PROVIDER_KEY": "ORDER",
"PROVIDER_VALUE": "USER_ID"
}
},
"PS_WORK_MODE": {
"NAME": "Payment system operating mode",
"SORT": "1100",
"INPUT": {
"TYPE": "ENUM",
"OPTIONS": {
"TEST": "Test",
"REGULAR": "Live"
}
}
}
}
}
}
);
const result = response.getData().result;
console.info(result);
}
catch(error)
{
console.error(error);
}
try {
$response = $b24Service
->core
->call(
'sale.paysystem.handler.add',
[
'NAME' => 'Handler.Rest FORM',
'CODE' => 'resthandlerform',
'SORT' => 100,
'SETTINGS' => [
'CURRENCY' => ['USD'],
'CLIENT_TYPE' => 'b2c',
'FORM_DATA' => [
'ACTION_URI' => 'http://example.com/payment_form.php',
'METHOD' => 'POST',
'FIELDS' => [
'phone' => [
'VISIBLE' => 'Y',
'CODE' => [
'NAME' => 'Phone number',
'TYPE' => 'STRING',
],
],
'selection' => [
'VISIBLE' => 'Y',
'CODE' => [
'NAME' => 'Selection illusion',
'INPUT' => [
'TYPE' => 'Y/N',
],
],
],
'paymentId' => [
'CODE' => 'PAYMENT_ID',
'VISIBLE' => 'Y',
],
'serviceid' => [
'CODE' => 'REST_SERVICE_ID',
],
],
],
'CODES' => [
'REST_SERVICE_ID' => [
'NAME' => 'Store number',
'DESCRIPTION' => 'Store number',
'SORT' => '100',
],
'REST_SERVICE_KEY' => [
'NAME' => 'Secret key',
'DESCRIPTION' => 'Secret key',
'SORT' => '300',
],
'PAYMENT_ID' => [
'NAME' => 'Payment number',
'SORT' => '400',
'GROUP' => 'PAYMENT',
'DEFAULT' => [
'PROVIDER_KEY' => 'PAYMENT',
'PROVIDER_VALUE' => 'ACCOUNT_NUMBER',
],
],
'PAYMENT_SHOULD_PAY' => [
'NAME' => 'Payment amount',
'SORT' => '600',
'GROUP' => 'PAYMENT',
'DEFAULT' => [
'PROVIDER_KEY' => 'PAYMENT',
'PROVIDER_VALUE' => 'SUM',
],
],
'PS_CHANGE_STATUS_PAY' => [
'NAME' => 'Automatic payment status change',
'SORT' => '700',
'INPUT' => [
'TYPE' => 'Y/N',
],
],
'PAYMENT_BUYER_ID' => [
'NAME' => 'Customer code',
'SORT' => '1000',
'GROUP' => 'PAYMENT',
'DEFAULT' => [
'PROVIDER_KEY' => 'ORDER',
'PROVIDER_VALUE' => 'USER_ID',
],
],
'PS_WORK_MODE' => [
'NAME' => 'Payment system operating mode',
'SORT' => '1100',
'INPUT' => [
'TYPE' => 'ENUM',
'OPTIONS' => [
'TEST' => 'Test',
'REGULAR' => 'Live',
],
],
],
],
],
]
);
$result = $response
->getResponseData()
->getResult();
echo 'Success: ' . print_r($result, true);
} catch (Throwable $e) {
error_log($e->getMessage());
echo 'Error adding payment system handler: ' . $e->getMessage();
}
BX24.callMethod(
"sale.paysystem.handler.add",
{
"NAME": "Handler.Rest FORM",
"CODE": "resthandlerform",
"SORT": 100,
"SETTINGS": {
"CURRENCY": [
"USD"
],
"CLIENT_TYPE": "b2c",
"FORM_DATA": {
"ACTION_URI": "http://example.com/payment_form.php",
"METHOD": "POST",
"FIELDS": {
"phone": {
"VISIBLE": "Y",
"CODE": {
"NAME": "Phone number",
"TYPE": "STRING"
}
},
"selection": {
"VISIBLE": "Y",
"CODE": {
"NAME": "Selection illusion",
"INPUT": {
"TYPE": "Y/N"
}
}
},
"paymentId": {
"CODE": "PAYMENT_ID",
"VISIBLE": "Y"
},
"serviceid": {
"CODE": "REST_SERVICE_ID"
}
}
},
"CODES": {
"REST_SERVICE_ID": {
"NAME": "Store number",
"DESCRIPTION": "Store number",
"SORT": "100"
},
"REST_SERVICE_KEY": {
"NAME": "Secret key",
"DESCRIPTION": "Secret key",
"SORT": "300"
},
"PAYMENT_ID": {
"NAME": "Payment number",
"SORT": "400",
"GROUP": "PAYMENT",
"DEFAULT": {
"PROVIDER_KEY": "PAYMENT",
"PROVIDER_VALUE": "ACCOUNT_NUMBER"
}
},
"PAYMENT_SHOULD_PAY": {
"NAME": "Payment amount",
"SORT": "600",
"GROUP": "PAYMENT",
"DEFAULT": {
"PROVIDER_KEY": "PAYMENT",
"PROVIDER_VALUE": "SUM"
}
},
"PS_CHANGE_STATUS_PAY": {
"NAME": "Automatic payment status change",
"SORT": "700",
"INPUT": {
"TYPE": "Y/N"
}
},
"PAYMENT_BUYER_ID": {
"NAME": "Customer code",
"SORT": "1000",
"GROUP": "PAYMENT",
"DEFAULT": {
"PROVIDER_KEY": "ORDER",
"PROVIDER_VALUE": "USER_ID"
}
},
"PS_WORK_MODE": {
"NAME": "Payment system operating mode",
"SORT": "1100",
"INPUT": {
"TYPE": "ENUM",
"OPTIONS": {
"TEST": "Test",
"REGULAR": "Live"
}
}
}
}
}
}
,
function (result) {
if (result.error())
{
console.error(result.error());
}
else
{
console.info(result.data());
}
}
);
require_once('crest.php');
$result = CRest::call(
'sale.paysystem.handler.add',
[
'NAME' => 'Handler.Rest FORM',
'CODE' => 'resthandlerform',
'SORT' => 100,
'SETTINGS' => [
'CURRENCY' => ['USD'],
'CLIENT_TYPE' => 'b2c',
'FORM_DATA' => [
'ACTION_URI' => 'http://example.com/payment_form.php',
'METHOD' => 'POST',
'FIELDS' => [
'phone' => [
'VISIBLE' => 'Y',
'CODE' => [
'NAME' => 'Phone number',
'TYPE' => 'STRING'
]
},
'selection' => [
'VISIBLE' => 'Y',
'CODE' => [
'NAME' => 'Selection illusion',
'INPUT' => [
'TYPE' => 'Y/N'
]
]
},
'paymentId' => [
'CODE' => 'PAYMENT_ID',
'VISIBLE' => 'Y'
},
'serviceid' => [
'CODE' => 'REST_SERVICE_ID'
]
]
],
'CODES' => [
'REST_SERVICE_ID' => [
'NAME' => 'Store number',
'DESCRIPTION' => 'Store number',
'SORT' => '100'
],
'REST_SERVICE_KEY' => [
'NAME' => 'Secret key',
'DESCRIPTION' => 'Secret key',
'SORT' => '300'
],
'PAYMENT_ID' => [
'NAME' => 'Payment number',
'SORT' => '400',
'GROUP' => 'PAYMENT',
'DEFAULT' => [
'PROVIDER_KEY' => 'PAYMENT',
'PROVIDER_VALUE' => 'ACCOUNT_NUMBER'
]
],
'PAYMENT_SHOULD_PAY' => [
'NAME' => 'Payment amount',
'SORT' => '600',
'GROUP' => 'PAYMENT',
'DEFAULT' => [
'PROVIDER_KEY' => 'PAYMENT',
'PROVIDER_VALUE' => 'SUM'
]
],
'PS_CHANGE_STATUS_PAY' => [
'NAME' => 'Automatic payment status change',
'SORT' => '700',
'INPUT' => [
'TYPE' => 'Y/N'
]
],
'PAYMENT_BUYER_ID' => [
'NAME' => 'Customer code',
'SORT' => '1000',
'GROUP' => 'PAYMENT',
'DEFAULT' => [
'PROVIDER_KEY' => 'ORDER',
'PROVIDER_VALUE' => 'USER_ID'
]
],
'PS_WORK_MODE' => [
'NAME' => 'Payment system operating mode',
'SORT' => '1100',
'INPUT' => [
'TYPE' => 'ENUM',
'OPTIONS' => [
'TEST' => 'Test',
'REGULAR' => 'Live'
]
]
]
]
]
]
);
echo '<PRE>';
print_r($result);
echo '</PRE>';
Checkout Operating Mode
When adding a handler, the CHECKOUT_DATA must be passed in the SETTINGS.
A script that will process the received data, create the payment, and return the identifier of the created payment and the URL of the payment page must be located at the address specified in ACTION_URI.
Data for payment will be sent to ACTION_URI in the form of an array. It contains an array of system parameters in the BX_SYSTEM_PARAMS key and the FIELDS values from CHECKOUT_DATA, each as a separate key at the top level of the array.
Structure of the BX_SYSTEM_PARAMS array:
|
Name |
Description |
|
RETURN_URL |
Current page |
|
PAYSYSTEM_ID |
Identifier of the payment system |
|
PAYMENT_ID |
Identifier of the payment |
|
SUM |
Payment amount |
|
CURRENCY |
Currency |
|
EXTERNAL_PAYMENT_ID |
Identifier of the payment in the payment system (if any). For example, if a request has already been sent to |
In response to a request to ACTION_URI, the script must return the identifier of the created payment and the URL of the payment page.
|
Name |
Description |
|
PAYMENT_URL |
URL of the payment page |
|
PAYMENT_ID |
Identifier of the payment in the payment system |
The customer will be redirected to the link from PAYMENT_URL automatically or by clicking the "Buy" button. If fields intended for filling through the form are passed among others in FIELDS, a form will be displayed to the customer.
As a result, an array of errors can be returned in the PAYMENT_ERRORS key. The manager will see the errors in the timeline or on the payment page (depending on the template used).
|
Name |
Description |
|
PAYMENT_ERRORS |
List of errors that occurred during payment creation |
If nothing is returned, the default error will be used: Error registering order in payment system.
Parameters Passed When Adding a Handler in the CHECKOUT_DATA Array
Required parameters are marked with *
|
Name |
Description |
|
ACTION_URI* |
URL to which the request for payment creation is sent |
|
FIELDS |
Description of fields sent to |
Code Examples
How to Use Examples in Documentation
curl -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{"NAME":"Handler.Rest CHECKOUT","CODE":"resthandlercheckout","SORT":100,"SETTINGS":{"CURRENCY":["USD"],"CLIENT_TYPE":"b2c","CHECKOUT_DATA":{"ACTION_URI":"http://example.com/payment_checkout.php","FIELDS":{"serviceKey":{"CODE":"REST_SERVICE_KEY_CHECKOUT"},"serviceid":{"CODE":"REST_SERVICE_ID_CHECKOUT"}}},"CODES":{"REST_SERVICE_ID_CHECKOUT":{"NAME":"Store number","DESCRIPTION":"Store number","SORT":"100"},"REST_SERVICE_KEY_CHECKOUT":{"NAME":"Secret key","DESCRIPTION":"Secret key","SORT":"300"},"PS_WORK_MODE_CHECKOUT":{"NAME":"Payment system operating mode","SORT":"1100","INPUT":{"TYPE":"ENUM","OPTIONS":{"TEST":"Test","REGULAR":"Live"}}}}}' \
https://**put_your_bitrix24_address**/rest/**put_your_user_id_here**/**put_your_webhook_here**/sale.paysystem.handler.add
curl -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{"NAME":"Handler.Rest CHECKOUT","CODE":"resthandlercheckout","SORT":100,"SETTINGS":{"CURRENCY":["USD"],"CLIENT_TYPE":"b2c","CHECKOUT_DATA":{"ACTION_URI":"http://example.com/payment_checkout.php","FIELDS":{"serviceKey":{"CODE":"REST_SERVICE_KEY_CHECKOUT"},"serviceid":{"CODE":"REST_SERVICE_ID_CHECKOUT"}}},"CODES":{"REST_SERVICE_ID_CHECKOUT":{"NAME":"Store number","DESCRIPTION":"Store number","SORT":"100"},"REST_SERVICE_KEY_CHECKOUT":{"NAME":"Secret key","DESCRIPTION":"Secret key","SORT":"300"},"PS_WORK_MODE_CHECKOUT":{"NAME":"Payment system operating mode","SORT":"1100","INPUT":{"TYPE":"ENUM","OPTIONS":{"TEST":"Test","REGULAR":"Live"}}}},"auth":"**put_access_token_here**"}' \
https://**put_your_bitrix24_address**/rest/sale.paysystem.handler.add
try
{
const response = await $b24.callMethod(
"sale.paysystem.handler.add",
{
"NAME": "Handler.Rest CHECKOUT",
"CODE": "resthandlercheckout",
"SORT": 100,
"SETTINGS": {
"CURRENCY": [
"USD"
],
"CLIENT_TYPE": "b2c",
"CHECKOUT_DATA": {
"ACTION_URI": "http://example.com/payment_checkout.php",
"FIELDS": {
"serviceKey": {
"CODE": "REST_SERVICE_KEY_CHECKOUT",
},
"serviceid": {
"CODE": "REST_SERVICE_ID_CHECKOUT"
}
}
},
"CODES": {
"REST_SERVICE_ID_CHECKOUT": {
"NAME": "Store number",
"DESCRIPTION": "Store number",
"SORT": "100"
},
"REST_SERVICE_KEY_CHECKOUT": {
"NAME": "Secret key",
"DESCRIPTION": "Secret key",
"SORT": "300"
},
"PS_WORK_MODE_CHECKOUT": {
"NAME": "Payment system operating mode",
"SORT": "1100",
"INPUT": {
"TYPE": "ENUM",
"OPTIONS": {
"TEST": "Test",
"REGULAR": "Live"
}
}
}
}
}
}
);
const result = response.getData().result;
console.info("Handler added with ID " + result);
}
catch( error )
{
console.error(error);
}
try {
$response = $b24Service
->core
->call(
'sale.paysystem.handler.add',
[
'NAME' => 'Handler.Rest CHECKOUT',
'CODE' => 'resthandlercheckout',
'SORT' => 100,
'SETTINGS' => [
'CURRENCY' => ['USD'],
'CLIENT_TYPE' => 'b2c',
'CHECKOUT_DATA' => [
'ACTION_URI' => 'http://example.com/payment_checkout.php',
'FIELDS' => [
'serviceKey' => [
'CODE' => 'REST_SERVICE_KEY_CHECKOUT',
],
'serviceid' => [
'CODE' => 'REST_SERVICE_ID_CHECKOUT'
]
]
],
'CODES' => [
'REST_SERVICE_ID_CHECKOUT' => [
'NAME' => 'Store number',
'DESCRIPTION' => 'Store number',
'SORT' => '100'
],
'REST_SERVICE_KEY_CHECKOUT' => [
'NAME' => 'Secret key',
'DESCRIPTION' => 'Secret key',
'SORT' => '300'
],
'PS_WORK_MODE_CHECKOUT' => [
'NAME' => 'Payment system operating mode',
'SORT' => '1100',
'INPUT' => [
'TYPE' => 'ENUM',
'OPTIONS' => [
'TEST' => 'Test',
'REGULAR' => 'Live'
]
]
]
]
]
]
);
$result = $response
->getResponseData()
->getResult();
echo 'Handler added with ID ' . $result;
} catch (Throwable $e) {
error_log($e->getMessage());
echo 'Error adding payment system handler: ' . $e->getMessage();
}
BX24.callMethod(
"sale.paysystem.handler.add",
{
"NAME": "Handler.Rest CHECKOUT",
"CODE": "resthandlercheckout",
"SORT": 100,
"SETTINGS": {
"CURRENCY": [
"USD"
],
"CLIENT_TYPE": "b2c",
"CHECKOUT_DATA": {
"ACTION_URI": "http://example.com/payment_checkout.php",
"FIELDS": {
"serviceKey": {
"CODE": "REST_SERVICE_KEY_CHECKOUT",
},
"serviceid": {
"CODE": "REST_SERVICE_ID_CHECKOUT"
}
}
},
"CODES": {
"REST_SERVICE_ID_CHECKOUT": {
"NAME": "Store number",
"DESCRIPTION": "Store number",
"SORT": "100"
},
"REST_SERVICE_KEY_CHECKOUT": {
"NAME": "Secret key",
"DESCRIPTION": "Secret key",
"SORT": "300"
},
"PS_WORK_MODE_CHECKOUT": {
"NAME": "Payment system operating mode",
"SORT": "1100",
"INPUT": {
"TYPE": "ENUM",
"OPTIONS": {
"TEST": "Test",
"REGULAR": "Live"
}
}
}
}
}
}
,
function (result) {
if (result.error())
{
console.error(result.error());
}
else
{
console.info("Handler added with ID " + result.data());
}
}
);
require_once('crest.php');
$result = CRest::call(
'sale.paysystem.handler.add',
[
'NAME' => 'Handler.Rest CHECKOUT',
'CODE' => 'resthandlercheckout',
'SORT' => 100,
'SETTINGS' => [
'CURRENCY' => ['USD'],
'CLIENT_TYPE' => 'b2c',
'CHECKOUT_DATA' => [
'ACTION_URI' => 'http://example.com/payment_checkout.php',
'FIELDS' => [
'serviceKey' => [
'CODE' => 'REST_SERVICE_KEY_CHECKOUT',
],
'serviceid' => [
'CODE' => 'REST_SERVICE_ID_CHECKOUT'
]
]
],
'CODES' => [
'REST_SERVICE_ID_CHECKOUT' => [
'NAME' => 'Store number',
'DESCRIPTION' => 'Store number',
'SORT' => '100'
],
'REST_SERVICE_KEY_CHECKOUT' => [
'NAME' => 'Secret key',
'DESCRIPTION' => 'Secret key',
'SORT' => '300'
],
'PS_WORK_MODE_CHECKOUT' => [
'NAME' => 'Payment system operating mode',
'SORT' => '1100',
'INPUT' => [
'TYPE' => 'ENUM',
'OPTIONS' => [
'TEST' => 'Test',
'REGULAR' => 'Live'
]
]
]
]
]
]
);
echo '<PRE>';
print_r($result);
echo '</PRE>';
IFrame Operating Mode
When adding a handler, the IFRAME_DATA must be passed in the SETTINGS.
A page that will be loaded in the iframe on the seller's site must be located at the address specified in ACTION_URI.
When loading the iframe via the Window.postMessage() method, the FIELDS values from IFRAME_DATA will be sent to ACTION_URI (each as a separate key at the top level of the array), along with the following data:
|
Name |
Description |
|
BX_SYSTEM_PARAMS |
System parameters |
|
BX_COMPUTED_STYLE |
Styles of the parent iframe element obtained via the window.getComputedStyle() method |
Data sent in BX_SYSTEM_PARAMS:
|
Name |
Description |
|
RETURN_URL |
Current page |
|
PAYSYSTEM_ID |
Identifier of the payment system |
|
PAYMENT_ID |
Identifier of the payment |
|
SUM |
Payment amount |
|
CURRENCY |
Currency |
You can obtain values in the iframe through the message event handler, for example:
document.addEventListener("DOMContentLoaded", function() {
window.addEventListener("message", function (event) {
// receiving data from the site (from the payment system)
var paymentData = event.data;
// working with BX_SYSTEM_PARAMS
if (paymentData.BX_SYSTEM_PARAMS)
{
// ...
}
// using site styles
if (paymentData.BX_COMPUTED_STYLE)
{
document.body.style.background = paymentData.BX_COMPUTED_STYLE.background;
document.body.style.color = paymentData.BX_COMPUTED_STYLE.color;
}
}, false);
});
By default, the width of the iframe is 100% of the parent element, and the height is 350px.
The dimensions of the iframe can be changed. To do this, the iframe must send the height and/or width to the seller's site. For example:
document.addEventListener("DOMContentLoaded", function() {
var size = {
width: document.body.scrollWidth,
height: document.body.scrollHeight
};
// sending data to the seller's site
parent.postMessage(size, "*");
});
width and height are reserved variable names, and only they are processed on the seller's site.
Parameters Passed When Adding a Handler in the IFRAME_DATA Array
Required parameters are marked with *
|
Name |
Description |
|
ACTION_URI* |
URL of the page that will be displayed in the iframe element |
|
FIELDS |
Description of fields sent to the |
Code Examples
How to Use Examples in Documentation
curl -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{"NAME":"Handler.Rest IFrame","CODE":"resthandleriframe","SORT":100,"SETTINGS":{"CURRENCY":["USD"],"CLIENT_TYPE":"b2c","IFRAME_DATA":{"ACTION_URI":"http://example.com/payment_iframe.php","FIELDS":{"serviceKey":{"CODE":"REST_SERVICE_KEY_IFRAME"},"serviceid":{"CODE":"REST_SERVICE_ID_IFRAME"}}},"CODES":{"REST_SERVICE_ID_IFRAME":{"NAME":"Store number","DESCRIPTION":"Store number","SORT":"100"},"REST_SERVICE_KEY_IFRAME":{"NAME":"Secret key","DESCRIPTION":"Secret key","SORT":"300"},"PS_WORK_MODE_IFRAME":{"NAME":"Payment system operating mode","SORT":"1100","INPUT":{"TYPE":"ENUM","OPTIONS":{"TEST":"Test","REGULAR":"Live"}}}}}' \
https://**put_your_bitrix24_address**/rest/**put_your_user_id_here**/**put_your_webhook_here**/sale.paysystem.handler.add
curl -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{"NAME":"Handler.Rest IFrame","CODE":"resthandleriframe","SORT":100,"SETTINGS":{"CURRENCY":["USD"],"CLIENT_TYPE":"b2c","IFRAME_DATA":{"ACTION_URI":"http://example.com/payment_iframe.php","FIELDS":{"serviceKey":{"CODE":"REST_SERVICE_KEY_IFRAME"},"serviceid":{"CODE":"REST_SERVICE_ID_IFRAME"}}},"CODES":{"REST_SERVICE_ID_IFRAME":{"NAME":"Store number","DESCRIPTION":"Store number","SORT":"100"},"REST_SERVICE_KEY_IFRAME":{"NAME":"Secret key","DESCRIPTION":"Secret key","SORT":"300"},"PS_WORK_MODE_IFRAME":{"NAME":"Payment system operating mode","SORT":"1100","INPUT":{"TYPE":"ENUM","OPTIONS":{"TEST":"Test","REGULAR":"Live"}}}},"auth":"**put_access_token_here**"}' \
https://**put_your_bitrix24_address**/rest/sale.paysystem.handler.add
try
{
const response = await $b24.callMethod(
"sale.paysystem.handler.add",
{
"NAME": "Handler.Rest IFrame",
"CODE": "resthandleriframe",
"SORT": 100,
"SETTINGS": {
"CURRENCY": [
"USD"
],
"CLIENT_TYPE": "b2c",
"IFRAME_DATA": {
"ACTION_URI": "http://example.com/payment_iframe.php",
"FIELDS": {
"serviceKey": {
"CODE": "REST_SERVICE_KEY_IFRAME",
},
"serviceid": {
"CODE": "REST_SERVICE_ID_IFRAME"
}
}
},
"CODES": {
"REST_SERVICE_ID_IFRAME": {
"NAME": "Store number",
"DESCRIPTION": "Store number",
"SORT": "100"
},
"REST_SERVICE_KEY_IFRAME": {
"NAME": "Secret key",
"DESCRIPTION": "Secret key",
"SORT": "300"
},
"PS_WORK_MODE_IFRAME": {
"NAME": "Payment system operating mode",
"SORT": "1100",
"INPUT": {
"TYPE": "ENUM",
"OPTIONS": {
"TEST": "Test",
"REGULAR": "Live"
}
}
}
}
}
}
);
const result = response.getData().result;
console.info(result);
}
catch( error )
{
console.error(error);
}
try {
$response = $b24Service
->core
->call(
'sale.paysystem.handler.add',
[
'NAME' => 'Handler.Rest IFrame',
'CODE' => 'resthandleriframe',
'SORT' => 100,
'SETTINGS' => [
'CURRENCY' => ['USD'],
'CLIENT_TYPE' => 'b2c',
'IFRAME_DATA' => [
'ACTION_URI' => 'http://example.com/payment_iframe.php',
'FIELDS' => [
'serviceKey' => [
'CODE' => 'REST_SERVICE_KEY_IFRAME',
],
'serviceid' => [
'CODE' => 'REST_SERVICE_ID_IFRAME'
]
]
],
'CODES' => [
'REST_SERVICE_ID_IFRAME' => [
'NAME' => 'Store number',
'DESCRIPTION' => 'Store number',
'SORT' => '100'
],
'REST_SERVICE_KEY_IFRAME' => [
'NAME' => 'Secret key',
'DESCRIPTION' => 'Secret key',
'SORT' => '300'
],
'PS_WORK_MODE_IFRAME' => [
'NAME' => 'Payment system operating mode',
'SORT' => '1100',
'INPUT' => [
'TYPE' => 'ENUM',
'OPTIONS' => [
'TEST' => 'Test',
'REGULAR' => 'Live'
]
]
]
]
]
]
);
$result = $response
->getResponseData()
->getResult();
echo 'Success: ' . print_r($result, true);
} catch (Throwable $e) {
error_log($e->getMessage());
echo 'Error adding payment system handler: ' . $e->getMessage();
}
BX24.callMethod(
"sale.paysystem.handler.add",
{
"NAME": "Handler.Rest IFrame",
"CODE": "resthandleriframe",
"SORT": 100,
"SETTINGS": {
"CURRENCY": [
"USD"
],
"CLIENT_TYPE": "b2c",
"IFRAME_DATA": {
"ACTION_URI": "http://example.com/payment_iframe.php",
"FIELDS": {
"serviceKey": {
"CODE": "REST_SERVICE_KEY_IFRAME",
},
"serviceid": {
"CODE": "REST_SERVICE_ID_IFRAME"
}
}
},
"CODES": {
"REST_SERVICE_ID_IFRAME": {
"NAME": "Store number",
"DESCRIPTION": "Store number",
"SORT": "100"
},
"REST_SERVICE_KEY_IFRAME": {
"NAME": "Secret key",
"DESCRIPTION": "Secret key",
"SORT": "300"
},
"PS_WORK_MODE_IFRAME": {
"NAME": "Payment system operating mode",
"SORT": "1100",
"INPUT": {
"TYPE": "ENUM",
"OPTIONS": {
"TEST": "Test",
"REGULAR": "Live"
}
}
}
}
}
}
,
function (result) {
if (result.error())
{
console.error(result.error());
}
else
{
console.info(result.data());
}
}
);
require_once('crest.php');
$result = CRest::call(
'sale.paysystem.handler.add',
[
'NAME' => 'Handler.Rest IFrame',
'CODE' => 'resthandleriframe',
'SORT' => 100,
'SETTINGS' => [
'CURRENCY' => ['USD'],
'CLIENT_TYPE' => 'b2c',
'IFRAME_DATA' => [
'ACTION_URI' => 'http://example.com/payment_iframe.php',
'FIELDS' => [
'serviceKey' => [
'CODE' => 'REST_SERVICE_KEY_IFRAME',
],
'serviceid' => [
'CODE' => 'REST_SERVICE_ID_IFRAME'
]
]
],
'CODES' => [
'REST_SERVICE_ID_IFRAME' => [
'NAME' => 'Store number',
'DESCRIPTION' => 'Store number',
'SORT' => '100'
],
'REST_SERVICE_KEY_IFRAME' => [
'NAME' => 'Secret key',
'DESCRIPTION' => 'Secret key',
'SORT' => '300'
],
'PS_WORK_MODE_IFRAME' => [
'NAME' => 'Payment system operating mode',
'SORT' => '1100',
'INPUT' => [
'TYPE' => 'ENUM',
'OPTIONS' => [
'TEST' => 'Test',
'REGULAR' => 'Live'
]
]
]
]
]
]
);
echo '<PRE>';
print_r($result);
echo '</PRE>';
Response Handling
HTTP status: 200
{
"result": 5,
"time": {
"start": 1712132792.910734,
"finish": 1712132793.530359,
"duration": 0.6196250915527344,
"processing": 0.032338857650756836,
"date_start": "2024-04-03T10:26:32+02:00",
"date_finish": "2024-04-03T10:26:33+02:00",
"operating_reset_at": 1705765533,
"operating": 3.3076241016387939
}
}
Returned Data
|
Name |
Description |
|
result |
Identifier of the created handler, used later for updating and deleting it |
|
time |
Information about the request execution time |
Error Handling
HTTP status: 400, 403
{
"error": "ERROR_HANDLER_ALREADY_EXIST",
"error_description": "Handler already exists!"
}
|
Name |
Description |
|
error |
String error code. It may consist of digits, Latin letters, and underscores |
|
error_description |
Textual description of the error. The description is not intended to be shown to the end user in its raw form |
Possible Error Codes
|
Code |
Description |
Status |
|
|
Insufficient rights to add the handler |
403 |
|
|
A required field value is not specified or the value of one of the fields is specified incorrectly |
400 |
|
|
A handler with the code specified in the |
400 |
|
|
Other errors. For detailed information about the error, see |
400 |
Statuses and System Error Codes
HTTP Status: 20x, 40x, 50x
The errors described below may occur when calling any method.
|
Status |
Code |
Description |
|
|
|
An internal server error has occurred, please contact the server administrator or Bitrix24 technical support |
|
|
|
An internal server error has occurred, please contact the server administrator or Bitrix24 technical support |
|
|
|
The request intensity limit has been exceeded |
|
|
|
The current method is not allowed to be called using batch |
|
|
|
The maximum length of parameters passed to the batch method has been exceeded |
|
|
|
Invalid access token or webhook code |
|
|
|
The methods must be called using the HTTPS protocol |
|
|
|
The REST API is blocked due to overload. This is a manual individual block, to remove it you need to contact Bitrix24 technical support |
|
|
|
The REST API is available only on commercial plans |
|
|
|
The user whose access token or webhook was used to call the method lacks permissions |
|
|
|
The manifest is not available |
|
|
|
The request requires higher privileges than those provided by the webhook token |
|
|
|
The provided access token has expired |
|
|
|
The user does not have access to the application. This means that the application is installed, but the account administrator has allowed access to this application only for specific users |
|
|
|
The public part of the site is closed. To open the public part of the site on an on-premise installation, disable the option "Temporary closure of the public part of the site". Path to the setting: Desktop > Settings > Product Settings > Module Settings > Main Module > Temporary closure of the public part of the site |
Continue Learning
- Update REST handler for payment system sale.paysystem.handler.update
- Get a list of REST handlers for the payment system sale.paysystem.handler.list
- Delete REST handler for payment system sale.paysystem.handler.delete
- Add Payment System sale.paysystem.add
- Update Payment System sale.paysystem.update
- Get a list of payment systems sale.paysystem.list
- Get Payment System Settings sale.paysystem.settings.get
- Update Payment System Settings sale.paysystem.settings.update
- Delete Payment System sale.paysystem.delete
- Pay for an order through a specific payment system sale.paysystem.pay.payment
- Pay an invoice through a specific payment system sale.paysystem.pay.invoice
- Get Payment System Settings for Specific Payment sale.paysystem.settings.payment.get
- Get payment system settings for a specific invoice sale.paysystem.settings.invoice.get