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,
            )
Exemple #2
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
Exemple #3
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
    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)