Class: OffsitePayments::Integrations::Paytm::Notification
- Inherits:
-
Notification
- Object
- Notification
- OffsitePayments::Integrations::Paytm::Notification
- 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
Instance Method Summary collapse
-
#account ⇒ Object
Merchant Id provided by the Paytm.
- #acknowledge ⇒ Object
-
#amount_ok?(order_amount) ⇒ Boolean
Order amount should be equal to gross.
- #checksum ⇒ Object
- #checksum_ok? ⇒ Boolean
- #complete? ⇒ Boolean
-
#currency ⇒ Object
What currency have we been dealing with.
- #gross ⇒ Object
-
#initialize(post, options = {}) ⇒ Notification
constructor
A new instance of Notification.
-
#invoice ⇒ Object
This is the invoice which you passed to Paytm.
- #invoice_ok?(order_id) ⇒ Boolean
- #item_id ⇒ Object
- #message ⇒ Object
-
#original_gross ⇒ Object
original amount send by merchant.
- #status ⇒ Object
-
#transaction_id ⇒ Object
ID of this transaction (Paytm transaction id).
-
#transaction_status ⇒ Object
Status of transaction return from the Paytm.
-
#type ⇒ Object
Mode of Payment.
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, = {}) super @secret_key = [:credential2] end |
Instance Method Details
#account ⇒ Object
Merchant Id provided by the Paytm
179 180 181 |
# File 'lib/offsite_payments/integrations/paytm.rb', line 179 def account @params['MID'] end |
#acknowledge ⇒ Object
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
138 139 140 |
# File 'lib/offsite_payments/integrations/paytm.rb', line 138 def amount_ok?(order_amount) BigDecimal(original_gross) == order_amount end |
#checksum ⇒ Object
196 197 198 |
# File 'lib/offsite_payments/integrations/paytm.rb', line 196 def checksum @params['CHECKSUMHASH'] end |
#checksum_ok? ⇒ 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
119 120 121 |
# File 'lib/offsite_payments/integrations/paytm.rb', line 119 def complete? status == 'Completed' end |
#currency ⇒ Object
What currency have we been dealing with
165 166 167 |
# File 'lib/offsite_payments/integrations/paytm.rb', line 165 def currency @params['CURRENCY'] end |
#gross ⇒ Object
188 189 190 |
# File 'lib/offsite_payments/integrations/paytm.rb', line 188 def gross parse_and_round_gross_amount(@params['TXNAMOUNT']) end |
#invoice ⇒ Object
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
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_id ⇒ Object
169 170 171 |
# File 'lib/offsite_payments/integrations/paytm.rb', line 169 def item_id @params['MERC_UNQ_REF'] end |
#message ⇒ Object
192 193 194 |
# File 'lib/offsite_payments/integrations/paytm.rb', line 192 def @params['RESPMSG'] end |
#original_gross ⇒ Object
original amount send by merchant
184 185 186 |
# File 'lib/offsite_payments/integrations/paytm.rb', line 184 def original_gross @params['TXNAMOUNT'] end |
#status ⇒ Object
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_id ⇒ Object
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_status ⇒ Object
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 |
#type ⇒ Object
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 |