class Docdata::Order::Request

Base class for XML requests to Docdata.

Attributes

options[R]

Public Class Methods

new(options = {}) click to toggle source
# File lib/docdata/order/request.rb, line 12
def initialize(options = {})
  @options = options
end

Public Instance Methods

to_s() click to toggle source
# File lib/docdata/order/request.rb, line 16
def to_s
  builder = Builder::XmlMarkup.new

  # Merchant credentials.
  if subject_merchant
    builder.merchant(name: merchant_name, password: merchant_password) do |merchant|
      # The merchant on whose behalf this request should be executed.
      merchant.subjectMerchant(name: subject_merchant_name, token: subject_merchant_token) do |subject|
        if subject_merchant_fee
          # The fee to apply to the subject merchant. If the fee is zero, then it is ignored. A fee can only be applied to create-order requests.
          subject.fee(moment: subject_merchant_fee_moment) do |fee|
            fee.amount(subject_merchant_fee_amount, currency: subject_merchant_fee_currency)
            fee.description(subject_merchant_fee_description) if subject_merchant_fee_description
          end
        end
      end
    end
  else
    builder.merchant(name: merchant_name, password: merchant_password)
  end

  build_request(builder)

  # This element contains information about the application contacting the webservice.
  # This info is useful when debugging troubleshooting technical integration issues.
  builder.integrationInfo do |integration|
    # The name of the plugin used to contact this webservice.
    integration.webshopPlugin("docdata-order")
    # The version of the plugin used to contact this webservice.
    integration.webshopPluginVersion(Docdata::Order::VERSION)
    # The name of the plugin creator used to contact this webservice.
    integration.integratorName("Kentaa")
    # The programming language used to contact this webservice.
    integration.programmingLanguage("Ruby #{RUBY_VERSION}")
    # The operating system from which this webservice is contacted.
    integration.operatingSystem(RUBY_PLATFORM)
    # The full version number (including minor e.q. 1.3.0)
    # of the xsd which is used during integration. DDP can make minor
    # (non-breaking) changes to the xsd. These are reflected in a minor
    # version number. It can therefore be useful to know if a different
    # minor version of the xsd was used during merchant development than
    # the one currently active in production.
    integration.ddpXsdVersion(Docdata::Order::Client::DDP_VERSION)
  end

  builder.target!
end

Private Instance Methods

build_request() click to toggle source
# File lib/docdata/order/request.rb, line 106
def build_request
  raise NotImplementedError
end
merchant_name() click to toggle source
# File lib/docdata/order/request.rb, line 66
def merchant_name
  options.fetch(:merchant).fetch(:name)
end
merchant_password() click to toggle source
# File lib/docdata/order/request.rb, line 70
def merchant_password
  options.fetch(:merchant).fetch(:password)
end
subject_merchant() click to toggle source
# File lib/docdata/order/request.rb, line 74
def subject_merchant
  options[:subject_merchant]
end
subject_merchant_fee() click to toggle source
# File lib/docdata/order/request.rb, line 86
def subject_merchant_fee
  subject_merchant[:fee]
end
subject_merchant_fee_amount() click to toggle source
# File lib/docdata/order/request.rb, line 98
def subject_merchant_fee_amount
  Amount.new(subject_merchant_fee.fetch(:amount)).to_cents
end
subject_merchant_fee_currency() click to toggle source
# File lib/docdata/order/request.rb, line 102
def subject_merchant_fee_currency
  subject_merchant_fee[:currency] || "EUR"
end
subject_merchant_fee_description() click to toggle source
# File lib/docdata/order/request.rb, line 94
def subject_merchant_fee_description
  subject_merchant_fee[:description]
end
subject_merchant_fee_moment() click to toggle source
# File lib/docdata/order/request.rb, line 90
def subject_merchant_fee_moment
  subject_merchant_fee[:moment] || "FULLY_PAID"
end
subject_merchant_name() click to toggle source
# File lib/docdata/order/request.rb, line 78
def subject_merchant_name
  subject_merchant.fetch(:name)
end
subject_merchant_token() click to toggle source
# File lib/docdata/order/request.rb, line 82
def subject_merchant_token
  subject_merchant.fetch(:token)
end