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



80
81
82
# File 'lib/active_merchant/billing/integrations/payu_in/notification.rb', line 80

def 
  params['key']
end

#acknowledgeObject



146
147
148
# File 'lib/active_merchant/billing/integrations/payu_in/notification.rb', line 146

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)


38
39
40
# File 'lib/active_merchant/billing/integrations/payu_in/notification.rb', line 38

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

#checksumObject



138
139
140
# File 'lib/active_merchant/billing/integrations/payu_in/notification.rb', line 138

def checksum
  params['hash']
end

#checksum_ok?Boolean

Returns:

  • (Boolean)


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

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 == "Completed"
end

#currencyObject

What currency have we been dealing with



66
67
68
# File 'lib/active_merchant/billing/integrations/payu_in/notification.rb', line 66

def currency
  'INR'
end

#customer_addressObject

Full address of the customer



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

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



105
106
107
# File 'lib/active_merchant/billing/integrations/payu_in/notification.rb', line 105

def customer_email
  params['email']
end

#customer_first_nameObject

Firstname of the customer



115
116
117
# File 'lib/active_merchant/billing/integrations/payu_in/notification.rb', line 115

def customer_first_name
  params['firstname']
end

#customer_last_nameObject

Lastname of the customer



120
121
122
# File 'lib/active_merchant/billing/integrations/payu_in/notification.rb', line 120

def customer_last_name
  params['lastname']
end

#customer_phoneObject

Phone of the customer



110
111
112
# File 'lib/active_merchant/billing/integrations/payu_in/notification.rb', line 110

def customer_phone
  params['phone']
end

#discountObject

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



90
91
92
# File 'lib/active_merchant/billing/integrations/payu_in/notification.rb', line 90

def discount
  params['discount']
end

#grossObject

original amount send by merchant



85
86
87
# File 'lib/active_merchant/billing/integrations/payu_in/notification.rb', line 85

def gross
  params['amount']
end

#invoiceObject

This is the invoice which you passed to PayU.in



75
76
77
# File 'lib/active_merchant/billing/integrations/payu_in/notification.rb', line 75

def invoice
  params['txnid']
end

#invoice_ok?(order_id) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/active_merchant/billing/integrations/payu_in/notification.rb', line 33

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

#item_idObject



70
71
72
# File 'lib/active_merchant/billing/integrations/payu_in/notification.rb', line 70

def item_id
  params['txnid']
end

#messageObject



142
143
144
# File 'lib/active_merchant/billing/integrations/payu_in/notification.rb', line 142

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

#offer_descriptionObject

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



95
96
97
# File 'lib/active_merchant/billing/integrations/payu_in/notification.rb', line 95

def offer_description
  params['offer']
end

#product_infoObject

Information about the product as send by merchant



100
101
102
# File 'lib/active_merchant/billing/integrations/payu_in/notification.rb', line 100

def product_info
  params['productinfo']
end

#statusObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/active_merchant/billing/integrations/payu_in/notification.rb', line 17

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_idObject

ID of this transaction (PayU.in number)



51
52
53
# File 'lib/active_merchant/billing/integrations/payu_in/notification.rb', line 51

def transaction_id
  params['mihpayid']
end

#transaction_statusObject

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

SUCCESS
PENDING
FAILURE


46
47
48
# File 'lib/active_merchant/billing/integrations/payu_in/notification.rb', line 46

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



61
62
63
# File 'lib/active_merchant/billing/integrations/payu_in/notification.rb', line 61

def type
  params['mode']
end

#user_definedObject



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

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