@@ -6,10 +6,10 @@ import moment from 'moment';
66import * as log from 'loglevel' ;
77import { SubscriptionStatus } from '@httptoolkit/accounts' ;
88
9- import { SKUs } from '../products' ;
9+ import { isProSubscription , isTeamSubscription , SKUs } from '../products' ;
1010import { recordCancellation , recordSubscription } from '../accounting' ;
1111import { PayingUserMetadata , getUsersByEmail } from '../auth0' ;
12- import { parseCheckoutPassthrough , reportSuccessfulCheckout , updateProUserData } from '../webhook-handling' ;
12+ import { parseCheckoutPassthrough , reportSuccessfulCheckout , updateProUserData , updateTeamData } from '../webhook-handling' ;
1313import {
1414 parsePayProCustomFields ,
1515 PayProOrderDateFormat ,
@@ -68,7 +68,7 @@ export const handler = catchErrors(async (event) => {
6868 const subscriptionId = eventData . SUBSCRIPTION_ID ;
6969 if ( ! subscriptionId ) throw new Error ( `Received webhook with no subscription id` ) ;
7070
71- await updateProUserData ( email , {
71+ const userData = {
7272 subscription_status : subState ,
7373 subscription_sku : sku ,
7474 subscription_quantity : quantity ,
@@ -77,7 +77,19 @@ export const handler = catchErrors(async (event) => {
7777
7878 payment_provider : 'paypro' ,
7979 subscription_id : subscriptionId // Useful for API requests later
80- } ) ;
80+ } as const ;
81+
82+ if ( isTeamSubscription ( sku ) ) {
83+ log . info ( `Updating Team user ${ email } to ${ JSON . stringify ( userData ) } ` ) ;
84+ await updateTeamData ( email , userData ) ;
85+ } else if ( isProSubscription ( sku ) ) {
86+ log . info ( `Updating Pro user ${ email } to ${ JSON . stringify ( userData ) } ` ) ;
87+ await updateProUserData ( email , userData ) ;
88+ } else {
89+ throw new Error ( `Webhook received for unknown subscription type: ${
90+ userData . subscription_sku
91+ } `) ;
92+ }
8193
8294 try {
8395 if ( eventType === 'OrderCharged' ) {
0 commit comments