Skip to content

Standardise currency value storage as cents (StripeQuantumCurrencyAmountField) #955

Open
@therefromhere

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 -

if not isinstance(amount, decimal.Decimal):
raise ValueError("You must supply a decimal value representing dollars.")

Thoughts @kavdev (cc @jleclanche )?

Related tickets: #247, #468

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    currency storageAnything to do with storing and surfacing currency to/from the database

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions