Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Mo Money Mo Problems (with ruby)

fedesoria
November 15, 2015

Mo Money Mo Problems (with ruby)

Are you thinking or starting to build an app that deals with money? Come to this talk to learn the best practices of handling money transactions. In my 2+ years working in a startup based on payments, I have been able to compile do's and don'ts of handling money.

fedesoria

November 15, 2015
Tweet

More Decks by fedesoria

Other Decks in Programming

Transcript

  1. Float The formulaic representation which approximates a real number so

    as to support a trade-off between range and precision 1. 1 https://en.wikipedia.org/wiki/IEEEfloatingpoint
  2. 1/3

  3. Round down (floor) Round up (ceiling) Round towards zero (truncate)

    Round away from zero Round to nearest Round half up Round half down Round half towards zero Round half away from zero Round half to even Round half to odd Stochastic rounding Round half alternatingly Rounding to a logarithmic scale ...
  4. Round down (floor) Round up (ceiling) Round towards zero (truncate)

    Round away from zero Round to nearest Round half up Round half down Round half towards zero Round half away from zero Round half to even Round half to odd Stochastic rounding Round half alternatingly Rounding to a logarithmic scale ...
  5. Round half to even Banker's rounding IEEE 754 1 1

    https://en.wikipedia.org/wiki/IEEEfloatingpoint
  6. # integer / integer 9 / 5 #=> 1 #

    float / integer 9.0 / 5 #=> 1.8 # integer / float 9 / 5.0 #=> 1.8
  7. !

  8. require 'money' require 'money/bank/google_currency' # 10.00 USD money = Money.new(1000,

    "USD") money.cents #=> 1000 money.currency #=> Currency.new("USD") money.format #=> "$10.00"
  9. # Monkey patch class Money def *(value) if value.is_a? Float

    raise ArgumentError, "Don't mix Float with money" else super end end end
  10. # Example using ActiveJob class PaymentJob < ActiveJob::Base queue_as :default

    def perform(*payment) # Code to run the payment end end PaymentJob.perform_later @payment
  11. @lock = Mutex.new @total_captured = 0 @lock.synchronize do @total_captured +=

    tom.capture(100) # => 100 @total_captured += mary.capture(200) # => 200 puts @total_captured # => 300 sam.payout(@total_captured) end
  12. Use social media Check for IP address vs origin of

    country of card You can tell from where the card is from using the first 6 digits http://www.binlist.net/