forked from pypi/warehouse
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
orgs: stripe data hygiene (pypi#17380)
* ensure we don't try to process checkout events unrelated to us * create _new_ subscription when existing subscriptions are cancelled Cancelled is a terminal state, we cannot "return" to re-enable a cancelled subscription. Must create a new one * translations * lint * implement Organization.manageable_subscription This is distinct from "active_subscription" as it determines if a user can self-service updating the subscription payment. Basically all states excepted Cancelled can be self-serviced.
- Loading branch information
Showing
11 changed files
with
157 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,59 @@ | |
|
||
class TestHandleBillingWebhookEvent: | ||
# checkout.session.completed | ||
def test_handle_billing_webhook_event_checkout_complete_not_us( | ||
self, db_request, subscription_service, monkeypatch, billing_service | ||
): | ||
organization = OrganizationFactory.create() | ||
stripe_customer = StripeCustomerFactory.create() | ||
OrganizationStripeCustomerFactory.create( | ||
organization=organization, customer=stripe_customer | ||
) | ||
subscription = StripeSubscriptionFactory.create(customer=stripe_customer) | ||
OrganizationStripeSubscriptionFactory.create( | ||
organization=organization, subscription=subscription | ||
) | ||
|
||
event = { | ||
"type": "checkout.session.completed", | ||
"data": { | ||
"object": { | ||
"id": "cs_test_12345", | ||
"customer": stripe_customer.customer_id, | ||
"status": "complete", | ||
"subscription": subscription.subscription_id, | ||
# Missing expected metadata tags (billing_service, domain) | ||
"metadata": {}, | ||
}, | ||
}, | ||
} | ||
|
||
checkout_session = { | ||
"id": "cs_test_12345", | ||
"customer": { | ||
"id": stripe_customer.customer_id, | ||
"email": "[email protected]", | ||
}, | ||
"status": "complete", | ||
"subscription": { | ||
"id": subscription.subscription_id, | ||
"items": { | ||
"data": [{"id": "si_12345"}], | ||
}, | ||
}, | ||
} | ||
|
||
get_checkout_session = pretend.call_recorder(lambda *a, **kw: checkout_session) | ||
monkeypatch.setattr( | ||
billing_service, "get_checkout_session", get_checkout_session | ||
) | ||
|
||
billing.handle_billing_webhook_event(db_request, event) | ||
|
||
assert ( | ||
get_checkout_session.calls == [] | ||
) # Should have stopped immediately before this call | ||
|
||
def test_handle_billing_webhook_event_checkout_complete_update( | ||
self, db_request, subscription_service, monkeypatch, billing_service | ||
): | ||
|
@@ -51,6 +104,10 @@ def test_handle_billing_webhook_event_checkout_complete_update( | |
"customer": stripe_customer.customer_id, | ||
"status": "complete", | ||
"subscription": subscription.subscription_id, | ||
"metadata": { | ||
"billing_service": "pypi", | ||
"domain": "localhost", | ||
}, | ||
}, | ||
}, | ||
} | ||
|
@@ -94,6 +151,10 @@ def test_handle_billing_webhook_event_checkout_complete_add( | |
"customer": stripe_customer.customer_id, | ||
"status": "complete", | ||
"subscription": "sub_12345", | ||
"metadata": { | ||
"billing_service": "pypi", | ||
"domain": "localhost", | ||
}, | ||
}, | ||
}, | ||
} | ||
|
@@ -131,6 +192,10 @@ def test_handle_billing_webhook_event_checkout_complete_invalid_status( | |
"customer": "cus_1234", | ||
"status": "invalid_status", | ||
"subscription": "sub_12345", | ||
"metadata": { | ||
"billing_service": "pypi", | ||
"domain": "localhost", | ||
}, | ||
}, | ||
}, | ||
} | ||
|
@@ -149,6 +214,10 @@ def test_handle_billing_webhook_event_checkout_complete_invalid_customer( | |
"customer": "", | ||
"status": "complete", | ||
"subscription": "sub_12345", | ||
"metadata": { | ||
"billing_service": "pypi", | ||
"domain": "localhost", | ||
}, | ||
}, | ||
}, | ||
} | ||
|
@@ -187,6 +256,10 @@ def test_handle_billing_webhook_event_checkout_complete_invalid_subscription( | |
"customer": "cus_1234", | ||
"status": "complete", | ||
"subscription": "", | ||
"metadata": { | ||
"billing_service": "pypi", | ||
"domain": "localhost", | ||
}, | ||
}, | ||
}, | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.