Skip to content

Commit

Permalink
handle multiple entries in validation result map for subscription an…
Browse files Browse the repository at this point in the history
…d in-app purchase
  • Loading branch information
al-af committed Nov 12, 2024
1 parent 7675278 commit a8b707f
Showing 1 changed file with 28 additions and 20 deletions.
48 changes: 28 additions & 20 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,26 @@ AppsFlyerPurchaseConnector.onSubscriptionValidationResultSuccess = (
}

const subValidationSuccessListener =
purchaseConnectorEventEmitter.addListener(
AppsFlyerConstants.SUBSCRIPTION_VALIDATION_SUCCESS,
(result) => {
try {
const firstEntryValue = Object.values(result)[0];
const validationResult =
SubscriptionValidationResult.fromJson(firstEntryValue);
onSuccess(validationResult);
} catch (error) {
console.error(
"Failed to parse subscription validation result:",
error
);
}
purchaseConnectorEventEmitter.addListener(
AppsFlyerConstants.SUBSCRIPTION_VALIDATION_SUCCESS,
(result) => {
try {
const parsedResults = Object.entries(result).reduce(
(acc, [purchaseToken, validationResult]) => {
acc[purchaseToken] = SubscriptionValidationResult.fromJson(validationResult);
return acc;
},
{}
);
onSuccess(parsedResults);
} catch (error) {
console.error(
"Failed to parse subscription validation results:",
error
);
}
);
}
);

pcEventsMap[AppsFlyerConstants.SUBSCRIPTION_VALIDATION_SUCCESS] =
subValidationSuccessListener;
Expand Down Expand Up @@ -104,13 +108,17 @@ AppsFlyerPurchaseConnector.onInAppValidationResultSuccess = (onSuccess) => {
AppsFlyerConstants.IN_APP_PURCHASE_VALIDATION_SUCCESS,
(result) => {
try {
const firstEntryValue = Object.values(result)[0];
const purchaseValidationResult =
InAppPurchaseValidationResult.fromJson(firstEntryValue);
onSuccess(purchaseValidationResult);
const parsedResults = Object.entries(result).reduce(
(acc, [purchaseToken, validationResult]) => {
acc[purchaseToken] = InAppPurchaseValidationResult.fromJson(validationResult);
return acc;
},
{}
);
onSuccess(parsedResults);
} catch (error) {
console.error(
"Failed to handle in-app purchase validation result:",
"Failed to handle in-app purchase validation results:",
error
);
}
Expand Down

0 comments on commit a8b707f

Please sign in to comment.