Exemple #1
0
 def test_add_customer(self):
     self.assertEqual(process.add_customer(self.factory), self.user)  # Make sure the customer object is returned.
     self.assertEqual(
         process.add_customer(self.factory).first_name, "Marcus"
     )  # Make sure that the data has been saved.
Exemple #2
0
def process_checkout(request):
	"""View to handle the Form Submit of the Checkout.
	This is where all data from the Checkout is processed and
	used to create an Order.
	"""
	# Validate Data, if failed, return checkout view again and display errors.
	errors = process.validate_checkout(request)
	if errors is not True:
		return checkout(request, errors)

	# Get the cart that is being checked out
	cart = process.get_cart(request)

	# Check if the checkout is a subscription or a normal transaction
	plan = process.get_plan(request)

	# Add User Data
	user = process.add_customer(request)

	# Add Address Data
	address = process.add_address(request)

	# Add Order Data
	order = Order(
		cart=cart, 
		user=user, 
		payment_option=request.POST.get('payment-option', None)
	)

	if plan is not None:
		order.subscription 			= True
		order.subscription_plan 	= plan
		order.subscription_enddate	= plan.get_expire()

	# Try uncommenting this line, to see if we can still process the transaction witout a saved order in the database.
	order.save()  # Save the order before we do the transaction, in case of error.


	# Add Custom Fields Data
	custom_fields = process.add_custom_fields(request, order)

	# Complete Transaction
	transaction_result = process.do_transaction(request, order)

	if 'error' not in transaction_result:
		print "Transaction Results are: %s" % transaction_result
		order.payment_status = transaction_result['payment_status']
		order.save()

		# Send confirmation email to the customer.
		try:
			order.send_confirmation()
		except Exception as ex:
			print "Error sending confirmation: %s" % ex.message

		# Callback to the payment module used when order is saved.
		payments[order.payment_option].order_success(order)

		#  Reset Cart
		del request.session['id_cart']
		return HttpResponseRedirect(reverse('shop:thank_you'))

	else:
		return HttpResponseRedirect(reverse('shop:checkout')+"?error=%s" % transaction_result['error'])