コード例 #1
0
    def test_send_thankyou_email(self):
        request = testing.DummyRequest()
        mailer = get_mailer(request)

        self.assertEqual(len(mailer.outbox), 0)

        donation = {
            'amount': 10,
            'firstname': 'John',
            'lastname': 'Doe',
            'city': 'Springfield',
            'country': 'Exampleland',
            'state': 'Example',
            'street': 'Main Street 10',
            'zip': '12345678',
            'email': '*****@*****.**',
            'creation': datetime.datetime.utcnow(),
            'send_sticker': True,
        }
        send_thankyou_email(request, donation)

        self.assertEqual(len(mailer.outbox), 1)
        message = mailer.outbox[0]
        self.assertEqual(message.subject, 'Thanks for your contribution!')
        self.assertEqual(message.recipients, ['*****@*****.**'])
コード例 #2
0
ファイル: views.py プロジェクト: srus/yith-library-server
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'))
コード例 #3
0
    def test_send_thankyou_email(self):
        request = FakeRequest()
        mailer = get_mailer(request)

        self.assertEqual(len(mailer.outbox), 0)

        send_thankyou_email(request, self.donation)

        self.assertEqual(len(mailer.outbox), 1)
        message = mailer.outbox[0]
        self.assertEqual(message.subject, 'Thanks for your contribution!')
        self.assertEqual(message.recipients, ['*****@*****.**'])
コード例 #4
0
    def test_send_thankyou_email(self):
        request = FakeRequest()
        mailer = get_mailer(request)

        self.assertEqual(len(mailer.outbox), 0)

        send_thankyou_email(request, self.donation)

        self.assertEqual(len(mailer.outbox), 1)
        message = mailer.outbox[0]
        self.assertEqual(message.subject, 'Thanks for your contribution!')
        self.assertEqual(message.recipients, ['*****@*****.**'])
コード例 #5
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"))
コード例 #6
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 = 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'))