Beispiel #1
0
 def test_delete_payment(self):
     existing_payment = MagicMock()
     payable = MockPayable(payer=self.member, payment=existing_payment)
     services.delete_payment(payable)
     self.assertIsNone(payable.payment)
     payable.save.assert_called_once()
     existing_payment.delete.assert_called_once()
Beispiel #2
0
 def _update_payment(order, payment_type=None, processed_by=None):
     if order.payment and payment_type == Payment.NONE:
         delete_payment(order)
     elif order.payment:
         if payment_type is None:
             payment_type = order.payment.type
         order.payment = create_payment(order, processed_by, payment_type)
         order.payment.save()
     else:
         order.payment = create_payment(order, processed_by, payment_type)
         order.save()
Beispiel #3
0
def update_registration_by_organiser(registration, member, data):
    if not is_organiser(member, registration.event):
        raise RegistrationError(_("You are not allowed to update this registration."))

    if "payment" in data:
        if data["payment"]["type"] == Payment.NONE and registration.payment is not None:
            delete_payment(registration)
        else:
            registration.payment = create_payment(
                payable=registration,
                processed_by=member,
                pay_type=data["payment"]["type"],
            )

    if "present" in data:
        registration.present = data["present"]

    registration.save()
    def test_delete_payment(self):
        existing_payment = MagicMock(batch=None)
        payable = MockPayable(payer=self.member, payment=existing_payment)
        payable.save.reset_mock()

        with self.subTest("Within deletion window"):
            payable.payment = existing_payment
            existing_payment.created_at = timezone.now()
            services.delete_payment(payable)
            self.assertIsNone(payable.payment)
            payable.save.assert_called_once()
            existing_payment.delete.assert_called_once()

        with self.subTest("Outside deletion window"):
            payable.payment = existing_payment
            existing_payment.created_at = timezone.now() - timezone.timedelta(
                seconds=settings.PAYMENT_CHANGE_WINDOW + 60)
            with self.assertRaisesMessage(
                    PaymentError,
                    "You are not authorized to delete this payment."):
                services.delete_payment(payable)
            self.assertIsNotNone(payable.payment)

        existing_payment.created_at = timezone.now()

        with self.subTest("Already processed"):
            payable.payment = existing_payment
            existing_payment.batch = Batch.objects.create(processed=True)
            with self.assertRaisesMessage(
                    PaymentError, "This payment has already been processed."):
                services.delete_payment(payable)
            self.assertIsNotNone(payable.payment)
Beispiel #5
0
 def delete(self, using=None, keep_parents=False):
     if self.payment is not None and self.can_be_changed:
         delete_payment(self)
     return super().delete(using, keep_parents)
Beispiel #6
0
 def _update_payment(order, payment_type=None, processed_by=None):
     if order.payment and payment_type == PaymentTypeField.NO_PAYMENT:
         delete_payment(order)
     else:
         order.payment = create_payment(order, processed_by, payment_type)
         order.save()