Skip to main content

API structure

Our REST API communicates with the terminal using JSON messages.

All requests and responses use the same JSON message format. Each message includes both system information and transaction data in one JSON object.

The message contains these common fields:

  • topic – The topic of message for transaction.
  • request_id – A unique ID used to match the request and response.
  • app_id – Identifies the app that sends the message.
  • timestamp – The time when the message is created.
  • version – The message protocol version.
  • biz_data – Contains the transaction business data.

The biz_data object holds the main transaction details. Its structure changes depending on the transaction type.

For example:

  • A payment request includes fields like trans_type, order_amount, and merchant_order_no.
  • A payment response includes the transaction result information.

More details about each field and the biz_data structure are explained in the following sections.

Common data

Different aspects of each field are defined in this document according to the following conventions.

  • M: Required parameters
  • C: Required parameters when some conditions are met
  • O: Optional parameters
  • -: Not Present

The common parameters is as follows:

Key Parameter type Request Response Description
topicstringMOMessage topic identifier. Please refer to the topic
request_idstringOOTransaction Request ID, used to receive the corresponding response. The caller needs to remain unique.This parameter must be present when using terminal confirmation mode.
timestampstringOOTimestamp Example: 1698302992263
versionstringOOThe API version.
app_idstringMOThe payment app id registered in CodePay PayPilot, Please refer to the Create payment app id
biz_dataJSONObjectMMBusiness Data. each transaction type has own business data
response_codestring-MThe order payment status code returned by CodePay Register, 000 means the transaction was successful, other means the transaction failed.Please refer to Response code

response_msgString-CFailed transaction error message returned by CodePay Register

Topic

Each transaction type has a message topic:

Key Name
ecrhub.pay.orderSubmit transaction
ecrhub.pay.queryQuery transaction
ecrhub.pay.closeClose transaction
ecrhub.pay.batch.closeBatch close
ecrhub.pay.tip.adjustmentTip adjustment

Transaction message

1. Submit transaction

Send transaction requests to the terminal, such as sale, void, refund, etc.

Message Topic

ecrhub.pay.order

Parameter list

Name Type Request Response Description
trans_typeStringMMSale, Void, Refund etc. Please refer to Transaction type.
merchant_order_noStringMMA unique id assigned by your POS to identify this transaction. No more than 32 alphanumeric characters.
orig_merchant_order_noStringCCThe merchant_order_no from the original transaction. If the transaction type is Void, Refund, Completion, it must be required.
price_currencyStringOOPrice Currency, compliant with ISO-4217 standard, described with a three-character code. For example: "USD"
order_amountStringMMOrder amount in base currency units.
tip_amountStringOOAmount paid for a tip.
tax_amountStringOOAmount paid for a tax.
on_screen_tipbooleanOOWhether or not to enter tips on the CodePay Register page, default is false.
cashback_amountStringOOThe cash-back amount included in the Sale payment request.
pay_method_idStringOOPayment method id. Please refer to Payment method

If the trans_type is Refund, this parameter will not required.
pay_scenarioStringOOPlease refer to PayScenario .
card_network_typeStringOOPlease refer to Card Type.
attachStringO-Additional data. Allows merchants to submit additional data, which will be returned as is.
descriptionStringOODescription of ordered goods or services.A brief description of the goods or services purchased by the customer.
notify_urlStringO-Callback address for payment notification.Receive payment notifications from the CodePay gateway to call back the server address, and only when the transaction goes through the CodePay payment gateway will there be a callback.
expiresStringO-Order expires time, after the expires time is not allowed to be paid, unit: seconds.
confirm_on_terminalbooleanO-Do you need terminal confirmation before proceeding with payment operations? The default is false. When set to true, you need to confirm the order first, otherwise you will directly enter the card reading interface.
receipt_print_modeIntegerO-0: No printing, default value;
1: Print merchant copy;
2: Print customer copy;
3: Print merchant copy + customer.
required_terminal_authenticationbooleanO-When refund or void a transaction, does the store manager role need to authorize this operation on the terminal? default value: false.
on_screen_signaturebooleanO-This parameter controls the display logic of electronic signatures:
  • true: Display the electronic signature page and print the signature information on the purchase order
  • false: The electronic signature page will not be displayed, but the signature area needs to be printed on the purchase order
But even if this parameter is set, CodePay Register still processes electronic signatures according to the following logic in the following situations:
  • Credit card network, APP does not display signature page, fixed on receipt to print signature column

  • Pin debit transactions do not require a signature, the APP does not display a signature page, and the receipt is not printed either
.
trans_noString-MTransaction number of CodePay. which uniquely identifies a transaction.
trans_statusString-MPlease refer to Transaction status.
trans_end_timestring-MTransaction completed time. If trans_status is successful, the returned data will include this parameters. Timezone: Local time zone, the time zone set by the payment terminal, Format: YYYY-MM-DD HH:mm:ss.
cashierstringO-The cashier's id number or name, the transaction will record this field for easy tip counting.
auth_codestring-CAuthentication code. Returned for card transactions.
ref_nostring-CRetrieval Reference Number .Returned for card transactions.
card_nostring-CCard PAN number, Masked per PCI DSS (e.g., 430277****5723). Returned for card transactions.
entry_modestring-CReturned for card transactions:
1: Magnetic stripe swipe,
2: Contact chip,
3: Contactless, 4: Manual entry.
merchant_nostring-CThe merchant number.
merchant_namestring-CThe merchant name.
pay_channel_merchant_idstring-CMerchant id of the payment processor.
pay_channel_terminal_idstring-CTerminal id of the payment processor.
signature_urlstring-CThe image URL of the handwritten signature value needs to be downloaded, converted to Base64, and stored in your database
card_holder_namestring-CThe name of the card holder

2. Query transaction

Retrieve a previous transaction, using merchant order no.

Message Topic

ecrhub.pay.query

Parameter list

Name Type Request Response Description
merchant_order_noStringMMThe merchant_order_no from the original transaction.
trans_typeString-MPlease refer to Transaction type.
price_currencyString-MPrice Currency, compliant with ISO-4217 standard, described with a three-character code. For example: "USD"
order_amountString-MOrder amount in base currency units.
tip_amountString-OAmount paid for a tip.
tax_amountString-OAmount paid for a tax.
cashback_amountString-OThe cash-back amount included in the Sale payment request.
attachString-OAdditional data. Allows merchants to submit additional data, which will be returned as is.
pay_scenarioString-OPlease refer to PayScenario .
pay_method_idString-OPlease refer to Payment method.
card_network_typeString-OPlease refer to Card Type.
trans_noString-MTransaction number of CodePay. which uniquely identifies a transaction.
trans_statusString-MPlease refer to Transaction status.
trans_end_timestring-MTransaction completed time. If trans_status is successful, the returned data will include this parameters. Timezone: Local time zone, the time zone set by the payment terminal, Format: YYYY-MM-DD HH:mm:ss.
cashierstring--The cashier's id number or name, the transaction will record this field for easy tip counting.
auth_codestring-CAuthentication code. Returned for card transactions.
ref_nostring-CRetrieval Reference Number .Returned for card transactions.
card_nostring-CCard PAN number, Masked per PCI DSS (e.g., 430277****5723). Returned for card transactions.
entry_modestring-CReturned for card transactions:
1: Magnetic stripe swipe,
2: Contact chip,
3: Contactless, 4: Manual entry.
merchant_nostring-CThe merchant no.
merchant_namestring-CThe merchant name.
pay_channel_merchant_idstring-CMerchant id of the payment processor.
pay_channel_terminal_idstring-CTerminal id of the payment processor.

3. Close transaction

Cancel the current pending transaction screen.

Message Topic

ecrhub.pay.close

Parameter list

Name Type Request Response Description
merchant_order_noStringCCThe merchant_order_no from the original transaction.

4. Batch Close

Message Topic

ecrhub.pay.batch.close

5. Tip Adjustment

Message Topic

ecrhub.pay.tip.adjustment

Parameter list

Name Type Request Response Description
merchant_order_noStringM-The merchant_order_no from the original transaction.
tip_adjustment_amountStringM-Amount for tip adjustment