Created
February 22, 2017 14:18
-
-
Save tyronewilson/a7d3112cf728c1b18177f621fb4b13da to your computer and use it in GitHub Desktop.
Example utility class for running a transaction
This file contains hidden or 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
module Banking | |
module Processing | |
class Debit | |
class << self | |
def execute(amount, payment_method) | |
# Do vital checks before doing any work | |
unless payment_method.registered? | |
raise Errors::UnregisteredPaymentMethod.new("You can't debit an unregistered payment method") | |
end | |
# Hit the API | |
SomeGateway::API.sale(amount: amount, payment_method) | |
# Manipulate local data | |
transaction = Transaction.create gateway_response.merge(amount: amount) | |
payment_method.transactions << transaction | |
transaction | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment