Skip to content

Add webhook for subscription creation#604

Merged
mnida merged 18 commits intouselotus:mainfrom
djanda97:590-subscription-creation-webhook
Mar 7, 2023
Merged

Add webhook for subscription creation#604
mnida merged 18 commits intouselotus:mainfrom
djanda97:590-subscription-creation-webhook

Conversation

@djanda97
Copy link
Copy Markdown
Contributor

@djanda97 djanda97 commented Feb 23, 2023

Fixes #590

Tasks:

  • Register new webhook with webhook server (svix)
  • Implement new webhook (frontend & backend)
  • Update documentation

@djanda97 djanda97 temporarily deployed to Development February 23, 2023 05:22 — with GitHub Actions Inactive
@djanda97 djanda97 temporarily deployed to Development February 23, 2023 07:18 — with GitHub Actions Inactive
@djanda97 djanda97 temporarily deployed to Development February 23, 2023 07:26 — with GitHub Actions Inactive
@djanda97
Copy link
Copy Markdown
Contributor Author

djanda97 commented Feb 23, 2023

UI with new checkbox for subscription.created webhook event:

image

@djanda97 djanda97 temporarily deployed to Development February 23, 2023 08:13 — with GitHub Actions Inactive
@djanda97
Copy link
Copy Markdown
Contributor Author

I apologize for the messy diffs in a few files, this was caused by alphabetizing based on method/class name 😅

@djanda97 djanda97 marked this pull request as ready for review February 23, 2023 08:15
"payload": payload,
}
event_id = (
slugify(str(subscription.customer))
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure which of the subscription fields would be appropriate for the event_id, so I just picked a couple.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A good one could be subscription_record_id (a UUID field)... unfortunately we created subscriptions when we had a slightly different model structure in the backend so they're referred to as subscription records everywhere.

@djanda97
Copy link
Copy Markdown
Contributor Author

@diego-escobedo I'm having some trouble trying to update the documentation.
After executing python3 ./backend/manage.py generate_schema as suggested in #440, I encountered the following error:

image

Does that command need to executed inside one of the docker containers?

@djanda97 djanda97 temporarily deployed to Development February 24, 2023 03:34 — with GitHub Actions Inactive
Comment thread frontend/src/components/Settings/settings/tabs/DeveloperTab.tsx
- Set left margin to 0px for subscription created webhook checkbox
@djanda97 djanda97 temporarily deployed to Development February 27, 2023 01:12 — with GitHub Actions Inactive
@diego-escobedo
Copy link
Copy Markdown
Collaborator

That's awesome! I'll take note of this perhaps a good idea to add to the developer section in case people want a bit of an easier workflow than doing it all through docker. I'll throw it on our todos.

🪷🪷

@djanda97
Copy link
Copy Markdown
Contributor Author

djanda97 commented Mar 7, 2023

I've updated the docs so this PR should be ready for review/testing!

type.
For `customer.created`, the response will be a [customer](../api-reference/customers/retrieve-customer).
For `invoice.*`, the response will be an [invoice](../api-reference/invoices/get-invoice).
For `subscription.created`, the response will be a [subscription](../api-reference/subscriptions/list-subscriptions).
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When browsing the api reference page, I couldn't find a request for getting a single subscription so I used the /api/subscriptions/ endpoint instead.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect @djanda97 . It can just be an object of a subscription. The api/subscriptions is just a list of these subscriptions.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Here is the payload I'm getting
{ "attempt": 5, "created_at": "2023-03-07 04:12:44.938810+00:00", "properties": { "event_type": "subscription.created", "payload": { "addons": [], "auto_renew": true, "billing_plan": { "plan_id": "plan_77af5f277e2347048d313ca1c4843251", "plan_name": "Events + Recordings - Pro", "version": 1, "version_id": "plan_version_399d3c5b9da9439a8d9412c70866d459" }, "customer": { "customer_id": "cust_deef1bed569343d2bc3e4614dc0e49ff", "customer_name": "MediumCompany 9cb1fc", "email": "3cc9e9350ae7458c8dfdf92f01478629@aca92ffe6ae84ce2ba961ddeadae0d03.com" }, "end_date": "2023-04-06T23:59:59.999999+00:00", "fully_billed": false, "is_new": true, "start_date": "2023-03-07T04:12:44.158000+00:00", "subscription_filters": [] } } }

@mnida mnida added this pull request to the merge queue Mar 7, 2023
Merged via the queue into uselotus:main with commit bd5346e Mar 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Webhook for subscription creation

3 participants