class OffsitePayments::Integrations::PagSeguro::Notification

Public Class Methods

new(post, options = {}) click to toggle source
# File lib/offsite_payments/integrations/pag_seguro.rb, line 170
def initialize(post, options = {})
  @acknowledge = true
  notify_code = parse_http_query(post)["notificationCode"]
  email = options[:credential1]
  token = options[:credential2]

  uri = URI.join(PagSeguro.notification_url, notify_code)
  parse_xml(web_get(uri, email: email, token: token))

rescue NotificationError
  @acknowledge = false
end

Public Instance Methods

acknowledge() click to toggle source
# File lib/offsite_payments/integrations/pag_seguro.rb, line 236
def acknowledge
  @acknowledge
end
complete?() click to toggle source
# File lib/offsite_payments/integrations/pag_seguro.rb, line 183
def complete?
  status == "Completed"
end
currency() click to toggle source
# File lib/offsite_payments/integrations/pag_seguro.rb, line 207
def currency
  "BRL"
end
gross() click to toggle source
# File lib/offsite_payments/integrations/pag_seguro.rb, line 203
def gross
  params["transaction"]["grossAmount"]
end
item_id() click to toggle source
# File lib/offsite_payments/integrations/pag_seguro.rb, line 187
def item_id
  params["transaction"]["reference"]
end
payer_email() click to toggle source
# File lib/offsite_payments/integrations/pag_seguro.rb, line 199
def payer_email
  params["sender"]["email"]
end
payment_method_code() click to toggle source
# File lib/offsite_payments/integrations/pag_seguro.rb, line 215
def payment_method_code
  params["transaction"]["paymentMethod"]["code"]
end
payment_method_type() click to toggle source
# File lib/offsite_payments/integrations/pag_seguro.rb, line 211
def payment_method_type
  params["transaction"]["paymentMethod"]["type"]
end
received_at() click to toggle source
# File lib/offsite_payments/integrations/pag_seguro.rb, line 195
def received_at
  params["transaction"]["date"]
end
status() click to toggle source
# File lib/offsite_payments/integrations/pag_seguro.rb, line 219
def status
  case params["transaction"]["status"]
  when "1", "2"
    "Pending"
  when "3"
    "Completed"
  when "4"
    "Available"
  when "5"
    "Dispute"
  when "6"
    "Reversed"
  when "7"
    "Failed"
  end
end
transaction_id() click to toggle source
# File lib/offsite_payments/integrations/pag_seguro.rb, line 191
def transaction_id
  params["transaction"]["code"]
end

Private Instance Methods

parse_http_query(post) click to toggle source
# File lib/offsite_payments/integrations/pag_seguro.rb, line 256
def parse_http_query(post)
  @raw = post
  params = {}
  for line in post.split('&')
    key, value = *line.scan( %r{^(\w+)\=(.*)$} ).flatten
    params[key] = value
  end
  params
end
parse_xml(post) click to toggle source

Take the posted data and move the relevant data into a hash

# File lib/offsite_payments/integrations/pag_seguro.rb, line 252
def parse_xml(post)
  @params = Hash.from_xml(post)
end
web_get(uri, params) click to toggle source
# File lib/offsite_payments/integrations/pag_seguro.rb, line 242
def web_get(uri, params)
  uri.query = URI.encode_www_form(params)

  response = Net::HTTP.get_response(uri)
  raise NotificationError if response.code.to_i > 200

  response.body
end