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

Money Makes Your App Go Round

6b767d8a4c9910e007c122d81eb4de73?s=47 Noel Rappin
September 15, 2016

Money Makes Your App Go Round

Your customers have money, and you’d like them to give it to you. Payment gateways, such as Stripe, Braintree, and Paypal, make it easy to start charging credit cards and get the money flowing. But charging cards is only the beginning. You need to worry that your app responds gracefully to service failures, since charging a customer for a failed transaction is bad. You need to guard against fraud and security breaches. You need administrative tools that are flexible but secure. You want to test against external services. And you’ll run up against the law. Learn from some of my mistakes and build a robust financial application.

6b767d8a4c9910e007c122d81eb4de73?s=128

Noel Rappin

September 15, 2016
Tweet

More Decks by Noel Rappin

Other Decks in Programming

Transcript

  1. We Are Experiencing An Introduction Please Stand By Noel Rappin,

    Money Makes Your App Go Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  2. I've made some mistakes Noel Rappin, Money Makes Your App

    Go Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  3. Noel Rappin, Money Makes Your App Go Round, WindyCityRails 2016.

    http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  4. Once upon a time... Noel Rappin, Money Makes Your App

    Go Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  5. I got a new client Noel Rappin, Money Makes Your

    App Go Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  6. They wanted to add complex payment logic to an existing

    payment gateway connection Noel Rappin, Money Makes Your App Go Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  7. The API call already existed I thought the hard part

    was done Noel Rappin, Money Makes Your App Go Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  8. (Spoiler Alert) The API call isn't the hard part Noel

    Rappin, Money Makes Your App Go Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  9. Money Makes Your App Go Round Noel Rappin, Table XI

    (@noelrap) Noel Rappin, Money Makes Your App Go Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  10. Some context Noel Rappin, Money Makes Your App Go Round,

    WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  11. token = params[:stripeToken] begin charge = Stripe::Charge.create( amount: 1000, currency:

    "usd", source: token, description: "Example charge") rescue Stripe::CardError => e # The card has been declined end Noel Rappin, Money Makes Your App Go Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  12. The resulting transaction involves at least ! institutions Noel Rappin,

    Money Makes Your App Go Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  13. As many as 1,000,000 per minute Noel Rappin, Money Makes

    Your App Go Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  14. But then there's this: Noel Rappin, Money Makes Your App

    Go Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  15. validates :last_4, format: {with: /X{12}\d{4}/} Noel Rappin, Money Makes Your

    App Go Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  16. There's a really common pattern Noel Rappin, Money Makes Your

    App Go Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  17. Save some data Charge the card Save the response Noel

    Rappin, Money Makes Your App Go Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  18. Charge Fails Save Succeeds Angry Manager! Noel Rappin, Money Makes

    Your App Go Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  19. Charge Succeeds Save Fails Angry Customer! Noel Rappin, Money Makes

    Your App Go Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  20. Back to validates :last_4, format: {with: /X{12}\d{4}/} Noel Rappin, Money

    Makes Your App Go Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  21. Every line of code after the card processes is a

    potential angry customer Noel Rappin, Money Makes Your App Go Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  22. Is this validation really necessary? Noel Rappin, Money Makes Your

    App Go Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  23. PragDave: "screw up in favor of the customer" Noel Rappin,

    Money Makes Your App Go Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  24. Mitigating failure Noel Rappin, Money Makes Your App Go Round,

    WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  25. Test failure conditions Noel Rappin, Money Makes Your App Go

    Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  26. Testing for credit card failures is actually pretty easy Noel

    Rappin, Money Makes Your App Go Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  27. Testing for local failures is trickier Noel Rappin, Money Makes

    Your App Go Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  28. Foreign key constraints are useful, but irritating Noel Rappin, Money

    Makes Your App Go Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  29. Small background jobs are great Noel Rappin, Money Makes Your

    App Go Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  30. Idempotence is your friend Noel Rappin, Money Makes Your App

    Go Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  31. It is often easier to see the result of bugs

    than to find the cause Noel Rappin, Money Makes Your App Go Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  32. An ounce of mitigation can be worth a pound of

    bug fixing Noel Rappin, Money Makes Your App Go Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  33. Money is precise Noel Rappin, Money Makes Your App Go

    Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  34. Money is so precise that it breaks math Noel Rappin,

    Money Makes Your App Go Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  35. Okay, it just breaks floating point numbers Noel Rappin, Money

    Makes Your App Go Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  36. Noel Rappin, Money Makes Your App Go Round, WindyCityRails 2016.

    http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  37. Use the Money gem to store money as BigDecimal Noel

    Rappin, Money Makes Your App Go Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  38. Noel Rappin, Money Makes Your App Go Round, WindyCityRails 2016.

    http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  39. Money requires records Noel Rappin, Money Makes Your App Go

    Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  40. Handling Fee: $2.00 Noel Rappin, Money Makes Your App Go

    Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  41. It's a constant HANDLING_FEE: 200 Noel Rappin, Money Makes Your

    App Go Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  42. Later... Noel Rappin, Money Makes Your App Go Round, WindyCityRails

    2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  43. Change the constant HANDLING_FEE: 250 Noel Rappin, Money Makes Your

    App Go Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  44. And we're done... Noel Rappin, Money Makes Your App Go

    Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  45. Except for the past Noel Rappin, Money Makes Your App

    Go Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  46. Store all your partial results Noel Rappin, Money Makes Your

    App Go Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  47. You should be able to recreate the entire purchase even

    if the logic has changed Noel Rappin, Money Makes Your App Go Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  48. If there is failure, keep a record of the failure

    Noel Rappin, Money Makes Your App Go Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  49. Audit changes Noel Rappin, Money Makes Your App Go Round,

    WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  50. Check your data Noel Rappin, Money Makes Your App Go

    Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  51. Money has legal obligations Noel Rappin, Money Makes Your App

    Go Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  52. Take your administrative users seriously Noel Rappin, Money Makes Your

    App Go Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  53. Pragmatic's admin code is 2x the size of the main

    app Noel Rappin, Money Makes Your App Go Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  54. Admins can change rules which makes them complicated Noel Rappin,

    Money Makes Your App Go Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  55. Example: Refunds Noel Rappin, Money Makes Your App Go Round,

    WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  56. Refunds are a one-line API call Noel Rappin, Money Makes

    Your App Go Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  57. But: 4 Who can authorize one? 4 Full or partial?

    4 How to manage response? 4 How to track inventory 4 How to track changes to revenue? 4 Etc.. Noel Rappin, Money Makes Your App Go Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  58. Take Reporting Seriously (I didn't) Noel Rappin, Money Makes Your

    App Go Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  59. Reporting is how you make business decisions Noel Rappin, Money

    Makes Your App Go Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  60. Taxes security requirements financial system compliance Noel Rappin, Money Makes

    Your App Go Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  61. Money is Private Noel Rappin, Money Makes Your App Go

    Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  62. Don't store personal information that you don't need Noel Rappin,

    Money Makes Your App Go Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  63. Don't store credit card info Noel Rappin, Money Makes Your

    App Go Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  64. Even seemingly boring information can be harmful Noel Rappin, Money

    Makes Your App Go Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  65. Takeaways Noel Rappin, Money Makes Your App Go Round, WindyCityRails

    2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  66. The API is the easy part Noel Rappin, Money Makes

    Your App Go Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  67. Run in small steps to manage potential failure points Noel

    Rappin, Money Makes Your App Go Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  68. Store all your work Store as little personal info as

    you can Noel Rappin, Money Makes Your App Go Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  69. Administration is important Noel Rappin, Money Makes Your App Go

    Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap
  70. Noel Rappin (@noelrap) Table XI http://pragprog.com/book/ nrwebpay http://www.noelrappin.com/trdd http://pragprog.com/book/ Noel

    Rappin, Money Makes Your App Go Round, WindyCityRails 2016. http://www.noelrappin.com | http://www.tablexi.com | @noelrap