Skip to content

Commit

Permalink
Fix/populate initial prices (#2582)
Browse files Browse the repository at this point in the history
This pull request addresses two  issues:

**Amazon pricing**
When dealing with Amazon pricing, 'localizedPrice' consistently defaults
to 0.0. To rectify this, we've leveraged the 'original price' as the
source value for 'localizedPrice.' The primary objective of this patch
is to seamlessly populate both 'localizedPrice' and 'price' with values
derived from 'originalPrice.'

**purchaseUpdatedListener notifications**
During our investigation, we encountered a similar
[issue](#2487)
where notifications weren't being received within the
purchaseUpdatedListener. Our solution involved the reintroduction of the
startListening method."

---------

Co-authored-by: Zach <[email protected]>
  • Loading branch information
zachariast and Zach authored Oct 31, 2023
1 parent b501f1e commit 30c25bf
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/eventEmitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {EmitterSubscription, NativeEventEmitter} from 'react-native';

import {TransactionEvent, transactionSk2ToPurchaseMap} from './types/appleSk2';
import {isIosStorekit2} from './iap';
import {getIosModule, getNativeModule, isIos} from './internal';
import { getAndroidModule, getIosModule, getNativeModule, isAndroid, isIos } from './internal';
import type {PurchaseError} from './purchaseError';
import type {Purchase} from './types';

Expand Down Expand Up @@ -52,6 +52,10 @@ export const purchaseUpdatedListener = (
proxyListener,
);

if (isAndroid) {
getAndroidModule().startListening();
}

return emitterSubscription;
};

Expand Down
3 changes: 3 additions & 0 deletions src/internal/fillProductsWithAdditionalData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ export const fillProductsWithAdditionalData = async <T extends ProductCommon>(
// Add currency to items
items.forEach((item) => {
if (currency) {
const {originalPrice} = item;
item.currency = currency;
item.price = originalPrice ?? '0.0';
item.localizedPrice = originalPrice ?? '0.0';
}
});
}
Expand Down
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export interface ProductCommon {
price: string;
currency: string;
localizedPrice: string;
originalPrice?: string;
countryCode?: string;
}

Expand Down

0 comments on commit 30c25bf

Please sign in to comment.