Sha256: 8627e6889446e72975c794a6f9b8344e934aafcf955d1b4fcb28c78ccc543b5c

Contents?: true

Size: 1.24 KB

Versions: 1

Compression:

Stored size: 1.24 KB

Contents

module Moiper
  module NotificationControllerHelper
    # Helper method to abstract how to create a notification during the Moip's
    # NASP request.
    #
    # @see http://labs.moip.com.br/referencia/nasp/ Moip's NASP documentation
    #
    # @param data [Hash] controller parameters
    # @yieldparam [Notification] notification update from Moip
    # @return [Notification]
    #
    # @example 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
    def moip_notification(data = params, &block)
      notification = Notification.new(data)
      yield notification if block_given?
      notification
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
moiper-0.1.2 lib/moiper/notification_controller_helper.rb