@@ -131,7 +131,7 @@ validate(Context) ->
131
131
validate_limits (Context , ? HTTP_GET ) ->
132
132
load_limit (Context );
133
133
validate_limits (Context , ? HTTP_POST ) ->
134
- cb_context :validate_request_data (<<" limits" >>, Context , fun on_successful_validation /1 ).
134
+ cb_context :validate_request_data (<<" limits" >>, cleanup_leaky_keys ( Context ) , fun on_successful_validation /1 ).
135
135
136
136
-spec post (cb_context :context ()) -> cb_context :context ().
137
137
post (Context ) ->
@@ -152,7 +152,38 @@ post(Context) ->
152
152
% %--------------------------------------------------------------------
153
153
-spec load_limit (cb_context :context ()) -> cb_context :context ().
154
154
load_limit (Context ) ->
155
- maybe_handle_load_failure (crossbar_doc :load (? PVT_TYPE , Context , ? TYPE_CHECK_OPTION (? PVT_TYPE ))).
155
+ leak_pvt_fields (crossbar_doc :load (? PVT_TYPE , Context , ? TYPE_CHECK_OPTION (? PVT_TYPE ))).
156
+
157
+ -spec leak_pvt_fields (cb_context :context ()) -> cb_context :context ().
158
+ -spec leak_pvt_fields (cb_context :context (), crossbar_status ()) -> cb_context :context ().
159
+ leak_pvt_fields (Context ) ->
160
+ leak_pvt_fields (Context , cb_context :resp_status (Context )).
161
+
162
+ leak_pvt_fields (Context , 'success' ) ->
163
+ Routines = [fun leak_pvt_allow_postpay /1
164
+ ,fun leak_pvt_max_postpay_amount /1
165
+ ],
166
+ cb_context :setters (Context , Routines );
167
+ leak_pvt_fields (Context , _Status ) ->
168
+ maybe_handle_load_failure (Context ).
169
+
170
+ -spec leak_pvt_allow_postpay (cb_context :context ()) -> cb_context :context ().
171
+ leak_pvt_allow_postpay (Context ) ->
172
+ cb_context :set_resp_data (Context
173
+ ,kz_json :set_value (<<" allow_postpay" >>
174
+ ,kz_json :is_true (<<" pvt_allow_postpay" >>, cb_context :doc (Context ), 'false' )
175
+ ,cb_context :resp_data (Context )
176
+ )
177
+ ).
178
+
179
+ -spec leak_pvt_max_postpay_amount (cb_context :context ()) -> cb_context :context ().
180
+ leak_pvt_max_postpay_amount (Context ) ->
181
+ cb_context :set_resp_data (Context
182
+ ,kz_json :set_value (<<" max_postpay_amount" >>
183
+ ,abs (kz_json :get_number_value (<<" pvt_max_postpay_amount" >>, cb_context :doc (Context ), 0 ))
184
+ ,cb_context :resp_data (Context )
185
+ )
186
+ ).
156
187
157
188
% %--------------------------------------------------------------------
158
189
% % @private
@@ -192,3 +223,18 @@ maybe_handle_load_failure(Context, 404) ->
192
223
,{fun cb_context :set_doc /2 , crossbar_doc :update_pvt_parameters (JObj , Context )}
193
224
]);
194
225
maybe_handle_load_failure (Context , _RespCode ) -> Context .
226
+
227
+ % %--------------------------------------------------------------------
228
+ % % @private
229
+ % % @doc
230
+ % %
231
+ % % @end
232
+ % %--------------------------------------------------------------------
233
+ -spec cleanup_leaky_keys (cb_context :context ()) -> cb_context :context ().
234
+ cleanup_leaky_keys (Context ) ->
235
+ RemoveKeys = [<<" allow_postpay" >>
236
+ ,<<" max_postpay_amount" >>
237
+ ],
238
+ ReqData = kz_json :delete_keys (RemoveKeys , cb_context :req_data (Context )),
239
+ cb_context :set_req_data (Context , ReqData ).
240
+
0 commit comments