Example #1
0
async def _():
    subscription = Subscription(
        id=1,
        user_id=1,
        status=SubscriptionStatus.PENDING,
    )

    subscription.mark_as_canceled()

    assert not subscription.is_active
    assert subscription.status == SubscriptionStatus.CANCELED
Example #2
0
async def _():
    subscription = Subscription(
        id=1,
        user_id=1,
        status=SubscriptionStatus.PENDING,
    )

    subscription.mark_as_active()

    assert subscription.is_active
    assert subscription.status == SubscriptionStatus.ACTIVE
Example #3
0
async def _():
    user = PastaportoUserInfo(id=1, email="*****@*****.**", is_staff=False)
    subscription = Subscription(id=1,
                                user_id=user.id,
                                status=SubscriptionStatus.CANCELED)
    payment = Payment(
        total=1000,
        subscription=subscription,
        idempotency_key="iv_abcabc",
        status=PaymentStatus.PAID,
        payment_date=datetime.now(timezone.utc),
        period_start=datetime.now(timezone.utc) + timedelta(days=0),
        period_end=datetime.now(timezone.utc) + timedelta(days=30),
    )
    StripeSubscriptionPayment(
        payment=payment,
        stripe_subscription_id="sub_abcabc",
        stripe_invoice_id="iv_abcabc",
        invoice_pdf="https://stripe.com/pdf/xxx",
    )

    checkout_session_id = await subscribe_user_to_association(
        user,
        association_repository=FakeAssociationMembershipRepository(
            [subscription]),
    )
    assert checkout_session_id == "cs_xxx"
Example #4
0
async def _():
    user = PastaportoUserInfo(id=1, email="*****@*****.**", is_staff=False)
    subscription = Subscription(id=1,
                                user_id=user.id,
                                status=SubscriptionStatus.CANCELED)
    payment = Payment(
        id=1,
        total=1000,
        idempotency_key="iv_abcabc",
        subscription=subscription,
        status=PaymentStatus.PAID,
        payment_date=datetime.now(timezone.utc),
        period_start=datetime.now(timezone.utc) + timedelta(days=0),
        period_end=datetime.now(timezone.utc) + timedelta(days=30),
    )
    StripeSubscriptionPayment(
        id=1,
        payment=payment,
        stripe_subscription_id="sub_abcabc",
        stripe_invoice_id="iv_abcabc",
        invoice_pdf="https://stripe.com/pdf/xxx",
    )
    stripe_customer = StripeCustomer(id=1,
                                     user_id=user.id,
                                     stripe_customer_id="cus_123")

    fake_repository = FakeAssociationMembershipRepository([subscription],
                                                          [stripe_customer])

    with raises(NoSubscriptionAvailable):
        await manage_user_association_subscription(
            user, association_repository=fake_repository)
Example #5
0
async def _():
    user = PastaportoUserInfo(id=1, email="*****@*****.**", is_staff=False)
    subscription = Subscription(id=1,
                                user_id=user.id,
                                status=SubscriptionStatus.ACTIVE)
    payment = Payment(
        id=1,
        total=1000,
        idempotency_key="iv_abcabc",
        subscription=subscription,
        status=PaymentStatus.PAID,
        payment_date=datetime.now(timezone.utc),
        period_start=datetime.now(timezone.utc) + timedelta(days=0),
        period_end=datetime.now(timezone.utc) + timedelta(days=30),
    )
    PretixPayment(
        id=1,
        payment=payment,
        order_code="ABC",
        event_organizer="local-test",
        event_id="pycon-demo",
    )

    fake_repository = FakeAssociationMembershipRepository([subscription], [])

    with raises(NotSubscribedViaStripe):
        await manage_user_association_subscription(
            user, association_repository=fake_repository)
Example #6
0
async def _():
    subscription = Subscription(
        id=1,
        user_id=1,
        status=SubscriptionStatus.PENDING,
    )

    subscription.add_stripe_subscription_payment(
        total=1000,
        status=PaymentStatus.PAID,
        payment_date=datetime.fromtimestamp(1618062032, tz=timezone.utc),
        period_start=datetime.fromtimestamp(1618062032, tz=timezone.utc),
        period_end=datetime.fromtimestamp(1618062032, tz=timezone.utc),
        stripe_subscription_id="cs_xxx",
        stripe_invoice_id="iv_xx",
        invoice_pdf="https://pdfpdf",
    )

    assert len(subscription._payments_to_add) == 1
    assert subscription._payments_to_add[0].stripe_subscription_id == "cs_xxx"
Example #7
0
 async def create_subscription(self, user_id):
     sub = Subscription(user_id=user_id, status=SubscriptionStatus.PENDING)
     self.SUBSCRIPTIONS_BY_USER_ID[user_id] = sub
     return sub