Sha256: 7f185094089ac98a48a3c28086524ccf1f2204c556b541144389dc18af35292b

Contents?: true

Size: 873 Bytes

Versions: 4

Compression:

Stored size: 873 Bytes

Contents

# frozen_string_literal: true

module PagSeguro
  class Transactions
    include Restful

    STATUSES = {
      "0" => :initiated,
      "1" => :waiting_payment,
      "2" => :in_analysis,
      "3" => :paid,
      "4" => :available,
      "5" => :in_dispute,
      "6" => :refunded,
      "7" => :cancelled,
      "8" => :chargeback_charged,
      "9" => :contested
    }

    def find(code)
      transform get("/v3/transactions/#{code}", nil, xml: :simple)
    end

    def find_by_notification_code(code)
      transform get("/v2/transactions/notifications/#{code}", nil, xml: :simple)
    end

    private
      def transform(body)
        if body.transaction?
          body.transaction.status = STATUSES[body.transaction.status]
          body.transaction
        elsif body.errors?
          body.errors
        else
          body
        end
      end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pagseguro_next-1.0.6 lib/pagseguro/transactions.rb
pagseguro_next-1.0.5 lib/pagseguro/transactions.rb
pagseguro_next-1.0.4 lib/pagseguro/transactions.rb
pagseguro_next-1.0.3 lib/pagseguro/transactions.rb