Created
November 30, 2012 13:16
-
-
Save nicholasjhenry/4175690 to your computer and use it in GitHub Desktop.
Dealing with Feature Envy
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
# Source: https://gist.github.com/4172391#gistcomment-610165 | |
class Order | |
def complete_purchase(purchase) | |
purchase.complete(credit_card, amount) | |
end | |
def purchase_completed(transaction_reference) | |
update_attibutes(:transaction_reference => transaction_reference) | |
end | |
def purchase_failed(error_message) | |
# error handling | |
end | |
end | |
class Purchase | |
def initialize(order) | |
@order = order | |
end | |
def submit | |
order.complete_purchase(self) | |
end | |
def complete(credit_card, amount) | |
result = Braintree::Transaction.sale(amount: @amount, credit_card: @credit_card) | |
if result.success? | |
order.purchase_succeeded(result.transaction_reference) | |
else | |
order.purchase_failed(result.error) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment