Module: Auth::Concerns::Shopping::PayUMoneyConcern

Extended by:
ActiveSupport::Concern
Includes:
ChiefModelConcern
Defined in:
app/models/auth/concerns/shopping/pay_u_money_concern.rb

Instance Method Summary collapse

Instance Method Details

#calculate_hashObject

needs to use the payumoney library.



48
49
50
51
52
# File 'app/models/auth/concerns/shopping/pay_u_money_concern.rb', line 48

def calculate_hash
	options = {:firstname => firstname, :email => email, :phone => phone, :txnid => txnid, :surl => surl, :furl => furl, :productinfo => productinfo, :amount => amount}
	service = PayuIndia::Helper.new(payment_gateway_key, payment_gateway_salt, options)
	self.hast = service.generate_checksum
end

#gateway_callback(pr, &block) ⇒ Object

this method is overriden here from the payment_concern. suppose the user is calling refresh_payment, basically an update call, then the mihpayid wont be present so the gateway callback becomes pointless. and then we just let verify payment handle the situation.



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'app/models/auth/concerns/shopping/pay_u_money_concern.rb', line 161

def gateway_callback(pr,&block)
	

	return if (self.new_record? || self.is_verify_payment == "true")
	
=begin
 	notification = PayuIndia::Notification.new("", options = {:key => Auth.configuration.payment_gateway_info[:key], :salt => Auth.configuration.payment_gateway_info[:salt], :params => pr})
 	self.payment_status = 0
 	if(notification.acknowledge && notification.complete?)
 		self.payment_status = 1 
 	end
=end

## we should just set, gateway callback complete as true, and based on that never show the pay with payumoney link again in the show action.

## just looking to see if  
if pr
	if (pr["mihpayid"] && pr["hash"] && (pr["txnid"] == self.id.to_s))
		self.gateway_callback_called = true
	end
end
 	yield if block_given?
 	return true
end

#payment_gateway_keyObject



148
149
150
# File 'app/models/auth/concerns/shopping/pay_u_money_concern.rb', line 148

def payment_gateway_key
	Auth.configuration.payment_gateway_info[:key]
end

#payment_gateway_saltObject



153
154
155
# File 'app/models/auth/concerns/shopping/pay_u_money_concern.rb', line 153

def payment_gateway_salt
	Auth.configuration.payment_gateway_info[:salt]
end

#verify_paymentObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'app/models/auth/concerns/shopping/pay_u_money_concern.rb', line 57

def verify_payment
	
	if self.new_record?
	
		return nil
	else
	
		if self.is_verify_payment == "true"
			#puts "yes is verify payment."
			#puts the payment is not getting set as pending.
			## that is the problem.
			if self.payment_pending
					
				if self.is_gateway?
				 	#puts "came to is gateway"
					options = {:var1 => self.txnid, :command => 'verify_payment'}
					webservice = PayuIndia::WebService.new(payment_gateway_key,payment_gateway_salt,options)
					sha_hash = webservice.generate_checksum
						if resp = Typhoeus.post(PayuIndia.webservice_url, body: 
							{ key: payment_gateway_key, command: 'verify_payment', hash: sha_hash, var1: self.txnid}, headers: {'Content-Type' => 'application/x-www-form-urlencoded'})
							Rails.logger.info(resp.body + ":transaction_id:" + self.id.to_s)
							begin
								details = JSON.parse(resp.body)

								if status = details["status"].to_s		
									self.payment_status = 0 if (status == "0")
										
									if status == "1"
										if details["transaction_details"]
											if transaction_details = 
											details["transaction_details"][txnid.to_s]

												if transaction_details["status"]
												
													self.payment_status = 1 if transaction_details["status"].to_s.downcase == "success" 
													self.payment_status = 0 if transaction_details["status"].to_s.downcase =~/pending|failure/
													if payment_status_changed?
														## prevents recursive callbacks, after save.
														## actually this may not be necessary here.
														self.is_verify_payment = "false"
														## so only if is_verify_payment is true,
													else
														self.errors.add(:payment_status,"transaction status was something other than failed|success|pending")
													end
												else
													self.errors.add(:payment_status,"transaction details does not have the status key. Please try to verify your payment later, or contact Support for more help.")
												end
											else
												self.errors.add(:payment_status,"transaction details does not have the transaction id. Please try to verify your payment later, or contact Support for more help.")
												
											end
										else
											self.errors.add(:payment_status,"transaction details key missing from response")
											
										end
									else
										self.errors.add(:payment_status,"status key is neither 1 not 0 : Please try to verify your payment later, or contact Support for more help.")
										
									end
									
								else
									self.errors.add(:payment_status,"no status key in payment verification response. Please try to verify your payment later, or contact Support for more help.")
									
								end

							rescue => e
								Rails.logger.error(e.to_s)
								self.errors.add(:payment_status,"failure parsing payment response. Please try to verify your payment later, or contact Support for more help.")
							end
						else
							## does nothing, the caller has to check the payment_status to infer that the call was not successfull.
							self.errors.add(:payment_status,"no response from verify endpoint. Please try to verify your payment later, or contact Support for more help.")
						end
				
					end

				return true
			else

				puts "not pending"
				return nil
			end
		else
			puts "is not verify payment."
			return nil
		end
	end
	
end