Skip to content

Commit

Permalink
feat: set client_user_agent on new order body
Browse files Browse the repository at this point in the history
get client ip from requet ip instead
  • Loading branch information
leomp12 committed Feb 9, 2023
1 parent e9bccda commit 9b28809
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
3 changes: 1 addition & 2 deletions bin/web.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ function middleware (id, meta, body, respond, req, res, resource, verb, endpoint
respond({}, null, 403, 121, 'Undefined or invalid Store ID')
return
}

// pass to endpoint
endpoint(id, meta, body, respond, storeId, ip)
endpoint(id, meta, body, respond, storeId, ip, req.headers['user-agent'])
} else {
respond({}, null, 403, 100, 'Who are you? Unknown IP address')
}
Expand Down
1 change: 1 addition & 0 deletions routes/#checkout.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ module.exports = (checkoutBody, checkoutRespond, storeId) => {
'utm',
'affiliate_code',
'browser_ip',
'client_user_agent',
'channel_id',
'channel_type',
'domain',
Expand Down
12 changes: 8 additions & 4 deletions routes/@checkout.js
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,11 @@ const schema = {
'maxLength': 50,
'description': 'IP address of the browser used by the customer when placing the order'
},
'client_user_agent': {
'type': 'string',
'maxLength': 255,
'description': 'User-Agent of the browser (if any) used by the customer'
},
'channel_id': {
'type': 'integer',
'min': 10000,
Expand Down Expand Up @@ -1053,7 +1058,7 @@ const GET = (id, meta, body, respond) => {
}
}

const POST = (id, meta, body, respond, storeId, ip) => {
const POST = (id, meta, body, respond, storeId, ip, userAgent) => {
// logger.log(JSON.stringify(body, null, 2))
// ajv
const valid = validate(body)
Expand All @@ -1062,9 +1067,8 @@ const POST = (id, meta, body, respond, storeId, ip) => {
} else {
// request body validated
// handle checkout
if (!body.browser_ip && ip) {
body.browser_ip = ip
}
body.browser_ip = ip || body.browser_ip
body.client_user_agent = userAgent || body.client_user_agent
checkout(body, respond, storeId)
}
}
Expand Down
5 changes: 5 additions & 0 deletions routes/create_transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,11 @@ const schema = {
'maxLength': 50,
'description': 'IP address of the browser used by the customer when placing the order'
},
'client_user_agent': {
'type': 'string',
'maxLength': 255,
'description': 'User-Agent of the browser (if any) used by the customer'
},
'channel_id': {
'type': 'integer',
'min': 10000,
Expand Down

0 comments on commit 9b28809

Please sign in to comment.