Sha256: d5f0b76a1a415e63dab4c66d79d95381472eed2f2dacbca444d83fd9e64128c2

Contents?: true

Size: 975 Bytes

Versions: 18

Compression:

Stored size: 975 Bytes

Contents

module CatarsePagarme
  class NotificationsController < CatarsePagarme::ApplicationController
    skip_before_filter :authenticate_user!

    def create
      if payment
        payment.payment_notifications.create(contribution: payment.contribution, extra_data: params.to_json)

        if valid_postback?
          delegator.change_status_by_transaction(params[:current_status])
          delegator.update_transaction

          return render nothing: true, status: 200
        end
      end

      render_invalid_postback_response
    end

    protected

    def payment
      @payment ||=  PaymentEngines.find_payment({ gateway_id: params[:id] })
    end

    def valid_postback?
      raw_post  = request.raw_post
      signature = request.headers['HTTP_X_HUB_SIGNATURE']
      PagarMe::Postback.valid_request_signature?(raw_post, signature)
    end

    def render_invalid_postback_response
      render json: {error: 'invalid postback'}, status: 400
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
catarse_pagarme-2.10.10 app/controllers/catarse_pagarme/notifications_controller.rb
catarse_pagarme-2.10.9 app/controllers/catarse_pagarme/notifications_controller.rb
catarse_pagarme-2.10.8 app/controllers/catarse_pagarme/notifications_controller.rb
catarse_pagarme-2.10.7 app/controllers/catarse_pagarme/notifications_controller.rb
catarse_pagarme-2.10.6 app/controllers/catarse_pagarme/notifications_controller.rb
catarse_pagarme-2.10.5 app/controllers/catarse_pagarme/notifications_controller.rb
catarse_pagarme-2.10.4 app/controllers/catarse_pagarme/notifications_controller.rb
catarse_pagarme-2.10.2 app/controllers/catarse_pagarme/notifications_controller.rb
catarse_pagarme-2.10.1 app/controllers/catarse_pagarme/notifications_controller.rb
catarse_pagarme-2.10.0 app/controllers/catarse_pagarme/notifications_controller.rb
catarse_pagarme-2.9.13 app/controllers/catarse_pagarme/notifications_controller.rb
catarse_pagarme-2.9.12 app/controllers/catarse_pagarme/notifications_controller.rb
catarse_pagarme-2.9.11 app/controllers/catarse_pagarme/notifications_controller.rb
catarse_pagarme-2.9.10 app/controllers/catarse_pagarme/notifications_controller.rb
catarse_pagarme-2.9.9 app/controllers/catarse_pagarme/notifications_controller.rb
catarse_pagarme-2.9.8 app/controllers/catarse_pagarme/notifications_controller.rb
catarse_pagarme-2.9.7 app/controllers/catarse_pagarme/notifications_controller.rb
catarse_pagarme-2.9.6 app/controllers/catarse_pagarme/notifications_controller.rb