Skip to content

Commit

Permalink
feat: update to ios rc.2
Browse files Browse the repository at this point in the history
  • Loading branch information
riderx committed Feb 4, 2022
1 parent 8102819 commit 015b698
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 48 deletions.
2 changes: 1 addition & 1 deletion CapacitorPurchases.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ Pod::Spec.new do |s|
s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
s.ios.deployment_target = '12.0'
s.dependency 'Capacitor'
s.dependency 'RevenueCat', '>= 4.0.0-beta.8'
s.dependency 'RevenueCat', '>= 4.0.0-rc.2'
s.swift_version = '5.1'
end
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -373,5 +373,4 @@ Holds the logIn result

### TODO

Migrate ios to rc-2
Prepare android migration to v5
97 changes: 52 additions & 45 deletions ios/Plugin/CapacitorPurchasesPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ extension String {
var iso8601withFractionalSeconds: Date? { return Formatter.iso8601withFractionalSeconds.date(from: self) }
}

@objc public extension RevenueCat.Transaction {
@objc public extension RevenueCat.StoreTransaction {
func toJson() -> [String: Any] {
return [
"productId": productId,
"revenueCatId": revenueCatId,
"productId": productIdentifier,
"revenueCatId": transactionIdentifier,
"purchaseDate": purchaseDate.iso8601withFractionalSeconds,
]
}
Expand Down Expand Up @@ -51,17 +51,25 @@ extension String {
"activeSubscriptions": Array(activeSubscriptions),
"allPurchasedProductIdentifiers": Array(allPurchasedProductIdentifiers),
"nonSubscriptionTransactions": [nonSubscriptionTransactions[0].toJson()],
"latestExpirationDate": latestExpirationDate?.iso8601withFractionalSeconds as Any,
"latestExpirationDate": latestExpirationDate?.iso8601withFractionalSeconds ?? [:],
"firstSeen": firstSeen.iso8601withFractionalSeconds,
"originalAppUserId": originalAppUserId,
"requestDate": requestDate.iso8601withFractionalSeconds,
"originalApplicationVersion": originalApplicationVersion as Any,
"originalPurchaseDate": originalPurchaseDate?.iso8601withFractionalSeconds as Any,
"managementURL": managementURL?.absoluteString as Any
"originalApplicationVersion": originalApplicationVersion ?? "",
"originalPurchaseDate": originalPurchaseDate?.iso8601withFractionalSeconds ?? "",
"managementURL": managementURL?.absoluteString ?? ""
]
}
}

@objc public extension SubscriptionPeriod {
func toJson() -> [String: Any] {
return [
"numberOfUnits": value,
"unit": unit.rawValue
]
}
}

@objc public extension SKProductSubscriptionPeriod {
func toJson() -> [String: Any] {
Expand All @@ -72,37 +80,35 @@ extension String {
}
}

@objc public extension SKProductDiscount {
@objc public extension StoreProductDiscount {
@available(iOS 12.2, *)
var localizedPrice: String {
if(sk1Discount == nil) {
return ""
}
let formatter = NumberFormatter()
formatter.numberStyle = .currency
formatter.locale = priceLocale
return formatter.string(from: price)!
formatter.locale = sk1Discount?.priceLocale
return formatter.string(from: NSNumber(nonretainedObject: price))!
}

@available(iOS 12.2, *)
func toJson() -> [String: Any] {
return [
"identifier": identifier as Any,
"type": type.rawValue,
"identifier": offerIdentifier ?? "",
"type": paymentMode,
"price": price,
"localizedPrice": localizedPrice,
"currencySymbol": priceLocale.currencySymbol as Any,
"currencyCode": priceLocale.currencyCode as Any,
"currencySymbol": sk1Discount?.priceLocale.currencySymbol ?? "",
"currencyCode": sk1Discount?.priceLocale.currencyCode ?? "",
"paymentMode": paymentMode.rawValue,
"numberOfPeriods": numberOfPeriods,
"numberOfPeriods": subscriptionPeriod.value,
"subscriptionPeriod": subscriptionPeriod.toJson(),
]
}
}

@objc public extension SKProduct {

var localizedPrice: String {
let formatter = NumberFormatter()
formatter.numberStyle = .currency
formatter.locale = priceLocale
return formatter.string(from: price)!
}
@objc public extension StoreProduct {

func toJson() -> [String: Any] {
var isFamilyShareable = false
Expand All @@ -113,21 +119,22 @@ extension String {
}
if #available(iOS 12.2, *) {
for disc in self.discounts {
discounts.append(disc.toJson() as Any)
discounts.append(disc.toJson())
}
introPrice = introductoryPrice?.toJson() as Any
introPrice = introductoryDiscount? .toJson() ?? [:]
}
// self.sk1Product.
return [
"description": localizedDescription,
"title": localizedTitle,
"price": price,
"priceString": localizedPrice,
"currencySymbol": priceLocale.currencySymbol as Any,
"currencyCode": priceLocale.currencyCode as Any,
"priceString": localizedPriceString,
"currencySymbol": priceFormatter?.currencySymbol ?? "",
"currencyCode": priceFormatter?.currencyCode ?? "",
"identifier": productIdentifier,
"isFamilyShareable": isFamilyShareable,
"subscriptionGroupIdentifier": subscriptionGroupIdentifier as Any,
"subscriptionPeriod": subscriptionPeriod?.toJson() as Any,
"subscriptionGroupIdentifier": subscriptionGroupIdentifier ?? "",
"subscriptionPeriod": subscriptionPeriod? .toJson() ?? [:],
"introductoryPrice": introPrice,
"discounts": discounts,
]
Expand Down Expand Up @@ -170,8 +177,8 @@ public extension PackageType {
func toJson() -> [String: Any] {
return [
"identifier": identifier,
"packageType": packageType.toJson() as Any,
"product": product.toJson(),
"packageType": packageType .toJson() ?? [:],
"product": storeProduct.toJson(),
"offeringIdentifier": offeringIdentifier
]
}
Expand All @@ -187,13 +194,13 @@ public extension PackageType {
"identifier": identifier,
"serverDescription": serverDescription,
"availablePackages": allPack,
"lifetime": lifetime?.toJson() as Any,
"annual": annual?.toJson() as Any,
"sixMonth": sixMonth?.toJson() as Any,
"threeMonth": threeMonth?.toJson() as Any,
"twoMonth": twoMonth?.toJson() as Any,
"monthly": monthly?.toJson() as Any,
"weekly": weekly?.toJson() as Any,
"lifetime": lifetime? .toJson() ?? [:],
"annual": annual? .toJson() ?? [:],
"sixMonth": sixMonth? .toJson() ?? [:],
"threeMonth": threeMonth? .toJson() ?? [:],
"twoMonth": twoMonth? .toJson() ?? [:],
"monthly": monthly? .toJson() ?? [:],
"weekly": weekly? .toJson() ?? [:],
]
}
}
Expand All @@ -205,7 +212,7 @@ public extension PackageType {
allJson[id] = off.toJson()
}
return [
"current": current?.toJson() as Any,
"current": current? .toJson() ?? [:],
"all": allJson
]
}
Expand Down Expand Up @@ -236,7 +243,7 @@ public class CapacitorPurchasesPlugin: CAPPlugin, PurchasesDelegate {
let offJson = offerings?.toJson()
if(offJson != nil) {
call.resolve([
"offerings": offJson as Any
"offerings": offJson ?? [:]
])
} else {
call.reject("getOfferings failed to convert in json")
Expand Down Expand Up @@ -268,7 +275,7 @@ public class CapacitorPurchasesPlugin: CAPPlugin, PurchasesDelegate {
} else {
if purchaserInfo!.entitlements["your_entitlement_id"]?.isActive == true {
call.resolve([
"purchaserInfo": purchaserInfo?.toJson() as Any
"purchaserInfo": purchaserInfo? .toJson() ?? [:]
])
} else {
call.reject("Purchase failed")
Expand All @@ -280,12 +287,12 @@ public class CapacitorPurchasesPlugin: CAPPlugin, PurchasesDelegate {
}

@objc func restoreTransactions(_ call: CAPPluginCall) {
Purchases.shared.restoreTransactions { purchaserInfo, error in
Purchases.shared.restorePurchases { purchaserInfo, error in
if ((error) != nil) {
call.reject("Restore failed")
} else {
call.resolve([
"purchaserInfo": purchaserInfo?.toJson() as Any
"purchaserInfo": purchaserInfo? .toJson() ?? [:]
])
}
}
Expand Down Expand Up @@ -329,7 +336,7 @@ public class CapacitorPurchasesPlugin: CAPPlugin, PurchasesDelegate {
call.reject("Get purchaser info failed")
} else {
call.resolve([
"purchaserInfo": purchaserInfo?.toJson() as Any,
"purchaserInfo": purchaserInfo? .toJson() ?? [:],
])
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "capacitor-purchases",
"version": "0.0.19",
"version": "0.1.0",
"description": "In-app Subscriptions Made Easy with RevenueCat sdk",
"main": "dist/plugin.cjs.js",
"module": "dist/esm/index.js",
Expand Down

0 comments on commit 015b698

Please sign in to comment.