Module: ZipMoney::Express

Defined in:
lib/zipMoney/express.rb

Constant Summary collapse

ACTION_GET_QUOTE_DETAILS =
'quotedetails'
ACTION_GET_SHIPPING_METHODS =
'shippingmethods'
ACTION_CONFIRM_SHIPPING_METHOD =
'confirmshippingmethod'
ACTION_CONFIRM_ORDER =
'confirmorder'
ACTION_FINALISE_ORDER =
'finaliseorder'
ACTION_CANCEL_QUOTE =
'cancelquote'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#merchant_idObject

Returns the value of attribute merchant_id.



3
4
5
# File 'lib/zipMoney/express.rb', line 3

def merchant_id
  @merchant_id
end

#merchant_keyObject

Returns the value of attribute merchant_key.



3
4
5
# File 'lib/zipMoney/express.rb', line 3

def merchant_key
  @merchant_key
end

Class Method Details

.append_api_credentials(response) ⇒ Object

Parameters:

  • response (response)


34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/zipMoney/express.rb', line 34

def self.append_api_credentials(response)
  response = Hash.new if !response.is_a?(Hash)

  if response["merchant_id"]  == nil 
     response["merchant_id"]  = Configuration.merchant_id
  end

  if response["merchant_key"] == nil
     response["merchant_key"] = Configuration.merchant_key
  end
  response 
end

.prepare_response(response) ⇒ Object

Parameters:

  • response (response)


50
51
52
53
# File 'lib/zipMoney/express.rb', line 50

def self.prepare_response(response)
  response = Util.json_parse(response)
  append_api_credentials(response)
end

.process(action, request, &block) ⇒ Object

Process the express checkout action

Returns the response to the zipMoney Express Api

Parameters:

  • Action (action)
  • Express (request)

    checkout request

  • Actions (block)

    to be taken for respective actions

Raises:



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/zipMoney/express.rb', line 19

def self.process(action, request, &block)
  raise ExpressRequestError, "Action empty" if action.nil?       
  raise ExpressRequestError, "Request empty" if request.nil?
  request = Util.json_parse(request)
  Configuration.credentials_valid(request["merchant_id"], request["merchant_key"])
  if (block.arity > 0)
        response = block.call(action, request)
        raise ExpressResponseError, "No response provided" if response.nil?
        puts send_response(response)
  end  
end

.send_response(response) ⇒ Object

Parameters:

  • response (response)


58
59
60
# File 'lib/zipMoney/express.rb', line 58

def self.send_response(response)
  prepare_response(response).to_json
end