Class: NimbleshopSplitable::Processor

Inherits:
Processor::Base
  • Object
show all
Defined in:
lib/nimbleshop_splitable/processor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Processor

Returns a new instance of Processor.



10
11
12
13
14
15
16
17
18
19
# File 'lib/nimbleshop_splitable/processor.rb', line 10

def initialize(options = {})

  unless @order = options[:order]
    invoice = options[:invoice].try(:to_s)
    @order   = Order.find_by_number(invoice)
  end

  @errors = []
  @payment_method = NimbleshopSplitable::Splitable.first
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



4
5
6
# File 'lib/nimbleshop_splitable/processor.rb', line 4

def errors
  @errors
end

#orderObject (readonly)

Returns the value of attribute order.



4
5
6
# File 'lib/nimbleshop_splitable/processor.rb', line 4

def order
  @order
end

#payment_methodObject (readonly)

Returns the value of attribute payment_method.



4
5
6
# File 'lib/nimbleshop_splitable/processor.rb', line 4

def payment_method
  @payment_method
end

Instance Method Details

#acknowledge(params = {}) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/nimbleshop_splitable/processor.rb', line 35

def acknowledge(params = {})
  if valid?(params)
    send(resolve_payment_kind(params[:payment_status]), params)
  else
    false
  end
end

#create_split(options = {}) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/nimbleshop_splitable/processor.rb', line 21

def create_split(options = {})
  options.symbolize_keys!
  options.assert_valid_keys(:request)

  response = gateway.create(order, options[:request])
  json = ActiveSupport::JSON.decode(response)
  result = json.values_at('error','split_url')
  if result.last
    order.update_attributes(payment_method: payment_method)
    order.pending
  end
  result
end

#gatewayObject



6
7
8
# File 'lib/nimbleshop_splitable/processor.rb', line 6

def gateway
  ::NimbleshopSplitable::Gateway.new(NimbleshopSplitable::Splitable.first)
end