Class: Kount::Inquiry

Inherits:
Request show all
Defined in:
lib/kount/request/inquiry.rb

Overview

This class extends the Request class.

Instance Attribute Summary collapse

Attributes inherited from Request

#params

Instance Method Summary collapse

Methods inherited from Request

#add_params

Constructor Details

#initialize(initial_params = {}) ⇒ Inquiry

Initialize an Inquiry object

Example usage

{:MACK => "Y", :AUTH => "A"}

Parameters:

  • initial_params (Hash) (defaults to: {})

    Initial params for request



13
14
15
16
17
18
19
# File 'lib/kount/request/inquiry.rb', line 13

def initialize(initial_params = {})
  super(initial_params)
  @cart = Cart.new
  # We want Request to default to MODE Q unless a different mode has
  # been passed.
  add_params(MODE: 'Q') unless initial_params.key?(:MODE)
end

Instance Attribute Details

#cartObject

Returns the value of attribute cart.



5
6
7
# File 'lib/kount/request/inquiry.rb', line 5

def cart
  @cart
end

Instance Method Details

#add_cart(cart) ⇒ Object

Puts the cart object into the request for processing

Parameters:



72
73
74
# File 'lib/kount/request/inquiry.rb', line 72

def add_cart(cart)
  @cart = cart
end

#add_payment(type, token = '') ⇒ Object

Convenience method to create the payment params

Parameters:

  • type (String)

    Payment type

  • token (String) (defaults to: '')

    Payment token



86
87
88
# File 'lib/kount/request/inquiry.rb', line 86

def add_payment(type, token = '')
  add_params(PTYP: type, PTOK: token)
end

#add_udf(name, value) ⇒ Object

Add UDF to request

Parameters:

  • name (String)

    UDF label name

  • value (String)

    UDF value



79
80
81
# File 'lib/kount/request/inquiry.rb', line 79

def add_udf(name, value)
  @params.merge!("UDF[#{name}]" => value)
end

#collect_cart_itemsObject

Pulls the cart data into the request params hash



60
61
62
63
64
65
66
67
68
# File 'lib/kount/request/inquiry.rb', line 60

def collect_cart_items
  {
    PROD_TYPE: cart.get_item(:TYPE),
    PROD_DESC: cart.get_item(:DESC),
    PROD_ITEM: cart.get_item(:ITEM),
    PROD_PRICE: cart.get_item(:PRICE),
    PROD_QUANT: cart.get_item(:QUANT)
  }
end

#fixup_payment_params(ksalt, merchant_id) ⇒ Object

rubocop:disable Metrics/AbcSize, Metrics/MethodLength



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/kount/request/inquiry.rb', line 38

def fixup_payment_params(ksalt, merchant_id)
  ptok = params[:PTOK]
  case params[:PTYP]
  when 'CARD', 'TOKEN'
    #ptok = Kount::SecurityMash.hash_credit_card(ptok, ksalt)
    ptok = Kount::NewKhash.HashPaymentToken(ptok, ksalt)
    params.merge!(PTOK: ptok, PENC: 'KHASH')
  when 'GIFT', 'OTHER'
    #ptok = Kount::SecurityMash.hash_gift_card(ptok, ksalt, merchant_id)
    ptok = Kount::NewKhash.HashGiftCard(ptok, ksalt, merchant_id)
    params.merge!(PTOK: ptok, PENC: 'KHASH')
  when 'CHEK', 'OTHER'
    ptok = Kount::NewKhash.HashCheckPayment(ptok, ksalt)
    params.merge!(PTOK: ptok, PENC: 'KHASH')
  when 'NONE'
    params.merge!(PTOK: nil, PENC: nil)
  else
    params[:PENC] ||= 'NONE'
  end
end

#prepare_params(version, merchant_id, response_format, ksalt) ⇒ Object

Parameters:

  • version (String)

    RIS version

  • merchant_id (String)

    Merchant ID

  • response_format (String)

    Response format (JSON)

  • ksalt (String)

    Kount supplied secret salt for KHASH



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/kount/request/inquiry.rb', line 25

def prepare_params(version, merchant_id, response_format, ksalt)
  super(version, merchant_id, response_format, ksalt)
  begin
    params.merge! collect_cart_items
    # The Kount::Request has no knowledge of the KSALT or merchant_id, both
    # of which are needed for KHASH. Request form params have everything we
    # need at this point to do the KHASH if needed.
    fixup_payment_params(ksalt, merchant_id)
  end
  params
end