Пример #1
0
 def form_valid(self, form):
     project = self.object
     if '_approve' in self.request.POST:
         messages.success(self.request, project.title + ' has been approved and is live.')
         project.approve_project()
     elif '_stage' in self.request.POST:
         messages.success(self.request, project.title + ' has been staged to go live.')
         project.stage_project()
     elif '_unapprove' in self.request.POST:
         messages.success(self.request, project.title + ' is no longer live.')
         project.unapprove_project()
     elif '_propose' in self.request.POST:
         messages.success(self.request, project.title + ' is now pending approval.')
         project.propose_project()
     elif '_deny' in self.request.POST:
         messages.info(self.request, project.title + ' has been denied.')
         project.deny_project()
     elif '_complete' in self.request.POST:
         messages.success(self.request, project.title + ' has been completed.')
         project.complete_project()
     elif '_incomplete' in self.request.POST:
         messages.info(self.request, project.title + ' has been marked as active again (not yet completed).')
         project.mark_as_incomplete_project()
     elif '_repayment' in self.request.POST:
         repayment_amount = Decimal(self.request.POST['_repayment_amount'])
         PaymentService.create_repayment(self.user_profile, repayment_amount, project)
         messages.success(self.request, '$' + str(repayment_amount) + ' repaid by ' + project.org_name)
     return redirect(self.get_success_url())
Пример #2
0
 def form_valid(self, form):
     project = self.object
     if '_approve' in self.request.POST:
         messages.success(self.request, project.title + ' has been approved and is live.')
         project.approve_project()
     elif '_stage' in self.request.POST:
         messages.success(self.request, project.title + ' has been staged to go live.')
         project.stage_project()
     elif '_unapprove' in self.request.POST:
         messages.success(self.request, project.title + ' is no longer live.')
         project.unapprove_project()
     elif '_propose' in self.request.POST:
         messages.success(self.request, project.title + ' is now pending approval.')
         project.propose_project()
     elif '_deny' in self.request.POST:
         messages.info(self.request, project.title + ' has been denied.')
         project.deny_project()
     elif '_complete' in self.request.POST:
         messages.success(self.request, project.title + ' has been completed.')
         project.complete_project()
     elif '_incomplete' in self.request.POST:
         messages.info(self.request, project.title + ' has been marked as active again (not yet completed).')
         project.mark_as_incomplete_project()
     elif '_repayment' in self.request.POST:
         repayment_amount = Decimal(self.request.POST['_repayment_amount'])
         PaymentService.create_repayment(self.user_profile, repayment_amount, project)
         messages.success(self.request, '$' + str(repayment_amount) + ' repaid by ' + project.org_name)
     return redirect(self.get_success_url())
Пример #3
0
    def test_create_payment(self, mock_amount, mock_instrument):
        """Verify that we can create a payment."""
        # Force the amount to be valid
        mock_amount.return_value = True
        mock_instrument.return_value = True

        # Mock out a payment instrument with paypal by default
        instrument_type = mock.PropertyMock(
            return_value=PaymentType.objects.get_paypal(), )
        payment_instrument = mock.Mock()
        type(payment_instrument).type = instrument_type
        project = Project.factories.base.create()
        user = (User.objects.create_user(username="******",
                                         password="******")).revolvuserprofile

        # Make the payment
        PaymentService.create_payment(
            user,
            user,
            10.00,
            project,
            payment_instrument,
        )

        # Check that the charge was actually made
        payment_instrument.charge.assert_called_once()

        with self.assertRaises(PaymentServiceException):
            PaymentService.create_payment(
                user,
                None,
                10.00,
                project,
                payment_instrument,
            )
Пример #4
0
    def test_check_valid_payment_instrument(self):
        """Verify that we can get a valid payment instrument type."""
        # Mock out a payment instrument
        instrument_type = PaymentType.objects.get_paypal()

        # Check that it returns True
        self.assertTrue(PaymentService.check_valid_payment_instrument(instrument_type))
Пример #5
0
    def process_payment(self, project, user):
        """
        Process the payment with given the credit card information.

        :project: revolv.project.models.Project
        :user: the User making the payment
        :return:
        """
        if not self.is_valid():
            raise Exception('Cannot process invalid form')

        # Remove the amount field for the tuple
        cc_dict = deepcopy(self.cleaned_data)
        del cc_dict['amount']

        credit_card = CreditCard(**cc_dict)

        instrument = PayPalCreditCardInstrument(credit_card)

        # TODO: error handling
        # Make the payment
        payment = PaymentService.create_payment(
            user.revolvuserprofile,
            user.revolvuserprofile,
            self.cleaned_data.get('amount'),
            project,
            instrument
        )

        return payment
Пример #6
0
    def process_payment(self, project, user):
        """
        Process the payment with given the credit card information.

        :project: revolv.project.models.Project
        :user: the User making the payment
        :return:
        """
        if not self.is_valid():
            raise Exception('Cannot process invalid form')

        # Remove the amount field for the tuple
        cc_dict = deepcopy(self.cleaned_data)
        del cc_dict['amount']

        credit_card = CreditCard(**cc_dict)

        instrument = PayPalCreditCardInstrument(credit_card)

        # TODO: error handling
        # Make the payment
        payment = PaymentService.create_payment(
            user.revolvuserprofile, user.revolvuserprofile,
            self.cleaned_data.get('amount'), project, instrument)

        return payment
Пример #7
0
    def test_check_valid_payment_instrument(self):
        """Verify that we can get a valid payment instrument type."""
        # Mock out a payment instrument
        instrument_type = PaymentType.objects.get_paypal()

        # Check that it returns True
        self.assertTrue(
            PaymentService.check_valid_payment_instrument(instrument_type))
Пример #8
0
    def test_create_payment(self, mock_amount, mock_instrument):
        """Verify that we can create a payment."""
        # Force the amount to be valid
        mock_amount.return_value = True
        mock_instrument.return_value = True

        # Mock out a payment instrument with paypal by default
        instrument_type = mock.PropertyMock(return_value=PaymentType.objects.get_paypal())
        payment_instrument = mock.Mock()
        type(payment_instrument).type = instrument_type
        project = Project.factories.base.create()
        user = (User.objects.create_user(username="******", password="******")).revolvuserprofile

        # Make the payment
        PaymentService.create_payment(user, user, 10.00, project, payment_instrument)

        # Check that the charge was actually made
        payment_instrument.charge.assert_called_once()

        with self.assertRaises(PaymentServiceException):
            PaymentService.create_payment(user, None, 10.00, project, payment_instrument)
Пример #9
0
 def test_check_valid_amount(self):
     """Verify that the amount is valid."""
     self.assertTrue(PaymentService.check_valid_amount(10.00))
     self.assertFalse(PaymentService.check_valid_amount(-10.00))
     self.assertFalse(PaymentService.check_valid_amount("abc"))
Пример #10
0
 def test_check_valid_amount(self):
     """Verify that the amount is valid."""
     self.assertTrue(PaymentService.check_valid_amount(10.00))
     self.assertFalse(PaymentService.check_valid_amount(-10.00))
     self.assertFalse(PaymentService.check_valid_amount("abc"))