Class: Docdata::Order::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/docdata/order/client.rb

Overview

Client for the Docdata Order API.

Constant Summary collapse

XMLNS_DDP =
"http://www.docdatapayments.com/services/paymentservice/1_3/"
DDP_VERSION =
"1.3"

Instance Method Summary collapse

Constructor Details

#initialize(name, password, options = {}) ⇒ Client



12
13
14
# File 'lib/docdata/order/client.rb', line 12

def initialize(name, password, options = {})
  @options = options.merge(merchant: { name: name, password: password })
end

Instance Method Details

#create(options = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
# 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 = {}) ⇒ Object



56
57
58
59
60
61
62
63
64
# 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 = {}) ⇒ Object



46
47
48
49
50
51
52
53
54
# 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 = {}) ⇒ Object



26
27
28
29
30
31
32
33
34
# 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 = {}) ⇒ Object



36
37
38
39
40
41
42
43
44
# 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