Class: GmoPayment::Client::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/gmo_payment/client/request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(called_method, args) ⇒ Request

Returns a new instance of Request.

Parameters:

  • called_method (Symbol)
  • args (Hash)


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/gmo_payment/client/request.rb', line 9

def initialize(called_method, args)
  @called_method = called_method
  input =
    args.each_with_object({}) do |(k, v), hash|
      key = k.to_s.downcase.to_sym
      value = case key
        when :job_cd
          v.to_s.upcase
        when :amount, :card_seq, :default_flag, :method, :pay_times, :seq_mode, :tax, :td_flag, :timeout
          v.to_i.to_s
        else
          v.to_s
        end
      hash[key] = value
    end
  [:site_id, :site_pass, :shop_id, :shop_pass].each do |key|
    if all_items.include?(key)
      input[key] ||= GmoPayment::Configure.__send__(key) || ENV[GmoPayment::GLOSSARY[key]]
    end
  end
  @input = input.reject { |_, v| v.nil? }
  @missing_items = self.missing_items
  @invalid_items = self.invalid_items
end

Instance Attribute Details

#called_methodObject (readonly)

Returns the value of attribute called_method.



35
36
37
# File 'lib/gmo_payment/client/request.rb', line 35

def called_method
  @called_method
end

Instance Method Details

#bodyString?

Request body.

Returns:

  • (String, nil)


101
102
103
104
105
106
107
108
109
# File 'lib/gmo_payment/client/request.rb', line 101

def body
  body_hash =
    @input.each_with_object({}) do |(k, v), hash|
      next unless (key = GmoPayment::GLOSSARY[k]) && all_items.include?(k)
      hash[key] = k == :td_tenant_name ? encode_euc_base64(v) : encode_sjis(v)
    end
  body = ::URI.encode_www_form(body_hash)
  body.empty? ? nil : body
end

#invalid?Bloolean

Whether to have invalid items or not.

Returns:

  • (Bloolean)


94
95
96
# File 'lib/gmo_payment/client/request.rb', line 94

def invalid?
  !invalid_items.empty?
end

#invalid_itemsHash

Validate to have invalid items.

Returns:

  • (Hash)


72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/gmo_payment/client/request.rb', line 72

def invalid_items
  return @invalid_items if @invalid_items

  items = @input.select { |k, v| validate_invalid?(k, v) if all_items.include?(k) }
  case @called_method
  when :entry_tran, :re_exec_tran, :change_tran
    unless (1..9_999_999).include?(@input[:amount].to_i + @input[:tax].to_i)
      items[:amount] = @input[:amount] if @input[:amount]
      items[:tax]    = @input[:tax]    if @input[:tax]
    end
  when :entry_tran_btc
    unless (1..300_000).include?(@input[:amount].to_i + @input[:tax].to_i)
      items[:amount] = @input[:amount] if @input[:amount]
      items[:tax]    = @input[:tax]    if @input[:tax]
    end
  end
  @invalid_items = items
end

#missing?Boolean

Whether to have missing items or not.

Returns:

  • (Boolean)


65
66
67
# File 'lib/gmo_payment/client/request.rb', line 65

def missing?
  !missing_items.empty?
end

#missing_itemsArray

Check missing items.

Returns:

  • (Array)


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/gmo_payment/client/request.rb', line 40

def missing_items
  return @missing_items if @missing_items

  array = case @called_method
    when :entry_tran
      if @input[:job_cd] && ['CAPTURE', 'AUTH', 'SAUTH'].include?(@input[:job_cd])
        required_items << :amount
      else
        required_items
      end
    when :exec_tran, :exec_tran_3d, :exec_tran_member, :exec_tran_member_3d, :re_exec_tran
      if @input[:method] && ['2', '4'].include?(@input[:method])
        required_items << :pay_times
      else
        required_items
      end
    else
      required_items
    end
  @missing_items = array.select { |item| @input[item].nil? }
end