Class: Moneybookers::API::PayOnDemand

Inherits:
Object
  • Object
show all
Defined in:
lib/moneybookers/api/pay_on_demand.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ PayOnDemand

Returns a new instance of PayOnDemand.



7
8
9
10
11
# File 'lib/moneybookers/api/pay_on_demand.rb', line 7

def initialize(params={})
  params[:password] ||= Moneybookers.password
  params[:email] ||= Moneybookers.email
  @parameters = params
end

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount.



5
6
7
# File 'lib/moneybookers/api/pay_on_demand.rb', line 5

def amount
  @amount
end

#currencyObject (readonly)

Returns the value of attribute currency.



5
6
7
# File 'lib/moneybookers/api/pay_on_demand.rb', line 5

def currency
  @currency
end

#mb_transaction_idObject (readonly)

Returns the value of attribute mb_transaction_id.



5
6
7
# File 'lib/moneybookers/api/pay_on_demand.rb', line 5

def mb_transaction_id
  @mb_transaction_id
end

#parametersObject (readonly)

Returns the value of attribute parameters.



5
6
7
# File 'lib/moneybookers/api/pay_on_demand.rb', line 5

def parameters
  @parameters
end

#prepare_responseObject (readonly)

Returns the value of attribute prepare_response.



5
6
7
# File 'lib/moneybookers/api/pay_on_demand.rb', line 5

def prepare_response
  @prepare_response
end

#request_responseObject (readonly)

Returns the value of attribute request_response.



5
6
7
# File 'lib/moneybookers/api/pay_on_demand.rb', line 5

def request_response
  @request_response
end

#session_idObject (readonly)

Returns the value of attribute session_id.



5
6
7
# File 'lib/moneybookers/api/pay_on_demand.rb', line 5

def session_id
  @session_id
end

#statusObject (readonly)

Returns the value of attribute status.



5
6
7
# File 'lib/moneybookers/api/pay_on_demand.rb', line 5

def status
  @status
end

#status_codeObject (readonly)

Returns the value of attribute status_code.



5
6
7
# File 'lib/moneybookers/api/pay_on_demand.rb', line 5

def status_code
  @status_code
end

Instance Method Details

#handle_prepare_responseObject

TODO: handle errors - moneybookers returns 200 with xml error_msg

Raises:

  • (StandardError)


27
28
29
30
31
32
# File 'lib/moneybookers/api/pay_on_demand.rb', line 27

def handle_prepare_response
  document = REXML::Document.new(@prepare_response.body)
  raise StandardError.new(document.elements["response/error/error_msg"].text) if document.elements["response/error"]
  @session_id = document.elements["response/sid"].text
  true
end

#handle_request_responseObject

Raises:

  • (StandardError)


34
35
36
37
38
39
40
41
42
43
44
# File 'lib/moneybookers/api/pay_on_demand.rb', line 34

def handle_request_response
  document = REXML::Document.new(@request_response.body)
  raise StandardError.new(document.elements["response/error/error_msg"].text) if document.elements["response/error"]
  document = document.elements["response/transaction"]
  @mb_transaction_id = document.elements["id"].text
  @amount         = document.elements["amount"].text
  @currency       = document.elements["currency"].text
  @status         = document.elements["status_msg"].text
  @status_code    = document.elements["status"].text
  true
end

#prepareObject



13
14
15
16
17
# File 'lib/moneybookers/api/pay_on_demand.rb', line 13

def prepare
  validate_prepare_parameters
  @prepare_response = Moneybookers::Request.new.post("/app/ondemand_request.pl", parameters.merge({:action => "prepare"}))
  handle_prepare_response
end

#request(params = {}) ⇒ Object



19
20
21
22
23
24
# File 'lib/moneybookers/api/pay_on_demand.rb', line 19

def request(params={})
  params[:action] ||= "request"
  params[:sid] ||= session_id || raise(ArgumentError.new("You must specify sid for pay-on-demand request transaction"))
  @request_response = Moneybookers::Request.new.post("/app/ondemand_request.pl", params)
  handle_request_response
end

#validate_prepare_parametersObject



46
47
48
49
50
51
52
53
54
# File 'lib/moneybookers/api/pay_on_demand.rb', line 46

def validate_prepare_parameters
  [:email, :password, :amount, :currency].each do |attribute|
    raise ArgumentError.new("You must specify #{attribute} for preparing pay-on-demand transaction") unless parameters[attribute]
  end
  if !parameters.has_key?(:rec_payment_id) and !parameters.has_key?(:frn_transaction_id)
    raise ArgumentError.new("You must specify frn_transaction_id or rec_payment_id for preparing pay-on-demand transaction")
  end
  true
end