class OffsitePayments::Integrations::Paytm::Notification

Constants

PAYTM_RESPONSE_PARAMS

Public Class Methods

new(post, options = {}) click to toggle source
Calls superclass method OffsitePayments::Notification::new
# File lib/offsite_payments/integrations/paytm.rb, line 114
def initialize(post, options = {})
  super
  @secret_key = options[:credential2]
end

Public Instance Methods

account() click to toggle source

Merchant Id provided by the Paytm

# File lib/offsite_payments/integrations/paytm.rb, line 179
def account
  @params['MID']
end
acknowledge() click to toggle source
# File lib/offsite_payments/integrations/paytm.rb, line 200
def acknowledge
  checksum_ok?
end
amount_ok?(order_amount) click to toggle source

Order amount should be equal to gross

# File lib/offsite_payments/integrations/paytm.rb, line 138
def amount_ok?(order_amount)
  BigDecimal(original_gross) == order_amount
end
checksum() click to toggle source
# File lib/offsite_payments/integrations/paytm.rb, line 196
def checksum
  @params['CHECKSUMHASH']
end
checksum_ok?() click to toggle source
# File lib/offsite_payments/integrations/paytm.rb, line 204
def checksum_ok?
  return false if checksum.nil?

  normalized_data = checksum.delete("\n").tr(' ', '+')
  encrypted_data = Base64.strict_decode64(normalized_data)

  aes = OpenSSL::Cipher::Cipher.new(CIPHER)
  aes.decrypt
  aes.key = @secret_key
  aes.iv = STATIC_IV
  received_checksum = aes.update(encrypted_data) + aes.final

  salt = received_checksum[-SALT_LENGTH..-1]
  expected_params = @params.keep_if { |k| PAYTM_RESPONSE_PARAMS.include?(k) }.sort.to_h
  expected_checksum = Paytm.checksum(expected_params, salt)

  if received_checksum == expected_checksum
    @message = @params['RESPMSG']
    @params['RESPCODE'] == '01'
  else
    @message = 'Return checksum not matching the data provided'
    false
  end
end
complete?() click to toggle source
# File lib/offsite_payments/integrations/paytm.rb, line 119
def complete?
  status == 'Completed'
end
currency() click to toggle source

What currency have we been dealing with

# File lib/offsite_payments/integrations/paytm.rb, line 165
def currency
  @params['CURRENCY']
end
gross() click to toggle source
# File lib/offsite_payments/integrations/paytm.rb, line 188
def gross
  parse_and_round_gross_amount(@params['TXNAMOUNT'])
end
invoice() click to toggle source

This is the invoice which you passed to Paytm

# File lib/offsite_payments/integrations/paytm.rb, line 174
def invoice
  @params['MERC_UNQ_REF']
end
invoice_ok?(order_id) click to toggle source
# File lib/offsite_payments/integrations/paytm.rb, line 133
def invoice_ok?(order_id)
  order_id.to_s == invoice.to_s
end
item_id() click to toggle source
# File lib/offsite_payments/integrations/paytm.rb, line 169
def item_id
  @params['MERC_UNQ_REF']
end
message() click to toggle source
# File lib/offsite_payments/integrations/paytm.rb, line 192
def message
  @params['RESPMSG']
end
original_gross() click to toggle source

original amount send by merchant

# File lib/offsite_payments/integrations/paytm.rb, line 184
def original_gross
  @params['TXNAMOUNT']
end
status() click to toggle source
# File lib/offsite_payments/integrations/paytm.rb, line 123
def status
  if transaction_status.casecmp("TXN_SUCCESS").zero?
    'Completed'
  elsif transaction_status.casecmp("pending").zero?
    'Pending'
  else
    'Failed'
  end
end
transaction_id() click to toggle source

ID of this transaction (Paytm transaction id)

# File lib/offsite_payments/integrations/paytm.rb, line 151
def transaction_id
  @params['TXNID']
end
transaction_status() click to toggle source

Status of transaction return from the Paytm. List of possible values:

TXN_SUCCESS
PENDING
TXN_FAILURE
# File lib/offsite_payments/integrations/paytm.rb, line 146
def transaction_status
  @params['STATUS']
end
type() click to toggle source

Mode of Payment

‘CC’ for credit-card ‘NB’ for net-banking ‘PPI’ for wallet

# File lib/offsite_payments/integrations/paytm.rb, line 160
def type
  @params['PAYMENTMODE']
end

Private Instance Methods

parse_and_round_gross_amount(amount) click to toggle source
# File lib/offsite_payments/integrations/paytm.rb, line 231
def parse_and_round_gross_amount(amount)
  rounded_amount = (amount.to_f * 100.0).round
  sprintf('%.2f', rounded_amount / 100.00)
end