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 2
2
See: https://siftscience.com/docs/references/events-api
3
3
"""
4
4
5
+ import decimal
5
6
import json
6
7
import requests
7
8
import requests .auth
@@ -26,6 +27,11 @@ def _quote_path(s):
26
27
# optional arg to override this
27
28
return urllib .parse .quote (s , '' )
28
29
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 )
29
35
30
36
class Client (object ):
31
37
@@ -165,7 +171,7 @@ def track(
165
171
try :
166
172
response = self .session .post (
167
173
path ,
168
- data = json .dumps (properties ),
174
+ data = json .dumps (properties , cls = DecimalEncoder ),
169
175
headers = headers ,
170
176
timeout = timeout ,
171
177
params = params )
Original file line number Diff line number Diff line change 3
3
import sys
4
4
import unittest
5
5
import warnings
6
+ from decimal import Decimal
6
7
7
8
import mock
8
9
import requests .exceptions
@@ -19,7 +20,7 @@ def valid_transaction_properties():
19
20
return {
20
21
'$buyer_user_id' : '123456' ,
21
22
'$seller_user_id' : '654321' ,
22
- '$amount' : 1253200 ,
23
+ '$amount' : Decimal ( ' 1253200.0' ) ,
23
24
'$currency_code' : 'USD' ,
24
25
'$time' : int (datetime .datetime .now ().strftime ('%s' )),
25
26
'$transaction_id' : 'my_transaction_id' ,
Original file line number Diff line number Diff line change 1
1
import datetime
2
+ from decimal import Decimal
2
3
import warnings
3
4
import json
4
5
import mock
@@ -16,7 +17,7 @@ def valid_transaction_properties():
16
17
return {
17
18
'$buyer_user_id' : '123456' ,
18
19
'$seller_user_id' : '654321' ,
19
- '$amount' : 1253200 ,
20
+ '$amount' : Decimal ( ' 1253200.0' ) ,
20
21
'$currency_code' : 'USD' ,
21
22
'$time' : int (datetime .datetime .now ().strftime ('%s' )),
22
23
'$transaction_id' : 'my_transaction_id' ,
You can’t perform that action at this time.
0 commit comments