@auth.requires_login()
def pay_courses():

	"""
	This function is responsible to redirect the user
	to the payment method it chose and process if
	the amount to be paid is free. In this case, it will
	enroll the student to the class. Other way, the user
	will be redirected to pay.
	"""

	order = Order(id=session.order)
	if order.amount == 0:
		pending = Pending.insert(
								order_id = session.order,
								confirmed = True
								)
		confirmed = Confirmed.insert(
									order_id=order.id,
									pending_id=pending.id,
									confirmation_time=request.now
									)
		order.update_record(status=2)
		session.pending = pending
		redirect(URL('success'))

		message = T('We just confirmed your payment for order number %s.') % order.token
		message += '\n'
		message += T('The total amount was R$%.2f.') % order.amount
		message += '\n'
		message += T('You can check your payment history after login in to your profile.')
		message += '\n\n'
		message += T('Thank you!')
		mail.send(to=order.user_id.email,
				subject=T("Payment confirmed!"),
				message = message
				)
	else:
		pending = Pending.insert(order_id = order.id)
		session.pending = pending
		redirect(URL('paypal'))
dataset/ETHPy150Open juliarizza/web2courses/controllers/payments.py/pay_courses/original