Skip to content

Commit

Permalink
feat: add currency regarding the new API (#2615)
Browse files Browse the repository at this point in the history
- addressing the missing currency issue in Storekit 2:
https://developer.apple.com/forums/thread/689978
- adding from here:
https://developer.apple.com/documentation/storekit/product/4044347-priceformatstyle
- as few changes as possible
  • Loading branch information
cervebar committed Dec 8, 2023
1 parent 2be708c commit a3d9e63
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion ios/IapSerializationUtils.swift
Expand Up @@ -19,7 +19,8 @@ func serialize(_ p: Product) -> [String: Any?] {
"jsonRepresentation": serializeDebug(p.jsonRepresentation),
"price": p.price,
"subscription": serialize(p.subscription),
"type": serialize(p.type)
"type": serialize(p.type),
"currency": p.priceFormatStyle.currencyCode
]
}

Expand Down
7 changes: 5 additions & 2 deletions src/types/appleSk2.ts
Expand Up @@ -36,6 +36,7 @@ export type SubscriptionInfo = {
export type RefundRequestStatus = 'success' | 'userCancelled';

export type ProductSk2 = {
currency: string;
description: string;
displayName: string;
displayPrice: string;
Expand All @@ -51,6 +52,7 @@ export const productSk2Map = ({
description,
displayName,
price,
currency,
displayPrice,
}: ProductSk2): ProductIOS => {
const prod: ProductIOS = {
Expand All @@ -60,7 +62,7 @@ export const productSk2Map = ({
type: 'iap',
price: String(price),
localizedPrice: displayPrice,
currency: '', // Not available on new API, use localizedPrice instead
currency
};
return prod;
};
Expand All @@ -70,6 +72,7 @@ export const subscriptionSk2Map = ({
description,
displayName,
price,
currency,
displayPrice,
subscription,
}: ProductSk2): SubscriptionIOS => {
Expand All @@ -81,7 +84,7 @@ export const subscriptionSk2Map = ({
type: 'subs',
price: String(price),
localizedPrice: displayPrice,
currency: '', // Not available on new API, use localizedPrice instead
currency,
subscriptionPeriodNumberIOS: `${subscription?.subscriptionPeriod?.value}`,
subscriptionPeriodUnitIOS:
subscription?.subscriptionPeriod?.unit.toUpperCase() as SubscriptionIosPeriod,
Expand Down

0 comments on commit a3d9e63

Please sign in to comment.