@kirz/react-native-toolkit
Version:
Toolkit to speed up React Native development
58 lines (57 loc) • 2.29 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.transformSubscription = transformSubscription;
var _reactNative = require("react-native");
var _parseIso8601Period = require("./parseIso8601Period");
var _types = require("../../types");
// eslint-disable-next-line max-len
function transformSubscription(subscription) {
if (_reactNative.Platform.OS === 'ios') {
const data = subscription;
return new _types.Subscription({
productId: data.productId,
title: data.title,
description: data.description,
price: parseFloat(data.price),
localizedPrice: data.localizedPrice,
currency: data.currency,
periodUnit: data.subscriptionPeriodUnitIOS.toLocaleLowerCase(),
numberOfPeriods: parseFloat(data.subscriptionPeriodNumberIOS),
...(data.introductoryPricePaymentModeIOS === 'FREETRIAL' && {
trial: {
periodUnit: data.introductoryPriceSubscriptionPeriodIOS.toLocaleLowerCase(),
numberOfPeriods: parseFloat(data.introductoryPriceNumberOfPeriodsIOS)
}
}),
originalData: data
});
}
if (_reactNative.Platform.OS === 'android') {
const data = subscription;
if (data.subscriptionOfferDetails.length !== 1) {
console.warn(`Multiple offsers detected for a subscription ${data.productId}. First offer will be used`);
}
const offerPrices = data.subscriptionOfferDetails[0].pricingPhases.pricingPhaseList;
const [priceInfo] = offerPrices.filter(x => x.priceAmountMicros !== '0');
const [trialInfo] = offerPrices.filter(y => y.priceAmountMicros === '0');
return new _types.Subscription({
productId: data.productId,
title: data.title,
description: data.description,
originalData: data,
price: parseFloat(priceInfo.priceAmountMicros) / 1e6,
localizedPrice: priceInfo.formattedPrice,
currency: priceInfo.priceCurrencyCode,
...(0, _parseIso8601Period.parseIso8601Period)(priceInfo.billingPeriod),
...(trialInfo && {
trial: {
...(0, _parseIso8601Period.parseIso8601Period)(trialInfo.billingPeriod)
}
})
});
}
throw new Error(`Platform not supported: ${_reactNative.Platform.OS}`);
}
//# sourceMappingURL=transformSubscription.js.map