Sha256: dbedb240b38a3c6e6ffbbe6eeb454e8986e95cc32a672de802d7307dad7d1659

Contents?: true

Size: 902 Bytes

Versions: 2

Compression:

Stored size: 902 Bytes

Contents

module PagSeguro
  class Transactions < Base
    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)
      response = api.get "/v3/transactions/#{code}" do |conn|
        conn.headers[:accept] = FORMATS[:xml]
      end

      parse_body response
    end

    def find_by_notification_code(code)
      response = api.get "/v2/transactions/notifications/#{code}" do |conn|
        conn.headers[:accept] = FORMATS[:xml]
      end

      parse_body response
    end

    private

    def parse_body(response)
      parse(response.body["transaction"]).tap do |transaction|
        transaction.status = STATUSES[transaction.status]
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pagseguro_next-0.1.1 lib/pagseguro/transactions.rb
pagseguro_next-0.1.0 lib/pagseguro/transactions.rb