def approve_payment(request):
	proj_name = settings.PROJECT_NAME
	stripe_public_key = settings.STRIPE_PUBLIC_KEY

	if request.method == 'POST':
		fd = request.POST.copy()
		if fd['reward'] != 'none':
			fd['reward_name'] = fd['reward']
			fd['reward_short_desc'] = Reward.objects.get(name=fd['reward']).short_desc
			fd['reward'] = True
		else:
			fd['reward'] = False
			fd['reward_name'] = ''
		if fd['ctype'] == 'eur':
			fd['amount_eur'] = fd['amount']
			fd['amount'] = eur_to_dollars(fd['amount'])
		elif fd['ctype'] == 'gbp':
			fd['amount_gbp'] = fd['amount']
			fd['amount'] = gbp_to_dollars(fd['amount'])
		request.session['fd'] = fd
		return render(request, 'payment/confirm.html', locals())
	elif settings.STOP and (settings.DATE - datetime.datetime.now()).days < 0:
		msg = 'The funding campaign is complete and is no longer accepting new contributions.'
		return render(request, 'error.html', locals())
	else:
		request.session['fd'] = {}
		rewards = sorted(Reward.objects.all(), key=lambda i: i.min_amount)
		return render(request, 'payment/cc.html', locals())
Ejemplo n.º 2
0
def approve_payment(request):
    proj_name = settings.PROJECT_NAME
    stripe_public_key = settings.STRIPE_PUBLIC_KEY

    if request.method == 'POST':
        fd = request.POST.copy()
        if fd['reward'] != 'none':
            fd['reward_name'] = fd['reward']
            fd['reward_short_desc'] = Reward.objects.get(
                name=fd['reward']).short_desc
            fd['reward'] = True
        else:
            fd['reward'] = False
            fd['reward_name'] = ''
        if fd['ctype'] == 'eur':
            fd['amount_eur'] = fd['amount']
            fd['amount'] = eur_to_dollars(fd['amount'])
        elif fd['ctype'] == 'gbp':
            fd['amount_gbp'] = fd['amount']
            fd['amount'] = gbp_to_dollars(fd['amount'])
        request.session['fd'] = fd
        return render(request, 'payment/confirm.html', locals())
    elif settings.STOP and (settings.DATE - datetime.datetime.now()).days < 0:
        msg = 'The funding campaign is complete and is no longer accepting new contributions.'
        return render(request, 'error.html', locals())
    else:
        request.session['fd'] = {}
        rewards = sorted(Reward.objects.all(), key=lambda i: i.min_amount)
        return render(request, 'payment/cc.html', locals())
Ejemplo n.º 3
0
def gbp_to_dollars(value):
    return currency.gbp_to_dollars(value)
Ejemplo n.º 4
0
def approve_payment(request):
    proj_name = settings.PROJECT_NAME
    if request.method == 'POST':
        fd = request.POST.copy()
        fd['ptype'] = 'PP'
        if fd['reward'] != 'none':
            fd['reward_name'] = fd['reward']
            fd['reward_short_desc'] = Reward.objects.get(
                name=fd['reward']).short_desc
            fd['reward'] = True
        else:
            fd['reward'] = False
            fd['reward_name'] = 'None'
            fd['reward_short_desc'] = 'No reward'
        if fd['ctype'] == 'eur':
            fd['amount_eur'] = fd['amount']
            fd['amount'] = eur_to_dollars(fd['amount'])
        elif fd['ctype'] == 'gbp':
            fd['amount_gbp'] = fd['amount']
            fd['amount'] = gbp_to_dollars(fd['amount'])
        request.session['fd'] = fd

        paypalrestsdk.configure({
            'mode': settings.PAYPAL_MODE,
            'client_id': settings.PAYPAL_CLIENT_ID,
            'client_secret': settings.PAYPAL_CLIENT_SECRET
        })
        pmt = paypalrestsdk.Payment({
            'intent':
            'sale',
            'payer': {
                'payment_method': 'paypal'
            },
            'redirect_urls': {
                'return_url': settings.PROJECT_ADDR + '/c/PP/confirm',
                'cancel_url': settings.PROJECT_ADDR + '/c/PP/cancel'
            },
            'transactions': [{
                'item_list': {
                    'items': [{
                        'name':
                        request.session['fd']['reward_name'],
                        'sku':
                        request.session['fd']['reward_name'],
                        'price':
                        str(
                            decimal.Decimal(
                                request.session['fd']['amount']).quantize(
                                    decimal.Decimal(10)**-2)),
                        'currency':
                        'USD',
                        'quantity':
                        1
                    }]
                },
                'amount': {
                    'total':
                    str(
                        decimal.Decimal(
                            request.session['fd']['amount']).quantize(
                                decimal.Decimal(10)**-2)),
                    'currency':
                    'USD'
                },
                'description':
                request.session['fd']['reward_name'] + ' - ' +
                request.session['fd']['reward_short_desc']
            }]
        })

        if pmt.create():
            request.session['paypal_id'] = pmt['id']
            for link in pmt.links:
                if link['method'] == 'REDIRECT':
                    return HttpResponseRedirect(link.href)
        else:
            msg = 'There was an error in creating your payment. Please try again. If this problem persists, please contact the site operator.\n' + str(
                pmt.error)
            return render(request, 'error.html', locals())
    elif settings.STOP and (settings.DATE - datetime.datetime.now()).days < 0:
        msg = 'The funding campaign is complete and is no longer accepting new contributions.'
        return render(request, 'error.html', locals())
    else:
        request.session['fd'] = {}
        rewards = sorted(Reward.objects.all(), key=lambda i: i.min_amount)
        return render(request, 'payment/pp.html', locals())
def approve_payment(request):
	proj_name = settings.PROJECT_NAME
	if request.method == 'POST':
		fd = request.POST.copy()
		fd['ptype'] = 'PP'
		if fd['reward'] != 'none':
			fd['reward_name'] = fd['reward']
			fd['reward_short_desc'] = Reward.objects.get(name=fd['reward']).short_desc
			fd['reward'] = True
		else:
			fd['reward'] = False
			fd['reward_name'] = 'None'
			fd['reward_short_desc'] = 'No reward'
		if fd['ctype'] == 'eur':
			fd['amount_eur'] = fd['amount']
			fd['amount'] = eur_to_dollars(fd['amount'])
		elif fd['ctype'] == 'gbp':
			fd['amount_gbp'] = fd['amount']
			fd['amount'] = gbp_to_dollars(fd['amount'])
		request.session['fd'] = fd

		paypalrestsdk.configure({
			'mode': settings.PAYPAL_MODE,
			'client_id': settings.PAYPAL_CLIENT_ID,
			'client_secret': settings.PAYPAL_CLIENT_SECRET
			})
		pmt = paypalrestsdk.Payment({
			'intent': 'sale',
			'payer': {
				'payment_method': 'paypal'
				},
			'redirect_urls': {
				'return_url': settings.PROJECT_ADDR + '/c/PP/confirm',
				'cancel_url': settings.PROJECT_ADDR + '/c/PP/cancel'
				},
			'transactions': [{
				'item_list': {
					'items': [{
						'name': request.session['fd']['reward_name'],
						'sku': request.session['fd']['reward_name'],
						'price': str(decimal.Decimal(request.session['fd']['amount']).quantize(decimal.Decimal(10) ** -2)),
						'currency': 'USD',
						'quantity': 1
						}]
					},
				'amount': {
					'total': str(decimal.Decimal(request.session['fd']['amount']).quantize(decimal.Decimal(10) ** -2)),
					'currency': 'USD'
					},
				'description': request.session['fd']['reward_name'] + ' - ' + request.session['fd']['reward_short_desc']
				}]
			})

		if pmt.create():
			request.session['paypal_id'] = pmt['id']
			for link in pmt.links:
				if link['method'] == 'REDIRECT':
					return HttpResponseRedirect(link.href)
		else:
			msg = 'There was an error in creating your payment. Please try again. If this problem persists, please contact the site operator.\n'+str(pmt.error)
			return render(request, 'error.html', locals())
	elif settings.STOP and (settings.DATE - datetime.datetime.now()).days < 0:
		msg = 'The funding campaign is complete and is no longer accepting new contributions.'
		return render(request, 'error.html', locals())
	else:
		request.session['fd'] = {}
		rewards = sorted(Reward.objects.all(), key=lambda i: i.min_amount)
		return render(request, 'payment/pp.html', locals())