Class: SolidusMpDois::MpPix

Inherits:
Spree::PaymentMethod
  • Object
show all
Defined in:
app/models/solidus_mp_dois/mp_pix.rb

Instance Method Summary collapse

Instance Method Details

#auto_capture?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'app/models/solidus_mp_dois/mp_pix.rb', line 19

def auto_capture?
  true
end

#create_payment(order) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/models/solidus_mp_dois/mp_pix.rb', line 32

def create_payment order
  existing_payment = find_existing_payment(order)
  return existing_payment if payment_usable?(order, existing_payment)

  payment = order.payments.new(amount: order.total, payment_method: self)
  payment.source = init_source(order)
  payment.save

  mp_payment = create_mp_payment(payment.source)
  process_payment_response(payment, mp_payment)
  payment
end

#find_payment(external_id) ⇒ Object



27
28
29
30
# File 'app/models/solidus_mp_dois/mp_pix.rb', line 27

def find_payment external_id
  MpApi.configuration.access_token = preferences[:access_token]
  MpApi::Payment.find_by_id(external_id)
end

#gateway_classObject



11
12
13
# File 'app/models/solidus_mp_dois/mp_pix.rb', line 11

def gateway_class
  MpGateway
end

#invalidate_payment(payment_source) ⇒ Object



45
46
47
48
49
50
51
52
53
54
# File 'app/models/solidus_mp_dois/mp_pix.rb', line 45

def invalidate_payment payment_source
  return false unless payment_source&.external_id
  MpApi.configuration.access_token = preferences[:access_token]
  mp_payment = find_payment(payment_source.external_id)
  return false if mp_payment.pix_paid?
  mp_payment.invalidate_pix!
  payment_source.payments[0].log_entries.create!(parsed_payment_response_details_with_fallback: failure_response("Pagamento cancelado"))
  payment_source.update(status: "cancelled")
  true
end

#partial_nameObject



23
24
25
# File 'app/models/solidus_mp_dois/mp_pix.rb', line 23

def partial_name
  "mercado_pago_pix"
end

#payment_source_classObject



7
8
9
# File 'app/models/solidus_mp_dois/mp_pix.rb', line 7

def payment_source_class
  PixSource
end

#purchase(money, source, options = {}) ⇒ Object



56
57
58
# File 'app/models/solidus_mp_dois/mp_pix.rb', line 56

def purchase(money, source, options = {})
  gateway.purchase(money, source, options)
end

#supports?(source) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'app/models/solidus_mp_dois/mp_pix.rb', line 15

def supports?(source)
  source.is_a?(payment_source_class)
end