Class: Newebpay::MPG::Form

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

Constant Summary collapse

REQUIRED_ATTRS =
%i[order_number description price email payment_methods].freeze
PAYMENT_METHODS =
%i[credit credit_red unionpay webatm vacc cvs barcode android_pay samsung_pay p2g].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Form

Returns a new instance of Form.



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

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.



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

def attrs
  @attrs
end

#merchant_idObject

Returns the value of attribute merchant_id.



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

def merchant_id
  @merchant_id
end

Instance Method Details

#encode_url_paramsObject



36
37
38
# File 'lib/newebpay/mpg/form.rb', line 36

def encode_url_params
  URI.encode_www_form(attrs)
end

#form_attrsObject



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

def form_attrs
  @form_attrs ||= {
    MerchantID: merchant_id,
    TradeInfo: trade_info,
    TradeSha: trade_sha,
    Version: version
  }
end

#trade_infoObject



28
29
30
# File 'lib/newebpay/mpg/form.rb', line 28

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

#trade_shaObject



32
33
34
# File 'lib/newebpay/mpg/form.rb', line 32

def trade_sha
  @trade_sha ||= Newebpay::NewebpayHelper.sha256_encode_trade_info(trade_info)
end

#versionObject



40
41
42
# File 'lib/newebpay/mpg/form.rb', line 40

def version
  '1.5'
end