{{* if we do not have a valid cart we will redirect to shopping-cart.html page *}}
	{{assign var=CartCollection				value=133}}
	{{assign var=DeliveryMethodCollection   value=136}}
	{{assign var=CouponsCollection          value=135}}
	{{assign var=CartDetailsCollection		value=134}}
	{{assign var=TaxCollection				value=151}}
	{{assign var=ShippingCollection			value=139}}
	
	
	{{assign var=SessionID   		value=''|sessionid}}
	{{getCollectionByCategory CollectionID=$CartCollection Collection_133_1=$SessionID aditionalFilter=' (Collection_133_5<>"on" or Collection_133_5 IS NULL) ' var=CartData OrderColumn='ID'}}
	{{assign var=CartDataItem value=$CartData[0]}}
	{{assign var=CartID value=$CartDataItem.Collection_133_ID}}
	{{assign var=PaymentMethodID value=$CartDataItem.Collection_133_19}}
	{{assign var=CouponID value=$CartDataItem.Collection_133_16}}
	{{assign var=MethodID value=$CartDataItem.Collection_133_17}}
	
		
	
	{{* if we do not have a valid billing info page we will redirect to personal-information *}}	
	{{getCollectionByCategory CollectionID=138 ColumnID=1 Value=$CartID var=BillingInformation OrderColumn='ID'}}
	{{if $BillingInformation|@count eq 0}}
		{{redirect page='/checkout/personal-information.html'}}	
	{{else}}
		{{assign var=BillingInfo value=$BillingInformation[0]}}
	{{/if}}
	
	
	{{getCollectionByCategory CollectionID=$ShippingCollection ColumnID=1 Value=$CartID var=ShippingInformation OrderColumn='ID'}}
	{{if $ShippingInformation|@count eq 0}}
			{{redirect page='/checkout/shipping-information.html'}}	
	{{else}}
			{{assign var=ShippingInfo value=$ShippingInformation[0]}}
	{{/if}}

	
	{{* if we do not have a valid payment info page we will redirect to shipping-information *}}	
	{{getCollectionByCategory CollectionID=$PaymentMethodID ColumnID=1 Value=$CartID var=PaymentInformation OrderColumn='ID'}}
	{{if $PaymentInformation|@count eq 0}}
			{{redirect page='/checkout/payment-information.html'}}	
	{{else}}
			{{assign var=PaymentInfo value=$PaymentInformation[0]}}
	{{/if}}
	
{{* If the payment method is check by mail we do not need to check with authorize net *}}
{{if $PaymentMethodID eq 150}}
	
	{{assign var=PaymentResult value=1}}
	
{{else}}
	
	{{* Now we need to check if the payment info is valid using authorize class *}}
	{{AuthorizeNET BillingInfo=$BillingInfo ShippingInfo=$ShippingInfo PaymentMethod=$PaymentMethodID PaymentInfo=$PaymentInfo CartID=$CartID CartData=$CartDataItem CartDetails=$CartDetails var=PaymentResult  errorsvar=PaymentErrors}}

	{{if $PaymentErrors|@count gt 0}}
			{{assign var=errorstr value=''}}
			{{foreach from=$PaymentErrors item=v key=k name=a}}
				{{if $smarty.foreach.a.iteration neq 1}}{{assign var=errorstr value=$errorstr|concat:'-'}}{{/if}}
				{{assign var=errorstr value=$errorstr|concat:$v}}
			{{/foreach}}
			{{assign var=pageToRedirect value='/checkout/payment-information.html'}}
			{{assign var=pageToRedirect value=$pageToRedirect|concat:'?errors='|concat:$errorstr}}
			{{redirect page=$pageToRedirect}}
	{{/if}}
	

		

{{/if}}	
		
{{if $PaymentResult eq 1}}
			
	{{* the process was a success and we display the receipt *}} 
	{{redirect page='/checkout.html'}}
		
{{/if}}