File tree Expand file tree Collapse file tree 3 files changed +11
-3
lines changed Expand file tree Collapse file tree 3 files changed +11
-3
lines changed Original file line number Diff line number Diff line change 22See: https://siftscience.com/docs/references/events-api
33"""
44
5+ import decimal
56import json
67import requests
78import requests .auth
@@ -26,6 +27,11 @@ def _quote_path(s):
2627 # optional arg to override this
2728 return urllib .parse .quote (s , '' )
2829
30+ class DecimalEncoder (json .JSONEncoder ):
31+ def default (self , o ):
32+ if isinstance (o , decimal .Decimal ):
33+ return (str (o ),)
34+ return super (DecimalEncoder , self ).default (o )
2935
3036class Client (object ):
3137
@@ -165,7 +171,7 @@ def track(
165171 try :
166172 response = self .session .post (
167173 path ,
168- data = json .dumps (properties ),
174+ data = json .dumps (properties , cls = DecimalEncoder ),
169175 headers = headers ,
170176 timeout = timeout ,
171177 params = params )
Original file line number Diff line number Diff line change 33import sys
44import unittest
55import warnings
6+ from decimal import Decimal
67
78import mock
89import requests .exceptions
@@ -19,7 +20,7 @@ def valid_transaction_properties():
1920 return {
2021 '$buyer_user_id' : '123456' ,
2122 '$seller_user_id' : '654321' ,
22- '$amount' : 1253200 ,
23+ '$amount' : Decimal ( ' 1253200.0' ) ,
2324 '$currency_code' : 'USD' ,
2425 '$time' : int (datetime .datetime .now ().strftime ('%s' )),
2526 '$transaction_id' : 'my_transaction_id' ,
Original file line number Diff line number Diff line change 11import datetime
2+ from decimal import Decimal
23import warnings
34import json
45import mock
@@ -16,7 +17,7 @@ def valid_transaction_properties():
1617 return {
1718 '$buyer_user_id' : '123456' ,
1819 '$seller_user_id' : '654321' ,
19- '$amount' : 1253200 ,
20+ '$amount' : Decimal ( ' 1253200.0' ) ,
2021 '$currency_code' : 'USD' ,
2122 '$time' : int (datetime .datetime .now ().strftime ('%s' )),
2223 '$transaction_id' : 'my_transaction_id' ,
You can’t perform that action at this time.
0 commit comments