Skip to content

Instantly share code, notes, and snippets.

@plukevdh
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save plukevdh/6e256e3c0ebfc1142941 to your computer and use it in GitHub Desktop.
Save plukevdh/6e256e3c0ebfc1142941 to your computer and use it in GitHub Desktop.
a design challenge
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