def contributions_paypal_success(request): error_msg = _('There was a problem in the confirmation process. Please start the checkout again') if request.method == 'POST': if 'submit' in request.POST: token = request.POST.get('token', None) payerid = request.POST.get('payerid', None) amount = request.POST.get('amount', None) success = False if token and payerid and amount: try: amount = int(amount) except ValueError: return HTTPBadRequest('Amount must be an integer') paypal = PayPalExpressCheckout(request) success = paypal.do_express_checkout_payment(token, payerid, amount) if success: donation = create_donation(request, request.POST) send_thankyou_email(request, donation) send_notification_to_admins(request, donation) request.session.flash( _('Thank you very much for your great contribution'), 'success', ) else: request.session.flash(error_msg, 'error') return HTTPFound(location=request.route_path('contributions_index')) elif 'cancel' in request.POST: return HTTPFound(location=request.route_path('contributions_paypal_cancel_callback')) else: return HTTPBadRequest('Wrong action') else: token = request.GET.get('token', None) payerid = request.GET.get('PayerID', None) if token and payerid: paypal = PayPalExpressCheckout(request) details = paypal.get_express_checkout_details(token, payerid) details.update({ 'token': token, 'payerid': payerid, }) amount = details['amount'] details['include_sticker'] = include_sticker(amount) return details else: request.session.flash(error_msg, 'error') return HTTPFound(location=request.route_path('contributions_index'))
def contributions_paypal_success(request): error_msg = _("There was a problem in the confirmation process. Please start the checkout again") if request.method == "POST": if "submit" in request.POST: token = request.POST.get("token", None) payerid = request.POST.get("payerid", None) amount = request.POST.get("amount", None) success = False if token and payerid and amount: try: amount = int(amount) except ValueError: return HTTPBadRequest("Amount must be an integer") paypal = PayPalExpressCheckout(request) success = paypal.do_express_checkout_payment(token, payerid, amount) if success: donation = create_donation(request, request.POST) send_thankyou_email(request, donation) send_notification_to_admins(request, donation) request.session.flash(_("Thank you very much for your great contribution"), "success") else: request.session.flash(error_msg, "error") return HTTPFound(location=request.route_path("contributions_index")) elif "cancel" in request.POST: return HTTPFound(location=request.route_path("contributions_paypal_cancel_callback")) else: return HTTPBadRequest("Wrong action") else: token = request.GET.get("token", None) payerid = request.GET.get("PayerID", None) if token and payerid: paypal = PayPalExpressCheckout(request) details = paypal.get_express_checkout_details(token, payerid) details.update({"token": token, "payerid": payerid}) amount = details["amount"] details["include_sticker"] = include_sticker(amount) return details else: request.session.flash(error_msg, "error") return HTTPFound(location=request.route_path("contributions_index"))
def test_include_sticker(self): self.assertFalse(include_sticker(1)) self.assertTrue(include_sticker(5)) self.assertTrue(include_sticker(10))
def contributions_paypal_success(request): error_msg = _('There was a problem in the confirmation process. Please start the checkout again') if request.method == 'POST': if 'submit' in request.POST: token = request.POST.get('token', None) payerid = request.POST.get('payerid', None) amount = request.POST.get('amount', None) success = False if token and payerid and amount: try: amount = int(amount) except ValueError: return HTTPBadRequest('Amount must be an integer') paypal = PayPalExpressCheckout(request) success = paypal.do_express_checkout_payment(token, payerid, amount) if success: donation = Donation( amount=amount, first_name=request.POST['firstname'], last_name=request.POST['lastname'], city=request.POST['city'], country=request.POST['country'], state=request.POST['state'], street=request.POST['street'], zipcode=request.POST['zip'], email=request.POST['email'], ) if donation.should_include_sticker(): if 'no-sticker' in request.POST: donation.send_sticker = False else: donation.send_sticker = True else: donation.send_sticker = False donation.user = request.user Session.add(donation) Session.flush() send_thankyou_email(request, donation) send_notification_to_admins(request, donation) request.session.flash( _('Thank you very much for your great contribution'), 'success', ) else: request.session.flash(error_msg, 'error') return HTTPFound(location=request.route_path('contributions_index')) elif 'cancel' in request.POST: return HTTPFound(location=request.route_path('contributions_paypal_cancel_callback')) else: return HTTPBadRequest('Wrong action') else: token = request.GET.get('token', None) payerid = request.GET.get('PayerID', None) if token and payerid: paypal = PayPalExpressCheckout(request) details = paypal.get_express_checkout_details(token, payerid) details.update({ 'token': token, 'payerid': payerid, }) amount = details['amount'] details['include_sticker'] = include_sticker(amount) return details else: request.session.flash(error_msg, 'error') return HTTPFound(location=request.route_path('contributions_index'))