-
-
Save brett-richardson/9291ba2d526da26d35cd to your computer and use it in GitHub Desktop.
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 CreditCardController < ApplicationController | |
def create | |
respond_with CreditCardCreator.new(params) | |
end | |
end | |
class Grouper::Responder | |
delegate :errors, to: :resource | |
def resource | |
raise NotImplementedError | |
end | |
def to_json | |
call | |
resource | |
end | |
end | |
class CreditCardCreator < Grouper::Responder | |
def initialize(params) | |
@params = params | |
end | |
def resource | |
@resource ||= CreditCard.new(@params) | |
end | |
def call | |
resource.save | |
... | |
response = Stripe.create_card(resource) | |
unless response.success? | |
errors << response.error_message | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment