class PagseguroV2::Client

Attributes

email[RW]
token[RW]

Public Class Methods

new(email, token) click to toggle source
Calls superclass method
# File lib/pagseguro_v2/client.rb, line 15
def initialize(email, token)
  super()
  self.email = email
  self.token = token
end

Public Instance Methods

checkout(attributes) click to toggle source
# File lib/pagseguro_v2/client.rb, line 21
def checkout(attributes)
  checkout = Checkout.new(attributes)
  checkout.client = self
  checkout
end
get(path, options = {}) click to toggle source
# File lib/pagseguro_v2/client.rb, line 77
def get(path, options = {})
  self.class.get(path, options)
end
inquiry(attributes) click to toggle source
# File lib/pagseguro_v2/client.rb, line 33
def inquiry(attributes)
  inquiry = Inquiry.new(attributes)
  inquiry.client = self
  inquiry
end
inquiry_transaction(inquiry) click to toggle source
# File lib/pagseguro_v2/client.rb, line 49
def inquiry_transaction(inquiry)
  path = PagseguroV2::Config::INQUIRY_PATH.gsub 'ID', inquiry.transaction_id
  options = { query: {email: email, token: token} }
  parse_get_response(path, options)
end
notification(attributes) click to toggle source
# File lib/pagseguro_v2/client.rb, line 27
def notification(attributes)
  notification = Notification.new(attributes)
  notification.client = self
  notification
end
parse_get_response(path, options) click to toggle source
# File lib/pagseguro_v2/client.rb, line 60
def parse_get_response(path, options)
  response = get(path, options)
  parse_response(response)
end
parse_post_response(path, object) click to toggle source
# File lib/pagseguro_v2/client.rb, line 55
def parse_post_response(path, object)
  response = post(path, object)
  parse_response(response)
end
parse_response(response) click to toggle source
# File lib/pagseguro_v2/client.rb, line 65
def parse_response(response)
  if response.code == 200
    response
  elsif response.code == 401
    raise PagseguroV2::Errors::Unauthorized
  elsif response.code == 400
    raise PagseguroV2::Errors::InvalidData.new(response.body)
  else
    raise PagseguroV2::Errors::UnknownError.new(response)
  end
end
post(path, object) click to toggle source
# File lib/pagseguro_v2/client.rb, line 81
def post(path, object)
  object_xml = object.to_xml
  header = {"Content-Type" => "application/xml; charset=UTF-8"}
  query = { :email => self.email, :token => self.token }
  options = {query: query, body: object_xml, headers: header}
  self.class.post(path, options)
end
proceed_checkout(checkout) click to toggle source
# File lib/pagseguro_v2/client.rb, line 39
def proceed_checkout(checkout)
  self.parse_post_response(PagseguroV2::Config::CHECKOUT_PATH, checkout)
end
query_transaction(notification) click to toggle source
# File lib/pagseguro_v2/client.rb, line 43
def query_transaction(notification)
  path = PagseguroV2::Config::NOTIFICATION_PATH.gsub 'ID', notification.code
  options = { query: {email: email, token: token} }
  parse_get_response(path, options)
end