Created
February 11, 2015 13:13
-
-
Save romikoops/f304000f9c61f6a80388 to your computer and use it in GitHub Desktop.
OBT architecture
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
# /payment_methods/ | |
# /payment_methods/obt/request.rb | |
# /payment_methods/obt/notification.rb | |
# /payment_methods/skrill/request.rb | |
# /payment_methods/skrill/notification.rb | |
# /payment_methods/base_request.rb | |
# /payment_methods/base_notification.rb | |
# /payment_provider.rb | |
module PaymentMethods | |
class BaseRequest | |
def initialize(params) | |
@params = params | |
end | |
def url | |
raise 'Not implemented' | |
end | |
end | |
module Skrill | |
class Request < BaseRequest | |
def url | |
#some implementation | |
end | |
end | |
end | |
module Obt | |
class Request < BaseRequest | |
def url | |
#some implementation | |
end | |
end | |
end | |
class BaseNotification | |
def initialize(response) | |
@response = response | |
end | |
def notify | |
raise 'Not implemented' | |
end | |
end | |
module Skrill | |
class Notification < BaseNotification | |
def notify | |
#some implementation | |
end | |
end | |
end | |
module Obt | |
class Notification < BaseNotification | |
def notify | |
#some implementation | |
end | |
end | |
end | |
end | |
module PaymentProvider | |
def self.for(type) | |
if known_payment_method?(type) | |
new(type) | |
else | |
raise "Unknown payment method '#{type}'" | |
end | |
end | |
def initialize(type) | |
@type = type | |
end | |
def request(params) | |
"PaymentMethods::#{klass}::Request".constantize.new(params) | |
end | |
def notification(response) | |
"PaymentMethods::#{klass}::Notification".constantize.new(response) | |
end | |
end | |
# main.rb | |
PaymentProvider.for(:skrill).request(params).url | |
PaymentProvider.for(:skrill).notification(response).notify |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment