Class: PayuIndia::Notification
- Inherits:
-
Object
- Object
- PayuIndia::Notification
- Defined in:
- lib/payuindia.rb
Instance Method Summary collapse
-
#account ⇒ Object
Merchant Id provided by the PayU.in.
- #acknowledge(authcode = nil) ⇒ Object
-
#amount_ok?(order_amount, order_discount = BigDecimal.new( '0.0' )) ⇒ Boolean
Order amount should be equal to gross - discount.
- #checksum ⇒ Object
- #checksum_ok? ⇒ Boolean
- #complete? ⇒ Boolean
-
#currency ⇒ Object
What currency have we been dealing with.
-
#customer_address ⇒ Object
Full address of the customer.
-
#customer_email ⇒ Object
Email of the customer.
-
#customer_first_name ⇒ Object
Firstname of the customer.
-
#customer_last_name ⇒ Object
Lastname of the customer.
-
#customer_phone ⇒ Object
Phone of the customer.
-
#discount ⇒ Object
This is discount given to user - based on promotion set by merchants.
-
#gross ⇒ Object
original amount send by merchant.
-
#initialize(post, options = {}) ⇒ Notification
constructor
A new instance of Notification.
-
#invoice ⇒ Object
This is the invoice which you passed to PayU.in.
- #invoice_ok?(order_id) ⇒ Boolean
- #message ⇒ Object
-
#offer_description ⇒ Object
Description offer for what PayU given the offer to user - based on promotion set by merchants.
- #params ⇒ Object
-
#product_info ⇒ Object
Information about the product as send by merchant.
- #status ⇒ Object
-
#transaction_id ⇒ Object
ID of this transaction (PayU.in number).
-
#transaction_status ⇒ Object
Status of transaction return from the PayU.
-
#type ⇒ Object
Mode of Payment.
- #user_defined ⇒ Object
Constructor Details
#initialize(post, options = {}) ⇒ Notification
Returns a new instance of Notification.
88 89 90 91 92 |
# File 'lib/payuindia.rb', line 88 def initialize(post, = {}) @key = [:key] @salt = [:salt] @params = [:params] end |
Instance Method Details
#account ⇒ Object
Merchant Id provided by the PayU.in
161 162 163 |
# File 'lib/payuindia.rb', line 161 def account params['key'] end |
#acknowledge(authcode = nil) ⇒ Object
224 225 226 |
# File 'lib/payuindia.rb', line 224 def acknowledge(authcode = nil) checksum_ok? end |
#amount_ok?(order_amount, order_discount = BigDecimal.new( '0.0' )) ⇒ Boolean
Order amount should be equal to gross - discount
123 124 125 |
# File 'lib/payuindia.rb', line 123 def amount_ok?( order_amount, order_discount = BigDecimal.new( '0.0' ) ) BigDecimal.new( gross ) == order_amount && BigDecimal.new( discount.to_s ) == order_discount end |
#checksum ⇒ Object
216 217 218 |
# File 'lib/payuindia.rb', line 216 def checksum params['hash'] end |
#checksum_ok? ⇒ Boolean
228 229 230 231 232 233 234 235 236 |
# File 'lib/payuindia.rb', line 228 def checksum_ok? checksum_fields = [transaction_status, *user_defined.reverse, customer_email, customer_first_name, product_info, gross, invoice] unless Digest::SHA512.hexdigest([@salt, *checksum_fields, @key].join("|")) == checksum @message = 'Return checksum not matching the data provided' return false end true end |
#complete? ⇒ Boolean
94 95 96 |
# File 'lib/payuindia.rb', line 94 def complete? status == "Completed" end |
#currency ⇒ Object
What currency have we been dealing with
151 152 153 |
# File 'lib/payuindia.rb', line 151 def currency 'INR' end |
#customer_address ⇒ Object
Full address of the customer
206 207 208 209 210 |
# File 'lib/payuindia.rb', line 206 def customer_address { :address1 => params['address1'], :address2 => params['address2'], :city => params['city'], :state => params['state'], :country => params['country'], :zipcode => params['zipcode'] } end |
#customer_email ⇒ Object
Email of the customer
186 187 188 |
# File 'lib/payuindia.rb', line 186 def customer_email params['email'] end |
#customer_first_name ⇒ Object
Firstname of the customer
196 197 198 |
# File 'lib/payuindia.rb', line 196 def customer_first_name params['firstname'] end |
#customer_last_name ⇒ Object
Lastname of the customer
201 202 203 |
# File 'lib/payuindia.rb', line 201 def customer_last_name params['lastname'] end |
#customer_phone ⇒ Object
Phone of the customer
191 192 193 |
# File 'lib/payuindia.rb', line 191 def customer_phone params['phone'] end |
#discount ⇒ Object
This is discount given to user - based on promotion set by merchants.
171 172 173 |
# File 'lib/payuindia.rb', line 171 def discount params['discount'] end |
#gross ⇒ Object
original amount send by merchant
166 167 168 |
# File 'lib/payuindia.rb', line 166 def gross params['amount'] end |
#invoice ⇒ Object
This is the invoice which you passed to PayU.in
156 157 158 |
# File 'lib/payuindia.rb', line 156 def invoice params['txnid'] end |
#invoice_ok?(order_id) ⇒ Boolean
118 119 120 |
# File 'lib/payuindia.rb', line 118 def invoice_ok?( order_id ) order_id.to_s == invoice.to_s end |
#message ⇒ Object
220 221 222 |
# File 'lib/payuindia.rb', line 220 def @message || "#{params['error']} - #{params['error_Message']}" end |
#offer_description ⇒ Object
Description offer for what PayU given the offer to user - based on promotion set by merchants.
176 177 178 |
# File 'lib/payuindia.rb', line 176 def offer_description params['offer'] end |
#params ⇒ Object
98 99 100 |
# File 'lib/payuindia.rb', line 98 def params @params end |
#product_info ⇒ Object
Information about the product as send by merchant
181 182 183 |
# File 'lib/payuindia.rb', line 181 def product_info params['productinfo'] end |
#status ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/payuindia.rb', line 102 def status @status ||= if checksum_ok? if transaction_id.blank? 'Invalid' else case transaction_status.downcase when 'success' then 'Completed' when 'failure' then 'Failed' when 'pending' then 'Pending' end end else 'Tampered' end end |
#transaction_id ⇒ Object
ID of this transaction (PayU.in number)
136 137 138 |
# File 'lib/payuindia.rb', line 136 def transaction_id params['mihpayid'] end |
#transaction_status ⇒ Object
Status of transaction return from the PayU. List of possible values:
SUCCESSPENDINGFAILURE
131 132 133 |
# File 'lib/payuindia.rb', line 131 def transaction_status params['status'] end |
#type ⇒ Object
Mode of Payment
‘CC’ for credit-card ‘NB’ for net-banking ‘CD’ for cheque or DD ‘CO’ for Cash Pickup
146 147 148 |
# File 'lib/payuindia.rb', line 146 def type params['mode'] end |
#user_defined ⇒ Object
212 213 214 |
# File 'lib/payuindia.rb', line 212 def user_defined @user_defined ||= 10.times.map { |i| params["udf#{i + 1}"] } end |