57 Commits

Author SHA1 Message Date
Prakhar Pratyush
3548764e21 push_notifications: Use SentPushNotificationResult dataclass.
Refactoring, no functional change.

This commit refactors `send_e2ee_push_notification_apple`
and `send_e2ee_push_notification_android` to return a
`SentPushNotificationResult` dataclass.

It's a cleaner protocol than passing a mutable data structure
`delete_device_ids` as argument and updating it within
functions.

Fixes part of #35368.
2025-08-27 10:56:42 -07:00
Prakhar Pratyush
6ab6df96c8 push_notification: Send a list of push requests.
Earlier, we were passing a map `device_id_to_encrypted_data`
and http headers as separate fields to bouncer.

The downside of that approach is it restricts the bouncer to
process only one type of notice i.e. either notification for
a new message or removal of sent notification, because it
used to receive a fixed priority and push_type for all the
entries in the map.

Also, using map restricts the bouncer to receive only one
request per device_id. Server can't send multiple notices
to a device in a single call to bouncer.

Currently, the server isn't modelled in a way to make a
single call to the bouncer with:
* Both send-notification & remove-notification request data.
* Multiple send-notification request data to the same device.

This commit replaces the old protocol of sending data with
a list of objects where each object has the required data
for bouncer to send it to FCM or APNs.

This makes things a lot flexible and opens possibility for
server to batch requests in a different way if we'd like to.
2025-07-25 12:47:55 -07:00
Prakhar Pratyush
29ea8a07c2 push_notification: Add support to configure priority and push_type.
This commit adds support to let server configure:
* fcm_priority
* apns_priority
* apns_push_type

while sending E2EE push notifications.

The values of these fields will vary depending on whether the
send request is to send push notification for a message or
revoke an already sent notification.

Since, the bouncer receives encrypted data so it can't inspect
the payload to determine whether it is a removal request or not,
hence can't configure priority on its own.

The server needs to specify explicitly.

We're not simply sending a single 'is_removal' flag because
allowing the server to configure them separately will help in
future to support other types of notifications with a different
combination of priority and push_type, like whose aim is to notify
user about information other than a new message or removal request.

Fixes part of #35368.
2025-07-24 11:56:42 -07:00
Prakhar Pratyush
7e1afa0e8a push_notification: Send end-to-end encrypted push notifications.
This commit adds support to send encrypted push notifications
to devices registered to receive encrypted notifications.

URL: `POST /api/v1/remotes/push/e2ee/notify`
payload: `realm_uuid` and `device_id_to_encrypted_data`

The POST request needs to be authenticated with the server’s
API key.

Note: For Zulip Cloud, a background fact about the push bouncer is
that it runs on the same server and database as the main application;
it’s not a separate service. So, as an optimization we directly call
'send_e2ee_push_notifications' function and skip the HTTP request.
2025-07-22 17:08:55 -07:00
Anders Kaseorg
8a7916f21a python: Consistently use from…import for datetime.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2023-12-05 12:01:18 -08:00
Mateusz Mandera
3cafdbdc1e counts: Add function compute_max_monthly_messages for remote servers.
This calculates the largest amount of messages sent within a month for
the last 3 months. The query is targeted for the specific use-case in
this function - for finding the count for a specific server. For
calculating this in bulk for a large number of remote server an
adapted, bulk query will be needed - rather than running this one in a
loop, which would likely be very inefficient.
2023-11-08 09:45:49 -08:00
Vishnu Ks
93b398bc0a billing: Move zilencer/lib/stripe to corporate. 2018-10-01 15:43:44 -07:00
Vishnu Ks
3e86fa84ea billing: Rename RealmAuditLog.STRIPE_CARD_ADDED to STRIPE_CARD_CHANGED. 2018-09-11 00:08:38 -07:00
Rishi Gupta
18b86a9499 billing: Fix RealmAuditLog accounting for downgrade. 2018-09-01 09:42:10 -07:00
Rishi Gupta
31ed4492ce billing: Add backend for downgrading. 2018-08-31 17:49:34 -07:00
Vishnu Ks
98dac0f0a9 billing: Remove Customer.billing_user. 2018-08-27 12:35:46 -07:00
Vishnu Ks
dcb7b15069 billing: Use UserProfile.is_billing_admin instead of Customer.billing_user. 2018-08-27 12:35:46 -07:00
Rishi Gupta
eec07072ee billing: Add coupons. 2018-08-24 17:27:26 -07:00
Rishi Gupta
d229948a43 billing: Make source optional when creating stripe customer. 2018-08-24 16:40:34 -07:00
Rishi Gupta
4ad8f20c28 billing: Add comment explaining race condition in customer creation. 2018-08-24 16:40:34 -07:00
Rishi Gupta
90407537a0 billing: Add comment explaining race conditions in initial subscription. 2018-08-22 21:30:48 -07:00
Rishi Gupta
d081cf7b78 billing: Add transaction.atomic() for Customer creation and logging. 2018-08-22 19:20:06 -07:00
Rishi Gupta
3cf9cd00d6 billing: Remove idempotency key from upgrade process.
This would be relevant if we retried on network failure, but we don't.
2018-08-22 19:18:32 -07:00
Vishnu Ks
9bb338be11 models: Add plan_type to Realm. 2018-08-21 12:39:06 -07:00
Rishi Gupta
4181d575b1 billing: Move Stripe call to end in do_subscribe_customer_to_plan.
In general, everything that could throw an error and that could come before
the Stripe call should do so.
2018-08-13 20:24:08 -07:00
Rishi Gupta
56d4034db4 billing: Require successful charge to establish billing relationship.
There are several situations in which we want to create a Customer and
stripe.Customer object before we really have a billing relationship with a
customer. The main one is giving non-profit or educational discounts.
2018-08-13 20:24:08 -07:00
Rishi Gupta
27d4b1a5f0 billing: Add RealmAuditLogProcessor. 2018-08-13 17:12:50 -07:00
Rishi Gupta
e804c563a8 billing: Update stripe error handling code. 2018-08-13 17:12:50 -07:00
Rishi Gupta
d0e377428a billing: Fix typo in CONTACT_SUPPORT error message. 2018-08-10 22:48:10 -07:00
Rishi Gupta
2855864f54 billing: Rename RealmAuditLog.REALM_PLAN_QUANTITY_RESET. 2018-08-10 15:54:31 -07:00
Rishi Gupta
abc044e869 billing: Rename RealmAuditLog.REALM_PLAN_STARTED. 2018-08-10 15:54:31 -07:00
Rishi Gupta
d33d7e1c28 billing: Rename RealmAuditLog.REALM_CARD_ADDED. 2018-08-10 15:54:30 -07:00
Rishi Gupta
bdb6d8213f billing: Rename RealmAuditLog.REALM_STRIPE_INITIALIZED. 2018-08-10 15:46:55 -07:00
Vishnu Ks
132480c031 billing: Pass email to stripe.Customer.create. 2018-08-10 13:52:35 -07:00
Rishi Gupta
2cdcf4b88f billing: Rename get_upcoming_invoice. 2018-08-06 16:24:09 -04:00
Rishi Gupta
89ca1d0d97 billing: Rename get_stripe_customer. 2018-08-06 16:24:09 -04:00
Rishi Gupta
086b7d76e5 billing: Rename customer_with_active_subscription in fixture generation.
Fixes regression introduced in 79dddd5.
2018-08-06 16:24:09 -04:00
Rishi Gupta
9f2b8a4a11 billing: Move checks from process_initial_upgrade into separate function. 2018-08-06 11:05:33 -04:00
Rishi Gupta
5719633992 billing: Update and unify billing error handling. 2018-08-06 11:05:33 -04:00
Vishnu Ks
e06957bef5 billing: Raise exceptions instead of returning errors in upgrade flow. 2018-08-06 11:05:33 -04:00
Vishnu Ks
8643c681f0 billing: Separate initial upgrade logic to another function. 2018-08-06 11:05:33 -04:00
Vishnu Ks
8bcd4131fe billing: Rename retrieve_customer fixture. 2018-08-04 19:17:34 -04:00
Vishnu Ks
b7d3a1a0f3 billing: Don't check for stripe key and plan objects in tests.
Stripe already returns an appropriate error in prod, and these checks are
just a hassle in tests.

Also fixes an error where the check for Plan.objects.exists() was missing
a "not".
2018-08-04 19:17:34 -04:00
Rishi Gupta
4554b564f7 billing: Rename RealmAuditLog.REALM_PLAN_QUANTITY_UPDATED. 2018-07-31 10:56:31 -04:00
Vishnu Ks
ba7db968d8 billing: Don't check for stripe config while running tests. 2018-07-25 23:03:55 -07:00
Vishnu Ks
51c82b6d4f models: Rename PLAN_QUANITY_UPDATED event type. 2018-07-25 23:03:55 -07:00
Vishnu Ks
975969aa89 stripe: Check for the existence of Pan objects in dev environment. 2018-07-25 23:03:55 -07:00
Vishnu Ks
b88613fd0b billing: Expand default_source object when retrieving customer. 2018-07-24 10:20:23 -07:00
Vishnu Ks
1225bfd6ee billing: Don't use data attribute for iterating through subscriptions.
Iterating through data attribute is same as iterating through
subscriptions.
2018-07-24 10:20:23 -07:00
Vishnu Ks
0bcc0ca0d8 stripe: Fix type of stripe_customer_id. 2018-07-24 10:20:23 -07:00
Vishnu Ks
d75054fb15 billing: Add function to sign strings. 2018-07-24 07:16:12 -07:00
Vishnu Ks
f2861442f7 billing: Enforce Customer can have only one live subscription at a time. 2018-07-23 19:03:36 -07:00
Vishnu Ks
db8700513b stripe: Fix type of stripe_plan_id in do_subscribe_customer_to_plan. 2018-07-23 17:55:15 -07:00
Vishnu Ks
28167585b1 models: Rename several RealmAuditlog event types to past tense.
These event types haven't been used in production yet, and thus are
save to change without a migration.
2018-07-22 20:00:05 -07:00
Vishnu Ks
377fac2864 billing: Pass stripe_customer instead of Customer in upgrade functions. 2018-07-12 12:51:38 +05:30