Class: PaymentMethod::Ifmb

Inherits:
Spree::PaymentMethod
  • Object
show all
Defined in:
app/models/payment_method/ifmb.rb

Instance Method Summary collapse

Instance Method Details

#actionsObject



10
11
12
# File 'app/models/payment_method/ifmb.rb', line 10

def actions
  %w{capture void}
end

#can_capture?(payment) ⇒ Boolean

Indicates whether its possible to capture the payment

Returns:

  • (Boolean)


15
16
17
# File 'app/models/payment_method/ifmb.rb', line 15

def can_capture?(payment)
  ['checkout', 'pending'].include?(payment.state)
end

#can_void?(payment) ⇒ Boolean

Indicates whether its possible to void the payment.

Returns:

  • (Boolean)


20
21
22
# File 'app/models/payment_method/ifmb.rb', line 20

def can_void?(payment)
  payment.state != 'void'
end

#capture(*args) ⇒ Object



24
25
26
# File 'app/models/payment_method/ifmb.rb', line 24

def capture(*args)
  ActiveMerchant::Billing::Response.new(true, "", {}, {})
end

#generate_ref(payment) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/models/payment_method/ifmb.rb', line 40

def generate_ref payment
  configuration = payment.payment_method.preferences
  order = payment.order
  order_id = order.id
  unique = nil
  while !unique
    opts = {
      entidade: configuration[:entity],
      sub_entidade: configuration[:sub_entity],
      order_id: order_id,
      order_value: order.total
    }
    generator =  Ifmb::Generator.new opts
    reference = generator.generate

    if 0 == IfmbReference.where(reference: reference).count
      unique = true
    else
      order_id += 1
    end
  end
  # payment.update_attribute :ifmb_reference, reference
  ifmb_reference = IfmbReference.find_or_initialize_by_payment_id payment.id
  ifmb_reference.reference = reference
  ifmb_reference.save
  reference
end

#html_reference(payment, size = :small) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'app/models/payment_method/ifmb.rb', line 68

def html_reference payment, size = :small
  ref = Ifmb::Reference.new
  configs = payment.payment_method.preferences
  ref.entidade = configs[:entity]
  ref.order_value = payment.amount
  reference = IfmbReference.where(payment_id: payment.id).first.try(:reference)

  ref.referencia= if reference
     reference
  else
    generate_ref(payment)
  end

  if size == :small
    Ifmb::HtmlFormatter.new(ref).small_html
  else
    Ifmb::HtmlFormatter.new(ref).html
  end
end

#payment_profiles_supported?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'app/models/payment_method/ifmb.rb', line 32

def payment_profiles_supported?
  false
end

#source_required?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'app/models/payment_method/ifmb.rb', line 36

def source_required?
  false
end

#void(*args) ⇒ Object



28
29
30
# File 'app/models/payment_method/ifmb.rb', line 28

def void(*args)
  ActiveMerchant::Billing::Response.new(true, "", {}, {})
end