def test_refresh_card_expiry_dates_refreshed():
    """Customer card already marked for 'refresh', so don't send an email."""
    with mock.patch('stripe.Customer.retrieve') as mock_retrieve:
        mock_retrieve.return_value = {
            'default_card': '1234',
            'cards': {
                'data': [
                    {
                        'id': '1234',
                        'exp_month': '8',
                        'exp_year': '1986',
                    },
                ],
            },
        }
        obj = ObjectPaymentPlanFactory(content_object=ContactFactory())
        ObjectPaymentPlanInstalmentFactory(
            object_payment_plan=obj
        )
        ObjectPaymentPlanInstalmentFactory(
            object_payment_plan=obj,
            due=date.today() + relativedelta(months=+1),
        )
        customer = CustomerFactory(
            email=obj.content_object.checkout_email,
            refresh=True,
        )
        ObjectPaymentPlan.objects.refresh_card_expiry_dates()
        customer.refresh_from_db()
        assert True == customer.refresh
        # check we didn't send a notification email
        assert 0 == Message.objects.count()
def test_outstanding_payment_plans_filter_two():
    obj = ObjectPaymentPlanFactory(content_object=ContactFactory())
    ObjectPaymentPlanInstalmentFactory(
        object_payment_plan=obj
    )
    ObjectPaymentPlanInstalmentFactory(
        object_payment_plan=obj,
        due=date.today() + relativedelta(months=+1),
    )
    assert 1 == ObjectPaymentPlan.objects.outstanding_payment_plans.count()
def test_outstanding_payment_plans_exclude_deleted():
    obj = ObjectPaymentPlanFactory(
        content_object=ContactFactory(),
        deleted=True,
    )
    ObjectPaymentPlanInstalmentFactory(object_payment_plan=obj)
    ObjectPaymentPlanInstalmentFactory(
        object_payment_plan=ObjectPaymentPlanFactory(
            content_object=ContactFactory(),
        ),
    )
    assert 1 == ObjectPaymentPlan.objects.outstanding_payment_plans.count()
def test_outstanding_payment_plans_exclude_success():
    ObjectPaymentPlanInstalmentFactory(
        object_payment_plan=ObjectPaymentPlanFactory(
            content_object=ContactFactory(),
        ),
    )
    ObjectPaymentPlanInstalmentFactory(
        state=CheckoutState.objects.success,
        object_payment_plan=ObjectPaymentPlanFactory(
            content_object=ContactFactory(),
        ),
    )
    assert 1 == ObjectPaymentPlan.objects.outstanding_payment_plans.count()
def test_report_card_expiry_dates():
    object_payment_plan = ObjectPaymentPlanFactory(
        content_object=ContactFactory()
    )
    ObjectPaymentPlanInstalmentFactory(object_payment_plan=object_payment_plan)
    obj = ObjectPaymentPlanInstalmentFactory(
        object_payment_plan=ObjectPaymentPlanFactory(
            content_object=ContactFactory()
        ),
    )
    CustomerFactory(
        email=obj.object_payment_plan.content_object.checkout_email
    )
    ObjectPaymentPlan.objects.report_card_expiry_dates
Beispiel #6
0
 def test_object_payment_plan_instalment_paid(self):
     obj = ObjectPaymentPlanInstalmentFactory(
         object_payment_plan=ObjectPaymentPlanFactory(
             content_object=ContactFactory(), ), )
     self.assert_staff_only(
         reverse('checkout.object.payment.plan.instalment.paid',
                 args=[obj.pk]))
def test_create_instalments_corrupt():
    object_payment_plan = ObjectPaymentPlanFactory(
        content_object=ContactFactory()
    )
    obj = ObjectPaymentPlanInstalmentFactory(
        object_payment_plan=object_payment_plan,
        count=2,
    )
    with pytest.raises(CheckoutError) as e:
        obj.object_payment_plan.create_instalments()
    assert 'no deposit record' in str(e.value)
def test_process_payments_fail(mocker):
    """Process payments."""
    with mock.patch('stripe.Customer.create') as mock_customer:
        mock_customer.side_effect = CheckoutError('Mock')
        today = date.today()
        install = ObjectPaymentPlanInstalmentFactory(
            due=today+relativedelta(days=-1),
            amount=Decimal('1'),
            object_payment_plan=ObjectPaymentPlanFactory(
                content_object=ContactFactory(),
            ),
        )
        CustomerFactory(
            email=install.object_payment_plan.content_object.checkout_email
        )
        NotifyFactory()
        ObjectPaymentPlanInstalment.objects.process_payments()
        # check
        install.refresh_from_db()
        assert install.state == CheckoutState.objects.fail
        assert 1 == Message.objects.count()
        assert 'FAIL' in Message.objects.first().subject
def test_refresh_card_expiry_dates():
    MailTemplateFactory(slug=Customer.MAIL_TEMPLATE_CARD_EXPIRY)
    with mock.patch('stripe.Customer.retrieve') as mock_retrieve:
        mock_retrieve.return_value = {
            'default_card': '1234',
            'cards': {
                'data': [
                    {
                        'id': '1234',
                        'exp_month': '8',
                        'exp_year': '1986',
                    },
                ],
            },
        }
        obj = ObjectPaymentPlanFactory(content_object=ContactFactory())
        ObjectPaymentPlanInstalmentFactory(
            object_payment_plan=obj
        )
        ObjectPaymentPlanInstalmentFactory(
            object_payment_plan=obj,
            due=date.today() + relativedelta(months=+1),
        )
        customer = CustomerFactory(
            email=obj.content_object.checkout_email
        )
        ObjectPaymentPlan.objects.refresh_card_expiry_dates()
        customer.refresh_from_db()
        assert True == customer.refresh
        # check email template context
        assert 1 == Message.objects.count()
        message = Message.objects.first()
        assert 1 == message.mail_set.count()
        mail = message.mail_set.first()
        assert 1 == mail.mailfield_set.count()
        assert {
            'name': customer.name,
        } == {f.key: f.value for f in mail.mailfield_set.all()}
def test_process_payments(mocker):
    """Process payments."""
    mocker.patch('stripe.Charge.create')
    mocker.patch('stripe.Customer.create')
    today = date.today()
    install_1 = ObjectPaymentPlanInstalmentFactory(
        due=today+relativedelta(days=1),
        amount=Decimal('2'),
        object_payment_plan=ObjectPaymentPlanFactory(
            content_object=ContactFactory(),
        ),
    )
    install_2 = ObjectPaymentPlanInstalmentFactory(
        due=today+relativedelta(days=-1),
        amount=Decimal('1'),
        object_payment_plan=ObjectPaymentPlanFactory(
            content_object=ContactFactory(),
        ),
    )
    install_3 = ObjectPaymentPlanInstalmentFactory(
        due=today+relativedelta(days=-2),
        amount=Decimal('2'),
        object_payment_plan=ObjectPaymentPlanFactory(
            content_object=ContactFactory(),
        ),
    )
    CustomerFactory(
        email=install_2.object_payment_plan.content_object.checkout_email
    )
    CustomerFactory(
        email=install_3.object_payment_plan.content_object.checkout_email
    )
    ObjectPaymentPlanInstalment.objects.process_payments()
    # check
    install_1.refresh_from_db()
    assert install_1.state == CheckoutState.objects.pending
    install_2.refresh_from_db()
    assert install_2.state == CheckoutState.objects.success
    install_3.refresh_from_db()
    assert install_3.state == CheckoutState.objects.success