nativescript-purchase
Version:
A NativeScript plugin for making in-app purchases
53 lines (49 loc) • 2.44 kB
JavaScript
/*! *****************************************************************************
Copyright (c) 2019 Tangra Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
***************************************************************************** */
;
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
var product_common_1 = require("./product-common");
__export(require("./product-common"));
var unitsAsString = ["D", "W", "M", "Y"];
var Product = (function (_super) {
__extends(Product, _super);
function Product(nativeValue, type) {
var _this = _super.call(this, nativeValue, type) || this;
var formatter = NSNumberFormatter.alloc().init();
formatter.numberStyle = 2 /* CurrencyStyle */;
formatter.locale = nativeValue.priceLocale;
_this.productIdentifier = nativeValue.productIdentifier;
_this.localizedDescription = nativeValue.localizedDescription;
_this.localizedTitle = nativeValue.localizedTitle;
_this.priceAmount = nativeValue.price.doubleValue;
_this.priceFormatted = formatter.stringFromNumber(nativeValue.price);
_this.priceCurrencyCode = nativeValue.priceLocale.objectForKey(NSLocaleCurrencyCode);
// NOTE: The following code will can ONLY on ios 11.2 as the subscriptionPeriod property is a new one
var subscriptionPeriod = nativeValue.subscriptionPeriod;
if (subscriptionPeriod) {
if (subscriptionPeriod.numberOfUnits > 0) {
_this.productType = "subs";
_this.subscriptionPeriod = "P" + subscriptionPeriod.numberOfUnits + unitsAsString[subscriptionPeriod.unit];
}
else {
_this.productType = "inapp";
}
}
return _this;
}
return Product;
}(product_common_1.ProductBase));
exports.Product = Product;