@capgo/native-purchases 8.3.7 → 8.3.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,6 +2,34 @@ require 'json'
2
2
 
3
3
  package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
4
4
 
5
+ def has_storekit_265_sdk?
6
+ developer_dirs = [
7
+ ENV['DEVELOPER_DIR'],
8
+ '/Applications/Xcode.app/Contents/Developer'
9
+ ].compact
10
+ sdk_roots = [ENV['SDKROOT']].compact
11
+
12
+ developer_dirs.each do |developer_dir|
13
+ sdk_roots.concat([
14
+ File.join(developer_dir, 'Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk'),
15
+ File.join(developer_dir, 'Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk')
16
+ ])
17
+ end
18
+
19
+ sdk_roots.any? do |sdk_root|
20
+ module_path = File.join(
21
+ sdk_root,
22
+ 'System/Library/Frameworks/StoreKit.framework/Modules/StoreKit.swiftmodule'
23
+ )
24
+ Dir[File.join(module_path, '*.swiftinterface')].any? do |path|
25
+ contents = File.read(path)
26
+ contents.include?('BillingPlanType') && contents.include?('pricingTerms')
27
+ rescue StandardError
28
+ false
29
+ end
30
+ end
31
+ end
32
+
5
33
  Pod::Spec.new do |s|
6
34
  s.name = 'CapgoNativePurchases'
7
35
  s.version = package['version']
@@ -15,4 +43,7 @@ Pod::Spec.new do |s|
15
43
  s.ios.deployment_target = '15.0'
16
44
  s.dependency 'Capacitor'
17
45
  s.swift_version = '5.1'
46
+ s.pod_target_xcconfig = {
47
+ 'OTHER_SWIFT_FLAGS' => has_storekit_265_sdk? ? '$(inherited) -D STOREKIT_26_5' : '$(inherited)'
48
+ }
18
49
  end
package/Package.swift CHANGED
@@ -1,6 +1,44 @@
1
1
  // swift-tools-version: 5.9
2
+ import Foundation
2
3
  import PackageDescription
3
4
 
5
+ func hasStoreKit265SDK() -> Bool {
6
+ let environment = ProcessInfo.processInfo.environment
7
+ let developerDirs = [
8
+ environment["DEVELOPER_DIR"],
9
+ "/Applications/Xcode.app/Contents/Developer"
10
+ ].compactMap { $0 }
11
+ var sdkRoots = [environment["SDKROOT"]].compactMap { $0 }
12
+
13
+ for developerDir in developerDirs {
14
+ sdkRoots.append(contentsOf: [
15
+ "\(developerDir)/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk",
16
+ "\(developerDir)/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk"
17
+ ])
18
+ }
19
+
20
+ for sdkRoot in sdkRoots {
21
+ let modulePath = "\(sdkRoot)/System/Library/Frameworks/StoreKit.framework/Modules/StoreKit.swiftmodule"
22
+ guard let interfaceFiles = try? FileManager.default.contentsOfDirectory(atPath: modulePath) else {
23
+ continue
24
+ }
25
+
26
+ for fileName in interfaceFiles where fileName.hasSuffix(".swiftinterface") {
27
+ let fileURL = URL(fileURLWithPath: modulePath).appendingPathComponent(fileName)
28
+ guard let contents = try? String(contentsOf: fileURL) else {
29
+ continue
30
+ }
31
+ if contents.contains("BillingPlanType") && contents.contains("pricingTerms") {
32
+ return true
33
+ }
34
+ }
35
+ }
36
+
37
+ return false
38
+ }
39
+
40
+ let storeKitSwiftSettings: [SwiftSetting] = hasStoreKit265SDK() ? [.define("STOREKIT_26_5")] : []
41
+
4
42
  let package = Package(
5
43
  name: "CapgoNativePurchases",
6
44
  platforms: [.iOS(.v15)],
@@ -19,7 +57,8 @@ let package = Package(
19
57
  .product(name: "Capacitor", package: "capacitor-swift-pm"),
20
58
  .product(name: "Cordova", package: "capacitor-swift-pm")
21
59
  ],
22
- path: "ios/Sources/NativePurchasesPlugin"),
60
+ path: "ios/Sources/NativePurchasesPlugin",
61
+ swiftSettings: storeKitSwiftSettings),
23
62
  .testTarget(
24
63
  name: "NativePurchasesPluginTests",
25
64
  dependencies: ["NativePurchasesPlugin"],
package/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # native-purchases
2
- <a href="https://capgo.app/"><img src='https://raw.githubusercontent.com/Cap-go/capgo/main/assets/capgo_banner.png' alt='Capgo - Instant updates for capacitor'/></a>
2
+ <a href="https://capgo.app/"><img src="https://capgo.app/readme-banner.svg?repo=Cap-go/capacitor-native-purchases" alt="Capgo - Instant updates for Capacitor" /></a>
3
3
 
4
4
  <div align="center">
5
5
  <h2><a href="https://capgo.app/?ref=plugin_native_purchases"> ➡️ Get Instant updates for your App with Capgo</a></h2>
@@ -1678,6 +1678,7 @@ This approach balances immediate user gratification with proper server-side vali
1678
1678
  * [`addListener('transactionVerificationFailed', ...)`](#addlistenertransactionverificationfailed-)
1679
1679
  * [`removeAllListeners()`](#removealllisteners)
1680
1680
  * [Interfaces](#interfaces)
1681
+ * [Type Aliases](#type-aliases)
1681
1682
  * [Enums](#enums)
1682
1683
 
1683
1684
  </docgen-index>
@@ -1758,14 +1759,14 @@ to determine if they should be grandfathered into free features.
1758
1759
  ### purchaseProduct(...)
1759
1760
 
1760
1761
  ```typescript
1761
- purchaseProduct(options: { productIdentifier: string; planIdentifier?: string; productType?: PURCHASE_TYPE; quantity?: number; appAccountToken?: string; isConsumable?: boolean; autoAcknowledgePurchases?: boolean; }) => Promise<Transaction>
1762
+ purchaseProduct(options: { productIdentifier: string; planIdentifier?: string; productType?: PURCHASE_TYPE; quantity?: number; billingPlanType?: 'monthly' | 'upFront'; appAccountToken?: string; isConsumable?: boolean; autoAcknowledgePurchases?: boolean; }) => Promise<Transaction>
1762
1763
  ```
1763
1764
 
1764
1765
  Started purchase process for the given product.
1765
1766
 
1766
- | Param | Type | Description |
1767
- | ------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------- |
1768
- | **`options`** | <code>{ productIdentifier: string; planIdentifier?: string; productType?: <a href="#purchase_type">PURCHASE_TYPE</a>; quantity?: number; appAccountToken?: string; isConsumable?: boolean; autoAcknowledgePurchases?: boolean; }</code> | - The product to purchase |
1767
+ | Param | Type | Description |
1768
+ | ------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------- |
1769
+ | **`options`** | <code>{ productIdentifier: string; planIdentifier?: string; productType?: <a href="#purchase_type">PURCHASE_TYPE</a>; quantity?: number; billingPlanType?: 'upFront' \| 'monthly'; appAccountToken?: string; isConsumable?: boolean; autoAcknowledgePurchases?: boolean; }</code> | - The product to purchase |
1769
1770
 
1770
1771
  **Returns:** <code>Promise&lt;<a href="#transaction">Transaction</a>&gt;</code>
1771
1772
 
@@ -2037,6 +2038,10 @@ which is useful for determining if users are entitled to features from earlier b
2037
2038
  | **`revocationReason`** | <code>'developerIssue' \| 'other' \| 'unknown'</code> | Reason why Apple revoked the transaction. Possible values: - `"developerIssue"`: Developer-initiated refund or issue - `"other"`: Apple-initiated (customer refund, billing problem, etc.) - `"unknown"`: StoreKit didn't report a specific reason | | 7.13.2 |
2038
2039
  | **`willCancel`** | <code>boolean \| null</code> | Whether the subscription will be cancelled at the end of the billing cycle. - `true`: User has cancelled but subscription remains active until expiration - `false`: Subscription will auto-renew - `null`: Status unknown or not available | <code>null</code> | 1.0.0 |
2039
2040
  | **`subscriptionState`** | <code>'unknown' \| 'subscribed' \| 'expired' \| 'revoked' \| 'inGracePeriod' \| 'inBillingRetryPeriod'</code> | Current subscription state reported by StoreKit. Possible values: - `"subscribed"`: Auto-renewing and in good standing - `"expired"`: Lapsed with no access - `"revoked"`: Access removed due to refund or issue - `"inGracePeriod"`: Payment issue but still in grace access window - `"inBillingRetryPeriod"`: StoreKit retrying failed billing - `"unknown"`: StoreKit did not report a state | | 7.13.2 |
2041
+ | **`billingPlanType`** | <code><a href="#subscriptionbillingplantype">SubscriptionBillingPlanType</a></code> | StoreKit billing plan type for auto-renewable subscriptions. - `"upFront"`: Standard subscription billing for the full billing period. - `"monthly"`: Monthly billing with a 12-month commitment. - `"unknown"`: StoreKit returned a future or unsupported value. | | 8.3.8 |
2042
+ | **`commitmentInfo`** | <code><a href="#transactioncommitmentinfo">TransactionCommitmentInfo</a></code> | Commitment metadata for monthly subscriptions with a 12-month commitment. Use `expirationDate` here only to display commitment progress. Continue using the top-level `expirationDate` to decide whether the current billing period grants entitlement access. | | 8.3.8 |
2043
+ | **`renewalInfo`** | <code><a href="#subscriptionrenewalinfo">SubscriptionRenewalInfo</a></code> | StoreKit renewal metadata for auto-renewable subscriptions. `willAutoRenew` here describes the next billing period. For monthly commitment subscriptions, `commitmentInfo.willAutoRenew` describes whether the next 12-month commitment renews after the current commitment ends. | | 8.3.8 |
2044
+ | **`currencyCode`** | <code>string</code> | Currency code associated with StoreKit transaction pricing metadata. | | 8.3.8 |
2040
2045
  | **`purchaseState`** | <code>string</code> | Purchase state of the transaction (numeric string value). **Android Values:** - `"1"`: Purchase completed and valid (PURCHASED state) - `"0"`: Payment pending (PENDING state, e.g., cash payment processing) - Other numeric values: Various other states Always check `purchaseState === "1"` on Android to verify a valid purchase. Refunded purchases typically disappear from getPurchases() rather than showing a different state. | | 1.0.0 |
2041
2046
  | **`orderId`** | <code>string</code> | Order ID associated with the transaction. Use this for server-side verification on Android. This is the Google Play order ID. | | 1.0.0 |
2042
2047
  | **`purchaseToken`** | <code>string</code> | Purchase token associated with the transaction. **This is the full verified purchase token from Google Play.** Send this to your backend for server-side validation with Google Play Developer API. This is the Android equivalent of iOS's receipt field. **For backend validation:** - Use Google Play Developer API v3 to verify the purchase - API endpoint: androidpublisher.purchases.products.get() or purchases.subscriptions.get() - This token contains all data needed for validation with Google servers - Can also be used for subscription status checks and cancellation detection | | 1.0.0 |
@@ -2051,33 +2056,103 @@ which is useful for determining if users are entitled to features from earlier b
2051
2056
  | **`isInGracePeriod`** | <code>boolean</code> | Whether the transaction is in a grace period. Grace period allows users to fix payment issues while maintaining access. You typically want to continue providing access during this time. - `true`: Subscription payment failed but user still has access - `false`: Not in grace period | | 1.0.0 |
2052
2057
 
2053
2058
 
2059
+ #### TransactionCommitmentInfo
2060
+
2061
+ | Prop | Type | Description |
2062
+ | ------------------------- | ------------------- | ---------------------------------------------------- |
2063
+ | **`billingPeriodNumber`** | <code>number</code> | Current billing period number within the commitment. |
2064
+ | **`totalBillingPeriods`** | <code>number</code> | Total number of billing periods in the commitment. |
2065
+ | **`expirationDate`** | <code>string</code> | End of the full commitment, in ISO 8601 format. |
2066
+ | **`price`** | <code>number</code> | Total commitment price in the local currency. |
2067
+
2068
+
2069
+ #### SubscriptionRenewalInfo
2070
+
2071
+ | Prop | Type | Description |
2072
+ | ---------------------------- | ----------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------ |
2073
+ | **`willAutoRenew`** | <code>boolean</code> | Whether the next billing period will renew. |
2074
+ | **`autoRenewProductId`** | <code>string</code> | <a href="#product">Product</a> StoreKit will renew into for the next billing period. |
2075
+ | **`renewalBillingPlanType`** | <code><a href="#subscriptionbillingplantype">SubscriptionBillingPlanType</a></code> | Billing plan StoreKit will use for the next billing period. |
2076
+ | **`renewalDate`** | <code>string</code> | Next billing period renewal date, in ISO 8601 format. |
2077
+ | **`renewalPrice`** | <code>number</code> | Next billing period renewal price in the local currency. |
2078
+ | **`currencyCode`** | <code>string</code> | Currency code for renewal pricing metadata. |
2079
+ | **`commitmentInfo`** | <code><a href="#renewalcommitmentinfo">RenewalCommitmentInfo</a></code> | Commitment renewal metadata for monthly subscriptions with a 12-month commitment. |
2080
+
2081
+
2082
+ #### RenewalCommitmentInfo
2083
+
2084
+ | Prop | Type | Description |
2085
+ | ---------------------------- | ----------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------ |
2086
+ | **`autoRenewProductId`** | <code>string</code> | <a href="#product">Product</a> StoreKit will renew into after the commitment ends. |
2087
+ | **`willAutoRenew`** | <code>boolean</code> | Whether the subscription renews into another commitment after the current commitment ends. |
2088
+ | **`renewalBillingPlanType`** | <code><a href="#subscriptionbillingplantype">SubscriptionBillingPlanType</a></code> | Billing plan StoreKit will use for the next commitment or renewal. |
2089
+ | **`renewalDate`** | <code>string</code> | Renewal date for the next commitment or renewal, in ISO 8601 format. |
2090
+ | **`renewalPrice`** | <code>number</code> | Renewal price in the local currency. |
2091
+
2092
+
2054
2093
  #### Product
2055
2094
 
2056
- | Prop | Type | Description |
2057
- | --------------------------------- | ----------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
2058
- | **`identifier`** | <code>string</code> | <a href="#product">Product</a> Id. Android subscriptions note: - `identifier` is the base plan ID (`offerDetails.getBasePlanId()`). - `planIdentifier` is the subscription product ID (`productDetails.getProductId()`). If you group/filter Android subscription results by `identifier`, you are grouping by base plan. |
2059
- | **`description`** | <code>string</code> | Description of the product. |
2060
- | **`title`** | <code>string</code> | Title of the product. |
2061
- | **`price`** | <code>number</code> | Price of the product in the local currency. |
2062
- | **`priceString`** | <code>string</code> | Formatted price of the item, including its currency sign, such as €3.99. |
2063
- | **`currencyCode`** | <code>string</code> | Currency code for price and original price. |
2064
- | **`currencySymbol`** | <code>string</code> | Currency symbol for price and original price. |
2065
- | **`isFamilyShareable`** | <code>boolean</code> | Boolean indicating if the product is sharable with family |
2066
- | **`subscriptionGroupIdentifier`** | <code>string</code> | Group identifier for the product. |
2067
- | **`planIdentifier`** | <code>string</code> | Android subscriptions only: Google Play product identifier tied to the offer/base plan set. |
2068
- | **`offerToken`** | <code>string</code> | Android subscriptions only: offer token required when purchasing specific offers. |
2069
- | **`offerId`** | <code>string \| null</code> | Android subscriptions only: offer identifier (null/undefined for base offers). |
2070
- | **`subscriptionPeriod`** | <code><a href="#subscriptionperiod">SubscriptionPeriod</a></code> | The <a href="#product">Product</a> subscription group identifier. |
2071
- | **`introductoryPrice`** | <code><a href="#skproductdiscount">SKProductDiscount</a> \| null</code> | The <a href="#product">Product</a> introductory Price. |
2072
- | **`discounts`** | <code>SKProductDiscount[]</code> | The <a href="#product">Product</a> discounts list. |
2095
+ | Prop | Type | Description | Since |
2096
+ | --------------------------------- | ----------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
2097
+ | **`identifier`** | <code>string</code> | <a href="#product">Product</a> Id. Android subscriptions note: - `identifier` is the base plan ID (`offerDetails.getBasePlanId()`). - `planIdentifier` is the subscription product ID (`productDetails.getProductId()`). If you group/filter Android subscription results by `identifier`, you are grouping by base plan. | |
2098
+ | **`description`** | <code>string</code> | Description of the product. | |
2099
+ | **`title`** | <code>string</code> | Title of the product. | |
2100
+ | **`price`** | <code>number</code> | Price of the product in the local currency. | |
2101
+ | **`priceString`** | <code>string</code> | Formatted price of the item, including its currency sign, such as €3.99. | |
2102
+ | **`currencyCode`** | <code>string</code> | Currency code for price and original price. | |
2103
+ | **`currencySymbol`** | <code>string</code> | Currency symbol for price and original price. | |
2104
+ | **`isFamilyShareable`** | <code>boolean</code> | Boolean indicating if the product is sharable with family | |
2105
+ | **`subscriptionGroupIdentifier`** | <code>string</code> | Group identifier for the product. | |
2106
+ | **`planIdentifier`** | <code>string</code> | Android subscriptions only: Google Play product identifier tied to the offer/base plan set. | |
2107
+ | **`offerToken`** | <code>string</code> | Android subscriptions only: offer token required when purchasing specific offers. | |
2108
+ | **`offerId`** | <code>string \| null</code> | Android subscriptions only: offer identifier (null/undefined for base offers). | |
2109
+ | **`pricingTerms`** | <code>SubscriptionPricingTerms[]</code> | iOS subscriptions only: StoreKit pricing terms by billing plan. For subscriptions with a monthly billing plan and 12-month commitment, this includes both the standard up-front plan and the monthly commitment plan. Display both `billingDisplayPrice` and `commitmentInfo.priceString` before starting a monthly commitment purchase. | 8.3.8 |
2110
+ | **`subscriptionPeriod`** | <code><a href="#subscriptionperiod">SubscriptionPeriod</a></code> | The <a href="#product">Product</a> subscription group identifier. | |
2111
+ | **`introductoryPrice`** | <code><a href="#skproductdiscount">SKProductDiscount</a> \| null</code> | The <a href="#product">Product</a> introductory Price. | |
2112
+ | **`discounts`** | <code>SKProductDiscount[]</code> | The <a href="#product">Product</a> discounts list. | |
2113
+
2114
+
2115
+ #### SubscriptionPricingTerms
2116
+
2117
+ | Prop | Type | Description |
2118
+ | ------------------------- | ----------------------------------------------------------------------------------- | ------------------------------------------------------------- |
2119
+ | **`billingPlanType`** | <code><a href="#subscriptionbillingplantype">SubscriptionBillingPlanType</a></code> | Billing plan represented by this pricing entry. |
2120
+ | **`commitmentInfo`** | <code><a href="#productcommitmentinfo">ProductCommitmentInfo</a></code> | Total commitment details for this billing plan. |
2121
+ | **`billingDisplayPrice`** | <code>string</code> | Formatted price for each billing period. |
2122
+ | **`billingPrice`** | <code>number</code> | Numeric price for each billing period. |
2123
+ | **`billingPeriod`** | <code><a href="#subscriptionperiod">SubscriptionPeriod</a></code> | Duration of each billing period. |
2124
+ | **`subscriptionOffers`** | <code>StoreKitSubscriptionOffer[]</code> | StoreKit subscription offers that apply to this billing plan. |
2125
+
2126
+
2127
+ #### ProductCommitmentInfo
2128
+
2129
+ | Prop | Type | Description |
2130
+ | ----------------- | ----------------------------------------------------------------- | --------------------------------------------- |
2131
+ | **`price`** | <code>number</code> | Total commitment price in the local currency. |
2132
+ | **`priceString`** | <code>string</code> | Formatted total commitment price. |
2133
+ | **`period`** | <code><a href="#subscriptionperiod">SubscriptionPeriod</a></code> | Full commitment period. |
2073
2134
 
2074
2135
 
2075
2136
  #### SubscriptionPeriod
2076
2137
 
2077
- | Prop | Type | Description |
2078
- | ------------------- | ------------------- | --------------------------------------- |
2079
- | **`numberOfUnits`** | <code>number</code> | The Subscription Period number of unit. |
2080
- | **`unit`** | <code>number</code> | The Subscription Period unit. |
2138
+ | Prop | Type | Description | Since |
2139
+ | ------------------- | -------------------------------------------------------------- | ---------------------------------------- | ----- |
2140
+ | **`numberOfUnits`** | <code>number</code> | The Subscription Period number of unit. | |
2141
+ | **`unit`** | <code>number</code> | The Subscription Period unit. | |
2142
+ | **`unitString`** | <code>'unknown' \| 'day' \| 'week' \| 'month' \| 'year'</code> | Human-readable subscription period unit. | 8.3.8 |
2143
+
2144
+
2145
+ #### StoreKitSubscriptionOffer
2146
+
2147
+ | Prop | Type | Description |
2148
+ | ----------------- | ----------------------------------------------------------------- | --------------------------------------- |
2149
+ | **`identifier`** | <code>string</code> | StoreKit offer identifier. |
2150
+ | **`type`** | <code>string</code> | StoreKit offer type. |
2151
+ | **`price`** | <code>number</code> | Offer price in the local currency. |
2152
+ | **`priceString`** | <code>string</code> | Formatted offer price. |
2153
+ | **`period`** | <code><a href="#subscriptionperiod">SubscriptionPeriod</a></code> | Offer billing period. |
2154
+ | **`periodCount`** | <code>number</code> | Number of periods the offer applies to. |
2155
+ | **`paymentMode`** | <code>string</code> | StoreKit offer payment mode. |
2081
2156
 
2082
2157
 
2083
2158
  #### SKProductDiscount
@@ -2110,6 +2185,14 @@ which is useful for determining if users are entitled to features from earlier b
2110
2185
  | **`error`** | <code>string</code> | Localized error message describing why verification failed. | 7.13.2 |
2111
2186
 
2112
2187
 
2188
+ ### Type Aliases
2189
+
2190
+
2191
+ #### SubscriptionBillingPlanType
2192
+
2193
+ <code>'upFront' | 'monthly' | 'unknown'</code>
2194
+
2195
+
2113
2196
  ### Enums
2114
2197
 
2115
2198
 
@@ -41,7 +41,7 @@ import org.json.JSONArray;
41
41
  @CapacitorPlugin(name = "NativePurchases")
42
42
  public class NativePurchasesPlugin extends Plugin {
43
43
 
44
- private final String pluginVersion = "8.3.7";
44
+ private final String pluginVersion = "8.3.9";
45
45
  public static final String TAG = "NativePurchases";
46
46
  private static final Phaser semaphoreReady = new Phaser(1);
47
47
  private BillingClient billingClient;