feat: added spend limits to customer billing controls
This commit is contained in:
@@ -16,7 +16,8 @@
|
||||
send_email_receipts?: boolean | null,
|
||||
processor?: object | null,
|
||||
processors?: object | null,
|
||||
auto_topups?: array | null
|
||||
auto_topups?: array | null,
|
||||
spend_limits?: array | null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,22 +54,22 @@ local updated_fields = {}
|
||||
-- For scalar fields (string, boolean, number), use JSON.SET with the value
|
||||
-- For object fields (metadata, processor, processors), encode as JSON
|
||||
|
||||
if updates.name ~= nil and updates.name ~= cjson.null then
|
||||
if not is_nil(updates.name) then
|
||||
redis.call('JSON.SET', cache_key, '$.name', cjson.encode(updates.name))
|
||||
table.insert(updated_fields, 'name')
|
||||
end
|
||||
|
||||
if updates.email ~= nil and updates.email ~= cjson.null then
|
||||
if not is_nil(updates.email) then
|
||||
redis.call('JSON.SET', cache_key, '$.email', cjson.encode(updates.email))
|
||||
table.insert(updated_fields, 'email')
|
||||
end
|
||||
|
||||
if updates.fingerprint ~= nil and updates.fingerprint ~= cjson.null then
|
||||
if not is_nil(updates.fingerprint) then
|
||||
redis.call('JSON.SET', cache_key, '$.fingerprint', cjson.encode(updates.fingerprint))
|
||||
table.insert(updated_fields, 'fingerprint')
|
||||
end
|
||||
|
||||
if updates.send_email_receipts ~= nil and updates.send_email_receipts ~= cjson.null then
|
||||
if not is_nil(updates.send_email_receipts) then
|
||||
local bool_val = 'false'
|
||||
if updates.send_email_receipts == true then
|
||||
bool_val = 'true'
|
||||
@@ -77,23 +78,23 @@ if updates.send_email_receipts ~= nil and updates.send_email_receipts ~= cjson.n
|
||||
table.insert(updated_fields, 'send_email_receipts')
|
||||
end
|
||||
|
||||
if updates.metadata ~= nil and updates.metadata ~= cjson.null then
|
||||
if not is_nil(updates.metadata) then
|
||||
redis.call('JSON.SET', cache_key, '$.metadata', cjson.encode(updates.metadata))
|
||||
table.insert(updated_fields, 'metadata')
|
||||
end
|
||||
|
||||
if updates.processor ~= nil and updates.processor ~= cjson.null then
|
||||
if not is_nil(updates.processor) then
|
||||
redis.call('JSON.SET', cache_key, '$.processor', cjson.encode(updates.processor))
|
||||
table.insert(updated_fields, 'processor')
|
||||
end
|
||||
|
||||
if updates.processors ~= nil and updates.processors ~= cjson.null then
|
||||
if not is_nil(updates.processors) then
|
||||
redis.call('JSON.SET', cache_key, '$.processors', cjson.encode(updates.processors))
|
||||
table.insert(updated_fields, 'processors')
|
||||
end
|
||||
|
||||
if updates.auto_topups ~= nil then
|
||||
if updates.auto_topups == cjson.null then
|
||||
if is_nil(updates.auto_topups) then
|
||||
redis.call('JSON.SET', cache_key, '$.auto_topups', 'null')
|
||||
else
|
||||
redis.call('JSON.SET', cache_key, '$.auto_topups', cjson.encode(updates.auto_topups))
|
||||
@@ -101,4 +102,13 @@ if updates.auto_topups ~= nil then
|
||||
table.insert(updated_fields, 'auto_topups')
|
||||
end
|
||||
|
||||
if updates.spend_limits ~= nil then
|
||||
if is_nil(updates.spend_limits) then
|
||||
redis.call('JSON.SET', cache_key, '$.spend_limits', 'null')
|
||||
else
|
||||
redis.call('JSON.SET', cache_key, '$.spend_limits', cjson.encode(updates.spend_limits))
|
||||
end
|
||||
table.insert(updated_fields, 'spend_limits')
|
||||
end
|
||||
|
||||
return cjson.encode({ success = true, updated_fields = updated_fields })
|
||||
|
||||
Reference in New Issue
Block a user