@@ -30,15 +30,21 @@ export const verifyAndDecodeAppleSignedData = async ({
3030 notification : ResponseBodyV2DecodedPayload ;
3131 environment : Environment ;
3232 verifier : SignedDataVerifier ;
33- } ) => {
33+ } ) : Promise < {
34+ transactionInfo ?: JWSTransactionDecodedPayload ;
35+ renewalInfo ?: JWSRenewalInfoDecodedPayload ;
36+ } > => {
37+ let renewalInfo : JWSRenewalInfoDecodedPayload | undefined = undefined ;
38+ let transactionInfo : JWSTransactionDecodedPayload | undefined = undefined ;
39+
3440 if ( ! isNullOrUndefined ( notification . data ?. signedRenewalInfo ) ) {
35- return await verifier . verifyAndDecodeTransaction (
41+ renewalInfo = await verifier . verifyAndDecodeRenewalInfo (
3642 notification . data . signedRenewalInfo ,
3743 ) ;
3844 }
3945
4046 if ( ! isNullOrUndefined ( notification . data ?. signedTransactionInfo ) ) {
41- return await verifier . verifyAndDecodeTransaction (
47+ transactionInfo = await verifier . verifyAndDecodeTransaction (
4248 notification . data . signedTransactionInfo ,
4349 ) ;
4450 }
@@ -52,30 +58,36 @@ export const verifyAndDecodeAppleSignedData = async ({
5258 'Missing signed data in notification data' ,
5359 ) ;
5460
55- return null ;
61+ return {
62+ transactionInfo,
63+ renewalInfo,
64+ } ;
5665} ;
5766
5867export const logAppleAnalyticsEvent = async (
59- data : JWSRenewalInfoDecodedPayload ,
68+ transactionInfo : JWSTransactionDecodedPayload ,
69+ renewalInfo : JWSRenewalInfoDecodedPayload ,
6070 eventName : AnalyticsEventName ,
6171 user : User ,
6272 currencyInUSD : number ,
6373) => {
64- if ( ! data || isTest ) {
74+ if ( ! transactionInfo || isTest ) {
6575 return ;
6676 }
6777
6878 const cycle =
69- productIdToCycle [ data ?. autoRenewProductId as keyof typeof productIdToCycle ] ;
70- const cost = data ?. renewalPrice ;
79+ productIdToCycle [
80+ renewalInfo ?. autoRenewProductId as keyof typeof productIdToCycle
81+ ] ;
82+ const cost = renewalInfo ?. renewalPrice ;
7183
7284 const extra = {
7385 payment : SubscriptionProvider . AppleStoreKit ,
7486 cycle,
7587 cost : currencyInUSD ,
7688 currency : 'USD' ,
7789 localCost : cost ? cost / 1000 : undefined ,
78- localCurrency : data ?. currency ,
90+ localCurrency : transactionInfo ?. currency ,
7991 payout : {
8092 total : currencyInUSD * 100 ,
8193 grandTotal : currencyInUSD * 100 ,
@@ -86,8 +98,8 @@ export const logAppleAnalyticsEvent = async (
8698 await sendAnalyticsEvent ( [
8799 {
88100 event_name : eventName ,
89- event_timestamp : new Date ( data ?. signedDate || '' ) ,
90- event_id : data . appTransactionId ,
101+ event_timestamp : new Date ( transactionInfo ?. signedDate || '' ) ,
102+ event_id : transactionInfo . appTransactionId ,
91103 app_platform : 'api' ,
92104 user_id : user . id ,
93105 extra : JSON . stringify ( extra ) ,
@@ -130,11 +142,11 @@ export const loadAppleRootCAs = async (): Promise<Buffer[]> => {
130142} ;
131143
132144export const getAppleTransactionType = ( {
133- decodedInfo ,
145+ transactionInfo ,
134146} : {
135- decodedInfo : JWSTransactionDecodedPayload ;
147+ transactionInfo : JWSTransactionDecodedPayload ;
136148} ) : AppleTransactionType | null => {
137- switch ( decodedInfo . type ) {
149+ switch ( transactionInfo . type ) {
138150 case 'Auto-Renewable Subscription' :
139151 return AppleTransactionType . AutoRenewableSubscription ;
140152 case 'Non-Consumable' :
0 commit comments