Class: OffsitePayments::Integrations::PayuIn::Notification

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

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.



95
96
97
98
99
# File 'lib/offsite_payments/integrations/payu_in.rb', line 95

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

Instance Method Details

#accountObject

Merchant Id provided by the PayU.in



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

def 
  params['key']
end

#acknowledge(authcode = nil) ⇒ Object



223
224
225
# File 'lib/offsite_payments/integrations/payu_in.rb', line 223

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

Returns:

  • (Boolean)


118
119
120
# File 'lib/offsite_payments/integrations/payu_in.rb', line 118

def amount_ok?( order_amount, order_discount = BigDecimal.new( '0.0' ) )
  BigDecimal.new( gross ) == order_amount && BigDecimal.new( discount.to_s ) == order_discount
end

#checksumObject



215
216
217
# File 'lib/offsite_payments/integrations/payu_in.rb', line 215

def checksum
  params['hash']
end

#checksum_ok?Boolean

Returns:

  • (Boolean)


227
228
229
230
231
232
233
234
235
# File 'lib/offsite_payments/integrations/payu_in.rb', line 227

def checksum_ok?
  checksum_fields = [transaction_status, *user_defined.reverse, customer_email, customer_first_name, product_info, gross, invoice]

  unless Digest::SHA512.hexdigest([@secret_key, *checksum_fields, @merchant_id].join("|")) == checksum
    @message = 'Return checksum not matching the data provided'
    return false
  end
  true
end

#complete?Boolean

Returns:

  • (Boolean)


101
102
103
# File 'lib/offsite_payments/integrations/payu_in.rb', line 101

def complete?
  status == "Completed"
end

#currencyObject

What currency have we been dealing with



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

def currency
  'INR'
end

#customer_addressObject

Full address of the customer



205
206
207
208
209
# File 'lib/offsite_payments/integrations/payu_in.rb', line 205

def customer_address
  { :address1 => params['address1'], :address2 => params['address2'],
    :city => params['city'], :state => params['state'],
    :country => params['country'], :zipcode => params['zipcode'] }
end

#customer_emailObject

Email of the customer



185
186
187
# File 'lib/offsite_payments/integrations/payu_in.rb', line 185

def customer_email
  params['email']
end

#customer_first_nameObject

Firstname of the customer



195
196
197
# File 'lib/offsite_payments/integrations/payu_in.rb', line 195

def customer_first_name
  params['firstname']
end

#customer_last_nameObject

Lastname of the customer



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

def customer_last_name
  params['lastname']
end

#customer_phoneObject

Phone of the customer



190
191
192
# File 'lib/offsite_payments/integrations/payu_in.rb', line 190

def customer_phone
  params['phone']
end

#discountObject

This is discount given to user - based on promotion set by merchants.



170
171
172
# File 'lib/offsite_payments/integrations/payu_in.rb', line 170

def discount
  params['discount']
end

#grossObject

original amount send by merchant



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

def gross
  params['amount']
end

#invoiceObject

This is the invoice which you passed to PayU.in



155
156
157
# File 'lib/offsite_payments/integrations/payu_in.rb', line 155

def invoice
  params['txnid']
end

#invoice_ok?(order_id) ⇒ Boolean

Returns:

  • (Boolean)


113
114
115
# File 'lib/offsite_payments/integrations/payu_in.rb', line 113

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

#item_idObject



150
151
152
# File 'lib/offsite_payments/integrations/payu_in.rb', line 150

def item_id
  params['txnid']
end

#messageObject



219
220
221
# File 'lib/offsite_payments/integrations/payu_in.rb', line 219

def message
  @message || params['error']
end

#offer_descriptionObject

Description offer for what PayU given the offer to user - based on promotion set by merchants.



175
176
177
# File 'lib/offsite_payments/integrations/payu_in.rb', line 175

def offer_description
  params['offer']
end

#product_infoObject

Information about the product as send by merchant



180
181
182
# File 'lib/offsite_payments/integrations/payu_in.rb', line 180

def product_info
  params['productinfo']
end

#statusObject



105
106
107
108
109
110
111
# File 'lib/offsite_payments/integrations/payu_in.rb', line 105

def status
  case transaction_status.downcase
  when 'success' then 'Completed'
  when 'failure' then 'Failed'
  when 'pending' then 'Pending'
  end
end

#transaction_idObject

ID of this transaction (PayU.in number)



131
132
133
# File 'lib/offsite_payments/integrations/payu_in.rb', line 131

def transaction_id
  params['mihpayid']
end

#transaction_statusObject

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

SUCCESS
PENDING
FAILURE


126
127
128
# File 'lib/offsite_payments/integrations/payu_in.rb', line 126

def transaction_status
  params['status']
end

#typeObject

Mode of Payment

‘CC’ for credit-card ‘NB’ for net-banking ‘CD’ for cheque or DD ‘CO’ for Cash Pickup



141
142
143
# File 'lib/offsite_payments/integrations/payu_in.rb', line 141

def type
  params['mode']
end

#user_definedObject



211
212
213
# File 'lib/offsite_payments/integrations/payu_in.rb', line 211

def user_defined
  @user_defined ||= 10.times.map { |i| params["udf#{i + 1}"] }
end