Module: Moiper::NotificationControllerHelper

Defined in:
lib/moiper/notification_controller_helper.rb

Instance Method Summary collapse

Instance Method Details

#moip_notification(data = params) {|notification| ... } ⇒ Notification

Helper method to abstract how to create a notification during the Moip’s NASP request.

Examples:

Usage inside a Rails controller

class OrdersController < ApplicationController
  include Moiper::NotificationControllerHelper

  def confirm
    moip_notification do |notification|
      # Here you can update your database with updated information.
      # Ex:
      @order = Order.find_by_unique_identifier(notification.id)
      @order.update_attribute :status, notification.payment_status
      @order.save

      # Moip will recognize the request as successfully if the statuses
      # are 200, 201, 202, 203, 204, 205, 206 or 207.
      head 200
    end
  end
end

Parameters:

  • data (Hash) (defaults to: params)

    controller parameters

Yield Parameters:

Returns:

See Also:



30
31
32
33
34
# File 'lib/moiper/notification_controller_helper.rb', line 30

def moip_notification(data = params, &block)
  notification = Notification.new(data)
  yield notification if block_given?
  notification
end