Last active
August 29, 2015 14:22
-
-
Save plukevdh/6e256e3c0ebfc1142941 to your computer and use it in GitHub Desktop.
a design challenge
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
class Order | |
has_one :receipt | |
def paid(receipt) | |
self.receipt = receipt | |
end | |
end | |
class Receipt | |
belongs_to :order | |
end | |
class BillingService | |
def charge | |
charge_details = Stripe::Charge.create(stripe_details) | |
Processor.new(charge_details).process | |
end | |
private | |
def for_stripe | |
# formats @order details for stripe params | |
end | |
end | |
class Processor | |
def process | |
Receipt.new(for_receipt) | |
end | |
private | |
def for_receipt | |
# formats @charge_details into a Receipt object | |
end | |
end | |
order = Order.new(plan: 1, quantity: 5) | |
receipt = BillingService.new(order).charge | |
order.paid(receipt) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment