tray-checkout 0.3.2 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +28 -0
- data/lib/tray/checkout/account.rb +14 -0
- data/lib/tray/checkout/account_response_parser.rb +70 -0
- data/lib/tray/checkout/{base_transaction.rb → base_service.rb} +1 -1
- data/lib/tray/checkout/{transaction_params_parser.rb → params_parser.rb} +1 -1
- data/lib/tray/checkout/parser.rb +4 -4
- data/lib/tray/checkout/response.rb +3 -0
- data/lib/tray/checkout/response_parser.rb +48 -105
- data/lib/tray/checkout/temp_transaction.rb +2 -2
- data/lib/tray/checkout/transaction.rb +2 -2
- data/lib/tray/checkout/transaction_response_parser.rb +76 -0
- data/lib/tray/checkout/version.rb +1 -1
- data/lib/tray-checkout.rb +5 -2
- data/spec/support/mock_request.rb +2 -1
- data/spec/support/responses/get_account_info.xml +23 -0
- data/spec/support/vcr/model/invalid_token.yml +72 -0
- data/spec/support/vcr/model/valid_token.yml +59 -0
- data/spec/tray/checkout/account_response_parser_spec.rb +70 -0
- data/spec/tray/checkout/account_spec.rb +50 -0
- data/spec/tray/checkout/params_parser_spec.rb +190 -0
- data/spec/tray/checkout/parser_spec.rb +8 -8
- data/spec/tray/checkout/response_parser_spec.rb +18 -155
- data/spec/tray/checkout/transaction_response_parser_spec.rb +183 -0
- data/spec/tray/checkout/transaction_spec.rb +6 -1
- metadata +22 -7
- data/spec/tray/checkout/transaction_params_parser_spec.rb +0 -152
    
        data/README.rdoc
    CHANGED
    
    | @@ -178,6 +178,34 @@ After creating a cart you can forward your client using the cart_url method: | |
| 178 178 | 
             
              temp_transaction = Tray::Checkout::TempTransaction.new
         | 
| 179 179 | 
             
              temp_transaction.cart_url # => http://checkout.sandbox.tray.com.br/payment/car/v1/a906bf32cb59060dfc90769524f99d4a
         | 
| 180 180 |  | 
| 181 | 
            +
             | 
| 182 | 
            +
            === Account
         | 
| 183 | 
            +
             | 
| 184 | 
            +
            You can check the existence as well as the info of an account through its token using the Account class:
         | 
| 185 | 
            +
             | 
| 186 | 
            +
              account = Tray::Checkout::Account.new
         | 
| 187 | 
            +
              response = account.get_by_token("8bfe5ddcb77107b")
         | 
| 188 | 
            +
             | 
| 189 | 
            +
            When account is found
         | 
| 190 | 
            +
             | 
| 191 | 
            +
              response.success? # => true
         | 
| 192 | 
            +
             | 
| 193 | 
            +
              response.people[:name]                  # test
         | 
| 194 | 
            +
              response.people[:email]                 # test@test.com
         | 
| 195 | 
            +
             | 
| 196 | 
            +
              response.service_contact[service_phone] # (55) 5555-5555
         | 
| 197 | 
            +
              response.service_contact[email_service] # test@test.com
         | 
| 198 | 
            +
             | 
| 199 | 
            +
              response.seconds_redirect               # seconds_redirect
         | 
| 200 | 
            +
             | 
| 201 | 
            +
            When account is not found
         | 
| 202 | 
            +
             | 
| 203 | 
            +
              response.success?               # => false
         | 
| 204 | 
            +
              response.people                 # => nil
         | 
| 205 | 
            +
              response.errors.first[:code]    # => "XXXXXX"
         | 
| 206 | 
            +
              response.errors.first[:message] # => "<Error Message>"
         | 
| 207 | 
            +
             | 
| 208 | 
            +
             | 
| 181 209 | 
             
            == Configurations
         | 
| 182 210 |  | 
| 183 211 | 
             
            === Environment
         | 
| @@ -0,0 +1,14 @@ | |
| 1 | 
            +
            # encoding: UTF-8
         | 
| 2 | 
            +
            module Tray
         | 
| 3 | 
            +
              module Checkout
         | 
| 4 | 
            +
                class Account < Tray::Checkout::BaseService
         | 
| 5 | 
            +
                  def api_url
         | 
| 6 | 
            +
                    "#{Tray::Checkout.api_url}/api/people/"
         | 
| 7 | 
            +
                  end
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                  def get_by_token(token)
         | 
| 10 | 
            +
                    request("get_seller_or_company", { token_account: token || Tray::Checkout::token_account })
         | 
| 11 | 
            +
                  end
         | 
| 12 | 
            +
                end
         | 
| 13 | 
            +
              end
         | 
| 14 | 
            +
            end
         | 
| @@ -0,0 +1,70 @@ | |
| 1 | 
            +
            # encoding: UTF-8
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            class Tray::Checkout::AccountResponseParser < Tray::Checkout::ResponseParser
         | 
| 4 | 
            +
              def parse
         | 
| 5 | 
            +
                response = super
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                if response.success?
         | 
| 8 | 
            +
                  response.people           = people
         | 
| 9 | 
            +
                  response.service_contact  = service_contact
         | 
| 10 | 
            +
                  response.seconds_redirect = seconds_redirect
         | 
| 11 | 
            +
                end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                response
         | 
| 14 | 
            +
              end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
              private
         | 
| 17 | 
            +
             | 
| 18 | 
            +
              def people
         | 
| 19 | 
            +
                data_clone = data.clone
         | 
| 20 | 
            +
                data_clone.delete(:service_contact)
         | 
| 21 | 
            +
                data_clone.delete(:seconds_redirect)
         | 
| 22 | 
            +
                data_clone
         | 
| 23 | 
            +
              end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
              def service_contact
         | 
| 26 | 
            +
                data[:service_contact]
         | 
| 27 | 
            +
              end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
              def seconds_redirect
         | 
| 30 | 
            +
                data[:seconds_redirect] ? data[:seconds_redirect][:seconds_redirect] : nil
         | 
| 31 | 
            +
              end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
              def create_data_response
         | 
| 34 | 
            +
                data_response = response_hash[:people] || response_hash[:data_response]
         | 
| 35 | 
            +
                people_map!           data_response
         | 
| 36 | 
            +
                service_contact_map!  data_response
         | 
| 37 | 
            +
                seconds_redirect_map! data_response
         | 
| 38 | 
            +
                date_to_time!         data_response
         | 
| 39 | 
            +
                data_response
         | 
| 40 | 
            +
              end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
              def people_map!(people)
         | 
| 43 | 
            +
                return {} unless people
         | 
| 44 | 
            +
             | 
| 45 | 
            +
                people[:contact_primary] = people.delete(:contact_primary) if people.has_key?(:contact_primary)
         | 
| 46 | 
            +
                people[:name]            = people.delete(:name)            if people.has_key?(:name)
         | 
| 47 | 
            +
                people[:trade_name]      = people.delete(:trade_name)      if people.has_key?(:trade_name)
         | 
| 48 | 
            +
                people[:email]           = people.delete(:email)           if people.has_key?(:email)
         | 
| 49 | 
            +
                people[:url_logo]        = people.delete(:url_logo)        if people.has_key?(:url_logo)
         | 
| 50 | 
            +
                people[:css_url]         = people.delete(:css_url)         if people.has_key?(:css_url)
         | 
| 51 | 
            +
              end
         | 
| 52 | 
            +
             | 
| 53 | 
            +
              def service_contact_map!(people)
         | 
| 54 | 
            +
                return {} if people.blank? || people[:service_contact].blank?
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                service_contact = people[:service_contact]
         | 
| 57 | 
            +
             | 
| 58 | 
            +
                service_contact[:service_phone]        = service_contact.delete(:service_phone) if service_contact.has_key?(:service_phone)
         | 
| 59 | 
            +
                service_contact[:email_service]        = service_contact.delete(:email_service) if service_contact.has_key?(:email_service)
         | 
| 60 | 
            +
                service_contact[:service_phone_status] = service_contact.delete(:service_phone_status)
         | 
| 61 | 
            +
                service_contact[:email_service_status] = service_contact.delete(:email_service_status)
         | 
| 62 | 
            +
              end
         | 
| 63 | 
            +
             | 
| 64 | 
            +
              def seconds_redirect_map!(people)
         | 
| 65 | 
            +
                return {} if people.blank? || people[:seconds_redirect].blank?
         | 
| 66 | 
            +
             | 
| 67 | 
            +
                seconds_redirect = people[:seconds_redirect]
         | 
| 68 | 
            +
                seconds_redirect = seconds_redirect.delete(:seconds_redirect) if seconds_redirect.has_key?(:seconds_redirect)
         | 
| 69 | 
            +
              end
         | 
| 70 | 
            +
            end
         | 
    
        data/lib/tray/checkout/parser.rb
    CHANGED
    
    | @@ -3,13 +3,13 @@ module Tray | |
| 3 3 | 
             
              module Checkout
         | 
| 4 4 | 
             
                class Parser
         | 
| 5 5 | 
             
                  def response(xml)
         | 
| 6 | 
            -
                    response_parser = ResponseParser. | 
| 6 | 
            +
                    response_parser = ResponseParser.get_parser(xml)
         | 
| 7 7 | 
             
                    response_parser.parse
         | 
| 8 8 | 
             
                  end
         | 
| 9 9 |  | 
| 10 | 
            -
                  def  | 
| 11 | 
            -
                     | 
| 12 | 
            -
                     | 
| 10 | 
            +
                  def response_params(params)
         | 
| 11 | 
            +
                    response_params_parser = Tray::Checkout::ParamsParser.new(params)
         | 
| 12 | 
            +
                    response_params_parser.parse
         | 
| 13 13 | 
             
                  end
         | 
| 14 14 | 
             
                end
         | 
| 15 15 | 
             
              end
         | 
| @@ -1,127 +1,70 @@ | |
| 1 1 | 
             
            # encoding: UTF-8
         | 
| 2 2 | 
             
            require 'active_support/core_ext'
         | 
| 3 3 |  | 
| 4 | 
            -
             | 
| 5 | 
            -
               | 
| 6 | 
            -
                 | 
| 7 | 
            -
             | 
| 8 | 
            -
                    @xml = xml
         | 
| 9 | 
            -
                  end
         | 
| 10 | 
            -
             | 
| 11 | 
            -
                  def parse
         | 
| 12 | 
            -
                    response = Response.new
         | 
| 13 | 
            -
                    response.success = success?
         | 
| 14 | 
            -
             | 
| 15 | 
            -
                    if response.success?
         | 
| 16 | 
            -
                      response.transaction = transaction
         | 
| 17 | 
            -
                      response.payment = payment
         | 
| 18 | 
            -
                      response.customer = customer
         | 
| 19 | 
            -
                    else
         | 
| 20 | 
            -
                      response.errors = errors
         | 
| 21 | 
            -
                    end
         | 
| 22 | 
            -
             | 
| 23 | 
            -
                    response
         | 
| 24 | 
            -
                  end
         | 
| 25 | 
            -
             | 
| 26 | 
            -
                  private
         | 
| 27 | 
            -
             | 
| 28 | 
            -
                  def response_hash
         | 
| 29 | 
            -
                    @response_hash ||= create_response_hash
         | 
| 30 | 
            -
                  end
         | 
| 31 | 
            -
             | 
| 32 | 
            -
                  def create_response_hash
         | 
| 33 | 
            -
                    hash = Hash.from_xml(@xml).symbolize_all_keys
         | 
| 34 | 
            -
                    hash[:response] || hash[:tmp_transaction]
         | 
| 35 | 
            -
                  end
         | 
| 36 | 
            -
             | 
| 37 | 
            -
                  def success?
         | 
| 38 | 
            -
                    response_hash[:message_response][:message] == "success"
         | 
| 39 | 
            -
                  end
         | 
| 40 | 
            -
             | 
| 41 | 
            -
                  def transaction
         | 
| 42 | 
            -
                    data_clone = data.clone
         | 
| 43 | 
            -
                    data_clone.delete(:payment)
         | 
| 44 | 
            -
                    data_clone.delete(:customer)
         | 
| 45 | 
            -
                    data_clone
         | 
| 46 | 
            -
                  end
         | 
| 47 | 
            -
             | 
| 48 | 
            -
                  def payment
         | 
| 49 | 
            -
                    data[:payment]
         | 
| 50 | 
            -
                  end
         | 
| 51 | 
            -
             | 
| 52 | 
            -
                  def customer
         | 
| 53 | 
            -
                    data[:customer]
         | 
| 54 | 
            -
                  end
         | 
| 4 | 
            +
            class Tray::Checkout::ResponseParser
         | 
| 5 | 
            +
              def self.transaction?(xml)
         | 
| 6 | 
            +
                xml.include?('<transaction>') || xml.include?('<tmp_transaction>')
         | 
| 7 | 
            +
              end
         | 
| 55 8 |  | 
| 56 | 
            -
             | 
| 57 | 
            -
             | 
| 58 | 
            -
                   | 
| 9 | 
            +
              def self.get_parser(xml)
         | 
| 10 | 
            +
                Tray::Checkout::ResponseParser.transaction?(xml) ? 
         | 
| 11 | 
            +
                  Tray::Checkout::TransactionResponseParser.new(xml) :
         | 
| 12 | 
            +
                  Tray::Checkout::AccountResponseParser.new(xml)
         | 
| 13 | 
            +
              end
         | 
| 59 14 |  | 
| 60 | 
            -
             | 
| 61 | 
            -
             | 
| 62 | 
            -
             | 
| 63 | 
            -
                    payment_map!     data_response
         | 
| 64 | 
            -
                    customer_map!    data_response
         | 
| 65 | 
            -
                    date_to_time!    data_response
         | 
| 66 | 
            -
                    data_response
         | 
| 67 | 
            -
                  end
         | 
| 15 | 
            +
              def initialize(xml)
         | 
| 16 | 
            +
                @xml = xml
         | 
| 17 | 
            +
              end
         | 
| 68 18 |  | 
| 69 | 
            -
             | 
| 70 | 
            -
             | 
| 19 | 
            +
              def parse
         | 
| 20 | 
            +
                response = Tray::Checkout::Response.new
         | 
| 21 | 
            +
                response.success = success?
         | 
| 71 22 |  | 
| 72 | 
            -
             | 
| 73 | 
            -
             | 
| 74 | 
            -
             | 
| 75 | 
            -
                    transaction[:products] = transaction.delete(:transaction_products) if transaction.has_key?(:transaction_products)
         | 
| 76 | 
            -
                  end
         | 
| 23 | 
            +
                unless response.success?
         | 
| 24 | 
            +
                  response.errors = errors
         | 
| 25 | 
            +
                end
         | 
| 77 26 |  | 
| 78 | 
            -
             | 
| 79 | 
            -
             | 
| 27 | 
            +
                response
         | 
| 28 | 
            +
              end
         | 
| 80 29 |  | 
| 81 | 
            -
             | 
| 30 | 
            +
              protected
         | 
| 82 31 |  | 
| 83 | 
            -
             | 
| 84 | 
            -
             | 
| 85 | 
            -
             | 
| 86 | 
            -
                  end
         | 
| 32 | 
            +
              def response_hash
         | 
| 33 | 
            +
                @response_hash ||= create_response_hash
         | 
| 34 | 
            +
              end
         | 
| 87 35 |  | 
| 88 | 
            -
             | 
| 89 | 
            -
             | 
| 36 | 
            +
              def create_response_hash
         | 
| 37 | 
            +
                hash = Hash.from_xml(@xml).symbolize_all_keys
         | 
| 38 | 
            +
                hash[:response] || hash[:tmp_transaction] || hash[:people]
         | 
| 39 | 
            +
              end
         | 
| 90 40 |  | 
| 91 | 
            -
             | 
| 41 | 
            +
              def success?
         | 
| 42 | 
            +
                response_hash[:message_response][:message] == "success"
         | 
| 43 | 
            +
              end
         | 
| 92 44 |  | 
| 93 | 
            -
             | 
| 94 | 
            -
             | 
| 95 | 
            -
             | 
| 96 | 
            -
                        contact[:id] = contact.delete(:contact_id) if contact.has_key?(:contact_id)
         | 
| 97 | 
            -
                        contact[:number] = contact.delete(:value) if contact.has_key?(:value)
         | 
| 98 | 
            -
                      end
         | 
| 99 | 
            -
                    else
         | 
| 100 | 
            -
                      customer[:contacts] = []
         | 
| 101 | 
            -
                    end
         | 
| 102 | 
            -
                  end
         | 
| 45 | 
            +
              def data
         | 
| 46 | 
            +
                @data ||= create_data_response
         | 
| 47 | 
            +
              end
         | 
| 103 48 |  | 
| 104 | 
            -
             | 
| 105 | 
            -
             | 
| 49 | 
            +
              def date_to_time!(hash)
         | 
| 50 | 
            +
                return nil unless hash
         | 
| 106 51 |  | 
| 107 | 
            -
             | 
| 108 | 
            -
             | 
| 52 | 
            +
                hash.each do |key, value|
         | 
| 53 | 
            +
                  date_to_time!(value) if value.is_a?(Hash)
         | 
| 109 54 |  | 
| 110 | 
            -
             | 
| 111 | 
            -
             | 
| 112 | 
            -
                      end
         | 
| 113 | 
            -
                    end
         | 
| 55 | 
            +
                  if key.to_s.starts_with?("date_") && value
         | 
| 56 | 
            +
                    hash[key] = (value.to_time rescue value) || value
         | 
| 114 57 | 
             
                  end
         | 
| 58 | 
            +
                end
         | 
| 59 | 
            +
              end
         | 
| 115 60 |  | 
| 116 | 
            -
             | 
| 117 | 
            -
             | 
| 118 | 
            -
             | 
| 119 | 
            -
                    if error_response[:validation_errors]
         | 
| 120 | 
            -
                      error_response[:errors] = error_response.delete(:validation_errors)
         | 
| 121 | 
            -
                    end
         | 
| 61 | 
            +
              def errors
         | 
| 62 | 
            +
                error_response = response_hash[:error_response]
         | 
| 122 63 |  | 
| 123 | 
            -
             | 
| 124 | 
            -
                   | 
| 64 | 
            +
                if error_response[:validation_errors]
         | 
| 65 | 
            +
                  error_response[:errors] = error_response.delete(:validation_errors)
         | 
| 125 66 | 
             
                end
         | 
| 67 | 
            +
             | 
| 68 | 
            +
                error_response[:errors]
         | 
| 126 69 | 
             
              end
         | 
| 127 70 | 
             
            end
         | 
| @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            # encoding: UTF-8
         | 
| 2 2 | 
             
            module Tray
         | 
| 3 3 | 
             
              module Checkout
         | 
| 4 | 
            -
                class TempTransaction < Tray::Checkout:: | 
| 4 | 
            +
                class TempTransaction < Tray::Checkout::BaseService
         | 
| 5 5 | 
             
                  def api_url
         | 
| 6 6 | 
             
                    "#{Tray::Checkout.api_url}/v1/tmp_transactions/"
         | 
| 7 7 | 
             
                  end
         | 
| @@ -15,7 +15,7 @@ module Tray | |
| 15 15 | 
             
                  end
         | 
| 16 16 |  | 
| 17 17 | 
             
                  def add_to_cart(params)
         | 
| 18 | 
            -
                    @response = request("create", parser. | 
| 18 | 
            +
                    @response = request("create", parser.response_params(params))
         | 
| 19 19 |  | 
| 20 20 | 
             
                    @token_transaction = @response.transaction[:token] if @response.transaction
         | 
| 21 21 |  | 
| @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            # encoding: UTF-8
         | 
| 2 2 | 
             
            module Tray
         | 
| 3 3 | 
             
              module Checkout
         | 
| 4 | 
            -
                class Transaction < Tray::Checkout:: | 
| 4 | 
            +
                class Transaction < Tray::Checkout::BaseService
         | 
| 5 5 | 
             
                  def api_url
         | 
| 6 6 | 
             
                    "#{Tray::Checkout.api_url}/v2/transactions/"
         | 
| 7 7 | 
             
                  end
         | 
| @@ -12,7 +12,7 @@ module Tray | |
| 12 12 | 
             
                  end
         | 
| 13 13 |  | 
| 14 14 | 
             
                  def create(params)
         | 
| 15 | 
            -
                    request("pay_complete", parser. | 
| 15 | 
            +
                    request("pay_complete", parser.response_params(params))
         | 
| 16 16 | 
             
                  end
         | 
| 17 17 | 
             
                end
         | 
| 18 18 | 
             
              end
         | 
| @@ -0,0 +1,76 @@ | |
| 1 | 
            +
            # encoding: UTF-8
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            class Tray::Checkout::TransactionResponseParser < Tray::Checkout::ResponseParser
         | 
| 4 | 
            +
              def parse
         | 
| 5 | 
            +
                response = super
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                if response.success?
         | 
| 8 | 
            +
                  response.transaction = transaction
         | 
| 9 | 
            +
                  response.payment = payment
         | 
| 10 | 
            +
                  response.customer = customer
         | 
| 11 | 
            +
                end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                response
         | 
| 14 | 
            +
              end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
              private
         | 
| 17 | 
            +
             | 
| 18 | 
            +
              def transaction
         | 
| 19 | 
            +
                data_clone = data.clone
         | 
| 20 | 
            +
                data_clone.delete(:payment)
         | 
| 21 | 
            +
                data_clone.delete(:customer)
         | 
| 22 | 
            +
                data_clone
         | 
| 23 | 
            +
              end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
              def payment
         | 
| 26 | 
            +
                data[:payment]
         | 
| 27 | 
            +
              end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
              def customer
         | 
| 30 | 
            +
                data[:customer]
         | 
| 31 | 
            +
              end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
              def create_data_response
         | 
| 34 | 
            +
                data_response = response_hash[:data_response][:transaction] || response_hash[:data_response]
         | 
| 35 | 
            +
                transaction_map! data_response
         | 
| 36 | 
            +
                payment_map!     data_response
         | 
| 37 | 
            +
                customer_map!    data_response
         | 
| 38 | 
            +
                date_to_time!    data_response
         | 
| 39 | 
            +
                data_response
         | 
| 40 | 
            +
              end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
              def transaction_map!(transaction)
         | 
| 43 | 
            +
                return {} unless transaction
         | 
| 44 | 
            +
             | 
| 45 | 
            +
                transaction[:status] = Tray::Checkout::TRANSACTION_STATUS.invert[transaction.delete(:status_id)] if transaction.has_key?(:status_id)
         | 
| 46 | 
            +
                transaction[:id] = transaction.delete(:transaction_id) if transaction.has_key?(:transaction_id)
         | 
| 47 | 
            +
                transaction[:token] = transaction.delete(:token_transaction) if transaction.has_key?(:token_transaction)
         | 
| 48 | 
            +
                transaction[:products] = transaction.delete(:transaction_products) if transaction.has_key?(:transaction_products)
         | 
| 49 | 
            +
              end
         | 
| 50 | 
            +
             | 
| 51 | 
            +
              def payment_map!(transaction)
         | 
| 52 | 
            +
                return {} if transaction.blank? || transaction[:payment].blank?
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                payment = transaction[:payment]
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                payment[:method] = Tray::Checkout::PAYMENT_METHOD.invert[payment.delete(:payment_method_id)] if payment.has_key?(:payment_method_id)
         | 
| 57 | 
            +
                payment[:method_name] = payment.delete(:payment_method_name) if payment.has_key?(:payment_method_name)
         | 
| 58 | 
            +
                payment[:price] = payment.delete(:price_payment) if payment.has_key?(:price_payment)
         | 
| 59 | 
            +
              end
         | 
| 60 | 
            +
             | 
| 61 | 
            +
              def customer_map!(transaction)
         | 
| 62 | 
            +
                return {} if transaction.blank? || transaction[:customer].blank?
         | 
| 63 | 
            +
             | 
| 64 | 
            +
                customer = transaction[:customer]
         | 
| 65 | 
            +
             | 
| 66 | 
            +
                if customer[:contacts]
         | 
| 67 | 
            +
                  customer[:contacts].each do |contact|
         | 
| 68 | 
            +
                    contact[:type] = Tray::Checkout::CONTACT_TYPE.invert[contact.delete(:type_contact)] if contact.has_key?(:type_contact)
         | 
| 69 | 
            +
                    contact[:id] = contact.delete(:contact_id) if contact.has_key?(:contact_id)
         | 
| 70 | 
            +
                    contact[:number] = contact.delete(:value) if contact.has_key?(:value)
         | 
| 71 | 
            +
                  end
         | 
| 72 | 
            +
                else
         | 
| 73 | 
            +
                  customer[:contacts] = []
         | 
| 74 | 
            +
                end
         | 
| 75 | 
            +
              end
         | 
| 76 | 
            +
            end
         | 
    
        data/lib/tray-checkout.rb
    CHANGED
    
    | @@ -6,10 +6,13 @@ require 'tray/checkout/hash' | |
| 6 6 | 
             
            require 'tray/checkout/parser'
         | 
| 7 7 | 
             
            require 'tray/checkout/response'
         | 
| 8 8 | 
             
            require 'tray/checkout/response_parser'
         | 
| 9 | 
            -
            require 'tray/checkout/ | 
| 9 | 
            +
            require 'tray/checkout/transaction_response_parser'
         | 
| 10 | 
            +
            require 'tray/checkout/account_response_parser'
         | 
| 11 | 
            +
            require 'tray/checkout/base_service'
         | 
| 12 | 
            +
            require 'tray/checkout/account'
         | 
| 10 13 | 
             
            require 'tray/checkout/transaction'
         | 
| 11 14 | 
             
            require 'tray/checkout/temp_transaction'
         | 
| 12 | 
            -
            require 'tray/checkout/ | 
| 15 | 
            +
            require 'tray/checkout/params_parser'
         | 
| 13 16 | 
             
            require 'tray/checkout/uri'
         | 
| 14 17 | 
             
            require 'tray/checkout/web_service'
         | 
| 15 18 | 
             
            require 'tray/checkout'
         | 
| @@ -14,7 +14,8 @@ def body_for(response) | |
| 14 14 | 
             
                   :create_success_boleto,
         | 
| 15 15 | 
             
                   :create_success_mastercard,
         | 
| 16 16 | 
             
                   :create_failure_validation_errors,
         | 
| 17 | 
            -
                   :create_temp_transaction_with_token
         | 
| 17 | 
            +
                   :create_temp_transaction_with_token,
         | 
| 18 | 
            +
                   :get_account_info
         | 
| 18 19 | 
             
                read_file_for(response)
         | 
| 19 20 | 
             
              else
         | 
| 20 21 | 
             
                response
         | 
| @@ -0,0 +1,23 @@ | |
| 1 | 
            +
            <people>
         | 
| 2 | 
            +
            	<script id="tinyhippos-injected"/>
         | 
| 3 | 
            +
            	<data_response>
         | 
| 4 | 
            +
            		<contact_primary>08000059230</contact_primary>
         | 
| 5 | 
            +
            		<name>Vendedor Loja Modelo</name>
         | 
| 6 | 
            +
            		<trade_name>Loja Modelo</trade_name>
         | 
| 7 | 
            +
            		<email>lojamodelo@tray.com.br</email>
         | 
| 8 | 
            +
            		<url_logo nil="true"/>
         | 
| 9 | 
            +
            		<css_url>http://default.com/default.css</css_url>
         | 
| 10 | 
            +
            		<service_contact>
         | 
| 11 | 
            +
            			<service_phone>(14)3412-1377</service_phone>
         | 
| 12 | 
            +
            			<email_service>lojamodelo@tray.com.br</email_service>
         | 
| 13 | 
            +
            			<service_phone_status>true</service_phone_status>
         | 
| 14 | 
            +
            			<email_service_status>true</email_service_status>
         | 
| 15 | 
            +
            		</service_contact>
         | 
| 16 | 
            +
            		<seconds_redirect>
         | 
| 17 | 
            +
            			<seconds_redirect nil="true"/>
         | 
| 18 | 
            +
            		</seconds_redirect>
         | 
| 19 | 
            +
            	</data_response>
         | 
| 20 | 
            +
            	<message_response>
         | 
| 21 | 
            +
            		<message>success</message>
         | 
| 22 | 
            +
            	</message_response>
         | 
| 23 | 
            +
            </people>
         | 
| @@ -0,0 +1,72 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            http_interactions:
         | 
| 3 | 
            +
            - request:
         | 
| 4 | 
            +
                method: post
         | 
| 5 | 
            +
                uri: http://api.sandbox.traycheckout.com.br//api/people/get_seller_or_company
         | 
| 6 | 
            +
                body:
         | 
| 7 | 
            +
                  encoding: US-ASCII
         | 
| 8 | 
            +
                  string: token_account=4567
         | 
| 9 | 
            +
                headers:
         | 
| 10 | 
            +
                  Accept:
         | 
| 11 | 
            +
                  - ! '*/*'
         | 
| 12 | 
            +
                  User-Agent:
         | 
| 13 | 
            +
                  - Ruby
         | 
| 14 | 
            +
              response:
         | 
| 15 | 
            +
                status:
         | 
| 16 | 
            +
                  code: 200
         | 
| 17 | 
            +
                  message: !binary |-
         | 
| 18 | 
            +
                    T0s=
         | 
| 19 | 
            +
                headers:
         | 
| 20 | 
            +
                  !binary "U2VydmVy":
         | 
| 21 | 
            +
                  - !binary |-
         | 
| 22 | 
            +
                    bmdpbngvMS40LjE=
         | 
| 23 | 
            +
                  !binary "RGF0ZQ==":
         | 
| 24 | 
            +
                  - !binary |-
         | 
| 25 | 
            +
                    VHVlLCAyNiBOb3YgMjAxMyAyMDo0Mzo1MiBHTVQ=
         | 
| 26 | 
            +
                  !binary "Q29udGVudC1UeXBl":
         | 
| 27 | 
            +
                  - !binary |-
         | 
| 28 | 
            +
                    YXBwbGljYXRpb24veG1sOyBjaGFyc2V0PXV0Zi04
         | 
| 29 | 
            +
                  !binary "VHJhbnNmZXItRW5jb2Rpbmc=":
         | 
| 30 | 
            +
                  - !binary |-
         | 
| 31 | 
            +
                    Y2h1bmtlZA==
         | 
| 32 | 
            +
                  !binary "Q29ubmVjdGlvbg==":
         | 
| 33 | 
            +
                  - !binary |-
         | 
| 34 | 
            +
                    a2VlcC1hbGl2ZQ==
         | 
| 35 | 
            +
                  !binary "U3RhdHVz":
         | 
| 36 | 
            +
                  - !binary |-
         | 
| 37 | 
            +
                    MjAwIE9L
         | 
| 38 | 
            +
                  !binary "WC1VYS1Db21wYXRpYmxl":
         | 
| 39 | 
            +
                  - !binary |-
         | 
| 40 | 
            +
                    SUU9RWRnZSxjaHJvbWU9MQ==
         | 
| 41 | 
            +
                  !binary "RXRhZw==":
         | 
| 42 | 
            +
                  - !binary |-
         | 
| 43 | 
            +
                    IjhlZTc2YWQ1MWRmOWFkMGY5ZTczOTM4Y2JiZmVhMzVmIg==
         | 
| 44 | 
            +
                  !binary "Q2FjaGUtQ29udHJvbA==":
         | 
| 45 | 
            +
                  - !binary |-
         | 
| 46 | 
            +
                    bWF4LWFnZT0wLCBwcml2YXRlLCBtdXN0LXJldmFsaWRhdGU=
         | 
| 47 | 
            +
                  !binary "WC1SZXF1ZXN0LUlk":
         | 
| 48 | 
            +
                  - !binary |-
         | 
| 49 | 
            +
                    ODJmOWIwMDk5ZWIwMmExY2Q5MTM4NTk4YTcyOTFmM2Q=
         | 
| 50 | 
            +
                  !binary "WC1SdW50aW1l":
         | 
| 51 | 
            +
                  - !binary |-
         | 
| 52 | 
            +
                    MC41MTQ4ODM=
         | 
| 53 | 
            +
                  !binary "WC1SYWNrLUNhY2hl":
         | 
| 54 | 
            +
                  - !binary |-
         | 
| 55 | 
            +
                    aW52YWxpZGF0ZSwgcGFzcw==
         | 
| 56 | 
            +
                  !binary "WC1Qb3dlcmVkLUJ5":
         | 
| 57 | 
            +
                  - !binary |-
         | 
| 58 | 
            +
                    UGh1c2lvbiBQYXNzZW5nZXIgNC4wLjE0
         | 
| 59 | 
            +
                body:
         | 
| 60 | 
            +
                  encoding: ASCII-8BIT
         | 
| 61 | 
            +
                  string: !binary |-
         | 
| 62 | 
            +
                    PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHBlb3Bs
         | 
| 63 | 
            +
                    ZT4KICA8ZXJyb3JfcmVzcG9uc2U+CiAgICA8ZXJyb3JzIHR5cGU9ImFycmF5
         | 
| 64 | 
            +
                    Ij4KICAgICAgPGVycm9yPgogICAgICAgIDxtZXNzYWdlPlRva2VuIGludsOh
         | 
| 65 | 
            +
                    bGlkbyBvdSBuw6NvIGVuY29udHJhZG88L21lc3NhZ2U+CiAgICAgICAgPGNv
         | 
| 66 | 
            +
                    ZGU+MDAxMDAxPC9jb2RlPgogICAgICA8L2Vycm9yPgogICAgPC9lcnJvcnM+
         | 
| 67 | 
            +
                    CiAgPC9lcnJvcl9yZXNwb25zZT4KICA8bWVzc2FnZV9yZXNwb25zZT4KICAg
         | 
| 68 | 
            +
                    IDxtZXNzYWdlPmVycm9yPC9tZXNzYWdlPgogIDwvbWVzc2FnZV9yZXNwb25z
         | 
| 69 | 
            +
                    ZT4KPC9wZW9wbGU+Cg==
         | 
| 70 | 
            +
                http_version: 
         | 
| 71 | 
            +
              recorded_at: Tue, 26 Nov 2013 20:43:50 GMT
         | 
| 72 | 
            +
            recorded_with: VCR 2.6.0
         | 
| @@ -0,0 +1,59 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            http_interactions:
         | 
| 3 | 
            +
            - request:
         | 
| 4 | 
            +
                method: post
         | 
| 5 | 
            +
                uri: http://api.sandbox.traycheckout.com.br//api/people/get_seller_or_company
         | 
| 6 | 
            +
                body:
         | 
| 7 | 
            +
                  encoding: US-ASCII
         | 
| 8 | 
            +
                  string: token_account=8bfe5ddcb77207b
         | 
| 9 | 
            +
                headers:
         | 
| 10 | 
            +
                  Accept:
         | 
| 11 | 
            +
                  - ! '*/*'
         | 
| 12 | 
            +
                  User-Agent:
         | 
| 13 | 
            +
                  - Ruby
         | 
| 14 | 
            +
              response:
         | 
| 15 | 
            +
                status:
         | 
| 16 | 
            +
                  code: 200
         | 
| 17 | 
            +
                  message: OK
         | 
| 18 | 
            +
                headers:
         | 
| 19 | 
            +
                  Server:
         | 
| 20 | 
            +
                  - nginx/1.4.1
         | 
| 21 | 
            +
                  Date:
         | 
| 22 | 
            +
                  - Tue, 26 Nov 2013 20:43:43 GMT
         | 
| 23 | 
            +
                  Content-Type:
         | 
| 24 | 
            +
                  - application/xml; charset=utf-8
         | 
| 25 | 
            +
                  Transfer-Encoding:
         | 
| 26 | 
            +
                  - chunked
         | 
| 27 | 
            +
                  Connection:
         | 
| 28 | 
            +
                  - keep-alive
         | 
| 29 | 
            +
                  Status:
         | 
| 30 | 
            +
                  - 200 OK
         | 
| 31 | 
            +
                  X-Ua-Compatible:
         | 
| 32 | 
            +
                  - IE=Edge,chrome=1
         | 
| 33 | 
            +
                  Etag:
         | 
| 34 | 
            +
                  - ! '"3b86a0217ec7a3e770282c02699ff481"'
         | 
| 35 | 
            +
                  Cache-Control:
         | 
| 36 | 
            +
                  - max-age=0, private, must-revalidate
         | 
| 37 | 
            +
                  X-Request-Id:
         | 
| 38 | 
            +
                  - 97dc4a30a04dda43e6569a4ac1828c19
         | 
| 39 | 
            +
                  X-Runtime:
         | 
| 40 | 
            +
                  - '16.021538'
         | 
| 41 | 
            +
                  X-Rack-Cache:
         | 
| 42 | 
            +
                  - invalidate, pass
         | 
| 43 | 
            +
                  X-Powered-By:
         | 
| 44 | 
            +
                  - Phusion Passenger 4.0.14
         | 
| 45 | 
            +
                body:
         | 
| 46 | 
            +
                  encoding: US-ASCII
         | 
| 47 | 
            +
                  string: ! "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<people>\n  <data_response>\n
         | 
| 48 | 
            +
                    \   <contact_primary>08000059230</contact_primary>\n    <name>Vendedor Loja
         | 
| 49 | 
            +
                    Modelo </name>\n    <trade_name>Loja Modelo </trade_name>\n    <email>lojamodelo@tray.com.br</email>\n
         | 
| 50 | 
            +
                    \   <url_logo nil=\"true\"/>\n    <css_url>http://default.com/default.css</css_url>\n
         | 
| 51 | 
            +
                    \   <service_contact>\n      <service_phone>(14)3412-1377</service_phone>\n
         | 
| 52 | 
            +
                    \     <email_service>lojamodelo@tray.com.br</email_service>\n      <service_phone_status>true</service_phone_status>\n
         | 
| 53 | 
            +
                    \     <email_service_status>true</email_service_status>\n    </service_contact>\n
         | 
| 54 | 
            +
                    \   <seconds_redirect>\n      <seconds_redirect nil=\"true\"/>\n    </seconds_redirect>\n
         | 
| 55 | 
            +
                    \ </data_response>\n  <message_response>\n    <message>success</message>\n
         | 
| 56 | 
            +
                    \ </message_response>\n</people>\n"
         | 
| 57 | 
            +
                http_version: 
         | 
| 58 | 
            +
              recorded_at: Tue, 26 Nov 2013 20:43:40 GMT
         | 
| 59 | 
            +
            recorded_with: VCR 2.6.0
         |