Last active
October 26, 2019 20:17
-
-
Save maxim/f24a52a704b9e1d4aaf44f4558f7c8b0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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