Add Payment sale.payment.add

Scope: sale

Who can execute the method: administrator

This method adds a new payment.

Method Parameters

Required parameters are marked with *

Name
type

Description

fields*
object

Field values (detailed description provided below) for creating a payment in the form of a structure:

fields: {
            orderId: "value",
            paySystemId: "value",
            paid: "value",
            datePaid: "value",
            empPaidId: "value",
            psStatus: "value",
            psStatusCode: "value",
            psStatusDescription: "value",
            psStatusMessage: "value",
            psSum: "value",
            psCurrency: "value",
            psResponseDate: "value",
            payVoucherNum: "value",
            payVoucherDate: "value",
            datePayBefore: "value",
            dateBill: "value",
            xmlId: "value",
            sum: "value",
            companyId: "value",
            payReturnNum: "value",
            priceCod: "value",
            payReturnDate: "value",
            empReturnId: "value",
            payReturnComment: "value",
            responsibleId: "value",
            empResponsibleId: "value",
            isReturn: "value",
            comments: "value",
            updated1c: "value",
            id1c: "value",
            version1c: "value",
            externalPayment: "value",
            psInvoiceId: "value",
            marked: "value",
            reasonMarked: "value",
            empMarkedId: "value",
        }
        

Parameter fields

Required parameters are marked with *

Name
type

Description

orderId*
sale_order.id

Order identifier

paySystemId*
sale_paysystem.id

Payment system identifier

paid
string

Payment status:

  • Y — yes
  • N — no

Defaults to N

datePaid
datetime

Payment date

empPaidId
user.id

Identifier of the user who made the payment

psStatus
string

Payment system status flag — whether the payment was successful. Options:

  • Y — yes
  • N — no

Defaults to null

psStatusCode
string

Payment system status code

psStatusDescription
string

Description of the payment system's result

psStatusMessage
string

Message from the payment system

psSum
double

Payment system amount

psCurrency
string

Payment system currency

psResponseDate
datetime

Payment system response date

payVoucherNum
string

Payment document number

payVoucherDate
datetime

Payment document date

datePayBefore
datetime

Deprecated.
Date by which the invoice must be paid

dateBill
datetime

Invoice date

xmlId
string

External identifier

sum
double

Payment amount

companyId
integer

Identifier of the company that will receive the payment

Currently not used

payReturnNum
string

Return document number

priceCod
double

Relevant only for on-premise version
Cost of payment upon delivery. Used for cash on delivery

payReturnDate
date

Return document date

empReturnId
user.id

Identifier of the user who processed the return

payReturnComment
string

Return comment

responsibleId
user.id

Identifier of the user responsible for the payment

empResponsibleId
user.id

Identifier of the user who assigned the responsible person

isReturn
string

Was the return processed:

  • Y — yes
  • N — no

Defaults to N

comments
string

Payment comments

updated1c
string

Payment updated via QuickBooks and other similar platforms:

  • Y — yes
  • N — no

Defaults to N

id1c
string

Identifier in QuickBooks and other similar platforms

version1c
string

Payment document version from QuickBooks and other similar platforms

externalPayment
string

Relevant only for on-premise version
External payment or not. Used for import from QuickBooks and other similar platforms via XML

  • Y — yes
  • F — yes, loaded with the order
  • N — no

Defaults to N

psInvoiceId
string

Payment identifier in the payment system

marked
string

Marking flag. Indicates whether the payment is marked as problematic:

  • Y — yes
  • N — no

Defaults to N

reasonMarked
string

Reason for marking

empMarkedId
user.id

Identifier of the user who marked the payment

Code Examples

How to Use Examples in Documentation

curl -X POST \
        -H "Content-Type: application/json" \
        -H "Accept: application/json" \
        -d '{"fields":{"orderId":200,"paySystemId":1,"paid":"Y","datePaid":"2024-04-10T10:00:00","empPaidId":1,"psStatus":"Y","psStatusCode":"","psStatusDescription":"","psStatusMessage":"","psSum":100,"psCurrency":"USD","psResponseDate":"2024-04-10T10:00:00","payVoucherNum":"","payVoucherDate":"2024-04-10T10:00:00","datePayBefore":"2024-04-10T10:00:00","dateBill":"2024-04-10T10:00:00","xmlId":"","sum":100,"companyId":1,"payReturnNum":"","priceCod":100,"payReturnDate":"2024-04-10T10:00:00","empReturnId":1,"payReturnComment":"","responsibleId":1,"empResponsibleId":1,"isReturn":"N","comments":"","updated1c":"N","id1c":"","version1c":"","externalPayment":"N","psInvoiceId":1,"marked":"N","reasonMarked":"","empMarkedId":1}}' \
        https://**put_your_bitrix24_address**/rest/**put_your_user_id_here**/**put_your_webhook_here**/sale.payment.add
        
curl -X POST \
        -H "Content-Type: application/json" \
        -H "Accept: application/json" \
        -d '{"fields":{"orderId":200,"paySystemId":1,"paid":"Y","datePaid":"2024-04-10T10:00:00","empPaidId":1,"psStatus":"Y","psStatusCode":"","psStatusDescription":"","psStatusMessage":"","psSum":100,"psCurrency":"USD","psResponseDate":"2024-04-10T10:00:00","payVoucherNum":"","payVoucherDate":"2024-04-10T10:00:00","datePayBefore":"2024-04-10T10:00:00","dateBill":"2024-04-10T10:00:00","xmlId":"","sum":100,"companyId":1,"payReturnNum":"","priceCod":100,"payReturnDate":"2024-04-10T10:00:00","empReturnId":1,"payReturnComment":"","responsibleId":1,"empResponsibleId":1,"isReturn":"N","comments":"","updated1c":"N","id1c":"","version1c":"","externalPayment":"N","psInvoiceId":1,"marked":"N","reasonMarked":"","empMarkedId":1},"auth":"**put_access_token_here**"}' \
        https://**put_your_bitrix24_address**/rest/sale.payment.add
        
try
        {
        	const response = await $b24.callMethod(
        		'sale.payment.add',
        		{
        			fields: {
        				orderId: 200,
        				paySystemId: 1,
        				paid: 'Y',
        				datePaid: '2024-04-10T10:00:00',
        				empPaidId: 1,
        				psStatus: 'Y',
        				psStatusCode: '',
        				psStatusDescription: '',
        				psStatusMessage: '',
        				psSum: 100,
        				psCurrency: 'USD',
        				psResponseDate: '2024-04-10T10:00:00',
        				payVoucherNum: '',
        				payVoucherDate: '2024-04-10T10:00:00',
        				datePayBefore: '2024-04-10T10:00:00',
        				dateBill: '2024-04-10T10:00:00',
        				xmlId: '',
        				sum: 100,
        				companyId: 1,
        				payReturnNum: '',
        				priceCod: 100,
        				payReturnDate: '2024-04-10T10:00:00',
        				empReturnId: 1,
        				payReturnComment: '',
        				responsibleId: 1,
        				empResponsibleId: 1,
        				isReturn: 'N',
        				comments: '',
        				updated1c: 'N',
        				id1c: '',
        				version1c: '',
        				externalPayment: 'N',
        				psInvoiceId: 1,
        				marked: 'N',
        				reasonMarked: '',
        				empMarkedId: 1,
        			}
        		}
        	);
        	
        	const result = response.getData().result;
        	console.info(result);
        }
        catch( error )
        {
        	console.error(error);
        }
        
try {
            $response = $b24Service
                ->core
                ->call(
                    'sale.payment.add',
                    [
                        'fields' => [
                            'orderId'             => 200,
                            'paySystemId'         => 1,
                            'paid'               => 'Y',
                            'datePaid'           => '2024-04-10T10:00:00',
                            'empPaidId'          => 1,
                            'psStatus'           => 'Y',
                            'psStatusCode'       => '',
                            'psStatusDescription' => '',
                            'psStatusMessage'    => '',
                            'psSum'              => 100,
                            'psCurrency'         => 'USD',
                            'psResponseDate'     => '2024-04-10T10:00:00',
                            'payVoucherNum'      => '',
                            'payVoucherDate'     => '2024-04-10T10:00:00',
                            'datePayBefore'      => '2024-04-10T10:00:00',
                            'dateBill'           => '2024-04-10T10:00:00',
                            'xmlId'              => '',
                            'sum'                => 100,
                            'companyId'          => 1,
                            'payReturnNum'       => '',
                            'priceCod'           => 100,
                            'payReturnDate'      => '2024-04-10T10:00:00',
                            'empReturnId'        => 1,
                            'payReturnComment'   => '',
                            'responsibleId'      => 1,
                            'empResponsibleId'   => 1,
                            'isReturn'           => 'N',
                            'comments'           => '',
                            'updated1c'          => 'N',
                            'id1c'               => '',
                            'version1c'          => '',
                            'externalPayment'    => 'N',
                            'psInvoiceId'        => 1,
                            'marked'             => 'N',
                            'reasonMarked'       => '',
                            'empMarkedId'        => 1,
                        ],
                    ]
                );
        
            $result = $response
                ->getResponseData()
                ->getResult();
        
            echo 'Success: ' . print_r($result, true);
        
        } catch (Throwable $e) {
            error_log($e->getMessage());
            echo 'Error adding payment: ' . $e->getMessage();
        }
        
BX24.callMethod(
            'sale.payment.add',
            {
                fields: {
                    orderId: 200,
                    paySystemId: 1,
                    paid: 'Y',
                    datePaid: '2024-04-10T10:00:00',
                    empPaidId: 1,
                    psStatus: 'Y',
                    psStatusCode: '',
                    psStatusDescription: '',
                    psStatusMessage: '',
                    psSum: 100,
                    psCurrency: 'USD',
                    psResponseDate: '2024-04-10T10:00:00',
                    payVoucherNum: '',
                    payVoucherDate: '2024-04-10T10:00:00',
                    datePayBefore: '2024-04-10T10:00:00',
                    dateBill: '2024-04-10T10:00:00',
                    xmlId: '',
                    sum: 100,
                    companyId: 1,
                    payReturnNum: '',
                    priceCod: 100,
                    payReturnDate: '2024-04-10T10:00:00',
                    empReturnId: 1,
                    payReturnComment: '',
                    responsibleId: 1,
                    empResponsibleId: 1,
                    isReturn: 'N',
                    comments: '',
                    updated1c: 'N',
                    id1c: '',
                    version1c: '',
                    externalPayment: 'N',
                    psInvoiceId: 1,
                    marked: 'N',
                    reasonMarked: '',
                    empMarkedId: 1,
                }
            },
            function(result) {
                if (result.error()) {
                    console.error(result.error());
                } else {
                    console.info(result.data());
                }
            }
        );
        
require_once('crest.php');
        
        $result = CRest::call(
            'sale.payment.add',
            [
                'fields' => [
                    'orderId' => 200,
                    'paySystemId' => 1,
                    'paid' => 'Y',
                    'datePaid' => '2024-04-10T10:00:00',
                    'empPaidId' => 1,
                    'psStatus' => 'Y',
                    'psStatusCode' => '',
                    'psStatusDescription' => '',
                    'psStatusMessage' => '',
                    'psSum' => 100,
                    'psCurrency' => 'USD',
                    'psResponseDate' => '2024-04-10T10:00:00',
                    'payVoucherNum' => '',
                    'payVoucherDate' => '2024-04-10T10:00:00',
                    'datePayBefore' => '2024-04-10T10:00:00',
                    'dateBill' => '2024-04-10T10:00:00',
                    'xmlId' => '',
                    'sum' => 100,
                    'companyId' => 1,
                    'payReturnNum' => '',
                    'priceCod' => 100,
                    'payReturnDate' => '2024-04-10T10:00:00',
                    'empReturnId' => 1,
                    'payReturnComment' => '',
                    'responsibleId' => 1,
                    'empResponsibleId' => 1,
                    'isReturn' => 'N',
                    'comments' => '',
                    'updated1c' => 'N',
                    'id1c' => '',
                    'version1c' => '',
                    'externalPayment' => 'N',
                    'psInvoiceId' => 1,
                    'marked' => 'N',
                    'reasonMarked' => '',
                    'empMarkedId' => 1,
                ]
            ]
        );
        
        echo '<PRE>';
        print_r($result);
        echo '</PRE>';
        

Response Handling

HTTP status: 200

{
            "result": {
                "payment": {
                    "accountNumber": "356\/1",
                    "comments": "",
                    "companyId": 1,
                    "currency": "USD",
                    "dateBill": "2024-04-10T09:00:00+02:00",
                    "dateMarked": "2024-04-16T16:32:49+02:00",
                    "datePaid": "2024-04-10T09:00:00+02:00",
                    "datePayBefore": "2024-04-10T09:00:00+02:00",
                    "dateResponsibleId": "2024-04-16T16:32:49+02:00",
                    "empMarkedId": 1,
                    "empPaidId": 1,
                    "empResponsibleId": 1,
                    "empReturnId": 1,
                    "externalPayment": "N",
                    "id": 144,
                    "id1c": "",
                    "isReturn": "N",
                    "marked": "N",
                    "orderId": 200,
                    "paid": "Y",
                    "payReturnComment": "",
                    "payReturnDate": "2024-04-10T09:00:00+02:00",
                    "payReturnNum": "",
                    "paySystemId": 1,
                    "paySystemIsCash": "N",
                    "paySystemName": "Bank Transfer (Company)",
                    "paySystemXmlId": "",
                    "payVoucherDate": "2024-04-10T09:00:00+02:00",
                    "payVoucherNum": "",
                    "priceCod": "100",
                    "psCurrency": "USD",
                    "psInvoiceId": 1,
                    "psResponseDate": "2024-04-10T09:00:00+02:00",
                    "psStatus": "Y",
                    "psStatusCode": "",
                    "psStatusDescription": "",
                    "psStatusMessage": "",
                    "psSum": 100,
                    "reasonMarked": "",
                    "responsibleId": 1,
                    "sum": 100,
                    "updated1c": "N",
                    "version1c": "",
                    "xmlId": ""
                }
            },
            "time": {
                "start": 1713277968.822151,
                "finish": 1713277972.577136,
                "duration": 3.7549850940704346,
                "processing": 3.3574018478393555,
                "date_start": "2024-04-16T17:32:48+02:00",
                "date_finish": "2024-04-16T17:32:52+02:00"
            }
        }
        

Returned Data

Name
type

Description

result
object

Root element of the response

payment
sale_order_payment

Object with information about the added payment

time
time

Information about the request execution time

Error Handling

HTTP status: 400

{
            "error":200040300020,
            "error_description":"Access Denied"
        }
        

Name
type

Description

error
string

String error code. It may consist of digits, Latin letters, and underscores

error_description
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

200040300020

Insufficient rights to add payment

100

Parameter fields is not specified or is empty

0

Required fields are not provided

0

Other errors (e.g., fatal errors)

Statuses and System Error Codes

HTTP Status: 20x, 40x, 50x

The errors described below may occur when calling any method.

Status

Code
Error Message

Description

500

INTERNAL_SERVER_ERROR
Internal server error

An internal server error has occurred, please contact the server administrator or Bitrix24 technical support

500

ERROR_UNEXPECTED_ANSWER
Server returned an unexpected response

An internal server error has occurred, please contact the server administrator or Bitrix24 technical support

503

QUERY_LIMIT_EXCEEDED
Too many requests

The request intensity limit has been exceeded

405

ERROR_BATCH_METHOD_NOT_ALLOWED
Method is not allowed for batch usage

The current method is not allowed to be called using batch

400

ERROR_BATCH_LENGTH_EXCEEDED
Max batch length exceeded

The maximum length of parameters passed to the batch method has been exceeded

401

NO_AUTH_FOUND
Wrong authorization data

Invalid access token or webhook code

400

INVALID_REQUEST
Https required

The methods must be called using the HTTPS protocol

503

OVERLOAD_LIMIT
REST API is blocked due to overload

The REST API is blocked due to overload. This is a manual individual block, to remove it you need to contact Bitrix24 technical support

403

ACCESS_DENIED
REST API is available only on commercial plans

The REST API is available only on commercial plans

403

INVALID_CREDENTIALS
Invalid request credentials

The user whose access token or webhook was used to call the method lacks permissions

404

ERROR_MANIFEST_IS_NOT_AVAILABLE
Manifest is not available

The manifest is not available

403

insufficient_scope
The request requires higher privileges than provided by the webhook token

The request requires higher privileges than those provided by the webhook token

401

expired_token
The access token provided has expired

The provided access token has expired

403

user_access_error
The user does not have access to the application

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

500

PORTAL_DELETED
Portal was deleted

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