private static Map<String, Information> convertSkuDetailsToInformationMap(List<String> skuDetailsStringList) throws JSONException { Map<String, Information> products = new HashMap<>(); for (String thisResponse : skuDetailsStringList) { JSONObject object = new JSONObject(thisResponse); String sku = object.getString(PRODUCT_ID); String price = object.getString(GoogleBillingConstants.SKU_PRICE); String title = object.getString(GoogleBillingConstants.SKU_TITLE); String description = object.getString(GoogleBillingConstants.SKU_DESCRIPTION); products.put(sku, Information.newBuilder() .localName(title) .localDescription(description) .localPricing(price) .priceInCents(priceInCents(object)) .priceCurrencyCode(object.getString(PRICE_CURRENCY_CODE)) .build()); } return products; }
private Information convertSkuDetailsToInformation(SkuDetails skuDetails) { String priceString = skuDetails.getPrice(); return Information.newBuilder() .localName(skuDetails.getTitle()) .localDescription(skuDetails.getDescription()) .localPricing(priceString) .priceCurrencyCode(skuDetails.getPriceCurrencyCode()) .priceInCents((int) (skuDetails.getPriceAmountMicros() / 10000)) .build(); }
public static Information informationFullEditionEntitlementNoPriceInCents() { return Information.newBuilder() .localName("Buy full edition") .localDescription("Access to all levels") .localPricing("€ 1.00") .priceCurrencyCode("EUR") .build(); } }
/** Converts a Product to our Information object. */ static Information convertProductToInformation(Product product) { String priceString = product.getPrice(); return Information.newBuilder() .localName(product.getTitle()) .localDescription(product.getDescription()) .localPricing(priceString) .priceCurrencyCode(tryParseCurrency(priceString)) .priceInCents(tryParsePriceInCents(priceString)) .build(); }
public static Information informationFullEditionEntitlement() { return Information.newBuilder() .localName("Buy full edition") .localDescription("Access to all levels") .localPricing( "€ 1.00") .priceCurrencyCode("EUR") .priceInCents(100) .build(); }
@Override public Information getInformation(String identifier) { if (products != null) { for (SKProduct p : products) { if (p.productIdentifier().equals(identifier)) { if (numberFormatter == null) { numberFormatter = NSNumberFormatter.alloc().init(); numberFormatter.setFormatterBehavior(NSNumberFormatterBehavior .Behavior10_4); numberFormatter.setNumberStyle(NSNumberFormatterStyle.CurrencyStyle); } numberFormatter.setLocale(p.priceLocale()); return Information.newBuilder() .localName(p.localizedTitle()) .localDescription(p.localizedDescription()) .localPricing(numberFormatter.stringFromNumber(p.price())) // p.priceLocale().currencyCode() is not supported on iOS 9 .priceCurrencyCode(String.valueOf(p.priceLocale().objectForKey("CurrencyCode"))) .build(); } } } return Information.UNAVAILABLE; }
@Override public Information getInformation(String identifier) { if (products != null) { for (SKProduct p : products) { if (p.getProductIdentifier().equals(identifier)) { if (numberFormatter == null) { numberFormatter = new NSNumberFormatter(); numberFormatter.setFormatterBehavior(NSNumberFormatterBehavior._10_4); numberFormatter.setNumberStyle(NSNumberFormatterStyle.Currency); } numberFormatter.setLocale(p.getPriceLocale()); return Information.newBuilder() .localName(p.getLocalizedTitle()) .localDescription(p.getLocalizedDescription()) .localPricing(numberFormatter.format(p.getPrice())) .priceCurrencyCode(p.getPriceLocale().getCurrencyCode()) .build(); } } } return Information.UNAVAILABLE; }