Standardise currency value storage as cents (StripeQuantumCurrencyAmountField) #955
Description
Stripe handles all currency values as integer cents, but we currently have a mixture of storage as cent and as decimals.
StripeDecimalCurrencyAmountField
stores as decimal dollar (etc) values, ie $1.99 = Decimal("1.99")
)
StripeQuantumCurrencyAmountField
stores as integer cents values, ie $1.99 = int(199)
Currently we have something like 16 Decimal fields and 12 Quantum fields (see below). 3 of the Quantum fields are new since 2.0 (those in PaymentIntent), so we could potentially switch them to decimal before 2.1 release.
We should have a documented policy on this (eg a "don't use this for new fields" note in the docstring of one of those field classes?) , and ultimately aim to switch all values to either cents or decimal.
Obviously migrating existing fields needs to be done very carefully so users don't accidentally send value 100x to large or small - I think the approach is a good idea -
dj-stripe/djstripe/models/core.py
Lines 727 to 728 in b247268
Thoughts @kavdev (cc @jleclanche )?
dump of current field usage, (editted from result ack ".* = StripeDecimalCurrencyAmountField|^class [^\(]*" -o
on current master)
Decimal:
core.py
36:class BalanceTransaction
81: amount = StripeDecimalCurrencyAmountField
82: amount_refunded = StripeDecimalCurrencyAmountField
connect.py
464:class Transfer
478: amount = StripeDecimalCurrencyAmountField
479: amount_reversed = StripeDecimalCurrencyAmountField
payment_methods.py
369:class Source
374: amount = StripeDecimalCurrencyAmountField
billing.py
27:class Coupon
29: amount_off = StripeDecimalCurrencyAmountField
126:class Invoice
153: amount_due = StripeDecimalCurrencyAmountField
162: amount_paid = StripeDecimalCurrencyAmountField
166: amount_remaining = StripeDecimalCurrencyAmountField
175: application_fee_amount = StripeDecimalCurrencyAmountField
338: subtotal = StripeDecimalCurrencyAmountField
342: tax = StripeDecimalCurrencyAmountField
356: total = StripeDecimalCurrencyAmountField
629:class InvoiceItem
641: amount = StripeDecimalCurrencyAmountField
740:class Plan
767: amount = StripeDecimalCurrencyAmountField
Quantum:
core.py
36:class BalanceTransaction
45: amount = StripeQuantumCurrencyAmountField
56: fee = StripeQuantumCurrencyAmountField
60: net = StripeQuantumCurrencyAmountField
1188:class Dispute
1196: amount = StripeQuantumCurrencyAmountField
1362:class PaymentIntent
1370: amount = StripeQuantumCurrencyAmountField
1373: amount_capturable = StripeQuantumCurrencyAmountField
1376: amount_received = StripeQuantumCurrencyAmountField
1873:class Refund
1880: amount = StripeQuantumCurrencyAmountField
connect.py
355:class ApplicationFee
365: amount = StripeQuantumCurrencyAmountField
366: amount_refunded = StripeQuantumCurrencyAmountField
392:class ApplicationFeeRefund
404: amount = StripeQuantumCurrencyAmountField
536:class TransferReversal
543: amount = StripeQuantumCurrencyAmountField
Activity