# Sending transaction data back to Custos from contracted vendors Custos-Enterprise API-P01 V1.0 When the employees from our enterprise customers go to our contracted vendors to buy/rent/repair something, the transaction details will be sent back to our database to accumulate the leaves and carbons. Our contracted vendors will call this API after the transaction has completed. [toc] ## Initiate 1. Request parameters: (1) Contracted vendor's serial number (#corp_data_id) (2) Contracted vendor item id: id of items that customers buy/rent/repair, defined by vendor. (#vendor_item_id) (3) Contracted vendor item name: name of items that customers buy/rent/repair, defined by vendor. (#item_name) (4) Employee cellphone number: Enterprise customer employee cellphone number keeps in contracted vendor's database after calling [API-P02](https://hackmd.io/@custos-it/B1GGjiiYn) authentication. (#to_emp_phone) (5) Action code: Buy = 5, Rent = 4, Repair = 2, Refund = 7 (#category_id) (6) Trading amount (#total_amt) (7) Date (#create_date) (8) Country and language setting (#language_setting) 2. Create system log: Contracted vendor #corp_data_id|Sending transaction data back|Process starts ## API Process Start 1. Select the following data by cellphone number (#to_emp_phone) from database (1) Backend login ID of the enterprise (#to_corp_id) (2) Serial number of the enterprise (#to_corp_data_id) (3) Employee ID (#to_emp_id) (4) Employee serial number (#to_emp_data_id) 2. Select the following data by contracted vendor's serial number (#corp_data_id) (1) Backend login ID of the contracted vendor (#corp_id) (2) Contact person employee id of the contracted vendor (#emp_id) (3) Contact person employee serial number of the contracted vendor (#emp_data_id) (4) Contact person cellphone number of the contracted vendor (#emp_phone) (5) First picture of the item that is uploaded to the marketplace by the contracted vendor (#item_image) 3. Insert new transaction data in corp_fm_transaction table *insert into corp_fm_transaction (vendor_item_id, corp_id, corp_data_id, to_corp_id, to_corp_data_id, emp_id, emp_data_id, to_emp_id, to_emp_data_id, emp_phone, to_emp_phone, category_id, total_amt, item_name, item_image, modify_oper, language_setting) values (#vendor_item_id, #corp_id, #corp_data_id, #to_corp_id, #to_corp_data_id, #emp_id, #emp_data_id, #to_emp_id, #to_emp_data_id, #emp_phone, #to_emp_phone, #category_id, #total_amt, #item_name, #item_image, #corp_id, #language_setting)* 4. If no data returned from the above step 1 or 2, create a system log: Contracted vendor #corp_data_id|Sending transaction data back: No data found when processing the transaction data|Processing 5. Return result = 'N', message = (the log content). ## API Process End Create system log: Contracted vendor #corp_data_id|Sending transaction data back|Process ends ## Exception Handling If there is error/exception occurs, create an error log: [YYYYMMDDHHMMSS] Enterprise-API-P01 Error! Message: (the system exception messages). ## Specification and Sample |API No.|Enterprise-API-P01| |-|-| |API Name|setTransactionRecords| |URL|${url}/APP/setData/setTransactionRecords| |Purpose|Receiving data from contracted vendor via API| |Description|Contracted vendors can send back all transaction details via this API and store in Custos database.| |Content-Type|application/json| **Request** |Parameters|Data Type|Mandatory|Length|Description| |-|-|:-:|:-:|-| |corp_data_id|INT|Y||Contracted vendor's serial number| |vendor_item_id|String|Y|45|ID of items that customers buy/rent/repair, defined by vendor| |item_name|String|Y|256|Name of items that customers buy/rent/repair, defined by vendor| |to_emp_phone|String|Y|16|Enterprise customer employee cellphone number| |category_id|INT|Y||Buy = 5, Rent = 4, Repair = 2, Repair = 7| |total_amt|Float|Y||Trading amount| |create_date|DateTime|Y||Trading date| |language_setting|String|Y|10|Country and language setting| **Response** |Parameters|Data Type|Mandatory|Description| |-|-|:-:|-| |result|String|Y|API process result,Y: Successfully, N: Failure| |message|String|N|API process failure description| **Request Sample** ```javascript var input = { "corp_data_id": 12, "vendor_item_id": "c-002135", "item_name": "1 liter cup", "to_emp_phone": "0912345678", "category_id": 3, "total_amt": "200", "create_date": "2023-06-01 10:03:28", "language_setting": "en-SG" } ``` **Response Sample** ```javascript { "result": "Y", //API process result "message": "..." //API process failure description } ```