def test_create_donation_with_sticker(self):
        self.request.user = None

        donation = create_donation(self.request, {
            'amount': 5,
            'firstname': 'John',
            'lastname': 'Doe',
            'city': 'Springfield',
            'country': 'Exampleland',
            'state': 'Example',
            'street': 'Main Street 10',
            'zip': '12345678',
            'email': '*****@*****.**',
        })

        self.assertEqual(donation['firstname'], 'John')
        self.assertEqual(donation['lastname'], 'Doe')
        self.assertEqual(donation['city'], 'Springfield')
        self.assertEqual(donation['country'], 'Exampleland')
        self.assertEqual(donation['state'], 'Example')
        self.assertEqual(donation['street'], 'Main Street 10')
        self.assertEqual(donation['zip'], '12345678')
        self.assertEqual(donation['email'], '*****@*****.**')
        self.assertEqual(donation['creation'],
                         datetime.datetime(2013, 1, 2, 10, 11, 2, tzinfo=utc))
        self.assertEqual(donation['send_sticker'], True)
        self.assertEqual(donation['user'], None)
Beispiel #2
0
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"))