-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integration offerId inconsistency #518
Comments
Unfortunately, we also ran into this problem while integrating IAP and need to solve this for a good flow. ProblemA bit more context to this problem. The JWP integration is configured using one asset. Based on this asset, the access fees configured in the dashboard will be transformed into two The ott-web-app/packages/common/src/services/integrations/jwp/JWPCheckoutService.ts Lines 49 to 55 in 7146972
When the PayPal payment succeeds, the user is sent to the following URL, which adds the
The WaitingForPayment component will poll until it has access to the given offerId: ott-web-app/packages/ui-react/src/components/WaitingForPayment/WaitingForPayment.tsx Line 15 in 7146972
In the Also note the fallback here: when no ott-web-app/packages/hooks-react/src/useCheckAccess.ts Lines 22 to 31 in 7146972
Finally, we call it ott-web-app/packages/common/src/services/integrations/jwp/JWPCheckoutService.ts Lines 218 to 224 in 7146972
Possible SolutionInstead of refactoring everything to generic types (which we eventually will do), I realised while writing this we could fix this in the JWPCheckoutService. The When retrieving the offers, we could hold a small dictionary with an offerId -> assetId mapping in the JWPCheckoutService. When the To make the asset ID more stable, we can also test the offersMap = new Map<string, number>()
getOffers: GetOffers = async (payload) => {
const offers = await Promise.all(
payload.offerIds.map(async (assetId) => {
try {
const { data } = await InPlayer.Asset.getAssetAccessFees(parseInt(`${assetId}`));
return data?.map((accessFee) => {
const offer = this.formatOffer(accessFee);
this.offersMap.set(offer.offerId, assetId);
return offer;
});
} catch {
throw new Error('Failed to get offers');
}
}),
);
return offers.flat();
}; We can use it as such: resolveAssetId(offerId: string) {
// when the offer id starts with a C or S, it's an access fee id
if (offerId.startsWith('C') || offerId.startsWith('S')) {
const assetId = this.offersMap.get(offerId);
if (typeof assetId !== 'undefined') return assetId;
throw new Error(`Couldn't resolve assetId from the given offerId: ${offerId}`);
}
// the offerId is an asset id
return parseInt(offerId);
}
getEntitlements: GetEntitlements = async ({ offerId }) => {
try {
const response = await InPlayer.Asset.checkAccessForAsset(this.resolveAssetId(offerId));
return this.formatEntitlements(response.data.expires_at, true);
} catch {
return this.formatEntitlements();
}
}; I can only think of 1 scenario where this doesn't work. When buying access to a PPV item, the asset and offers are fetched. However, when the user is redirected back to the site from PayPal or 3D Secure, this asset might not be fetched. |
Maybe we can append the resolved |
Yes, but it's preferred that only the JWP integration is aware of the |
We found some issues with the offerIds being used differently between the JWP and Cleeng integrations.
The difference between JWP assets and Cleeng offers is that JWP uses a single asset with two pricing options (monthly & annual). But for Cleeng, two offers need to be created. In the codebase, JWP imitates having two offers and this has some problems with backtracking the correct assetId for some places.
We should consider making this more generic and not integration-specific in the business logic.
See #492 for more information about this.
The text was updated successfully, but these errors were encountered: