Class: Spree::Conekta::PaymentNotificationHandler

Inherits:
Object
  • Object
show all
Includes:
Celluloid
Defined in:
lib/spree/conekta/payment_notification_handler.rb

Constant Summary collapse

ACTIONS =
Hash.new(:failure!).merge! 'charge.paid' => :capture!

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params, delay = 60) ⇒ PaymentNotificationHandler



12
13
14
15
16
17
# File 'lib/spree/conekta/payment_notification_handler.rb', line 12

def initialize(params, delay = 60)
  @params = params
  @delay  = delay
  @action = ACTIONS[params['type']]
  @order  = params['data']['object']['reference_id'].split('-').first
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



8
9
10
# File 'lib/spree/conekta/payment_notification_handler.rb', line 8

def action
  @action
end

#delayObject (readonly)

Returns the value of attribute delay.



8
9
10
# File 'lib/spree/conekta/payment_notification_handler.rb', line 8

def delay
  @delay
end

#orderObject (readonly)

Returns the value of attribute order.



8
9
10
# File 'lib/spree/conekta/payment_notification_handler.rb', line 8

def order
  @order
end

#paramsObject (readonly)

Returns the value of attribute params.



8
9
10
# File 'lib/spree/conekta/payment_notification_handler.rb', line 8

def params
  @params
end

Instance Method Details

#perform_actionObject



19
20
21
22
23
24
25
# File 'lib/spree/conekta/payment_notification_handler.rb', line 19

def perform_action
  after(delay) do
    ActiveRecord::Base.connection_pool.with_connection do
      payment.try(action)
    end
  end
end