@@ -4,7 +4,11 @@ import type {
44 ResponseBodyV2DecodedPayload ,
55} from '@apple/app-store-server-library' ;
66import type { User } from '../../entity/user/User' ;
7- import { getAppleTransactionType } from './utils' ;
7+ import {
8+ getAnalyticsEventFromAppleNotification ,
9+ getAppleTransactionType ,
10+ logAppleAnalyticsEvent ,
11+ } from './utils' ;
812import { AppleTransactionType } from './types' ;
913import {
1014 UserTransaction ,
@@ -24,6 +28,7 @@ import type { Block, KnownBlock } from '@slack/web-api';
2428import { webhooks } from '../slack' ;
2529import { checkUserCoresAccess } from '../user' ;
2630import { CoresRole } from '../../types' ;
31+ import { convertCurrencyToUSD } from '../../integrations/openExchangeRates' ;
2732
2833export const isCorePurchaseApple = ( {
2934 transactionInfo,
@@ -143,6 +148,7 @@ export const notifyNewStoreKitPurchase = async ({
143148export const handleCoresPurchase = async ( {
144149 transactionInfo,
145150 user,
151+ notification,
146152} : {
147153 transactionInfo : JWSTransactionDecodedPayload ;
148154 user : Pick < User , 'id' | 'subscriptionFlags' | 'coresRole' > ;
@@ -234,12 +240,32 @@ export const handleCoresPurchase = async ({
234240 return userTransaction ;
235241 } ) ;
236242
243+ const currencyInUSD = await convertCurrencyToUSD (
244+ ( transactionInfo . price || 0 ) / 1000 ,
245+ transactionInfo . currency || 'USD' ,
246+ ) ;
247+
248+ const eventName = getAnalyticsEventFromAppleNotification (
249+ notification . notificationType ,
250+ notification . subtype ,
251+ ) ;
252+
253+ if ( eventName ) {
254+ await logAppleAnalyticsEvent (
255+ transactionInfo ,
256+ undefined ,
257+ eventName ,
258+ user ,
259+ currencyInUSD ,
260+ ) ;
261+ }
262+
237263 if ( transaction . status === UserTransactionStatus . Success ) {
238264 await notifyNewStoreKitPurchase ( {
239265 data : transactionInfo ,
240266 transaction,
241267 user,
242- currencyInUSD : transaction . valueIncFees ,
268+ currencyInUSD,
243269 } ) ;
244270 }
245271
0 commit comments