def complete_payment(request):
	if request.session['fd']:
		stripe.api_key = settings.STRIPE_PRIVATE_KEY
		proj_name = settings.PROJECT_NAME
		proj_addr = settings.PROJECT_ADDR
		time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M')
		reward_desc = (Reward.objects.get(name=request.session['fd']['reward_name']).desc if request.session['fd']['reward'] else 'None')

		# amount in cents
		amount = int(request.session['fd']['amount']) * 100
		token = request.session['fd']['stripeToken']
		desc = request.session['fd']['email']

		try:
			o = Order(
				name=(request.session['fd']['sh_name'] if request.session['fd']['sh_name'] else request.session['fd']['cc_name']),
				addr1=request.session['fd']['sh_addr1'],
				addr2=request.session['fd']['sh_addr2'],
				city=request.session['fd']['sh_city'],
				state=request.session['fd']['sh_state'],
				pcode=request.session['fd']['sh_post'],
				country=request.session['fd']['sh_country'],
				reward=(Reward.objects.get(name=request.session['fd']['reward_name']) if request.session['fd']['reward'] else None),
				amount=decimal.Decimal(request.session['fd']['amount']),
				ptype='CC',
				pref=request.session['fd']['cc_type'] + ' x-'+ request.session['fd']['cc_last4'],
				email=request.session['fd']['email'],
				namecredit=request.session['fd']['namecredit'],
				notes=request.session['fd']['notes']
			)
		except:
			msg = "There was a problem saving your order details to the database. Your card has NOT been charged. Please notify the site operator."
			return render(request, 'error.html', locals())

		try:
			charge = stripe.Charge.create(
				amount=amount,
				currency="usd",
				card=token,
				description=desc
			)
			try:
				o.notify = request.session['fd']['notify']
			except:
				pass
			o.save()
			send_mail(
				subject=proj_name+' - Thank you for your contribution',
				message=get_template('notify.txt').render(Context({'order': request.session['fd'], 'proj_name': proj_name, 'proj_addr': proj_addr, 'time': time, 'reward_desc': reward_desc})),
				from_email=settings.NOTIFY_SENDER, 
				recipient_list=[request.session['fd']['email']],
				fail_silently=False)
			request.session['fd'] = {}
			return render(request, 'payment/success.html', locals())
		except stripe.CardError, e:
			msg = "Your card has been declined. Please choose a new card or a new payment method and restart your order."
			return render(request, 'error.html', locals())
		except:
def complete_payment(request):
	paypalrestsdk.configure({
		'mode': settings.PAYPAL_MODE,
		'client_id': settings.PAYPAL_CLIENT_ID,
		'client_secret': settings.PAYPAL_CLIENT_SECRET
	})
	if request.session['fd'] and request.session['paypal_id']:
		time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M')
		reward_desc = (Reward.objects.get(name=request.session['fd']['reward_name']).desc if request.session['fd']['reward'] else 'None')
		pmt = paypalrestsdk.Payment.find(request.session['paypal_id'])
		if pmt['state'] == 'created':
			if pmt.execute({"payer_id": request.session['paypal_pid']}):
				o = Order(
					name=(request.session['fd']['namecredit'] if request.session['fd']['namecredit'] else 'PayPal User'),
					addr1='',
					addr2='',
					city='',
					state='',
					pcode='',
					country='',
					reward=(Reward.objects.get(name=request.session['fd']['reward_name']) if request.session['fd']['reward'] else None),
					amount=decimal.Decimal(request.session['fd']['amount']),
					ptype='PP',
					pref=request.session['paypal_id'],
					email=request.session['fd']['email'],
					namecredit=request.session['fd']['namecredit'],
					notes=request.session['fd']['notes']
				)
				request.session['paypal_id'] = {}
				request.session['paypal_pid'] = {}
				try:
					o.notify = request.session['fd']['notify']
				except:
					pass
				o.save()
				if request.session['fd']['email']:
					send_mail(
						subject=settings.PROJECT_NAME+' - Thank you for your contribution',
						message=get_template('notify.txt').render(Context({'order': request.session['fd'], 'proj_name': settings.PROJECT_NAME, 'proj_addr': settings.PROJECT_ADDR, 'time': time, 'reward_desc': reward_desc})),
						from_email=settings.NOTIFY_SENDER, 
						recipient_list=[request.session['fd']['email']],
						fail_silently=True)
				request.session['fd'] = {}
				return render(request, 'payment/success.html', locals())
			else:
				request.session['paypal_id'] = {}
				request.session['paypal_pid'] = {}
				msg = 'There was an error with your payment.\n'+str(pmt.error)
				return render(request, 'error.html', locals())
		else:
			request.session['paypal_id'] = {}
			request.session['paypal_pid'] = {}
			msg = 'An unexpected error has occurred. Please try again.'
			return render(request, 'error.html', locals())
	else:
		msg = 'Your session data could not be found. Please retry your submission again.'
		return render(request, 'error.html', locals())
Пример #3
0
def complete_payment(request):
    proj_name = settings.PROJECT_NAME
    proj_addr = settings.PROJECT_ADDR
    time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M')
    if request.session['fd']:
        reward_desc = (Reward.objects.get(
            name=request.session['fd']['reward_name']).desc
                       if request.session['fd']['reward'] else 'None')
        btc = True
        o = Order(
            name=(request.session['fd']['namecredit']
                  if request.session['fd']['namecredit'] else
                  (request.session['fd']['sh_name']
                   if request.session['fd']['sh_name'] else 'Bitcoin User')),
            addr1=request.session['fd']['sh_addr1'],
            addr2=request.session['fd']['sh_addr2'],
            city=request.session['fd']['sh_city'],
            state=request.session['fd']['sh_state'],
            pcode=request.session['fd']['sh_post'],
            country=request.session['fd']['sh_country'],
            reward=(Reward.objects.get(
                name=request.session['fd']['reward_name'])
                    if request.session['fd']['reward'] else None),
            amount=decimal.Decimal(
                float(get_btc_rate()) *
                float(request.session['fd']['amount'])),
            ptype='BC',
            pref=request.session['fd']['ref'],
            email=request.session['fd']['email'],
            namecredit=request.session['fd']['namecredit'],
            notes=request.session['fd']['notes'])
        try:
            o.notify = request.session['fd']['notify']
        except:
            pass
        o.save()
        if request.session['fd']['email']:
            send_mail(subject='Thank you for your contribution',
                      message=get_template('notify.txt').render(
                          Context({
                              'order': request.session['fd'],
                              'proj_name': proj_name,
                              'proj_addr': proj_addr,
                              'time': time,
                              'reward_desc': reward_desc
                          })),
                      from_email=settings.NOTIFY_SENDER,
                      recipient_list=[request.session['fd']['email']],
                      fail_silently=False)
        request.session['fd'] = {}
        return render(request, 'payment/success.html', locals())
    else:
        msg = 'Your session data could not be found. Please retry your submission again.'
        return render(request, 'error.html', locals())
def complete_payment(request):
	proj_name = settings.PROJECT_NAME
	proj_addr = settings.PROJECT_ADDR
	time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M')
	if request.session['fd']:
		reward_desc = (Reward.objects.get(name=request.session['fd']['reward_name']).desc if request.session['fd']['reward'] else 'None')
		btc = True
		o = Order(
			name=(request.session['fd']['namecredit'] if request.session['fd']['namecredit'] else (request.session['fd']['sh_name'] if request.session['fd']['sh_name'] else 'Bitcoin User')),
			addr1=request.session['fd']['sh_addr1'],
			addr2=request.session['fd']['sh_addr2'],
			city=request.session['fd']['sh_city'],
			state=request.session['fd']['sh_state'],
			pcode=request.session['fd']['sh_post'],
			country=request.session['fd']['sh_country'],
			reward=(Reward.objects.get(name=request.session['fd']['reward_name']) if request.session['fd']['reward'] else None),
			amount=decimal.Decimal(float(get_btc_rate()) * float(request.session['fd']['amount'])),
			ptype='BC',
			pref=request.session['fd']['ref'],
			email=request.session['fd']['email'],
			namecredit=request.session['fd']['namecredit'],
			notes=request.session['fd']['notes']
		)
		try:
			o.notify = request.session['fd']['notify']
		except:
			pass
		o.save()
		if request.session['fd']['email']:
			send_mail(
				subject='Thank you for your contribution',
				message=get_template('notify.txt').render(Context({'order': request.session['fd'], 'proj_name': proj_name, 'proj_addr': proj_addr, 'time': time, 'reward_desc': reward_desc})),
				from_email=settings.NOTIFY_SENDER, 
				recipient_list=[request.session['fd']['email']],
				fail_silently=False)
		request.session['fd'] = {}
		return render(request, 'payment/success.html', locals())
	else:
		msg = 'Your session data could not be found. Please retry your submission again.'
		return render(request, 'error.html', locals())
Пример #5
0
def complete_payment(request):
    paypalrestsdk.configure({
        'mode': settings.PAYPAL_MODE,
        'client_id': settings.PAYPAL_CLIENT_ID,
        'client_secret': settings.PAYPAL_CLIENT_SECRET
    })
    if request.session['fd'] and request.session['paypal_id']:
        time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M')
        reward_desc = (Reward.objects.get(
            name=request.session['fd']['reward_name']).desc
                       if request.session['fd']['reward'] else 'None')
        pmt = paypalrestsdk.Payment.find(request.session['paypal_id'])
        if pmt['state'] == 'created':
            if pmt.execute({"payer_id": request.session['paypal_pid']}):
                o = Order(
                    name=(request.session['fd']['namecredit']
                          if request.session['fd']['namecredit'] else
                          'PayPal User'),
                    addr1='',
                    addr2='',
                    city='',
                    state='',
                    pcode='',
                    country='',
                    reward=(Reward.objects.get(
                        name=request.session['fd']['reward_name'])
                            if request.session['fd']['reward'] else None),
                    amount=decimal.Decimal(request.session['fd']['amount']),
                    ptype='PP',
                    pref=request.session['paypal_id'],
                    email=request.session['fd']['email'],
                    namecredit=request.session['fd']['namecredit'],
                    notes=request.session['fd']['notes'])
                request.session['paypal_id'] = {}
                request.session['paypal_pid'] = {}
                try:
                    o.notify = request.session['fd']['notify']
                except:
                    pass
                o.save()
                if request.session['fd']['email']:
                    send_mail(subject=settings.PROJECT_NAME +
                              ' - Thank you for your contribution',
                              message=get_template('notify.txt').render(
                                  Context({
                                      'order': request.session['fd'],
                                      'proj_name': settings.PROJECT_NAME,
                                      'proj_addr': settings.PROJECT_ADDR,
                                      'time': time,
                                      'reward_desc': reward_desc
                                  })),
                              from_email=settings.NOTIFY_SENDER,
                              recipient_list=[request.session['fd']['email']],
                              fail_silently=True)
                request.session['fd'] = {}
                return render(request, 'payment/success.html', locals())
            else:
                request.session['paypal_id'] = {}
                request.session['paypal_pid'] = {}
                msg = 'There was an error with your payment.\n' + str(
                    pmt.error)
                return render(request, 'error.html', locals())
        else:
            request.session['paypal_id'] = {}
            request.session['paypal_pid'] = {}
            msg = 'An unexpected error has occurred. Please try again.'
            return render(request, 'error.html', locals())
    else:
        msg = 'Your session data could not be found. Please retry your submission again.'
        return render(request, 'error.html', locals())
Пример #6
0
def complete_payment(request):
    if request.session['fd']:
        stripe.api_key = settings.STRIPE_PRIVATE_KEY
        proj_name = settings.PROJECT_NAME
        proj_addr = settings.PROJECT_ADDR
        time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M')
        reward_desc = (Reward.objects.get(
            name=request.session['fd']['reward_name']).desc
                       if request.session['fd']['reward'] else 'None')

        # amount in cents
        amount = int(request.session['fd']['amount']) * 100
        token = request.session['fd']['stripeToken']
        desc = request.session['fd']['email']

        try:
            o = Order(name=(request.session['fd']['sh_name']
                            if request.session['fd']['sh_name'] else
                            request.session['fd']['cc_name']),
                      addr1=request.session['fd']['sh_addr1'],
                      addr2=request.session['fd']['sh_addr2'],
                      city=request.session['fd']['sh_city'],
                      state=request.session['fd']['sh_state'],
                      pcode=request.session['fd']['sh_post'],
                      country=request.session['fd']['sh_country'],
                      reward=(Reward.objects.get(
                          name=request.session['fd']['reward_name'])
                              if request.session['fd']['reward'] else None),
                      amount=decimal.Decimal(request.session['fd']['amount']),
                      ptype='CC',
                      pref=request.session['fd']['cc_type'] + ' x-' +
                      request.session['fd']['cc_last4'],
                      email=request.session['fd']['email'],
                      namecredit=request.session['fd']['namecredit'],
                      notes=request.session['fd']['notes'])
        except:
            msg = "There was a problem saving your order details to the database. Your card has NOT been charged. Please notify the site operator."
            return render(request, 'error.html', locals())

        try:
            charge = stripe.Charge.create(amount=amount,
                                          currency="usd",
                                          card=token,
                                          description=desc)
            try:
                o.notify = request.session['fd']['notify']
            except:
                pass
            o.save()
            send_mail(subject=proj_name + ' - Thank you for your contribution',
                      message=get_template('notify.txt').render(
                          Context({
                              'order': request.session['fd'],
                              'proj_name': proj_name,
                              'proj_addr': proj_addr,
                              'time': time,
                              'reward_desc': reward_desc
                          })),
                      from_email=settings.NOTIFY_SENDER,
                      recipient_list=[request.session['fd']['email']],
                      fail_silently=False)
            request.session['fd'] = {}
            return render(request, 'payment/success.html', locals())
        except stripe.CardError, e:
            msg = "Your card has been declined. Please choose a new card or a new payment method and restart your order."
            return render(request, 'error.html', locals())
        except: