Class: OffsitePayments::Integrations::Paytm::Notification

Inherits:
Notification
  • Object
show all
Defined in:
lib/offsite_payments/integrations/paytm.rb

Constant Summary collapse

PAYTM_RESPONSE_PARAMS =
%w(MID BANKTXNID TXNAMOUNT CURRENCY STATUS RESPCODE RESPMSG TXNDATE GATEWAYNAME BANKNAME PAYMENTMODE PROMO_CAMP_ID PROMO_STATUS PROMO_RESPCODE ORDERID TXNID REFUNDAMOUNT REFID MERC_UNQ_REF CUSTID TXNDATETIME).freeze

Instance Attribute Summary

Attributes inherited from Notification

#params, #raw

Instance Method Summary collapse

Methods inherited from Notification

#amount, #empty!, #gross_cents, #iso_currency, #test?, #valid_sender?

Constructor Details

#initialize(post, options = {}) ⇒ Notification

Returns a new instance of Notification.



114
115
116
117
# File 'lib/offsite_payments/integrations/paytm.rb', line 114

def initialize(post, options = {})
  super
  @secret_key = options[:credential2]
end

Instance Method Details

#accountObject

Merchant Id provided by the Paytm



179
180
181
# File 'lib/offsite_payments/integrations/paytm.rb', line 179

def 
  @params['MID']
end

#acknowledgeObject



200
201
202
# File 'lib/offsite_payments/integrations/paytm.rb', line 200

def acknowledge
  checksum_ok?
end

#amount_ok?(order_amount) ⇒ Boolean

Order amount should be equal to gross

Returns:

  • (Boolean)


138
139
140
# File 'lib/offsite_payments/integrations/paytm.rb', line 138

def amount_ok?(order_amount)
  BigDecimal(original_gross) == order_amount
end

#checksumObject



196
197
198
# File 'lib/offsite_payments/integrations/paytm.rb', line 196

def checksum
  @params['CHECKSUMHASH']
end

#checksum_ok?Boolean

Returns:

  • (Boolean)


204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# 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?Boolean

Returns:

  • (Boolean)


119
120
121
# File 'lib/offsite_payments/integrations/paytm.rb', line 119

def complete?
  status == 'Completed'
end

#currencyObject

What currency have we been dealing with



165
166
167
# File 'lib/offsite_payments/integrations/paytm.rb', line 165

def currency
  @params['CURRENCY']
end

#grossObject



188
189
190
# File 'lib/offsite_payments/integrations/paytm.rb', line 188

def gross
  parse_and_round_gross_amount(@params['TXNAMOUNT'])
end

#invoiceObject

This is the invoice which you passed to Paytm



174
175
176
# File 'lib/offsite_payments/integrations/paytm.rb', line 174

def invoice
  @params['MERC_UNQ_REF']
end

#invoice_ok?(order_id) ⇒ Boolean

Returns:

  • (Boolean)


133
134
135
# File 'lib/offsite_payments/integrations/paytm.rb', line 133

def invoice_ok?(order_id)
  order_id.to_s == invoice.to_s
end

#item_idObject



169
170
171
# File 'lib/offsite_payments/integrations/paytm.rb', line 169

def item_id
  @params['MERC_UNQ_REF']
end

#messageObject



192
193
194
# File 'lib/offsite_payments/integrations/paytm.rb', line 192

def message
  @params['RESPMSG']
end

#original_grossObject

original amount send by merchant



184
185
186
# File 'lib/offsite_payments/integrations/paytm.rb', line 184

def original_gross
  @params['TXNAMOUNT']
end

#statusObject



123
124
125
126
127
128
129
130
131
# 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_idObject

ID of this transaction (Paytm transaction id)



151
152
153
# File 'lib/offsite_payments/integrations/paytm.rb', line 151

def transaction_id
  @params['TXNID']
end

#transaction_statusObject

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

TXN_SUCCESS
PENDING
TXN_FAILURE


146
147
148
# File 'lib/offsite_payments/integrations/paytm.rb', line 146

def transaction_status
  @params['STATUS']
end

#typeObject

Mode of Payment

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



160
161
162
# File 'lib/offsite_payments/integrations/paytm.rb', line 160

def type
  @params['PAYMENTMODE']
end