Class: Newebpay::Periodical::Form

Inherits:
Object
  • Object
show all
Defined in:
lib/newebpay/periodical/form.rb

Constant Summary collapse

REQUIRED_ATTRS =
%i[order_number description price email].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Form

Returns a new instance of Form.



9
10
11
12
13
14
15
16
17
18
# File 'lib/newebpay/periodical/form.rb', line 9

def initialize(options)
  check_valid(options)
  @attrs = {}
  @merchant_id = options[:merchant_id] || Newebpay.config.merchant_id
  parse_attr(options)

  @attrs['Version'] = version
  @attrs['TimeStamp'] = Time.now.to_i
  @attrs['RespondType'] = 'JSON'
end

Instance Attribute Details

#attrsObject

Returns the value of attribute attrs.



8
9
10
# File 'lib/newebpay/periodical/form.rb', line 8

def attrs
  @attrs
end

#merchant_idObject

Returns the value of attribute merchant_id.



8
9
10
# File 'lib/newebpay/periodical/form.rb', line 8

def merchant_id
  @merchant_id
end

Instance Method Details

#encode_url_paramsObject



31
32
33
# File 'lib/newebpay/periodical/form.rb', line 31

def encode_url_params
  URI.encode_www_form(attrs)
end

#form_attrsObject



20
21
22
23
24
25
# File 'lib/newebpay/periodical/form.rb', line 20

def form_attrs
  @form_attrs ||= {
    MerchantID_: merchant_id,
    PostData_: trade_info
  }
end

#trade_infoObject



27
28
29
# File 'lib/newebpay/periodical/form.rb', line 27

def trade_info
  @trade_info ||= Newebpay::NewebpayHelper.encrypt_data(encode_url_params)
end

#versionObject



35
36
37
# File 'lib/newebpay/periodical/form.rb', line 35

def version
  '1.0'
end