webhooks/stripe: Handle invoice events explicitly.

Closes #10909
This commit is contained in:
sameerchoubey 2019-01-26 16:14:46 +05:30 committed by Eeshan Garg
parent bffc473ec8
commit 65489b0391
12 changed files with 1157 additions and 97 deletions

View File

@ -0,0 +1,106 @@
{
"created": 1326853478,
"livemode": false,
"id": "invoice.created_00000000000000",
"type": "invoice.created",
"object": "event",
"request": null,
"pending_webhooks": 1,
"api_version": "2018-11-08",
"data": {
"object": {
"id": "in_00000000000000",
"object": "invoice",
"amount_due": 1000,
"amount_paid": 0,
"amount_remaining": 1000,
"application_fee": null,
"attempt_count": 0,
"attempted": false,
"auto_advance": true,
"billing": "send_invoice",
"billing_reason": "manual",
"charge": null,
"currency": "usd",
"custom_fields": null,
"customer": "cus_00000000000000",
"date": 1546862399,
"default_source": null,
"description": null,
"discount": null,
"due_date": 1549454425,
"ending_balance": 0,
"finalized_at": 1546862425,
"footer": null,
"hosted_invoice_url": "https://pay.stripe.com/invoice/invst_IH3jVDl7ovgEn6FgamLGRz0uiA",
"invoice_pdf": "https://pay.stripe.com/invoice/invst_IH3jVDl7ovgEn6FgamLGRz0uiA/pdf",
"lines": {
"data": [
{
"id": "sli_00000000000000",
"object": "line_item",
"amount": 999,
"currency": "usd",
"description": "1 × Diamond Essentials (at $9.99 / month)",
"discountable": true,
"livemode": false,
"metadata": {
},
"period": {
"end": 1551072697,
"start": 1548394297
},
"plan": {
"id": "plan_00000000000000",
"object": "plan",
"active": true,
"aggregate_usage": null,
"amount": 999,
"billing_scheme": "per_unit",
"created": 1548385214,
"currency": "usd",
"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"
},
"proration": false,
"quantity": 1,
"subscription": "sub_00000000000000",
"subscription_item": "si_00000000000000",
"type": "subscription"
}
],
"has_more": false,
"object": "list",
"url": "/v1/invoices/in_1DpwlvHOC2HiLzOV3LVuwMuC/lines"
},
"livemode": false,
"metadata": {
},
"next_payment_attempt": null,
"number": "7DBE74C-0001",
"paid": true,
"period_end": 1546862399,
"period_start": 1546862399,
"receipt_number": null,
"starting_balance": 0,
"statement_descriptor": null,
"status": "open",
"subscription": null,
"subtotal": 1000,
"tax": 0,
"tax_percent": null,
"total": 1000,
"webhooks_delivered_at": null
}
}
}

View File

@ -0,0 +1,106 @@
{
"created": 1326853478,
"livemode": false,
"id": "invoice.deleted_00000000000000",
"type": "invoice.deleted",
"object": "event",
"request": null,
"pending_webhooks": 1,
"api_version": "2018-11-08",
"data": {
"object": {
"id": "in_00000000000000",
"object": "invoice",
"amount_due": 1000,
"amount_paid": 0,
"amount_remaining": 1000,
"application_fee": null,
"attempt_count": 0,
"attempted": false,
"auto_advance": true,
"billing": "send_invoice",
"billing_reason": "manual",
"charge": null,
"currency": "usd",
"custom_fields": null,
"customer": "cus_00000000000000",
"date": 1546862399,
"default_source": null,
"description": null,
"discount": null,
"due_date": 1549454425,
"ending_balance": 0,
"finalized_at": 1546862425,
"footer": null,
"hosted_invoice_url": "https://pay.stripe.com/invoice/invst_IH3jVDl7ovgEn6FgamLGRz0uiA",
"invoice_pdf": "https://pay.stripe.com/invoice/invst_IH3jVDl7ovgEn6FgamLGRz0uiA/pdf",
"lines": {
"data": [
{
"id": "sli_00000000000000",
"object": "line_item",
"amount": 999,
"currency": "usd",
"description": "1 × Diamond Essentials (at $9.99 / month)",
"discountable": true,
"livemode": false,
"metadata": {
},
"period": {
"end": 1551072770,
"start": 1548394370
},
"plan": {
"id": "plan_00000000000000",
"object": "plan",
"active": true,
"aggregate_usage": null,
"amount": 999,
"billing_scheme": "per_unit",
"created": 1548385214,
"currency": "usd",
"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"
},
"proration": false,
"quantity": 1,
"subscription": "sub_00000000000000",
"subscription_item": "si_00000000000000",
"type": "subscription"
}
],
"has_more": false,
"object": "list",
"url": "/v1/invoices/in_1DpwlvHOC2HiLzOV3LVuwMuC/lines"
},
"livemode": false,
"metadata": {
},
"next_payment_attempt": null,
"number": "7DBE74C-0001",
"paid": false,
"period_end": 1546862399,
"period_start": 1546862399,
"receipt_number": null,
"starting_balance": 0,
"statement_descriptor": null,
"status": "open",
"subscription": null,
"subtotal": 1000,
"tax": 0,
"tax_percent": null,
"total": 1000,
"webhooks_delivered_at": null
}
}
}

View File

@ -0,0 +1,106 @@
{
"created": 1326853478,
"livemode": false,
"id": "invoice.finalized_00000000000000",
"type": "invoice.finalized",
"object": "event",
"request": null,
"pending_webhooks": 1,
"api_version": "2018-11-08",
"data": {
"object": {
"id": "in_00000000000000",
"object": "invoice",
"amount_due": 1000,
"amount_paid": 0,
"amount_remaining": 1000,
"application_fee": null,
"attempt_count": 0,
"attempted": false,
"auto_advance": true,
"billing": "send_invoice",
"billing_reason": "manual",
"charge": null,
"currency": "usd",
"custom_fields": null,
"customer": "cus_00000000000000",
"date": 1546862399,
"default_source": null,
"description": null,
"discount": null,
"due_date": 1549454425,
"ending_balance": 0,
"finalized_at": 1546862425,
"footer": null,
"hosted_invoice_url": "https://pay.stripe.com/invoice/invst_IH3jVDl7ovgEn6FgamLGRz0uiA",
"invoice_pdf": "https://pay.stripe.com/invoice/invst_IH3jVDl7ovgEn6FgamLGRz0uiA/pdf",
"lines": {
"data": [
{
"id": "sli_00000000000000",
"object": "line_item",
"amount": 999,
"currency": "usd",
"description": "1 × Diamond Essentials (at $9.99 / month)",
"discountable": true,
"livemode": false,
"metadata": {
},
"period": {
"end": 1551072823,
"start": 1548394423
},
"plan": {
"id": "plan_00000000000000",
"object": "plan",
"active": true,
"aggregate_usage": null,
"amount": 999,
"billing_scheme": "per_unit",
"created": 1548385214,
"currency": "usd",
"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"
},
"proration": false,
"quantity": 1,
"subscription": "sub_00000000000000",
"subscription_item": "si_00000000000000",
"type": "subscription"
}
],
"has_more": false,
"object": "list",
"url": "/v1/invoices/in_1DpwlvHOC2HiLzOV3LVuwMuC/lines"
},
"livemode": false,
"metadata": {
},
"next_payment_attempt": null,
"number": "7DBE74C-0001",
"paid": false,
"period_end": 1546862399,
"period_start": 1546862399,
"receipt_number": null,
"starting_balance": 0,
"statement_descriptor": null,
"status": "open",
"subscription": null,
"subtotal": 1000,
"tax": 0,
"tax_percent": null,
"total": 1000,
"webhooks_delivered_at": null
}
}
}

View File

@ -0,0 +1,107 @@
{
"created": 1326853478,
"livemode": false,
"id": "invoice.marked_00000000000000",
"type": "invoice.marked_uncollectible",
"object": "event",
"request": null,
"pending_webhooks": 1,
"api_version": "2018-11-08",
"data": {
"object": {
"id": "in_00000000000000",
"object": "invoice",
"amount_due": 1000,
"amount_paid": 0,
"amount_remaining": 1000,
"application_fee": null,
"attempt_count": 0,
"attempted": false,
"auto_advance": true,
"billing": "send_invoice",
"billing_reason": "manual",
"charge": null,
"currency": "usd",
"custom_fields": null,
"customer": "cus_00000000000000",
"date": 1546862399,
"default_source": null,
"description": null,
"discount": null,
"due_date": 1549454425,
"ending_balance": 0,
"finalized_at": 1546862425,
"footer": null,
"hosted_invoice_url": "https://pay.stripe.com/invoice/invst_IH3jVDl7ovgEn6FgamLGRz0uiA",
"invoice_pdf": "https://pay.stripe.com/invoice/invst_IH3jVDl7ovgEn6FgamLGRz0uiA/pdf",
"lines": {
"data": [
{
"id": "sli_00000000000000",
"object": "line_item",
"amount": 999,
"currency": "usd",
"description": "1 × Diamond Essentials (at $9.99 / month)",
"discountable": true,
"livemode": false,
"metadata": {
},
"period": {
"end": 1551072873,
"start": 1548394473
},
"plan": {
"id": "plan_00000000000000",
"object": "plan",
"active": true,
"aggregate_usage": null,
"amount": 999,
"billing_scheme": "per_unit",
"created": 1548385214,
"currency": "usd",
"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"
},
"proration": false,
"quantity": 1,
"subscription": "sub_00000000000000",
"subscription_item": "si_00000000000000",
"type": "subscription"
}
],
"has_more": false,
"object": "list",
"url": "/v1/invoices/in_1DpwlvHOC2HiLzOV3LVuwMuC/lines"
},
"livemode": false,
"metadata": {
},
"next_payment_attempt": null,
"number": "7DBE74C-0001",
"paid": false,
"period_end": 1546862399,
"period_start": 1546862399,
"receipt_number": null,
"starting_balance": 0,
"statement_descriptor": null,
"status": "open",
"subscription": null,
"subtotal": 1000,
"tax": 0,
"tax_percent": null,
"total": 1000,
"webhooks_delivered_at": null
}
}
}

View File

@ -1,83 +1,107 @@
{
"created": 1326853478,
"livemode": false,
"id": "evt_00000000000000",
"type": "invoice.payment_failed",
"object": "event",
"request": null,
"pending_webhooks": 1,
"api_version": "2016-07-06",
"data": {
"object": {
"id": "in_00000000000000",
"object": "invoice",
"amount_due": 0,
"application_fee": null,
"attempt_count": 0,
"attempted": true,
"charge": null,
"closed": false,
"currency": "aud",
"customer": "cus_00000000000000",
"date": 1480672129,
"description": null,
"discount": null,
"ending_balance": null,
"forgiven": false,
"lines": {
"data": [
{
"id": "sub_9fYmJQOQy04yoh",
"object": "line_item",
"amount": 2000,
"currency": "aud",
"description": null,
"discountable": true,
"livemode": true,
"metadata": {},
"period": {
"start": 1483350529,
"end": 1486028929
},
"plan": {
"id": "gold",
"object": "plan",
"amount": 2000,
"created": 1480672129,
"currency": "aud",
"interval": "month",
"interval_count": 1,
"livemode": false,
"metadata": {},
"name": "Gold Special",
"statement_descriptor": null,
"trial_period_days": null
},
"proration": false,
"quantity": 1,
"subscription": null,
"type": "subscription"
}
],
"total_count": 1,
"object": "list",
"url": "/v1/invoices/in_19MDevCV4wXizEw4B4lY7YPR/lines"
},
"created": 1326853478,
"livemode": false,
"id": "invoice.payment_00000000000000",
"type": "invoice.payment_failed",
"object": "event",
"request": null,
"pending_webhooks": 1,
"api_version": "2018-11-08",
"data": {
"object": {
"id": "in_00000000000000",
"object": "invoice",
"amount_due": 1000,
"amount_paid": 0,
"amount_remaining": 1000,
"application_fee": null,
"attempt_count": 0,
"attempted": true,
"auto_advance": true,
"billing": "send_invoice",
"billing_reason": "manual",
"charge": null,
"currency": "usd",
"custom_fields": null,
"customer": "cus_00000000000000",
"date": 1546862399,
"default_source": null,
"description": null,
"discount": null,
"due_date": 1549454425,
"ending_balance": 0,
"finalized_at": 1546862425,
"footer": null,
"hosted_invoice_url": "https://pay.stripe.com/invoice/invst_IH3jVDl7ovgEn6FgamLGRz0uiA",
"invoice_pdf": "https://pay.stripe.com/invoice/invst_IH3jVDl7ovgEn6FgamLGRz0uiA/pdf",
"lines": {
"data": [
{
"id": "sli_00000000000000",
"object": "line_item",
"amount": 999,
"currency": "usd",
"description": "1 × Diamond Essentials (at $9.99 / month)",
"discountable": true,
"livemode": false,
"metadata": {},
"next_payment_attempt": 1480675729,
"paid": false,
"period_end": 1480672129,
"period_start": 1480672129,
"receipt_number": null,
"starting_balance": 0,
"statement_descriptor": null,
"subscription": null,
"subtotal": 0,
"tax": null,
"tax_percent": null,
"total": 0,
"webhooks_delivered_at": null
}
"metadata": {
},
"period": {
"end": 1551072969,
"start": 1548394569
},
"plan": {
"id": "plan_00000000000000",
"object": "plan",
"active": true,
"aggregate_usage": null,
"amount": 999,
"billing_scheme": "per_unit",
"created": 1548385214,
"currency": "usd",
"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"
},
"proration": false,
"quantity": 1,
"subscription": "sub_00000000000000",
"subscription_item": "si_00000000000000",
"type": "subscription"
}
],
"has_more": false,
"object": "list",
"url": "/v1/invoices/in_1DpwlvHOC2HiLzOV3LVuwMuC/lines"
},
"livemode": false,
"metadata": {
},
"next_payment_attempt": null,
"number": "7DBE74C-0001",
"paid": false,
"period_end": 1546862399,
"period_start": 1546862399,
"receipt_number": null,
"starting_balance": 0,
"statement_descriptor": null,
"status": "open",
"subscription": null,
"subtotal": 1000,
"tax": 0,
"tax_percent": null,
"total": 1000,
"webhooks_delivered_at": null,
"closed": false
}
}
}

View File

@ -0,0 +1,107 @@
{
"created": 1326853478,
"livemode": false,
"id": "invoice.payment_00000000000000",
"type": "invoice.payment_succeeded",
"object": "event",
"request": null,
"pending_webhooks": 1,
"api_version": "2018-11-08",
"data": {
"object": {
"id": "in_00000000000000",
"object": "invoice",
"amount_due": 1000,
"amount_paid": 0,
"amount_remaining": 1000,
"application_fee": null,
"attempt_count": 0,
"attempted": true,
"auto_advance": true,
"billing": "send_invoice",
"billing_reason": "manual",
"charge": "_00000000000000",
"currency": "usd",
"custom_fields": null,
"customer": "cus_00000000000000",
"date": 1546862399,
"default_source": null,
"description": null,
"discount": null,
"due_date": 1549454425,
"ending_balance": 0,
"finalized_at": 1546862425,
"footer": null,
"hosted_invoice_url": "https://pay.stripe.com/invoice/invst_IH3jVDl7ovgEn6FgamLGRz0uiA",
"invoice_pdf": "https://pay.stripe.com/invoice/invst_IH3jVDl7ovgEn6FgamLGRz0uiA/pdf",
"lines": {
"data": [
{
"id": "sli_00000000000000",
"object": "line_item",
"amount": 999,
"currency": "usd",
"description": "1 × Diamond Essentials (at $9.99 / month)",
"discountable": true,
"livemode": false,
"metadata": {
},
"period": {
"end": 1551073031,
"start": 1548394631
},
"plan": {
"id": "plan_00000000000000",
"object": "plan",
"active": true,
"aggregate_usage": null,
"amount": 999,
"billing_scheme": "per_unit",
"created": 1548385214,
"currency": "usd",
"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"
},
"proration": false,
"quantity": 1,
"subscription": "sub_00000000000000",
"subscription_item": "si_00000000000000",
"type": "subscription"
}
],
"has_more": false,
"object": "list",
"url": "/v1/invoices/in_1DpwlvHOC2HiLzOV3LVuwMuC/lines"
},
"livemode": false,
"metadata": {
},
"next_payment_attempt": null,
"number": "7DBE74C-0001",
"paid": true,
"period_end": 1546862399,
"period_start": 1546862399,
"receipt_number": null,
"starting_balance": 0,
"statement_descriptor": null,
"status": "open",
"subscription": null,
"subtotal": 1000,
"tax": 0,
"tax_percent": null,
"total": 1000,
"webhooks_delivered_at": null,
"closed": true
}
}
}

View File

@ -0,0 +1,106 @@
{
"created": 1326853478,
"livemode": false,
"id": "invoice.sent_00000000000000",
"type": "invoice.sent",
"object": "event",
"request": null,
"pending_webhooks": 1,
"api_version": "2018-11-08",
"data": {
"object": {
"id": "in_00000000000000",
"object": "invoice",
"amount_due": 1000,
"amount_paid": 0,
"amount_remaining": 1000,
"application_fee": null,
"attempt_count": 0,
"attempted": false,
"auto_advance": true,
"billing": "send_invoice",
"billing_reason": "manual",
"charge": null,
"currency": "usd",
"custom_fields": null,
"customer": "cus_00000000000000",
"date": 1546862399,
"default_source": null,
"description": null,
"discount": null,
"due_date": 1549454425,
"ending_balance": 0,
"finalized_at": 1546862425,
"footer": null,
"hosted_invoice_url": "https://pay.stripe.com/invoice/invst_IH3jVDl7ovgEn6FgamLGRz0uiA",
"invoice_pdf": "https://pay.stripe.com/invoice/invst_IH3jVDl7ovgEn6FgamLGRz0uiA/pdf",
"lines": {
"data": [
{
"id": "sli_00000000000000",
"object": "line_item",
"amount": 999,
"currency": "usd",
"description": "1 × Diamond Essentials (at $9.99 / month)",
"discountable": true,
"livemode": false,
"metadata": {
},
"period": {
"end": 1551073074,
"start": 1548394674
},
"plan": {
"id": "plan_00000000000000",
"object": "plan",
"active": true,
"aggregate_usage": null,
"amount": 999,
"billing_scheme": "per_unit",
"created": 1548385214,
"currency": "usd",
"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"
},
"proration": false,
"quantity": 1,
"subscription": "sub_00000000000000",
"subscription_item": "si_00000000000000",
"type": "subscription"
}
],
"has_more": false,
"object": "list",
"url": "/v1/invoices/in_1DpwlvHOC2HiLzOV3LVuwMuC/lines"
},
"livemode": false,
"metadata": {
},
"next_payment_attempt": null,
"number": "7DBE74C-0001",
"paid": false,
"period_end": 1546862399,
"period_start": 1546862399,
"receipt_number": null,
"starting_balance": 0,
"statement_descriptor": null,
"status": "open",
"subscription": null,
"subtotal": 1000,
"tax": 0,
"tax_percent": null,
"total": 1000,
"webhooks_delivered_at": null
}
}
}

View File

@ -0,0 +1,106 @@
{
"created": 1326853478,
"livemode": false,
"id": "invoice.upcoming_00000000000000",
"type": "invoice.upcoming",
"object": "event",
"request": null,
"pending_webhooks": 1,
"api_version": "2018-11-08",
"data": {
"object": {
"id": null,
"object": "invoice",
"amount_due": 1000,
"amount_paid": 0,
"amount_remaining": 1000,
"application_fee": null,
"attempt_count": 0,
"attempted": false,
"auto_advance": true,
"billing": "send_invoice",
"billing_reason": "manual",
"charge": null,
"currency": "usd",
"custom_fields": null,
"customer": "cus_00000000000000",
"date": 1546862399,
"default_source": null,
"description": null,
"discount": null,
"due_date": 1549454425,
"ending_balance": 0,
"finalized_at": 1546862425,
"footer": null,
"hosted_invoice_url": "https://pay.stripe.com/invoice/invst_IH3jVDl7ovgEn6FgamLGRz0uiA",
"invoice_pdf": "https://pay.stripe.com/invoice/invst_IH3jVDl7ovgEn6FgamLGRz0uiA/pdf",
"lines": {
"data": [
{
"id": "sli_00000000000000",
"object": "line_item",
"amount": 999,
"currency": "usd",
"description": "1 × Titanium Corporate (at $9.99 / month)",
"discountable": true,
"livemode": false,
"metadata": {
},
"period": {
"end": 1551113860,
"start": 1548435460
},
"plan": {
"id": "plan_00000000000000",
"object": "plan",
"active": true,
"aggregate_usage": null,
"amount": 999,
"billing_scheme": "per_unit",
"created": 1548434720,
"currency": "usd",
"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"
},
"proration": false,
"quantity": 1,
"subscription": "sub_00000000000000",
"subscription_item": "si_00000000000000",
"type": "subscription"
}
],
"has_more": false,
"object": "list",
"url": "/v1/invoices/in_1DpwlvHOC2HiLzOV3LVuwMuC/lines"
},
"livemode": false,
"metadata": {
},
"next_payment_attempt": null,
"number": "7DBE74C-0001",
"paid": false,
"period_end": 1546862399,
"period_start": 1546862399,
"receipt_number": null,
"starting_balance": 0,
"statement_descriptor": null,
"status": "open",
"subscription": null,
"subtotal": 1000,
"tax": 0,
"tax_percent": null,
"total": 1000,
"webhooks_delivered_at": null
}
}
}

View File

@ -0,0 +1,110 @@
{
"created": 1326853478,
"livemode": false,
"id": "invoice.updated_00000000000000",
"type": "invoice.updated",
"object": "event",
"request": null,
"pending_webhooks": 1,
"api_version": "2018-11-08",
"data": {
"object": {
"id": "in_00000000000000",
"object": "invoice",
"amount_due": 1000,
"amount_paid": 0,
"amount_remaining": 1000,
"application_fee": null,
"attempt_count": 0,
"attempted": false,
"auto_advance": true,
"billing": "send_invoice",
"billing_reason": "manual",
"charge": null,
"currency": "usd",
"custom_fields": null,
"customer": "cus_00000000000000",
"date": 1546862399,
"default_source": null,
"description": null,
"discount": null,
"due_date": 1549454425,
"ending_balance": 0,
"finalized_at": 1546862425,
"footer": null,
"hosted_invoice_url": "https://pay.stripe.com/invoice/invst_IH3jVDl7ovgEn6FgamLGRz0uiA",
"invoice_pdf": "https://pay.stripe.com/invoice/invst_IH3jVDl7ovgEn6FgamLGRz0uiA/pdf",
"lines": {
"data": [
{
"id": "sli_00000000000000",
"object": "line_item",
"amount": 999,
"currency": "usd",
"description": "1 × Titanium Corporate (at $9.99 / month)",
"discountable": true,
"livemode": false,
"metadata": {
},
"period": {
"end": 1551114237,
"start": 1548435837
},
"plan": {
"id": "plan_00000000000000",
"object": "plan",
"active": true,
"aggregate_usage": null,
"amount": 999,
"billing_scheme": "per_unit",
"created": 1548434720,
"currency": "usd",
"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"
},
"proration": false,
"quantity": 1,
"subscription": "sub_00000000000000",
"subscription_item": "si_00000000000000",
"type": "subscription"
}
],
"has_more": false,
"object": "list",
"url": "/v1/invoices/in_1DpwlvHOC2HiLzOV3LVuwMuC/lines"
},
"livemode": false,
"metadata": {
},
"next_payment_attempt": null,
"number": "7DBE74C-0001",
"paid": false,
"period_end": 1546862399,
"period_start": 1546862399,
"receipt_number": null,
"starting_balance": 0,
"statement_descriptor": null,
"status": "open",
"subscription": null,
"subtotal": 1000,
"tax": 0,
"tax_percent": null,
"total": 1000,
"webhooks_delivered_at": null
},
"previous_attributes": {
"lines": [
]
}
}
}

View File

@ -0,0 +1,106 @@
{
"created": 1326853478,
"livemode": false,
"id": "invoice.voided_00000000000000",
"type": "invoice.voided",
"object": "event",
"request": null,
"pending_webhooks": 1,
"api_version": "2018-11-08",
"data": {
"object": {
"id": "in_00000000000000",
"object": "invoice",
"amount_due": 1000,
"amount_paid": 0,
"amount_remaining": 1000,
"application_fee": null,
"attempt_count": 0,
"attempted": false,
"auto_advance": true,
"billing": "send_invoice",
"billing_reason": "manual",
"charge": null,
"currency": "usd",
"custom_fields": null,
"customer": "cus_00000000000000",
"date": 1546862399,
"default_source": null,
"description": null,
"discount": null,
"due_date": 1549454425,
"ending_balance": 0,
"finalized_at": 1546862425,
"footer": null,
"hosted_invoice_url": "https://pay.stripe.com/invoice/invst_IH3jVDl7ovgEn6FgamLGRz0uiA",
"invoice_pdf": "https://pay.stripe.com/invoice/invst_IH3jVDl7ovgEn6FgamLGRz0uiA/pdf",
"lines": {
"data": [
{
"id": "sli_00000000000000",
"object": "line_item",
"amount": 999,
"currency": "usd",
"description": "1 × Diamond Essentials (at $9.99 / month)",
"discountable": true,
"livemode": false,
"metadata": {
},
"period": {
"end": 1551073198,
"start": 1548394798
},
"plan": {
"id": "plan_00000000000000",
"object": "plan",
"active": true,
"aggregate_usage": null,
"amount": 999,
"billing_scheme": "per_unit",
"created": 1548385214,
"currency": "usd",
"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"
},
"proration": false,
"quantity": 1,
"subscription": "sub_00000000000000",
"subscription_item": "si_00000000000000",
"type": "subscription"
}
],
"has_more": false,
"object": "list",
"url": "/v1/invoices/in_1DpwlvHOC2HiLzOV3LVuwMuC/lines"
},
"livemode": false,
"metadata": {
},
"next_payment_attempt": null,
"number": "7DBE74C-0001",
"paid": false,
"period_end": 1546862399,
"period_start": 1546862399,
"receipt_number": null,
"starting_balance": 0,
"statement_descriptor": null,
"status": "open",
"subscription": null,
"subtotal": 1000,
"tax": 0,
"tax_percent": null,
"total": 1000,
"webhooks_delivered_at": null
}
}
}

View File

@ -112,12 +112,6 @@ Billing method: send invoice"""
self.send_and_test_stream_message('customer_discount_created', expected_topic, expected_message,
content_type="application/x-www-form-urlencoded")
def test_invoice_payment_failed(self) -> None:
expected_topic = u"cus_00000000000000"
expected_message = u"[Invoice](https://dashboard.stripe.com/invoices/in_00000000000000) payment failed"
self.send_and_test_stream_message('invoice_payment_failed', expected_topic, expected_message,
content_type="application/x-www-form-urlencoded")
def test_payout_canceled(self) -> None:
expected_topic = u"Payout po_00000000000000"
expected_message = u"**[Payout](https://dashboard.stripe.com/payout/po_00000000000000)** for amount **$11.00** has been canceled."
@ -152,3 +146,62 @@ Billing method: send invoice"""
self.send_and_test_stream_message('payout_updated', expected_topic, expected_message,
content_type="application/x-www-form-urlencoded")
def test_invoice_created(self) -> None:
expected_topic = u"invoice in_00000000000000"
expected_message = u"An **[invoice](https://dashboard.stripe.com/invoices/in_00000000000000)** for the payment of amount **$10.00** has been created."
self.send_and_test_stream_message('invoice_created', expected_topic, expected_message,
content_type="application/x-www-form-urlencoded")
def test_invoice_deleted(self) -> None:
expected_topic = u"invoice in_00000000000000"
expected_message = u"An **[invoice](https://dashboard.stripe.com/invoices/in_00000000000000)** for the payment of amount **$10.00** has been deleted."
self.send_and_test_stream_message('invoice_deleted', expected_topic, expected_message,
content_type="application/x-www-form-urlencoded")
def test_invoice_finalized(self) -> None:
expected_topic = u"invoice in_00000000000000"
expected_message = u"An **[invoice](https://dashboard.stripe.com/invoices/in_00000000000000)** for the payment of amount **$10.00** has been finalized."
self.send_and_test_stream_message('invoice_finalized', expected_topic, expected_message,
content_type="application/x-www-form-urlencoded")
def test_invoice_marked_uncollectible(self) -> None:
expected_topic = u"invoice in_00000000000000"
expected_message = u"An **[invoice](https://dashboard.stripe.com/invoices/in_00000000000000)** for the payment of amount **$10.00** has been marked as uncollectible."
self.send_and_test_stream_message('invoice_marked_uncollectible', expected_topic, expected_message, content_type="application/x-www-form-urlencoded")
def test_invoice_payment_failed(self) -> None:
expected_topic = u"invoice in_00000000000000"
expected_message = u"An **[invoice](https://dashboard.stripe.com/invoices/in_00000000000000)** for the payment of amount **$10.00** has failed."
self.send_and_test_stream_message('invoice_payment_failed', expected_topic, expected_message,
content_type="application/x-www-form-urlencoded")
def test_invoice_payment_succeeded(self) -> None:
expected_topic = u"invoice in_00000000000000"
expected_message = u"An **[invoice](https://dashboard.stripe.com/invoices/in_00000000000000)** for the payment of amount **$10.00** has succeeded."
self.send_and_test_stream_message('invoice_payment_succeeded', expected_topic, expected_message,
content_type="application/x-www-form-urlencoded")
def test_invoice_sent(self) -> None:
expected_topic = u"invoice in_00000000000000"
expected_message = u"An **[invoice](https://dashboard.stripe.com/invoices/in_00000000000000)** for the payment of amount **$10.00** has been sent."
self.send_and_test_stream_message('invoice_sent', expected_topic, expected_message,
content_type="application/x-www-form-urlencoded")
def test_invoice_upcoming(self) -> None:
expected_topic = u"invoice None"
expected_message = u"An upcoming **[invoice](https://dashboard.stripe.com/invoices/None)** for the payment of amount **$10.00** has been created."
self.send_and_test_stream_message('invoice_upcoming', expected_topic, expected_message,
content_type="application/x-www-form-urlencoded")
def test_invoice_updated(self) -> None:
expected_topic = u"invoice in_00000000000000"
expected_message = u"An **[invoice](https://dashboard.stripe.com/invoices/in_00000000000000)** for the payment of amount **$10.00** has been updated."
self.send_and_test_stream_message('invoice_updated', expected_topic, expected_message,
content_type="application/x-www-form-urlencoded")
def test_invoice_voided(self) -> None:
expected_topic = u"invoice in_00000000000000"
expected_message = u"An **[invoice](https://dashboard.stripe.com/invoices/in_00000000000000)** for the payment of amount **$10.00** has been voided."
self.send_and_test_stream_message('invoice_voided', expected_topic, expected_message,
content_type="application/x-www-form-urlencoded")

View File

@ -14,6 +14,19 @@ from zerver.lib.webhooks.common import check_send_webhook_message, \
UnexpectedWebhookEventType
from zerver.models import UserProfile
INVOICE_INFO = {
"created": "has been created",
"deleted": "has been deleted",
"finalized": "has been finalized",
"marked_uncollectible": "has been marked as uncollectible",
"payment_failed": "has failed",
"payment_succeeded": "has succeeded",
"sent": "has been sent",
"upcoming": "has been created",
"updated": "has been updated",
"voided": "has been voided"
}
class SuppressedEvent(Exception):
pass
@ -148,18 +161,6 @@ def topic_and_body(payload: Dict[str, Any]) -> Tuple[str, str]:
topic = 'files'
body = default_body() + ' ({purpose}). \nTitle: {title}'.format(
purpose=object_['purpose'].replace('_', ' '), title=object_['title'])
if category == 'invoice':
if event == 'upcoming': # nocoverage
body = 'Upcoming invoice created'
else:
body = default_body(update_blacklist=['lines', 'description', 'number', 'finalized_at'])
if event == 'created': # nocoverage
# Could potentially add link to invoice PDF here
body += ' ({reason})\nBilling method: {method}\nTotal: {total}\nAmount due: {due}'.format(
reason=object_['billing_reason'].replace('_', ' '),
method=object_['billing'].replace('_', ' '),
total=amount_string(object_['total'], object_['currency']),
due=amount_string(object_['amount_due'], object_['currency']))
if category == 'invoiceitem': # nocoverage
body = default_body(update_blacklist=['description'])
if event == 'created':
@ -198,6 +199,28 @@ def topic_and_body(payload: Dict[str, Any]) -> Tuple[str, str]:
amount=amount,
end=end
)
if category.startswith('invoice'):
object_id = object_['id']
link = "https://dashboard.stripe.com/invoices/{}".format(object_id)
amount = amount_string(object_["amount_due"], object_["currency"])
body_t = "An {invoice_type} **[invoice]({link})** for the payment of amount **{amount}** {end}."
end = INVOICE_INFO.get(event) # type: ignore # expression has type Optional[str]
if event == "upcoming":
invoice_type = "upcoming"
else:
invoice_type = ""
topic = "invoice {}".format(object_id)
body = body_t.format(
invoice_type = invoice_type,
link=link,
amount=amount,
end=end
)
if category in ['payment_intent', 'plan', 'product', 'recipient',
'reporting', 'review', 'sigma', 'sku', 'source', 'subscription_schedule',
'topup', 'transfer']: # nocoverage