Class: OffsitePayments::Integrations::Newebpay::Helper

Inherits:
Helper
  • Object
show all
Defined in:
lib/offsite_payments/integrations/newebpay/helper.rb

Overview

The Helper to build payment form

Since:

  • 0.1.0

Instance Method Summary collapse

Constructor Details

#initialize(order, account, options = {}) ⇒ Helper

Returns a new instance of Helper.

See Also:

  • Helper#initialize

Since:

  • 0.1.0



13
14
15
16
17
18
19
# File 'lib/offsite_payments/integrations/newebpay/helper.rb', line 13

def initialize(order, , options = {})
  super
  add_field('RespondType', 'JSON')
  add_field('TimeStamp', Time.now.to_i)
  add_field('Version', VERSION)
  add_field('ItemDesc', options[:description])
end

Instance Method Details

#form_fieldsHash

Fields to build form

Returns:

  • (Hash)

Since:

  • 0.1.0



57
58
59
# File 'lib/offsite_payments/integrations/newebpay/helper.rb', line 57

def form_fields
  fields.merge('TradeInfo' => trade_info, 'TradeSha' => trade_sha)
end

#paramsString

The content of trade information

Returns:

  • (String)

Since:

  • 0.1.0



48
49
50
# File 'lib/offsite_payments/integrations/newebpay/helper.rb', line 48

def params
  URI.encode_www_form(fields)
end

#trade_infoString

The encrypted trade information

Returns:

  • (String)

Since:

  • 0.1.0



66
67
68
# File 'lib/offsite_payments/integrations/newebpay/helper.rb', line 66

def trade_info
  ::Newebpay::Cipher.encrypt(params)
end

#trade_shaString

The checksum for trade info

Returns:

  • (String)

Since:

  • 0.1.0



75
76
77
78
79
# File 'lib/offsite_payments/integrations/newebpay/helper.rb', line 75

def trade_sha
  Digest::SHA256
    .hexdigest("HashKey=#{::Newebpay::Config.hash_key}&#{trade_info}&HashIV=#{::Newebpay::Config.hash_iv}")
    .upcase
end