Skip to content

Instantly share code, notes, and snippets.

@tyronewilson
Created February 22, 2017 14:18
Show Gist options
  • Save tyronewilson/a7d3112cf728c1b18177f621fb4b13da to your computer and use it in GitHub Desktop.
Save tyronewilson/a7d3112cf728c1b18177f621fb4b13da to your computer and use it in GitHub Desktop.
Example utility class for running a transaction
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