Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Next Next commit
Added currency code and numerical price to product detail model.
  • Loading branch information
BeMacized committed Apr 7, 2021
commit 83875194f2a94ed9d1dcfc5945ea2b4c42c69912
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:io';

import 'package:in_app_purchase/store_kit_wrappers.dart';
import 'package:in_app_purchase/billing_client_wrappers.dart';
import 'in_app_purchase_connection.dart';
Expand All @@ -17,6 +19,8 @@ class ProductDetails {
required this.title,
required this.description,
required this.price,
required this.rawPrice,
required this.currencyCode,
this.skProduct,
this.skuDetail});

Expand All @@ -33,6 +37,13 @@ class ProductDetails {
/// Formatted with currency symbol ("$0.99").
final String price;

// The unformatted price of the product, specified in the App Store Connect or Sku in Google Play console based on the platform.
final double rawPrice;

// The currency code for the price of the product.
// Based on the price specified in the App Store Connect or Sku in Google Play console based on the platform.
final String currencyCode;

/// Points back to the `StoreKits`'s [SKProductWrapper] object that generated this [ProductDetails] object.
///
/// This is `null` on Android.
Expand All @@ -49,6 +60,8 @@ class ProductDetails {
this.title = product.localizedTitle,
this.description = product.localizedDescription,
this.price = product.priceLocale.currencySymbol + product.price,
this.rawPrice = double.tryParse(product.price) ?? 0,
this.currencyCode = product.priceLocale.currencyCode,
this.skProduct = product,
this.skuDetail = null;

Expand All @@ -58,6 +71,8 @@ class ProductDetails {
this.title = skuDetails.title,
this.description = skuDetails.description,
this.price = skuDetails.price,
this.rawPrice = ((skuDetails.priceAmountMicros) / 1000000.0).toDouble(),
this.currencyCode = skuDetails.priceCurrencyCode,
this.skProduct = null,
this.skuDetail = skuDetails;
}
Expand Down