Class: Mercadopago::ProcessNotification
- Inherits:
-
Object
- Object
- Mercadopago::ProcessNotification
- Defined in:
- app/services/mercadopago/process_notification.rb
Constant Summary collapse
- STATES =
Equivalent payment states MP state => Spree state
approved => complete pending => pend in_process => pend rejected => failed refunded => void cancelled => void in_mediation => pend charged_back => void
{ complete: %w[approved], failure: %w[rejected], void: %w[refunded cancelled charged_back] }.freeze
Instance Attribute Summary collapse
-
#notification ⇒ Object
readonly
Returns the value of attribute notification.
Instance Method Summary collapse
-
#initialize(notification) ⇒ ProcessNotification
constructor
A new instance of ProcessNotification.
- #process! ⇒ Object
Constructor Details
#initialize(notification) ⇒ ProcessNotification
Returns a new instance of ProcessNotification.
34 35 36 |
# File 'app/services/mercadopago/process_notification.rb', line 34 def initialize(notification) @notification = notification end |
Instance Attribute Details
#notification ⇒ Object (readonly)
Returns the value of attribute notification.
32 33 34 |
# File 'app/services/mercadopago/process_notification.rb', line 32 def notification @notification end |
Instance Method Details
#process! ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/services/mercadopago/process_notification.rb', line 38 def process! # Fix: Payment method is an instance of Spree::PaymentMethod::Mercadopago not THE class client = ::Spree::PaymentMethod::Mercadopago.first.provider raw_op_info = client.get_operation_info(notification.operation_id) op_info = raw_op_info['collection'] if raw_op_info.present? # TODO: rewrite this. if op_info && (payment = Spree::Payment.where(number: op_info['external_reference']).first) if STATES[:complete].include?(op_info['status']) payment.complete elsif STATES[:failure].include?(op_info['status']) payment.failure elsif STATES[:void].include?(op_info['status']) payment.void end # When Spree issue #5246 is fixed we can remove this line payment.order.updater.update end end |