Class: PagseguroV2::Client
- Inherits:
-
Object
- Object
- PagseguroV2::Client
- Includes:
- HTTParty
- Defined in:
- lib/pagseguro_v2/client.rb
Instance Attribute Summary collapse
-
#email ⇒ Object
Returns the value of attribute email.
-
#token ⇒ Object
Returns the value of attribute token.
Instance Method Summary collapse
- #checkout(attributes) ⇒ Object
- #get(path, options = {}) ⇒ Object
-
#initialize(email, token) ⇒ Client
constructor
A new instance of Client.
- #inquiry(attributes) ⇒ Object
- #inquiry_transaction(inquiry) ⇒ Object
- #notification(attributes) ⇒ Object
- #parse_get_response(path, options) ⇒ Object
- #parse_post_response(path, object) ⇒ Object
- #parse_response(response) ⇒ Object
- #post(path, object) ⇒ Object
- #proceed_checkout(checkout) ⇒ Object
- #query_transaction(notification) ⇒ Object
Constructor Details
#initialize(email, token) ⇒ Client
Returns a new instance of Client.
15 16 17 18 19 |
# File 'lib/pagseguro_v2/client.rb', line 15 def initialize(email, token) super() self.email = email self.token = token end |
Instance Attribute Details
#email ⇒ Object
Returns the value of attribute email.
12 13 14 |
# File 'lib/pagseguro_v2/client.rb', line 12 def email @email end |
#token ⇒ Object
Returns the value of attribute token.
13 14 15 |
# File 'lib/pagseguro_v2/client.rb', line 13 def token @token end |
Instance Method Details
#checkout(attributes) ⇒ Object
21 22 23 24 25 |
# File 'lib/pagseguro_v2/client.rb', line 21 def checkout(attributes) checkout = Checkout.new(attributes) checkout.client = self checkout end |
#get(path, options = {}) ⇒ Object
77 78 79 |
# File 'lib/pagseguro_v2/client.rb', line 77 def get(path, = {}) self.class.get(path, ) end |
#inquiry(attributes) ⇒ Object
33 34 35 36 37 |
# File 'lib/pagseguro_v2/client.rb', line 33 def inquiry(attributes) inquiry = Inquiry.new(attributes) inquiry.client = self inquiry end |
#inquiry_transaction(inquiry) ⇒ Object
49 50 51 52 53 |
# File 'lib/pagseguro_v2/client.rb', line 49 def inquiry_transaction(inquiry) path = PagseguroV2::Config::INQUIRY_PATH.gsub 'ID', inquiry.transaction_id = { query: {email: email, token: token} } parse_get_response(path, ) end |
#notification(attributes) ⇒ Object
27 28 29 30 31 |
# 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) ⇒ Object
60 61 62 63 |
# File 'lib/pagseguro_v2/client.rb', line 60 def parse_get_response(path, ) response = get(path, ) parse_response(response) end |
#parse_post_response(path, object) ⇒ Object
55 56 57 58 |
# 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) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 |
# 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) ⇒ Object
81 82 83 84 85 86 87 |
# 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 } = {query: query, body: object_xml, headers: header} self.class.post(path, ) end |
#proceed_checkout(checkout) ⇒ Object
39 40 41 |
# 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) ⇒ Object
43 44 45 46 47 |
# File 'lib/pagseguro_v2/client.rb', line 43 def query_transaction(notification) path = PagseguroV2::Config::NOTIFICATION_PATH.gsub 'ID', notification.code = { query: {email: email, token: token} } parse_get_response(path, ) end |