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.



97
98
99
100
101
# File 'lib/offsite_payments/integrations/payu_in.rb', line 97

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



162
163
164
# File 'lib/offsite_payments/integrations/payu_in.rb', line 162

def 
  params['key']
end

#acknowledge(authcode = nil) ⇒ Object



229
230
231
# File 'lib/offsite_payments/integrations/payu_in.rb', line 229

def acknowledge(authcode = nil)
  checksum_ok?
end

#amount_ok?(order_amount, order_discount = BigDecimal( '0.0' )) ⇒ Boolean

Order amount should be equal to gross - discount

Returns:

  • (Boolean)


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

def amount_ok?( order_amount, order_discount = BigDecimal( '0.0' ) )
  parsed_discount = discount.nil? ? 0.to_d : discount.to_d
  BigDecimal( original_gross ) == order_amount && parsed_discount == order_discount
end

#checksumObject



221
222
223
# File 'lib/offsite_payments/integrations/payu_in.rb', line 221

def checksum
  params['hash']
end

#checksum_ok?Boolean

Returns:

  • (Boolean)


233
234
235
236
237
238
239
240
241
# File 'lib/offsite_payments/integrations/payu_in.rb', line 233

def checksum_ok?
  checksum_fields = [transaction_status, *user_defined.reverse, customer_email, customer_first_name, product_info, original_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)


103
104
105
# File 'lib/offsite_payments/integrations/payu_in.rb', line 103

def complete?
  status == "Completed"
end

#currencyObject

What currency have we been dealing with



148
149
150
# File 'lib/offsite_payments/integrations/payu_in.rb', line 148

def currency
  'INR'
end

#customer_addressObject

Full address of the customer



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

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



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

def customer_email
  params['email']
end

#customer_first_nameObject

Firstname of the customer



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

def customer_first_name
  params['firstname']
end

#customer_last_nameObject

Lastname of the customer



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

def customer_last_name
  params['lastname']
end

#customer_phoneObject

Phone of the customer



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

def customer_phone
  params['phone']
end

#discountObject

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



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

def discount
  params['discount']
end

#grossObject



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

def gross
  parse_and_round_gross_amount(params['amount'])
end

#invoiceObject

This is the invoice which you passed to PayU.in



157
158
159
# File 'lib/offsite_payments/integrations/payu_in.rb', line 157

def invoice
  params['txnid']
end

#invoice_ok?(order_id) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#item_idObject



152
153
154
# File 'lib/offsite_payments/integrations/payu_in.rb', line 152

def item_id
  params['txnid']
end

#messageObject



225
226
227
# File 'lib/offsite_payments/integrations/payu_in.rb', line 225

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

#offer_descriptionObject

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



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

def offer_description
  params['offer']
end

#original_grossObject

original amount send by merchant



167
168
169
# File 'lib/offsite_payments/integrations/payu_in.rb', line 167

def original_gross
  params['amount']
end

#product_infoObject

Information about the product as send by merchant



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

def product_info
  params['productinfo']
end

#statusObject



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

def status
  case transaction_status.downcase
    when 'success' then 'Completed'
    else 'Failed'
  end
end

#transaction_idObject

ID of this transaction (PayU.in number)



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

def transaction_id
  params['mihpayid']
end

#transaction_statusObject

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

SUCCESS
PENDING
FAILURE


128
129
130
# File 'lib/offsite_payments/integrations/payu_in.rb', line 128

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



143
144
145
# File 'lib/offsite_payments/integrations/payu_in.rb', line 143

def type
  params['mode']
end

#user_definedObject



217
218
219
# File 'lib/offsite_payments/integrations/payu_in.rb', line 217

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