diff --git a/apps/event-system/services/stripe/stripe-webhook.service.ts b/apps/event-system/services/stripe/stripe-webhook.service.ts index bcb7ec3..3d0fa94 100644 --- a/apps/event-system/services/stripe/stripe-webhook.service.ts +++ b/apps/event-system/services/stripe/stripe-webhook.service.ts @@ -1,6 +1,19 @@ import { ServiceSchema } from 'moleculer'; import Stripe from 'stripe'; -import { resultErr, resultOk } from '@event-inc/utils'; +import { resultErr, resultOk, makeHttpNetworkCall } from '@event-inc/utils'; + +const TRACK_EVENT = `${process.env.CONNECTIONS_API_BASE_URL}v1/public/mark`; + +const context = { + locale: "", + page: { + path: "", + search: "", + title: "", + url: "" + }, + userAgent: "", +} export default { name: 'stripe-webhook', @@ -65,15 +78,22 @@ export default { billing }); - await ctx.broker.call('v1.tracking.public.track', { - path: 't', + await makeHttpNetworkCall({ + url: TRACK_EVENT, + method: 'POST', data: { - event: 'Created Subscription', - properties: subscriptionCreated, - userId: client?.author?._id + path: 't', + data: { + event: 'Created Subscription', + properties: { + ...subscriptionCreated, + version: "pica-1.0.0" + }, + context, + userId: client?.author?._id + } } }); - } break; @@ -103,13 +123,21 @@ export default { } ); - await ctx.broker.call('v1.tracking.public.track', { - path: 't', + await makeHttpNetworkCall({ + url: TRACK_EVENT, + method: 'POST', data: { - event: 'Updated Subscription', - properties: subscriptionUpdated, - userId: updatedClient?.author?._id, - }, + path: 't', + data: { + event: 'Updated Subscription', + properties: { + ...subscriptionUpdated, + version: "pica-1.0.0" + }, + context, + userId: updatedClient?.author?._id, + } + } }); break; @@ -151,14 +179,22 @@ export default { billing: updatedBilling, } ); - - await ctx.broker.call('v1.tracking.public.track', { - path: 't', + + await makeHttpNetworkCall({ + url: TRACK_EVENT, + method: 'POST', data: { - event: 'Created Subscription', - properties: subscriptionCreated, - userId: client?.author?._id, - }, + path: 't', + data: { + event: 'Created Subscription', + properties: { + ...subscriptionCreated, + version: "pica-1.0.0" + }, + context, + userId: client?.author?._id, + } + } }); } @@ -169,15 +205,23 @@ export default { } ); - await ctx.broker.call('v1.tracking.public.track', { - path: 't', + await makeHttpNetworkCall({ + url: TRACK_EVENT, + method: 'POST', data: { - event: 'Deleted Subscription', - properties: subscriptionDeleted, - userId: client?.author?._id, - }, + path: 't', + data: { + event: 'Deleted Subscription', + properties: { + ...subscriptionDeleted, + version: "pica-1.0.0" + }, + context, + userId: client?.author?._id, + } + } }); - + break; case 'invoice.payment_failed': @@ -200,16 +244,24 @@ export default { } ); - await ctx.broker.call('v1.tracking.public.track', { - path: 't', + await makeHttpNetworkCall({ + url: TRACK_EVENT, + method: 'POST', data: { - event: 'Failed Invoice Payment', - properties: invoicePaymentFailed, - userId: currentClient?.author?._id, - }, + path: 't', + data: { + event: 'Failed Invoice Payment', + properties: { + ...invoicePaymentFailed, + version: "pica-1.0.0" + }, + context, + userId: currentClient?.author?._id, + } + } }); - break; + break; case 'invoice.payment_succeeded': const invoicePaymentSucceeded = event.data.object; @@ -225,13 +277,21 @@ export default { } ); - await ctx.broker.call('v1.tracking.public.track', { - path: 't', + await makeHttpNetworkCall({ + url: TRACK_EVENT, + method: 'POST', data: { - event: 'Successful Invoice Payment', - properties: invoicePaymentSucceeded, - userId: succeededInvoiceClient?.author?._id, - }, + path: 't', + data: { + event: 'Successful Invoice Payment', + properties: { + ...invoicePaymentSucceeded, + version: "pica-1.0.0" + }, + context, + userId: succeededInvoiceClient?.author?._id, + } + } }); break; diff --git a/libs-private/service-logic/services/onboarding/useOnboardingService.ts b/libs-private/service-logic/services/onboarding/useOnboardingService.ts index 35e1c7c..64e1dac 100644 --- a/libs-private/service-logic/services/onboarding/useOnboardingService.ts +++ b/libs-private/service-logic/services/onboarding/useOnboardingService.ts @@ -2,10 +2,12 @@ import { Context } from 'moleculer'; import { Ownership } from '@libs-private/data-models'; import Stripe from 'stripe'; import { BResult } from '@event-inc/types'; -import { resultErr, resultOk } from '@event-inc/utils'; +import { makeHttpNetworkCall, resultErr, resultOk } from '@event-inc/utils'; import { ClientRecord } from '@event-inc/types/generic'; import { useSettingsService } from '../settings/useSettingsService'; +const TRACK_EVENT = `${process.env.CONNECTIONS_API_BASE_URL}v1/public/mark`; + export const useOnboardingService = (ctx: Context, ownership: Ownership) => { return { async init({ @@ -50,13 +52,29 @@ export const useOnboardingService = (ctx: Context, ownership: Ownership) => { billing, }); - // Track customer creation - await ctx.broker.call('v1.tracking.public.track', { - path: 't', + await makeHttpNetworkCall({ + url: TRACK_EVENT, + method: 'POST', data: { - event: 'Created Customer', - properties: response?.customer, - userId: client?.author?._id + path: 't', + data: { + event: 'Created Customer', + properties: { + ...response?.customer, + version: "pica-1.0.0" + }, + context: { + locale: "", + page: { + path: "", + search: "", + title: "", + url: "" + }, + userAgent: "", + }, + userId: client?.author?._id, + } } });