Class: Moneybookers::API::PayOnDemand
- Inherits:
-
Object
- Object
- Moneybookers::API::PayOnDemand
- Defined in:
- lib/moneybookers/api/pay_on_demand.rb
Instance Attribute Summary collapse
-
#amount ⇒ Object
readonly
Returns the value of attribute amount.
-
#currency ⇒ Object
readonly
Returns the value of attribute currency.
-
#mb_transaction_id ⇒ Object
readonly
Returns the value of attribute mb_transaction_id.
-
#parameters ⇒ Object
readonly
Returns the value of attribute parameters.
-
#prepare_response ⇒ Object
readonly
Returns the value of attribute prepare_response.
-
#request_response ⇒ Object
readonly
Returns the value of attribute request_response.
-
#session_id ⇒ Object
readonly
Returns the value of attribute session_id.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#status_code ⇒ Object
readonly
Returns the value of attribute status_code.
Instance Method Summary collapse
-
#handle_prepare_response ⇒ Object
TODO: handle errors - moneybookers returns 200 with xml error_msg.
- #handle_request_response ⇒ Object
-
#initialize(params = {}) ⇒ PayOnDemand
constructor
A new instance of PayOnDemand.
- #prepare ⇒ Object
- #request(params = {}) ⇒ Object
- #validate_prepare_parameters ⇒ Object
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
#amount ⇒ Object (readonly)
Returns the value of attribute amount.
5 6 7 |
# File 'lib/moneybookers/api/pay_on_demand.rb', line 5 def amount @amount end |
#currency ⇒ Object (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_id ⇒ Object (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 |
#parameters ⇒ Object (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_response ⇒ Object (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_response ⇒ Object (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_id ⇒ Object (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 |
#status ⇒ Object (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_code ⇒ Object (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_response ⇒ Object
TODO: handle errors - moneybookers returns 200 with xml error_msg
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_response ⇒ Object
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 |
#prepare ⇒ Object
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_parameters ⇒ Object
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 |