Sha256: 7b165ed93f431d91ea6b1108c6ec09d159df7855704f62b7ee59ac113c4604fe

Contents?: true

Size: 1.12 KB

Versions: 73

Compression:

Stored size: 1.12 KB

Contents

class CatarsePagarme::VerifyPagarmeWorker
  include Sidekiq::Worker
  sidekiq_options retry: 5

  def perform key
    source = find_source_by_key key
    payment = PaymentEngines.find_payment({ key: key })

    raise "payment not found" unless payment.present?
    raise "source not found" unless source.present? && source.try(:[], "metadata").try(:[], "key") == key

    payment.update_attributes({gateway_id: source["id"]})
    payment.pagarme_delegator.update_transaction
    payment.pagarme_delegator.change_status_by_transaction source["status"]
  end

  private

  def find_source_by_key key
    ::PagarMe.api_key = CatarsePagarme.configuration.api_key
    request = PagarMe::Request.new('/search', 'GET')
    query = {
      type: 'transaction',
      query: {
        from: 0,
        size: 1,
        query: {
          bool: {
            must: {
              match: {
                "metadata.key" => key
              }
            }
          }
        }
      }.to_json
    }

    request.parameters.merge!(query)
    response = request.run
    response.try(:[], "hits").try(:[], "hits").try(:[], 0).try(:[], "_source")
  end
end

Version data entries

73 entries across 73 versions & 1 rubygems

Version Path
catarse_pagarme-2.9.12 app/workers/catarse_pagarme/verify_pagarme_worker.rb
catarse_pagarme-2.9.11 app/workers/catarse_pagarme/verify_pagarme_worker.rb
catarse_pagarme-2.9.10 app/workers/catarse_pagarme/verify_pagarme_worker.rb
catarse_pagarme-2.9.9 app/workers/catarse_pagarme/verify_pagarme_worker.rb
catarse_pagarme-2.9.8 app/workers/catarse_pagarme/verify_pagarme_worker.rb
catarse_pagarme-2.9.7 app/workers/catarse_pagarme/verify_pagarme_worker.rb
catarse_pagarme-2.9.6 app/workers/catarse_pagarme/verify_pagarme_worker.rb
catarse_pagarme-2.9.5 app/workers/catarse_pagarme/verify_pagarme_worker.rb
catarse_pagarme-2.9.4 app/workers/catarse_pagarme/verify_pagarme_worker.rb
catarse_pagarme-2.9.3 app/workers/catarse_pagarme/verify_pagarme_worker.rb
catarse_pagarme-2.9.2 app/workers/catarse_pagarme/verify_pagarme_worker.rb
catarse_pagarme-2.9.0 app/workers/catarse_pagarme/verify_pagarme_worker.rb
catarse_pagarme-2.8.10 app/workers/catarse_pagarme/verify_pagarme_worker.rb
catarse_pagarme-2.8.9 app/workers/catarse_pagarme/verify_pagarme_worker.rb
catarse_pagarme-2.8.8 app/workers/catarse_pagarme/verify_pagarme_worker.rb
catarse_pagarme-2.8.7 app/workers/catarse_pagarme/verify_pagarme_worker.rb
catarse_pagarme-2.8.6 app/workers/catarse_pagarme/verify_pagarme_worker.rb
catarse_pagarme-2.8.5 app/workers/catarse_pagarme/verify_pagarme_worker.rb
catarse_pagarme-2.8.4 app/workers/catarse_pagarme/verify_pagarme_worker.rb
catarse_pagarme-2.8.3 app/workers/catarse_pagarme/verify_pagarme_worker.rb