class GpWebpay::Http::HttpRequest

Constants

ATTRS_TO_GP_MAPPER

Attributes

attributes[RW]

Public Class Methods

new(attributes) click to toggle source
# File lib/gp_webpay/http/http_request.rb, line 28
def initialize(attributes)
  @attributes = attributes || {}
end

Public Instance Methods

to_gpwebpay() click to toggle source
# File lib/gp_webpay/http/http_request.rb, line 32
def to_gpwebpay
  @to_gpwebpay ||= transform_to_gpwebpay
end

Private Instance Methods

add_info_to_xml() click to toggle source
# File lib/gp_webpay/http/http_request.rb, line 47
def add_info_to_xml
  builder = Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml|
    xml.additionalInfoRequest(xmlns: 'http://gpe.cz/gpwebpay/additionalInfo/request',
                              'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
                              version: 4.0) do
      xml.requestReturnInfo do
        xml.requestCardsDetails true
      end
    end
  end
  builder.to_xml(
    save_with: Nokogiri::XML::Node::SaveOptions::AS_XML
  ).strip.gsub("\n", '')
end
transform_to_gpwebpay() click to toggle source
# File lib/gp_webpay/http/http_request.rb, line 38
def transform_to_gpwebpay
  result = ATTRS_TO_GP_MAPPER.each_with_object({}) do |(k, v), attrs|
    attribute_value = attributes[v] || attributes[v.to_s]
    attrs[k] = attribute_value if attribute_value
  end
  result = result.merge({ 'ADDINFO' => add_info_to_xml }) if attributes[:add_info] || attributes['add_info']
  result
end