Skip to content

Instantly share code, notes, and snippets.

@romikoops
Created February 11, 2015 12:44
Show Gist options
  • Save romikoops/49ec0b8a4ade2fe540ca to your computer and use it in GitHub Desktop.
Save romikoops/49ec0b8a4ade2fe540ca to your computer and use it in GitHub Desktop.
design
module PaymentMethods
class Base
def request_url(params)
raise 'Not implemented'
end
def response_notification
raise 'Not implemented'
end
end
class Skrill < Base
def request_url(params)
#some implementation
end
def response_notification
#some implementation
end
end
class Obt < Base
def request_url(params)
#some implementation
end
def response_notification
#some implementation
end
end
end
module PaymentProvider
def self.for(type)
if known_payment_method?(type)
klass = type.classify.constantize
"PaymentMethods::#{klass}".constantize.new
else
raise "Unknown payment method '#{type}'"
end
end
end
PaymentProvider.for(:skrill).request_url(params)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment