From b007d1cc6fc94cac9bfba97d2a6be047348a98ca Mon Sep 17 00:00:00 2001 From: Shur Singh Date: Thu, 20 Aug 2020 00:06:25 -0700 Subject: [PATCH] feat: expose currencyCode on Product struct in IAP module --- docs/api/structures/product.md | 1 + shell/browser/api/electron_api_in_app_purchase.cc | 3 +++ shell/browser/mac/in_app_purchase_product.h | 3 +++ shell/browser/mac/in_app_purchase_product.mm | 8 ++++++++ 4 files changed, 15 insertions(+) diff --git a/docs/api/structures/product.md b/docs/api/structures/product.md index 09edff1859f66..9180f597a0446 100644 --- a/docs/api/structures/product.md +++ b/docs/api/structures/product.md @@ -7,4 +7,5 @@ * `contentLengths` Number[] - The total size of the content, in bytes. * `price` Number - The cost of the product in the local currency. * `formattedPrice` String - The locale formatted price of the product. +* `currencyCode` String - 3 character code presenting a product's currency based on the ISO 4217 standard. * `isDownloadable` Boolean - A Boolean value that indicates whether the App Store has downloadable content for this product. `true` if at least one file has been associated with the product. diff --git a/shell/browser/api/electron_api_in_app_purchase.cc b/shell/browser/api/electron_api_in_app_purchase.cc index d02d7e892527f..f2f18f0d74f43 100644 --- a/shell/browser/api/electron_api_in_app_purchase.cc +++ b/shell/browser/api/electron_api_in_app_purchase.cc @@ -61,6 +61,9 @@ struct Converter { dict.Set("price", val.price); dict.Set("formattedPrice", val.formattedPrice); + // Currency Information + dict.Set("currencyCode", val.currencyCode); + // Downloadable Content Information dict.Set("isDownloadable", val.isDownloadable); diff --git a/shell/browser/mac/in_app_purchase_product.h b/shell/browser/mac/in_app_purchase_product.h index 718629180529b..e8e8fc97ec549 100644 --- a/shell/browser/mac/in_app_purchase_product.h +++ b/shell/browser/mac/in_app_purchase_product.h @@ -28,6 +28,9 @@ struct Product { double price = 0.0; std::string formattedPrice; + // Currency Information + std::string currencyCode; + // Downloadable Content Information bool isDownloadable = false; diff --git a/shell/browser/mac/in_app_purchase_product.mm b/shell/browser/mac/in_app_purchase_product.mm index fc3e6ea8c37f1..5b13692ba4a10 100644 --- a/shell/browser/mac/in_app_purchase_product.mm +++ b/shell/browser/mac/in_app_purchase_product.mm @@ -146,6 +146,14 @@ - (NSString*)formatPrice:(NSDecimalNumber*)price productStruct.formattedPrice = [[self formatPrice:product.price withLocal:product.priceLocale] UTF8String]; + + // Currency Information + if (@available(macOS 10.12, *)) { + if (product.priceLocale.currencyCode != nil) { + productStruct.currencyCode = + [product.priceLocale.currencyCode UTF8String]; + } + } } }