mirror of https://github.com/zulip/zulip.git
webhooks/stripe: Format timestamps as dates.
This commit is contained in:
parent
027d5e90c5
commit
76aebac568
|
@ -1,129 +1,111 @@
|
|||
{
|
||||
"created":1326853478,
|
||||
"livemode":false,
|
||||
"id":"customer.subscription.updated_00000000000000",
|
||||
"type":"customer.subscription.updated",
|
||||
"object":"event",
|
||||
"request":null,
|
||||
"pending_webhooks":1,
|
||||
"api_version":"2018-02-28",
|
||||
"data":{
|
||||
"object":{
|
||||
"id":"sub_00000000000000",
|
||||
"object":"subscription",
|
||||
"application_fee_percent":null,
|
||||
"billing":"charge_automatically",
|
||||
"billing_cycle_anchor":1542644734,
|
||||
"cancel_at_period_end":false,
|
||||
"canceled_at":null,
|
||||
"created":1542644734,
|
||||
"current_period_end":1545236734,
|
||||
"current_period_start":1542644734,
|
||||
"customer":"cus_00000000000000",
|
||||
"days_until_due":null,
|
||||
"default_source":null,
|
||||
"discount":null,
|
||||
"ended_at":null,
|
||||
"items":{
|
||||
"object":"list",
|
||||
"data":[
|
||||
{
|
||||
"id":"si_00000000000000",
|
||||
"object":"subscription_item",
|
||||
"created":1542644735,
|
||||
"metadata":{
|
||||
|
||||
},
|
||||
"plan":{
|
||||
"id":"gold_00000000000000",
|
||||
"object":"plan",
|
||||
"active":true,
|
||||
"aggregate_usage":null,
|
||||
"amount":2000,
|
||||
"billing_scheme":"per_unit",
|
||||
"created":1394782612,
|
||||
"currency":"cad",
|
||||
"interval":"month",
|
||||
"interval_count":1,
|
||||
"livemode":false,
|
||||
"metadata":{
|
||||
|
||||
},
|
||||
"nickname":null,
|
||||
"product":"prod_00000000000000",
|
||||
"tiers":null,
|
||||
"tiers_mode":null,
|
||||
"transform_usage":null,
|
||||
"trial_period_days":null,
|
||||
"usage_type":"licensed"
|
||||
},
|
||||
"quantity":1,
|
||||
"subscription":"sub_00000000000000"
|
||||
}
|
||||
],
|
||||
"has_more":false,
|
||||
"total_count":1,
|
||||
"url":"/v1/subscription_items?subscription=sub_E0G5y2VdPVOB4o"
|
||||
"id": "evt_1DeFo8DEQaroqDjsk4tzzzdV",
|
||||
"object": "event",
|
||||
"api_version": "2018-11-08",
|
||||
"created": 1544075636,
|
||||
"data": {
|
||||
"object": {
|
||||
"id": "sub_E6STM5w5EX3K28",
|
||||
"object": "subscription",
|
||||
"application_fee_percent": null,
|
||||
"billing": "send_invoice",
|
||||
"billing_cycle_anchor": 1572609600,
|
||||
"cancel_at_period_end": false,
|
||||
"canceled_at": null,
|
||||
"created": 1544074670,
|
||||
"current_period_end": 1572609600,
|
||||
"current_period_start": 1544075635,
|
||||
"customer": "cus_00000000000000",
|
||||
"days_until_due": 7,
|
||||
"default_source": null,
|
||||
"discount": null,
|
||||
"ended_at": null,
|
||||
"items": {
|
||||
"object": "list",
|
||||
"data": [
|
||||
{
|
||||
"id": "si_E6STR3cU0bwWFG",
|
||||
"object": "subscription_item",
|
||||
"created": 1544074671,
|
||||
"metadata": {
|
||||
},
|
||||
"livemode":false,
|
||||
"metadata":{
|
||||
|
||||
"plan": {
|
||||
"id": "plan_E6SQ6RAtmLVtzg",
|
||||
"object": "plan",
|
||||
"active": true,
|
||||
"aggregate_usage": null,
|
||||
"amount": 100,
|
||||
"billing_scheme": "per_unit",
|
||||
"created": 1544074513,
|
||||
"currency": "usd",
|
||||
"interval": "year",
|
||||
"interval_count": 1,
|
||||
"livemode": true,
|
||||
"metadata": {
|
||||
},
|
||||
"nickname": "flatrate",
|
||||
"product": "prod_E6SPZ5RKfKClNL",
|
||||
"tiers": null,
|
||||
"tiers_mode": null,
|
||||
"transform_usage": null,
|
||||
"trial_period_days": null,
|
||||
"usage_type": "licensed"
|
||||
},
|
||||
"plan":{
|
||||
"id":"gold_00000000000000",
|
||||
"object":"plan",
|
||||
"active":true,
|
||||
"aggregate_usage":null,
|
||||
"amount":2000,
|
||||
"billing_scheme":"per_unit",
|
||||
"created":1394782612,
|
||||
"currency":"cad",
|
||||
"interval":"month",
|
||||
"interval_count":1,
|
||||
"livemode":false,
|
||||
"metadata":{
|
||||
|
||||
},
|
||||
"nickname":null,
|
||||
"product":"prod_00000000000000",
|
||||
"tiers":null,
|
||||
"tiers_mode":null,
|
||||
"transform_usage":null,
|
||||
"trial_period_days":null,
|
||||
"usage_type":"licensed"
|
||||
},
|
||||
"quantity":1,
|
||||
"start":1542644734,
|
||||
"status":"active",
|
||||
"tax_percent":null,
|
||||
"trial_end":null,
|
||||
"trial_start":null
|
||||
"quantity": 800,
|
||||
"subscription": "sub_E6STM5w5EX3K28"
|
||||
}
|
||||
],
|
||||
"has_more": false,
|
||||
"total_count": 1,
|
||||
"url": "/v1/subscription_items?subscription=sub_E6STM5w5EX3K28"
|
||||
},
|
||||
"livemode": true,
|
||||
"metadata": {
|
||||
},
|
||||
"plan": {
|
||||
"id": "plan_E6SQ6RAtmLVtzg",
|
||||
"object": "plan",
|
||||
"active": true,
|
||||
"aggregate_usage": null,
|
||||
"amount": 100,
|
||||
"billing_scheme": "per_unit",
|
||||
"created": 1544074513,
|
||||
"currency": "usd",
|
||||
"interval": "year",
|
||||
"interval_count": 1,
|
||||
"livemode": true,
|
||||
"metadata": {
|
||||
},
|
||||
"previous_attributes":{
|
||||
"plan":{
|
||||
"id":"OLD_00000000000000",
|
||||
"object":"plan",
|
||||
"active":true,
|
||||
"aggregate_usage":null,
|
||||
"amount":2000,
|
||||
"billing_scheme":"per_unit",
|
||||
"created":1542644734,
|
||||
"currency":"cad",
|
||||
"interval":"month",
|
||||
"interval_count":1,
|
||||
"livemode":false,
|
||||
"metadata":{
|
||||
|
||||
},
|
||||
"nickname":null,
|
||||
"product":"prod_00000000000000",
|
||||
"tiers":null,
|
||||
"tiers_mode":null,
|
||||
"transform_usage":null,
|
||||
"trial_period_days":null,
|
||||
"usage_type":"licensed",
|
||||
"name":"Old plan"
|
||||
}
|
||||
}
|
||||
"nickname": "flatrate",
|
||||
"product": "prod_E6SPZ5RKfKClNL",
|
||||
"tiers": null,
|
||||
"tiers_mode": null,
|
||||
"transform_usage": null,
|
||||
"trial_period_days": null,
|
||||
"usage_type": "licensed"
|
||||
},
|
||||
"quantity": 800,
|
||||
"start": 1544075635,
|
||||
"status": "trialing",
|
||||
"tax_percent": null,
|
||||
"trial_end": 1572609600,
|
||||
"trial_start": 1544075635
|
||||
},
|
||||
"previous_attributes": {
|
||||
"billing_cycle_anchor": 1544074670,
|
||||
"current_period_end": 1575610670,
|
||||
"current_period_start": 1544074670,
|
||||
"start": 1544074670,
|
||||
"status": "active",
|
||||
"trial_end": null,
|
||||
"trial_start": null
|
||||
}
|
||||
},
|
||||
"livemode": true,
|
||||
"pending_webhooks": 1,
|
||||
"request": {
|
||||
"id": "req_X3p7qbGSX2wZ8D",
|
||||
"idempotency_key": null
|
||||
},
|
||||
"type": "customer.subscription.updated"
|
||||
}
|
||||
|
|
|
@ -74,6 +74,20 @@ Quantity: 1"""
|
|||
self.send_and_test_stream_message('customer_subscription_deleted', expected_topic, expected_message,
|
||||
content_type="application/x-www-form-urlencoded")
|
||||
|
||||
def test_customer_subscription_updated(self) -> None:
|
||||
expected_topic = u"cus_00000000000000"
|
||||
expected_message = """\
|
||||
[Subscription](https://dashboard.stripe.com/subscriptions/sub_E6STM5w5EX3K28) updated
|
||||
* Billing cycle anchor is now Nov 01, 2019, 12:00:00 UTC
|
||||
* Current period end is now Nov 01, 2019, 12:00:00 UTC
|
||||
* Current period start is now Dec 06, 2018, 05:53:55 UTC
|
||||
* Start is now Dec 06, 2018, 05:53:55 UTC
|
||||
* Status is now trialing
|
||||
* Trial end is now Nov 01, 2019, 12:00:00 UTC
|
||||
* Trial start is now Dec 06, 2018, 05:53:55 UTC"""
|
||||
self.send_and_test_stream_message('customer_subscription_updated', expected_topic, expected_message,
|
||||
content_type="application/x-www-form-urlencoded")
|
||||
|
||||
def test_customer_subscription_trial_will_end(self) -> None:
|
||||
expected_topic = u"cus_00000000000000"
|
||||
expected_message = u"[Subscription](https://dashboard.stripe.com/subscriptions/sub_00000000000000) trial will end in 3 days"
|
||||
|
|
|
@ -9,6 +9,7 @@ from django.utils.translation import ugettext as _
|
|||
from zerver.decorator import api_key_only_webhook_view
|
||||
from zerver.lib.request import REQ, has_request_variables
|
||||
from zerver.lib.response import json_error, json_success
|
||||
from zerver.lib.timestamp import timestamp_to_datetime
|
||||
from zerver.lib.webhooks.common import check_send_webhook_message, \
|
||||
UnexpectedWebhookEventType
|
||||
from zerver.models import UserProfile
|
||||
|
@ -60,7 +61,7 @@ def topic_and_body(payload: Dict[str, Any]) -> Tuple[str, str]:
|
|||
if not previous_attributes: # nocoverage
|
||||
raise SuppressedEvent()
|
||||
return ''.join('\n* ' + attribute.replace('_', ' ').capitalize() +
|
||||
' is now ' + str(object_[attribute])
|
||||
' is now ' + stringify(object_[attribute])
|
||||
for attribute in sorted(previous_attributes.keys()))
|
||||
|
||||
def default_body(update_blacklist: List[str]=[]) -> str:
|
||||
|
@ -237,3 +238,8 @@ def linkified_id(object_id: str, lower: bool=False) -> str:
|
|||
if url_prefix is None: # nocoverage
|
||||
return name
|
||||
return '[{}](https://dashboard.stripe.com/{}/{})'.format(name, url_prefix, object_id)
|
||||
|
||||
def stringify(value: Any) -> str:
|
||||
if isinstance(value, int) and value > 1500000000 and value < 2000000000:
|
||||
return timestamp_to_datetime(value).strftime('%b %d, %Y, %H:%M:%S %Z')
|
||||
return str(value)
|
||||
|
|
Loading…
Reference in New Issue