@auth.requires_login()
def success():
	
	"""
	This function is supposed to show a success or error message
	depending of what PayPal IPN returns.

	Since in localhost we receive no return of PayPal, we can
	hack a little bit in order to make the app continuous.
	"""

	if request.is_local:
		log_in_file(str(request.vars), '/tmp/paypalreturn.txt')
	else:
		log_in_file(str(request.vars), '/var/log/paypalreturn.txt')

	pending = Pending(id=session.pending)
	if request.is_local:
		## do what ipn was supposed to do
		## just for continuity purposes
		confirmed = Confirmed.insert(
									order_id=pending.order_id,
									pending_id=pending.id,
									confirmation_time=request.now
									)
		pending.update_record(confirmed=True)
		Order(id=pending.order_id).update_record(status=2)
		mail_message = T('We just confirmed your payment for order number %s.') % pending.order_id.token
		mail_message += '\n'
		mail_message += T('The total amount was R$%.2f.') % pending.order_id.amount
		mail_message += '\n'
		mail_message += T('You can check your payment history after login in to your profile.')
		mail_message += '\n\n'
		mail_message += T('Thank you!')
		mail.send(to=pending.order_id.user_id.email,
				subject=T("Payment confirmed!"),
				message = mail_message
				)

	if pending.confirmed or request.is_local:
		message = T('Payment completed! Congratulations for your purchase!')
		for cart_class in pending.order_id.products:
			Student.insert(student = auth.user.id, class_id = cart_class)
	else:
		message = T('Sorry! Something bad happened!')
	return dict(message=message)
dataset/ETHPy150Open juliarizza/web2courses/controllers/payments.py/success/original