Module: OffsitePayments::Integrations::Newebpay::HasTradeInfo

Included in:
Notification, Return
Defined in:
lib/offsite_payments/integrations/newebpay/concern/has_trade_info.rb

Overview

The shared module for return and notification object

Since:

  • 0.1.0

Instance Method Summary collapse

Instance Method Details

#checksumString

The TradeSha calculated in client-side

Returns:

  • (String)

Since:

  • 0.1.0



27
28
29
30
31
32
33
# File 'lib/offsite_payments/integrations/newebpay/concern/has_trade_info.rb', line 27

def checksum
  @checksum ||=
    Digest::SHA256
    .hexdigest("HashKey=#{::Newebpay::Config.hash_key}&" \
               "#{params['TradeInfo']}&HashIV=#{::Newebpay::Config.hash_iv}")
    .upcase
end

#trade_infoHash

Trade Information from NewebPay

Returns:

  • (Hash)

Since:

  • 0.1.0



15
16
17
18
19
20
# File 'lib/offsite_payments/integrations/newebpay/concern/has_trade_info.rb', line 15

def trade_info
  @trade_info ||=
    JSON.parse(::Newebpay::Cipher.decrypt(params['TradeInfo']))
rescue JSON::ParserError, TypeError
  {}
end

#valid?TrueClass|FalseClass

Does TradeInfo is valid

Returns:

  • (TrueClass|FalseClass)

Since:

  • 0.1.0



40
41
42
# File 'lib/offsite_payments/integrations/newebpay/concern/has_trade_info.rb', line 40

def valid?
  checksum == params['TradeSha']
end