Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

(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

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

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

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

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

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

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

Slide 30

Slide 30 text

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

Slide 31

Slide 31 text

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

Slide 32

Slide 32 text

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

Slide 33

Slide 33 text

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

Slide 34

Slide 34 text

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

Slide 35

Slide 35 text

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

Slide 36

Slide 36 text

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

Slide 37

Slide 37 text

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

Slide 38

Slide 38 text

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

Slide 39

Slide 39 text

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

Slide 40

Slide 40 text

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

Slide 41

Slide 41 text

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

Slide 42

Slide 42 text

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

Slide 43

Slide 43 text

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

Slide 44

Slide 44 text

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

Slide 45

Slide 45 text

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

Slide 46

Slide 46 text

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

Slide 47

Slide 47 text

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

Slide 48

Slide 48 text

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

Slide 49

Slide 49 text

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

Slide 50

Slide 50 text

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

Slide 51

Slide 51 text

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

Slide 52

Slide 52 text

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

Slide 53

Slide 53 text

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

Slide 54

Slide 54 text

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

Slide 55

Slide 55 text

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

Slide 56

Slide 56 text

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

Slide 57

Slide 57 text

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

Slide 58

Slide 58 text

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

Slide 59

Slide 59 text

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

Slide 60

Slide 60 text

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

Slide 61

Slide 61 text

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

Slide 62

Slide 62 text

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

Slide 63

Slide 63 text

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

Slide 64

Slide 64 text

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

Slide 65

Slide 65 text

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

Slide 66

Slide 66 text

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

Slide 67

Slide 67 text

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

Slide 68

Slide 68 text

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

Slide 69

Slide 69 text

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

Slide 70

Slide 70 text

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