class Docdata::Order::Client

Client for the Docdata Order API.

Constants

DDP_VERSION
XMLNS_DDP

Public Class Methods

new(name, password, options = {}) click to toggle source
# File lib/docdata/order/client.rb, line 12
def initialize(name, password, options = {})
  @options = options.merge(merchant: { name: name, password: password })
end

Public Instance Methods

create(options = {}) click to toggle source
# File lib/docdata/order/client.rb, line 16
def create(options = {})
  params = @options.merge(options)

  response = client.call(:create, message: CreateRequest.new(params), attributes: { xmlns: XMLNS_DDP, version: DDP_VERSION })

  raise Docdata::Order::Exception, response unless response.success?

  CreateResponse.new(params, response)
end
payment_methods(options = {}) click to toggle source
# File lib/docdata/order/client.rb, line 56
def payment_methods(options = {})
  params = @options.merge(options)

  response = client.call(:list_payment_methods, message: ListPaymentMethodsRequest.new(params), attributes: { xmlns: XMLNS_DDP, version: DDP_VERSION })

  raise Docdata::Order::Exception, response unless response.success?

  ListPaymentMethodsResponse.new(params, response)
end
refund(options = {}) click to toggle source
# File lib/docdata/order/client.rb, line 46
def refund(options = {})
  params = @options.merge(options)

  response = client.call(:refund, message: RefundRequest.new(params), attributes: { xmlns: XMLNS_DDP, version: DDP_VERSION })

  raise Docdata::Order::Exception, response unless response.success?

  RefundResponse.new(params, response)
end
start(options = {}) click to toggle source
# File lib/docdata/order/client.rb, line 26
def start(options = {})
  params = @options.merge(options)

  response = client.call(:start, message: StartRequest.new(params), attributes: { xmlns: XMLNS_DDP, version: DDP_VERSION })

  raise Docdata::Order::Exception, response unless response.success?

  StartResponse.new(params, response)
end
status(options = {}) click to toggle source
# File lib/docdata/order/client.rb, line 36
def status(options = {})
  params = @options.merge(options)

  response = client.call(:status_extended, message: ExtendedStatusRequest.new(params), attributes: { xmlns: XMLNS_DDP, version: DDP_VERSION })

  raise Docdata::Order::Exception, response unless response.success?

  ExtendedStatusResponse.new(params, response)
end

Private Instance Methods

client() click to toggle source
# File lib/docdata/order/client.rb, line 68
def client
  @client ||= begin
    params = { wsdl: wsdl_url, raise_errors: false, namespace_identifier: nil, namespaces: { "xmlns:ddp" => XMLNS_DDP } }

    params.merge!(log: true, log_level: :debug, pretty_print_xml: true) if @options[:debug]

    params[:logger] = Rails.logger if defined?(Rails)

    Savon.client(params)
  end
end
wsdl_url() click to toggle source
# File lib/docdata/order/client.rb, line 80
def wsdl_url
  if @options[:test]
    Urls::WSDL_TEST_URL
  else
    Urls::WSDL_LIVE_URL
  end
end