Skip to content

Commit

Permalink
Adding pag seguro payment method
Browse files Browse the repository at this point in the history
  • Loading branch information
teonimesic committed Feb 16, 2012
1 parent 9182b22 commit 9e6e6e6
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
2 changes: 1 addition & 1 deletion GEM_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.0.beta24
1.0.0.beta25
33 changes: 33 additions & 0 deletions app/models/spree/payment_method/pag_seguro_method.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module Spree
class PaymentMethod::PagSeguroMethod < PaymentMethod
def actions
%w{capture void}
end

# Indicates whether its possible to capture the payment
def can_capture?(payment)
['checkout', 'pending'].include?(payment.state)
end

# Indicates whether its possible to void the payment.
def can_void?(payment)
payment.state != 'void'
end

def capture(payment)
payment.update_attribute(:state, 'pending') if payment.state == 'checkout'
payment.complete
true
end

def void(payment)
payment.update_attribute(:state, 'pending') if payment.state == 'checkout'
payment.void
true
end

def source_required?
false
end
end
end
10 changes: 7 additions & 3 deletions lib/spree_pag_seguro/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@ module PagSeguro
class Engine < Rails::Engine
engine_name 'spree_pag_seguro'

initializer "spree.active_shipping.configuration", :after => "spree.environment" do |app|
initializer "spree.active_shipping.configuration", after: "spree.environment" do |app|
Dir.glob(File.join(File.dirname(__FILE__), "../../lib/spree_pag_seguro_configuration.rb")) do |c|
Rails.configuration.cache_classes ? require(c) : load(c)
end
end

initializer "spree.pag_seguro.preferences", :after => "spree.active_shipping.configuration" do |app|
initializer "spree.pag_seguro.preferences", after: "spree.active_shipping.configuration" do |app|
Spree::PagSeguro::Config = Spree::PagSeguroConfiguration.new
end

initializer "spree.resgiter.pag_seguro_method", after: "spree.register.payment_methods" do |app|
app.config.spree.payment_methods << Spree::PaymentMethod::PagSeguroMethod
end

config.autoload_paths += %W(#{config.root}/lib)

Expand All @@ -29,4 +33,4 @@ def self.activate
config.to_prepare &method(:activate).to_proc
end
end
end
end

0 comments on commit 9e6e6e6

Please sign in to comment.