def PaymentOptionsView(request, total=0, counter=0):
HIDDEN
stripe.api_key = settings.STRIPE_SECRET_KEY
stripe_total = int(total * 100)
description = 'Recruitment Platform - New Order'
data_key = settings.STRIPE_PUBLISHABLE_KEY
if request.method == 'POST':
HIDDEN
try:
token = request.POST['stripeToken']
email = request.POST['stripeEmail']
billingName = request.POST['stripeBillingName']
billingAddress1 = request.POST['stripeBillingAddressLine1']
billingcity = request.POST['stripeBillingAddressCity']
billingPostcode = request.POST['stripeBillingAddressZip']
billingCountry = request.POST['stripeBillingAddressCountryCode']
shippingName = request.POST['stripeShippingName']
shippingAddress1 = request.POST['stripeShippingAddressLine1']
shippingcity = request.POST['stripeShippingAddressCity']
shippingPostcode = request.POST['stripeShippingAddressZip']
shippingCountry = request.POST['stripeShippingAddressCountryCode']
HIDDEN
# stripe.Customer is Internal Stripe Table to maintain Customer Record
customer = stripe.Customer.create(
email=email,
source=token
HIDDEN
)
# Charge is Stripe Internal Table
charge = stripe.Charge.create(
amount = stripe_total,
currency = "USD",
description = description,
customer = customer.id
)
#### Create Order #####
try:
order_details = Order.objects.create(
token = token,
total = total,
emailAddress = email,
billingName = billingName,
billingAddress = billingAddress1,
billingCity = billingcity,
billingPostCode = billingPostcode,
billingCountry = billingCountry,
shippingName = shippingName,
shippingAdress1 = shippingAddress1,
shippingCity = shippingcity,
shippingPostCde = shippingPostcode,
shippingCountry = shippingCountry
)
order_details.save()
try:
print('Email sent to the Customer!')
sendEmail(order_details.id)
#thanksView(request, order_details.id)
except IOError as e:
return e