Class: ActiveMerchant::Billing::Integrations::PayuIn::Notification

Inherits:
Notification
  • Object
show all
Defined in:
lib/active_merchant/billing/integrations/payu_in/notification.rb

Instance Attribute Summary

Attributes inherited from Notification

#params, #raw

Instance Method Summary collapse

Methods inherited from Notification

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

Constructor Details

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

Returns a new instance of Notification.



7
8
9
10
11
# File 'lib/active_merchant/billing/integrations/payu_in/notification.rb', line 7

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



82
83
84
# File 'lib/active_merchant/billing/integrations/payu_in/notification.rb', line 82

def 
  params['key']
end

#acknowledgeObject



148
149
150
# File 'lib/active_merchant/billing/integrations/payu_in/notification.rb', line 148

def acknowledge
  checksum_ok?
end

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

Order amount should be equal to gross - discount

Returns:

  • (Boolean)


40
41
42
# File 'lib/active_merchant/billing/integrations/payu_in/notification.rb', line 40

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

#checksumObject



140
141
142
# File 'lib/active_merchant/billing/integrations/payu_in/notification.rb', line 140

def checksum
  params['hash']
end

#checksum_ok?Boolean

Returns:

  • (Boolean)


152
153
154
155
156
157
158
159
160
# File 'lib/active_merchant/billing/integrations/payu_in/notification.rb', line 152

def checksum_ok?
  fields = user_defined.dup.push( customer_email, customer_first_name, product_info, gross, invoice, :reverse => true )
  fields.unshift( transaction_status )
  unless PayuIn.checksum(@merchant_id, @secret_key, *fields ) == checksum
    @message = 'Return checksum not matching the data provided'
    return false
  end
  true
end

#complete?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/active_merchant/billing/integrations/payu_in/notification.rb', line 13

def complete?
  status == "success"
end

#currencyObject

What currency have we been dealing with



68
69
70
# File 'lib/active_merchant/billing/integrations/payu_in/notification.rb', line 68

def currency
  'INR'
end

#customer_addressObject

Full address of the customer



127
128
129
130
131
# File 'lib/active_merchant/billing/integrations/payu_in/notification.rb', line 127

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



107
108
109
# File 'lib/active_merchant/billing/integrations/payu_in/notification.rb', line 107

def customer_email
  params['email']
end

#customer_first_nameObject

Firstname of the customer



117
118
119
# File 'lib/active_merchant/billing/integrations/payu_in/notification.rb', line 117

def customer_first_name
  params['firstname']
end

#customer_last_nameObject

Lastname of the customer



122
123
124
# File 'lib/active_merchant/billing/integrations/payu_in/notification.rb', line 122

def customer_last_name
  params['lastname']
end

#customer_phoneObject

Phone of the customer



112
113
114
# File 'lib/active_merchant/billing/integrations/payu_in/notification.rb', line 112

def customer_phone
  params['phone']
end

#discountObject

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



92
93
94
# File 'lib/active_merchant/billing/integrations/payu_in/notification.rb', line 92

def discount
  params['discount']
end

#grossObject

original amount send by merchant



87
88
89
# File 'lib/active_merchant/billing/integrations/payu_in/notification.rb', line 87

def gross
  params['amount']
end

#invoiceObject

This is the invoice which you passed to PayU.in



77
78
79
# File 'lib/active_merchant/billing/integrations/payu_in/notification.rb', line 77

def invoice
  params['txnid']
end

#invoice_ok?(order_id) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/active_merchant/billing/integrations/payu_in/notification.rb', line 35

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

#item_idObject



72
73
74
# File 'lib/active_merchant/billing/integrations/payu_in/notification.rb', line 72

def item_id
  params['txnid']
end

#messageObject



144
145
146
# File 'lib/active_merchant/billing/integrations/payu_in/notification.rb', line 144

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

#offer_descriptionObject

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



97
98
99
# File 'lib/active_merchant/billing/integrations/payu_in/notification.rb', line 97

def offer_description
  params['offer']
end

#product_infoObject

Information about the product as send by merchant



102
103
104
# File 'lib/active_merchant/billing/integrations/payu_in/notification.rb', line 102

def product_info
  params['productinfo']
end

#statusObject

Status of the transaction. List of possible values:

invalid

transaction id is not present

tampered

transaction data has been tampered

success

transaction successful

pending

transaction is pending for some approval

failure

transaction failure



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/active_merchant/billing/integrations/payu_in/notification.rb', line 23

def status
  @status ||= if checksum_ok?
    if transaction_id.blank?
      'invalid'
    else
      transaction_status.downcase
    end
  else
    'tampered'
  end
end

#transaction_idObject

ID of this transaction (PayU.in number)



53
54
55
# File 'lib/active_merchant/billing/integrations/payu_in/notification.rb', line 53

def transaction_id
  params['mihpayid']
end

#transaction_statusObject

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

SUCCESS
PENDING
FAILURE


48
49
50
# File 'lib/active_merchant/billing/integrations/payu_in/notification.rb', line 48

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



63
64
65
# File 'lib/active_merchant/billing/integrations/payu_in/notification.rb', line 63

def type
  params['mode']
end

#user_definedObject



133
134
135
136
137
138
# File 'lib/active_merchant/billing/integrations/payu_in/notification.rb', line 133

def user_defined
  return @user_defined if @user_defined
  @user_defined = []
  10.times{ |i| @user_defined.push( params[ "udf#{i+1}" ] ) }
  @user_defined
end