Skip to content

Instantly share code, notes, and snippets.

@maxim
Last active October 26, 2019 20:17
Show Gist options
  • Save maxim/f24a52a704b9e1d4aaf44f4558f7c8b0 to your computer and use it in GitHub Desktop.
Save maxim/f24a52a704b9e1d4aaf44f4558f7c8b0 to your computer and use it in GitHub Desktop.
def plain_text_receipt # => Runtime: 5 sec, Network Timeout
<<-TEXT
Thank you for your order!
Product: #{name} - #{price} # => 2 DB queries
Tax: #{tax_amount} # => 1 DB query, 1 API call
Total: #{total_amount} # => 2 DB queries, 1 API call
TEXT
end
private
def name
Product.find(id).name
end
def total_amount
tax_amount + price
end
def tax_amount
client = TaxServiceClient.new
price * client.find_tax_rate(address)
end
def price
Product.find(id).price
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment