Class: Newebpay::Donation::Form

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

Constant Summary collapse

REQUIRED_ATTRS =
%i[order_number description price].freeze
PAYMENT_METHODS =
%i[credit webatm vacc cvs barcode].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(donation_url, options) ⇒ Form

Returns a new instance of Form.



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

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

  check_valid(options)
  parse_attr(options)

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

Instance Attribute Details

#attrsObject

Returns the value of attribute attrs.



5
6
7
# File 'lib/newebpay/donation/form.rb', line 5

def attrs
  @attrs
end

#donation_urlObject

Returns the value of attribute donation_url.



5
6
7
# File 'lib/newebpay/donation/form.rb', line 5

def donation_url
  @donation_url
end

#merchant_idObject

Returns the value of attribute merchant_id.



5
6
7
# File 'lib/newebpay/donation/form.rb', line 5

def merchant_id
  @merchant_id
end

Instance Method Details

#check_valueObject



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

def check_value
  @check_value ||= Newebpay::NewebpayHelper.sha256_encode(Newebpay.config.hash_key, Newebpay.config.hash_iv, check_value_raw)
end

#check_value_rawObject



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

def check_value_raw
  URI.encode_www_form(attrs.slice('Amt', 'MerchantID', 'MerchantOrderNo', 'TimeStamp', 'Version').sort)
end

#form_attrsObject



23
24
25
# File 'lib/newebpay/donation/form.rb', line 23

def form_attrs
  @form_attrs ||= @attrs
end

#versionObject



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

def version
  '1.0'
end