Created
June 25, 2013 16:40
-
-
Save bamorim/5860042 to your computer and use it in GitHub Desktop.
Idéia de API para gem de pagamentos
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
#... | |
gem 'salesman' | |
gem 'salesman_pagseguro' | |
#... |
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 Item | |
include Salesman::Item #ou talvez act_as_sellable, sei lá | |
belongs_to :user | |
#Cost é apenas informado na geração da ordem de compra, mas não aumenta o preço | |
add_cost :taxa_pagseguro { |i| i.price * 0.05 } # Por padrão os custos fazem parte do que o usuário recebe | |
add_tax :taxa_fixa_item, 2.00 # Por padrão as taxas são enviadas ao sistema | |
add_tax :commission {|i| i.price * 0.02 } # Taxa é adicionada ao preço | |
# Adaptative payment ( quando disponível ) | |
pay to: :user # Envia o preço, subtraido dos custos ao usuário | |
collect :commission # Envia a taxa de comissão para a conta do sistema, por padrão todas as taxas já são coletadas pelo sistema. | |
end |
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 | |
include Salesman::Order | |
has_items Item # Associa linhas de items da classe Item | |
add_cost :taxa_fixa_pagseguro, 0.4 | |
end |
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
Salesman.setup do |config| | |
config.gateways << [:pagseguro] | |
config.methods[:pagseguro] = [:boleto, :credito, :debito] | |
config.accounts[:pagseguro] = ENV['PAGSEGURO_ID'] | |
config.gateways << [:moip] | |
config.methods[:moip] = [:credito] | |
config.accounts[:moip] = ENV['MOIP_ID'] | |
end | |
# OU | |
Salesman.setup do |config| | |
config.add_gateway :pagseguro do |g| | |
g.methods = [:boleto, :credito, :debito] | |
g.account = ENV['PAGSEGURO_ID'] | |
end | |
config.add_gateway :moip do |g| | |
g.methods = [:credito] | |
g.account = ENV['MOIP_ID'] | |
end | |
end |
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 User | |
# ... | |
attr_accessible :pagseguro_id # Convention over configuration. | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment