@capgo/native-purchases 8.9.6 → 8.9.8
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.
- package/README.md +178 -49
- package/android/build.gradle +1 -0
- package/android/src/main/java/ee/forgr/nativepurchases/NativePurchasesPlugin.java +116 -27
- package/android/src/main/java/ee/forgr/nativepurchases/ProductPayloadMapper.java +14 -0
- package/android/src/main/java/ee/forgr/nativepurchases/SubscriptionOfferSelector.java +136 -0
- package/dist/docs.json +70 -20
- package/dist/esm/definitions.d.ts +94 -13
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +4 -1
- package/dist/esm/web.js +2 -1
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +1 -1
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +1 -1
- package/dist/plugin.js.map +1 -1
- package/ios/Sources/NativePurchasesPlugin/NativePurchasesPlugin+TransactionFinishing.swift +30 -5
- package/ios/Sources/NativePurchasesPlugin/NativePurchasesPlugin.swift +1 -1
- package/ios/Sources/NativePurchasesPlugin/TransactionHelpers.swift +16 -2
- package/package.json +1 -1
|
@@ -43,7 +43,67 @@ import org.json.JSONArray;
|
|
|
43
43
|
@CapacitorPlugin(name = "NativePurchases")
|
|
44
44
|
public class NativePurchasesPlugin extends Plugin {
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
/** Outcome of choosing a subscription offer token before launching the billing flow. */
|
|
47
|
+
enum SubscriptionOfferPurchaseOutcome {
|
|
48
|
+
/** An offer was selected; {@link SubscriptionOfferPurchaseResult#offerToken} is set. */
|
|
49
|
+
OK,
|
|
50
|
+
/** The product details contained no subscription offers. */
|
|
51
|
+
NO_OFFERS,
|
|
52
|
+
/** An explicit offer token matched nothing in the query result. */
|
|
53
|
+
OFFER_TOKEN_NOT_FOUND
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Result of {@link #resolveSubscriptionOfferForPurchase}. */
|
|
57
|
+
static final class SubscriptionOfferPurchaseResult {
|
|
58
|
+
|
|
59
|
+
final SubscriptionOfferPurchaseOutcome outcome;
|
|
60
|
+
final String offerToken;
|
|
61
|
+
final String basePlanId;
|
|
62
|
+
|
|
63
|
+
private SubscriptionOfferPurchaseResult(SubscriptionOfferPurchaseOutcome outcome, String offerToken, String basePlanId) {
|
|
64
|
+
this.outcome = outcome;
|
|
65
|
+
this.offerToken = offerToken;
|
|
66
|
+
this.basePlanId = basePlanId;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
static SubscriptionOfferPurchaseResult ok(String offerToken, String basePlanId) {
|
|
70
|
+
return new SubscriptionOfferPurchaseResult(SubscriptionOfferPurchaseOutcome.OK, offerToken, basePlanId);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
static SubscriptionOfferPurchaseResult noOffers() {
|
|
74
|
+
return new SubscriptionOfferPurchaseResult(SubscriptionOfferPurchaseOutcome.NO_OFFERS, null, null);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
static SubscriptionOfferPurchaseResult offerTokenNotFound() {
|
|
78
|
+
return new SubscriptionOfferPurchaseResult(SubscriptionOfferPurchaseOutcome.OFFER_TOKEN_NOT_FOUND, null, null);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Selects the subscription offer token for {@link #purchaseProduct}, using the same rules
|
|
84
|
+
* as {@link SubscriptionOfferSelector}.
|
|
85
|
+
*/
|
|
86
|
+
static SubscriptionOfferPurchaseResult resolveSubscriptionOfferForPurchase(
|
|
87
|
+
List<ProductDetails.SubscriptionOfferDetails> subscriptionOffers,
|
|
88
|
+
String planIdentifier,
|
|
89
|
+
String offerToken
|
|
90
|
+
) {
|
|
91
|
+
if (subscriptionOffers == null || subscriptionOffers.isEmpty()) {
|
|
92
|
+
return SubscriptionOfferPurchaseResult.noOffers();
|
|
93
|
+
}
|
|
94
|
+
int selectedIndex = SubscriptionOfferSelector.selectIndex(
|
|
95
|
+
SubscriptionOfferSelector.adapt(subscriptionOffers),
|
|
96
|
+
planIdentifier,
|
|
97
|
+
offerToken
|
|
98
|
+
);
|
|
99
|
+
if (selectedIndex == SubscriptionOfferSelector.NOT_FOUND) {
|
|
100
|
+
return SubscriptionOfferPurchaseResult.offerTokenNotFound();
|
|
101
|
+
}
|
|
102
|
+
ProductDetails.SubscriptionOfferDetails selected = subscriptionOffers.get(selectedIndex);
|
|
103
|
+
return SubscriptionOfferPurchaseResult.ok(selected.getOfferToken(), selected.getBasePlanId());
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
private final String pluginVersion = "8.9.8";
|
|
47
107
|
public static final String TAG = "NativePurchases";
|
|
48
108
|
private static final int BILLING_CONNECTION_MAX_ATTEMPTS = 2;
|
|
49
109
|
private static final long BILLING_SETUP_TIMEOUT_SECONDS = 5;
|
|
@@ -67,11 +127,19 @@ public class NativePurchasesPlugin extends Plugin {
|
|
|
67
127
|
call.resolve();
|
|
68
128
|
}
|
|
69
129
|
|
|
130
|
+
/**
|
|
131
|
+
* Acknowledges the purchase whose token is passed as {@code transactionId}, matching finishTransaction on iOS.
|
|
132
|
+
*/
|
|
70
133
|
@PluginMethod
|
|
71
134
|
public void finishTransaction(PluginCall call) {
|
|
72
|
-
call.
|
|
73
|
-
|
|
74
|
-
|
|
135
|
+
String transactionId = call.getString("transactionId");
|
|
136
|
+
if (transactionId == null || transactionId.isEmpty()) {
|
|
137
|
+
call.reject("transactionId is required");
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
// Android transaction IDs are purchase tokens, and Play Billing has no client-side unverified state.
|
|
141
|
+
call.getData().put("purchaseToken", transactionId);
|
|
142
|
+
acknowledgePurchase(call);
|
|
75
143
|
}
|
|
76
144
|
|
|
77
145
|
@PluginMethod
|
|
@@ -299,6 +367,19 @@ public class NativePurchasesPlugin extends Plugin {
|
|
|
299
367
|
}
|
|
300
368
|
}
|
|
301
369
|
|
|
370
|
+
/**
|
|
371
|
+
* Reject a purchase whose {@code offerToken} matched no current offer.
|
|
372
|
+
*
|
|
373
|
+
* Shared by the subscription and one-time paths because `definitions.ts`
|
|
374
|
+
* documents that rejection as one rule covering both product types, so
|
|
375
|
+
* the two must not drift apart in wording.
|
|
376
|
+
*/
|
|
377
|
+
private void rejectOfferTokenNotFound(PluginCall call, String productIdentifier) {
|
|
378
|
+
NativePurchasesLog.d(TAG, "Offer token not found for product: " + productIdentifier);
|
|
379
|
+
closeBillingClient();
|
|
380
|
+
call.reject("Offer token not found for product: " + productIdentifier);
|
|
381
|
+
}
|
|
382
|
+
|
|
302
383
|
private void closeBillingClientLocked() {
|
|
303
384
|
NativePurchasesLog.d(TAG, "closeBillingClient() called");
|
|
304
385
|
if (billingClient != null) {
|
|
@@ -747,10 +828,13 @@ public class NativePurchasesPlugin extends Plugin {
|
|
|
747
828
|
call.reject("productType is empty");
|
|
748
829
|
return;
|
|
749
830
|
}
|
|
750
|
-
|
|
751
|
-
|
|
831
|
+
boolean hasOfferToken = offerToken != null && !offerToken.isEmpty();
|
|
832
|
+
if (productType.equals("subs") && !SubscriptionOfferSelector.canSelect(planIdentifier, offerToken)) {
|
|
833
|
+
// The caller named no offer at all. SubscriptionOfferSelector owns
|
|
834
|
+
// this rule: see canSelect for why either value alone is enough,
|
|
835
|
+
// and for what it deliberately does not catch.
|
|
752
836
|
NativePurchasesLog.d(TAG, "Error: planIdentifier cannot be empty if productType is subs");
|
|
753
|
-
call.reject("planIdentifier cannot be empty if productType is subs");
|
|
837
|
+
call.reject("planIdentifier cannot be empty if productType is subs unless offerToken is provided");
|
|
754
838
|
return;
|
|
755
839
|
}
|
|
756
840
|
assert quantity != null;
|
|
@@ -812,35 +896,42 @@ public class NativePurchasesPlugin extends Plugin {
|
|
|
812
896
|
BillingFlowParams.ProductDetailsParams.newBuilder().setProductDetails(productDetailsItem);
|
|
813
897
|
if (productType.equals("subs")) {
|
|
814
898
|
NativePurchasesLog.d(TAG, "Processing subscription product");
|
|
815
|
-
//
|
|
816
|
-
|
|
817
|
-
|
|
899
|
+
// Prefer an explicit offerToken, then the planIdentifier's base
|
|
900
|
+
// plan, then the first offer. See SubscriptionOfferSelector.
|
|
901
|
+
List<ProductDetails.SubscriptionOfferDetails> subscriptionOffers =
|
|
902
|
+
productDetailsItem.getSubscriptionOfferDetails();
|
|
818
903
|
NativePurchasesLog.d(
|
|
819
904
|
TAG,
|
|
820
|
-
"Available offer details count: " +
|
|
905
|
+
"Available offer details count: " + (subscriptionOffers == null ? 0 : subscriptionOffers.size())
|
|
821
906
|
);
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
907
|
+
|
|
908
|
+
SubscriptionOfferPurchaseResult subscriptionSelection = resolveSubscriptionOfferForPurchase(
|
|
909
|
+
subscriptionOffers,
|
|
910
|
+
planIdentifier,
|
|
911
|
+
offerToken
|
|
912
|
+
);
|
|
913
|
+
if (subscriptionSelection.outcome == SubscriptionOfferPurchaseOutcome.NO_OFFERS) {
|
|
914
|
+
NativePurchasesLog.w(TAG, "No subscription offer details found for product: " + productIdentifier);
|
|
915
|
+
closeBillingClient();
|
|
916
|
+
call.reject("No subscription offer details found for product: " + productIdentifier);
|
|
917
|
+
return;
|
|
829
918
|
}
|
|
830
|
-
if (
|
|
831
|
-
|
|
832
|
-
|
|
919
|
+
if (subscriptionSelection.outcome == SubscriptionOfferPurchaseOutcome.OFFER_TOKEN_NOT_FOUND) {
|
|
920
|
+
rejectOfferTokenNotFound(call, productIdentifier);
|
|
921
|
+
return;
|
|
833
922
|
}
|
|
834
|
-
|
|
923
|
+
|
|
924
|
+
NativePurchasesLog.d(TAG, "Selected base plan: " + subscriptionSelection.basePlanId);
|
|
925
|
+
productDetailsParams.setOfferToken(subscriptionSelection.offerToken);
|
|
835
926
|
NativePurchasesLog.d(
|
|
836
927
|
TAG,
|
|
837
|
-
"Set offer token: " + NativePurchasesLog.redactSensitive(
|
|
928
|
+
"Set offer token: " + NativePurchasesLog.redactSensitive(subscriptionSelection.offerToken)
|
|
838
929
|
);
|
|
839
930
|
} else if (productType.equals("inapp")) {
|
|
840
931
|
NativePurchasesLog.d(TAG, "Processing in-app product");
|
|
841
932
|
List<ProductDetails.OneTimePurchaseOfferDetails> oneTimeOffers =
|
|
842
933
|
ProductPayloadMapper.resolveOneTimePurchaseOffers(productDetailsItem);
|
|
843
|
-
if (
|
|
934
|
+
if (hasOfferToken) {
|
|
844
935
|
ProductDetails.OneTimePurchaseOfferDetails selectedOffer = null;
|
|
845
936
|
for (ProductDetails.OneTimePurchaseOfferDetails offerDetails : oneTimeOffers) {
|
|
846
937
|
if (offerToken.equals(offerDetails.getOfferToken())) {
|
|
@@ -849,9 +940,7 @@ public class NativePurchasesPlugin extends Plugin {
|
|
|
849
940
|
}
|
|
850
941
|
}
|
|
851
942
|
if (selectedOffer == null) {
|
|
852
|
-
|
|
853
|
-
closeBillingClient();
|
|
854
|
-
call.reject("Offer token not found for product: " + productIdentifier);
|
|
943
|
+
rejectOfferTokenNotFound(call, productIdentifier);
|
|
855
944
|
return;
|
|
856
945
|
}
|
|
857
946
|
productDetailsParams.setOfferToken(selectedOffer.getOfferToken());
|
|
@@ -87,6 +87,14 @@ final class ProductPayloadMapper {
|
|
|
87
87
|
List<ProductDetails.PricingPhase> phases =
|
|
88
88
|
offerDetails.getPricingPhases() == null ? List.of() : offerDetails.getPricingPhases().getPricingPhaseList();
|
|
89
89
|
|
|
90
|
+
ProductDetails.InstallmentPlanDetails installmentPlanDetails = offerDetails.getInstallmentPlanDetails();
|
|
91
|
+
if (installmentPlanDetails != null) {
|
|
92
|
+
int commitmentPayments = installmentPlanDetails.getInstallmentPlanCommitmentPaymentsCount();
|
|
93
|
+
if (commitmentPayments > 0) {
|
|
94
|
+
product.put("subscriptionBillingCycles", commitmentPayments);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
90
98
|
ProductDetails.PricingPhase standardPhase = findStandardPricingPhase(phases);
|
|
91
99
|
if (standardPhase != null) {
|
|
92
100
|
double price = standardPhase.getPriceAmountMicros() / 1_000_000.0;
|
|
@@ -94,6 +102,12 @@ final class ProductPayloadMapper {
|
|
|
94
102
|
product.put("priceString", standardPhase.getFormattedPrice());
|
|
95
103
|
product.put("currencyCode", standardPhase.getPriceCurrencyCode());
|
|
96
104
|
product.put("currencySymbol", currencySymbol(standardPhase.getPriceCurrencyCode()));
|
|
105
|
+
int recurrenceMode = standardPhase.getRecurrenceMode();
|
|
106
|
+
if (recurrenceMode == RECURRENCE_MODE_INFINITE_RECURRING) {
|
|
107
|
+
product.put("subscriptionPeriod", subscriptionPeriodFromBillingPeriod(standardPhase.getBillingPeriod()));
|
|
108
|
+
} else if (recurrenceMode == RECURRENCE_MODE_FINITE_RECURRING && installmentPlanDetails != null) {
|
|
109
|
+
product.put("subscriptionPeriod", subscriptionPeriodFromBillingPeriod(standardPhase.getBillingPeriod()));
|
|
110
|
+
}
|
|
97
111
|
}
|
|
98
112
|
|
|
99
113
|
String currencyCode = standardPhase != null ? standardPhase.getPriceCurrencyCode() : product.getString("currencyCode", "");
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
package ee.forgr.nativepurchases;
|
|
2
|
+
|
|
3
|
+
import com.android.billingclient.api.ProductDetails;
|
|
4
|
+
import java.util.ArrayList;
|
|
5
|
+
import java.util.List;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Chooses which of a subscription's offers a purchase should use.
|
|
9
|
+
*
|
|
10
|
+
* Play returns one {@link ProductDetails.SubscriptionOfferDetails} per
|
|
11
|
+
* (base plan, offer) pair, and the offer token the billing flow is given is
|
|
12
|
+
* what decides the price actually charged. Selecting by base plan alone is
|
|
13
|
+
* therefore ambiguous as soon as a base plan carries an offer: the base plan
|
|
14
|
+
* and the offer are two entries with the same {@code basePlanId}, and taking
|
|
15
|
+
* the first means the caller cannot say whether the offer applies.
|
|
16
|
+
*
|
|
17
|
+
* Order of preference:
|
|
18
|
+
* <ol>
|
|
19
|
+
* <li>an explicit {@code offerToken}, matched exactly: the caller named a
|
|
20
|
+
* specific offer, which is the most specific thing they can say;</li>
|
|
21
|
+
* <li>the first offer whose base plan matches {@code planIdentifier};</li>
|
|
22
|
+
* <li>the first offer the store returned.</li>
|
|
23
|
+
* </ol>
|
|
24
|
+
*
|
|
25
|
+
* An {@code offerToken} that matches nothing is reported rather than
|
|
26
|
+
* silently falling through to (2) or (3): it means the caller asked for an
|
|
27
|
+
* offer that is not on offer, usually a token cached past its query, and
|
|
28
|
+
* charging a different price than the one they named is the worse outcome.
|
|
29
|
+
* This mirrors how the one-time purchase path already treats an unknown
|
|
30
|
+
* token.
|
|
31
|
+
*
|
|
32
|
+
* An index is returned rather than an offer, so the caller indexes back into
|
|
33
|
+
* Play's own list. The {@link Offer} seam exists only so the choice can be
|
|
34
|
+
* unit-tested without constructing Billing objects, the same way
|
|
35
|
+
* {@link PurchaseActionDecider} can be; handing the wrapper back would make
|
|
36
|
+
* the caller unwrap to reach something it already holds.
|
|
37
|
+
*/
|
|
38
|
+
public final class SubscriptionOfferSelector {
|
|
39
|
+
|
|
40
|
+
/** No offer to use; see {@link #selectIndex}. */
|
|
41
|
+
static final int NOT_FOUND = -1;
|
|
42
|
+
|
|
43
|
+
private SubscriptionOfferSelector() {}
|
|
44
|
+
|
|
45
|
+
/** The fields of an offer this choice depends on. */
|
|
46
|
+
interface Offer {
|
|
47
|
+
String getBasePlanId();
|
|
48
|
+
|
|
49
|
+
String getOfferToken();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The index of the offer to purchase, or {@link #NOT_FOUND}.
|
|
54
|
+
*
|
|
55
|
+
* {@code NOT_FOUND} means either that there was nothing to choose from,
|
|
56
|
+
* or that an explicit {@code offerToken} matched none of the offers. The
|
|
57
|
+
* caller tells those apart by checking the list before calling, because
|
|
58
|
+
* it is the one that can name the product that had no offers.
|
|
59
|
+
*/
|
|
60
|
+
static int selectIndex(List<Offer> offers, String planIdentifier, String offerToken) {
|
|
61
|
+
if (offers == null || offers.isEmpty()) {
|
|
62
|
+
return NOT_FOUND;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (isPresent(offerToken)) {
|
|
66
|
+
for (int i = 0; i < offers.size(); i++) {
|
|
67
|
+
if (offerToken.equals(offers.get(i).getOfferToken())) {
|
|
68
|
+
return i;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return NOT_FOUND;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (isPresent(planIdentifier)) {
|
|
75
|
+
for (int i = 0; i < offers.size(); i++) {
|
|
76
|
+
if (planIdentifier.equals(offers.get(i).getBasePlanId())) {
|
|
77
|
+
return i;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return 0;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Whether a subscription purchase named an offer at all.
|
|
87
|
+
*
|
|
88
|
+
* Either value is enough on its own: an {@code offerToken} names one
|
|
89
|
+
* specific offer, and a {@code planIdentifier} names the base plan whose
|
|
90
|
+
* first offer {@link #selectIndex} then takes. Only when both are absent
|
|
91
|
+
* has the caller said nothing to go on, and such a purchase is rejected
|
|
92
|
+
* rather than charged whichever offer the store happened to return first.
|
|
93
|
+
*
|
|
94
|
+
* Saying something is not the same as saying something that matches: a
|
|
95
|
+
* {@code planIdentifier} matching no base plan still falls back to the
|
|
96
|
+
* first offer, as it did before this was checked.
|
|
97
|
+
*/
|
|
98
|
+
static boolean canSelect(String planIdentifier, String offerToken) {
|
|
99
|
+
return isPresent(offerToken) || isPresent(planIdentifier);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
private static boolean isPresent(String value) {
|
|
103
|
+
return value != null && !value.isEmpty();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** Adapt Play's own offer details to {@link Offer}. */
|
|
107
|
+
static List<Offer> adapt(List<ProductDetails.SubscriptionOfferDetails> offerDetailsList) {
|
|
108
|
+
if (offerDetailsList == null) {
|
|
109
|
+
return new ArrayList<>();
|
|
110
|
+
}
|
|
111
|
+
List<Offer> offers = new ArrayList<>(offerDetailsList.size());
|
|
112
|
+
for (ProductDetails.SubscriptionOfferDetails offerDetails : offerDetailsList) {
|
|
113
|
+
offers.add(new SubscriptionOfferDetailsAdapter(offerDetails));
|
|
114
|
+
}
|
|
115
|
+
return offers;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
private static final class SubscriptionOfferDetailsAdapter implements Offer {
|
|
119
|
+
|
|
120
|
+
private final ProductDetails.SubscriptionOfferDetails details;
|
|
121
|
+
|
|
122
|
+
SubscriptionOfferDetailsAdapter(ProductDetails.SubscriptionOfferDetails details) {
|
|
123
|
+
this.details = details;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
@Override
|
|
127
|
+
public String getBasePlanId() {
|
|
128
|
+
return details.getBasePlanId();
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
@Override
|
|
132
|
+
public String getOfferToken() {
|
|
133
|
+
return details.getOfferToken();
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
package/dist/docs.json
CHANGED
|
@@ -148,11 +148,11 @@
|
|
|
148
148
|
},
|
|
149
149
|
{
|
|
150
150
|
"name": "param",
|
|
151
|
-
"text": "options.planIdentifier - Only Android, the identifier of the base plan you want to purchase from Google Play Console.
|
|
151
|
+
"text": "options.planIdentifier - Only Android, the identifier of the base plan you want to purchase from Google Play Console, the value `getProducts()` reports as `Product.identifier` for a subscription, not `Product.planIdentifier`. Required for Android subscriptions unless `offerToken` is given; ignored for one-time products and on iOS."
|
|
152
152
|
},
|
|
153
153
|
{
|
|
154
154
|
"name": "param",
|
|
155
|
-
"text": "options.offerToken - Only Android, the offer token for the selected subscription or one-time product offer. Use the `offerToken` returned by `getProducts()` / `getProduct()`."
|
|
155
|
+
"text": "options.offerToken - Only Android, the offer token for the selected subscription or one-time product offer. Use the `offerToken` returned by `getProducts()` / `getProduct()`. For a subscription it takes precedence over `planIdentifier`, since it names one specific offer, and makes `planIdentifier` optional. When the token is absent from the plugin query result the purchase is rejected instead of falling back to another offer. Google Play may still change what the user can buy after the query. Offer tokens come from a specific product query and go stale, so read one from the same query you purchase from. Omit it to keep the previous behaviour."
|
|
156
156
|
},
|
|
157
157
|
{
|
|
158
158
|
"name": "param",
|
|
@@ -175,7 +175,7 @@
|
|
|
175
175
|
"text": "options.autoAcknowledgePurchases - When false, this purchase is not auto-finished/acknowledged when\n `autoFinishTransactions` is also true. Does not disable auto-finishing on\n the iOS `transactionUpdated` listener; use `configure({ autoFinishTransactions: false })`\n for manual finishing across purchase and recovery flows. Defaults to true.\n - **Android**: Must acknowledge within 3 days or Google Play will refund\n - **iOS**: Unfinished transactions remain in the queue and may block future purchases"
|
|
176
176
|
}
|
|
177
177
|
],
|
|
178
|
-
"docs": "Started purchase process for the given product.",
|
|
178
|
+
"docs": "Started purchase process for the given product.\n\nOn Android, `offerToken` selects which offer is charged. If the token is\nmissing from the product details returned by the plugin's query, the plugin\nrejects the purchase instead of selecting another offer. Other failures can\nalso reject the purchase. Google Play may still show a different checkout,\nfor example if the offer stops being eligible after the query, so the final\nprice is not guaranteed.\nOffer tokens come from a specific product query and go stale, so read\none from the same `getProducts()` / `getProduct()` call you purchase\nfrom.\n\nFor a **subscription** (`productType: 'subs'`) the order is: an explicit\n`offerToken`, then the first offer whose base plan matches\n`planIdentifier`, then the first offer the store returned.\n`planIdentifier` is the **base plan id**, which `getProducts()` reports\nas `Product.identifier`, not `Product.planIdentifier`, which holds the\nPlay product id. It is required unless an `offerToken` is given, since\na token already identifies one offer on its own.\n\nFor a **one-time product** (`productType: 'inapp'`) there is no base\nplan, so `planIdentifier` plays no part, and an `offerToken` selects one\nof the product's purchase offers. Without a token no offer token is set\nat all whenever the product still has a backward-compatible purchase\noption, which leaves the choice to Play: it charges whichever buy\npurchase option is marked backward-compatible, which is the first\n*created* one by default and another only if one was marked\n`legacyCompatible`. Either way it need not be the first offer\n`getProducts()` returned. Only for a product with no backward-compatible\noption does the first offer in the list get used. So pass the token\nwhenever a specific one-time offer matters.",
|
|
179
179
|
"complexTypes": [
|
|
180
180
|
"Transaction",
|
|
181
181
|
"PURCHASE_TYPE"
|
|
@@ -440,19 +440,23 @@
|
|
|
440
440
|
},
|
|
441
441
|
{
|
|
442
442
|
"name": "finishTransaction",
|
|
443
|
-
"signature": "(options: { transactionId: string; }) => Promise<void>",
|
|
443
|
+
"signature": "(options: { transactionId: string; allowUnverified?: boolean; }) => Promise<void>",
|
|
444
444
|
"parameters": [
|
|
445
445
|
{
|
|
446
446
|
"name": "options",
|
|
447
447
|
"docs": "",
|
|
448
|
-
"type": "{ transactionId: string; }"
|
|
448
|
+
"type": "{ transactionId: string; allowUnverified?: boolean | undefined; }"
|
|
449
449
|
}
|
|
450
450
|
],
|
|
451
451
|
"returns": "Promise<void>",
|
|
452
452
|
"tags": [
|
|
453
453
|
{
|
|
454
454
|
"name": "param",
|
|
455
|
-
"text": "options.transactionId
|
|
455
|
+
"text": "options.transactionId Transaction ID from the `Transaction` object (numeric string on iOS, purchase token on Android)."
|
|
456
|
+
},
|
|
457
|
+
{
|
|
458
|
+
"name": "param",
|
|
459
|
+
"text": "options.allowUnverified Finish the transaction even if StoreKit could not verify it. Defaults to `false`."
|
|
456
460
|
},
|
|
457
461
|
{
|
|
458
462
|
"name": "since",
|
|
@@ -464,25 +468,35 @@
|
|
|
464
468
|
},
|
|
465
469
|
{
|
|
466
470
|
"name": "platform",
|
|
467
|
-
"text": "android
|
|
471
|
+
"text": "android Acknowledges the purchase with Google Play"
|
|
468
472
|
}
|
|
469
473
|
],
|
|
470
|
-
"docs": "Finish a StoreKit 2 transaction on iOS after you validate delivery on your backend.\n\nEquivalent to `acknowledgePurchase({ purchaseToken: transactionId })` on iOS. Safe to call more\nthan once; finishing an already finished transaction resolves successfully.\n\n**Android**:
|
|
474
|
+
"docs": "Finish a StoreKit 2 transaction on iOS after you validate delivery on your backend.\n\nEquivalent to `acknowledgePurchase({ purchaseToken: transactionId })` on iOS. Safe to call more\nthan once; finishing an already finished transaction resolves successfully.\n\nA transaction StoreKit could not verify is rejected unless `allowUnverified` is `true`. Finishing\none only removes it from the queue so StoreKit stops re-delivering it; never grant entitlements from it.\n\n**Android**: Acknowledges the purchase, using `transactionId` as the purchase token. Use\n`consumePurchase({ purchaseToken })` instead for consumables that must be purchasable again.\n`allowUnverified` has no effect because Play Billing has no client-side unverified state.",
|
|
471
475
|
"complexTypes": [],
|
|
472
476
|
"slug": "finishtransaction"
|
|
473
477
|
},
|
|
474
478
|
{
|
|
475
479
|
"name": "getUnfinishedTransactions",
|
|
476
|
-
"signature": "() => Promise<{ transactions: Transaction[]; }>",
|
|
477
|
-
"parameters": [
|
|
480
|
+
"signature": "(options?: { includeUnverified?: boolean | undefined; } | undefined) => Promise<{ transactions: Transaction[]; }>",
|
|
481
|
+
"parameters": [
|
|
482
|
+
{
|
|
483
|
+
"name": "options",
|
|
484
|
+
"docs": "",
|
|
485
|
+
"type": "{ includeUnverified?: boolean | undefined; } | undefined"
|
|
486
|
+
}
|
|
487
|
+
],
|
|
478
488
|
"returns": "Promise<{ transactions: Transaction[]; }>",
|
|
479
489
|
"tags": [
|
|
490
|
+
{
|
|
491
|
+
"name": "param",
|
|
492
|
+
"text": "options.includeUnverified Also return unfinished transactions StoreKit could not verify. Defaults to `false`."
|
|
493
|
+
},
|
|
480
494
|
{
|
|
481
495
|
"name": "since",
|
|
482
496
|
"text": "8.9.0"
|
|
483
497
|
}
|
|
484
498
|
],
|
|
485
|
-
"docs": "Returns transactions that still need finishing on iOS, or unacknowledged purchases on Android.\n\nUse on app launch when `autoFinishTransactions` is `false` to recover work after a restart.\n\n**Android recovery:** After validation, call `consumePurchase({ purchaseToken })` for consumable\nin-app products (acknowledges and consumes). Call `acknowledgePurchase({ purchaseToken })` for\nnon-consumables and subscriptions. Includes only purchases in the `PURCHASED` state that are not\nyet acknowledged. Pending purchases are excluded until Google Play marks them purchased.",
|
|
499
|
+
"docs": "Returns transactions that still need finishing on iOS, or unacknowledged purchases on Android.\n\nUse on app launch when `autoFinishTransactions` is `false` to recover work after a restart.\n\n**Android recovery:** After validation, call `consumePurchase({ purchaseToken })` for consumable\nin-app products (acknowledges and consumes). Call `acknowledgePurchase({ purchaseToken })` for\nnon-consumables and subscriptions. Includes only purchases in the `PURCHASED` state that are not\nyet acknowledged. Pending purchases are excluded until Google Play marks them purchased.\n\n**Unverified transactions:** With `includeUnverified: true`, iOS also returns transactions StoreKit\ncould not verify, each with `verificationError` set. Do not grant entitlements from those; pass them\nto `finishTransaction({ transactionId, allowUnverified: true })` to clear them. Android has no\nclient-side unverified state, so the option does not change its results.",
|
|
486
500
|
"complexTypes": [
|
|
487
501
|
"Transaction"
|
|
488
502
|
],
|
|
@@ -1419,6 +1433,26 @@
|
|
|
1419
1433
|
"docs": "Whether the StoreKit transaction still needs to be finished with `finishTransaction()`.\n\nPresent when the transaction is returned from `getUnfinishedTransactions()` or from\n`transactionUpdated` while `autoFinishTransactions` is `false`.",
|
|
1420
1434
|
"complexTypes": [],
|
|
1421
1435
|
"type": "boolean | undefined"
|
|
1436
|
+
},
|
|
1437
|
+
{
|
|
1438
|
+
"name": "verificationError",
|
|
1439
|
+
"tags": [
|
|
1440
|
+
{
|
|
1441
|
+
"text": "8.10.0",
|
|
1442
|
+
"name": "since"
|
|
1443
|
+
},
|
|
1444
|
+
{
|
|
1445
|
+
"text": "ios Present when StoreKit reports the transaction as unverified",
|
|
1446
|
+
"name": "platform"
|
|
1447
|
+
},
|
|
1448
|
+
{
|
|
1449
|
+
"text": "android Not available (Play Billing has no client-side unverified state)",
|
|
1450
|
+
"name": "platform"
|
|
1451
|
+
}
|
|
1452
|
+
],
|
|
1453
|
+
"docs": "Why StoreKit could not verify this transaction. Treat the transaction as untrusted and do not\ngrant entitlements from it.\n\nPresent only on unverified entries returned by `getUnfinishedTransactions({ includeUnverified: true })`.",
|
|
1454
|
+
"complexTypes": [],
|
|
1455
|
+
"type": "string | undefined"
|
|
1422
1456
|
}
|
|
1423
1457
|
]
|
|
1424
1458
|
},
|
|
@@ -1605,7 +1639,7 @@
|
|
|
1605
1639
|
{
|
|
1606
1640
|
"name": "priceString",
|
|
1607
1641
|
"tags": [],
|
|
1608
|
-
"docs": "Formatted price of the item, including its currency sign, such as €3.99.",
|
|
1642
|
+
"docs": "Formatted price of the item, including its currency sign, such as €3.99.\n\nAndroid subscriptions: set from the standard recurring pricing phase (see\n`ProductPayloadMapper`). When the offer has an introductory phase, `introductoryPrice`\ndescribes that phase, so a pre purchase message should include both or defer confirmation\nto the store sheet.",
|
|
1609
1643
|
"complexTypes": [],
|
|
1610
1644
|
"type": "string"
|
|
1611
1645
|
},
|
|
@@ -1647,7 +1681,7 @@
|
|
|
1647
1681
|
{
|
|
1648
1682
|
"name": "offerToken",
|
|
1649
1683
|
"tags": [],
|
|
1650
|
-
"docs": "Android: offer token required when purchasing a specific subscription or one-time offer.",
|
|
1684
|
+
"docs": "Android: offer token required when purchasing a specific subscription or one-time offer.\n\nPass it to `purchaseProduct({ offerToken })` to buy this exact offer. It belongs to the\nquery that returned it and goes stale, so read it from the same `getProducts()` /\n`getProduct()` call you purchase from.",
|
|
1651
1685
|
"complexTypes": [],
|
|
1652
1686
|
"type": "string | undefined"
|
|
1653
1687
|
},
|
|
@@ -1732,26 +1766,42 @@
|
|
|
1732
1766
|
},
|
|
1733
1767
|
{
|
|
1734
1768
|
"name": "subscriptionPeriod",
|
|
1735
|
-
"tags": [
|
|
1736
|
-
|
|
1769
|
+
"tags": [
|
|
1770
|
+
{
|
|
1771
|
+
"text": "ios From StoreKit `subscription.subscriptionPeriod`.",
|
|
1772
|
+
"name": "platform"
|
|
1773
|
+
},
|
|
1774
|
+
{
|
|
1775
|
+
"text": "android From the standard pricing phase billing period when recurrence is\ninfinite recurring, or finite recurring on installment offers (`ProductPayloadMapper.applySubscriptionPricing`).\nOmitted for prepaid (non-recurring) phases.",
|
|
1776
|
+
"name": "platform"
|
|
1777
|
+
}
|
|
1778
|
+
],
|
|
1779
|
+
"docs": "Recurring billing period for subscription products.",
|
|
1737
1780
|
"complexTypes": [
|
|
1738
1781
|
"SubscriptionPeriod"
|
|
1739
1782
|
],
|
|
1740
1783
|
"type": "SubscriptionPeriod"
|
|
1741
1784
|
},
|
|
1742
1785
|
{
|
|
1743
|
-
"name": "
|
|
1786
|
+
"name": "subscriptionBillingCycles",
|
|
1744
1787
|
"tags": [
|
|
1745
1788
|
{
|
|
1746
|
-
"text": "
|
|
1789
|
+
"text": "android From `InstallmentPlanDetails.getInstallmentPlanCommitmentPaymentsCount()`.",
|
|
1747
1790
|
"name": "platform"
|
|
1748
1791
|
},
|
|
1749
1792
|
{
|
|
1750
|
-
"text": "
|
|
1793
|
+
"text": "ios Not available",
|
|
1751
1794
|
"name": "platform"
|
|
1752
1795
|
}
|
|
1753
1796
|
],
|
|
1754
|
-
"docs": "
|
|
1797
|
+
"docs": "Android subscriptions only: committed payment count for installment base plans when Play\nexposes it on the offer.",
|
|
1798
|
+
"complexTypes": [],
|
|
1799
|
+
"type": "number | undefined"
|
|
1800
|
+
},
|
|
1801
|
+
{
|
|
1802
|
+
"name": "introductoryPrice",
|
|
1803
|
+
"tags": [],
|
|
1804
|
+
"docs": "Introductory price for this product line when the store exposes it. Pair with `priceString`\nfor full subscription offer wording before purchase. iOS: from StoreKit introductory offers\nwhen available. Android base subscription offers (`offerId` null): from the first pricing\nphase when multiple phases exist (intro then recurring). Android promotional offer lines\n(`offerId` set): null; phase pricing is not exposed on `Product`, so defer price confirmation\nto Play checkout instead of using `priceString` alone. Mapping matches `ProductPayloadMapper`.",
|
|
1755
1805
|
"complexTypes": [
|
|
1756
1806
|
"SKProductDiscount"
|
|
1757
1807
|
],
|
|
@@ -1787,7 +1837,7 @@
|
|
|
1787
1837
|
"name": "platform"
|
|
1788
1838
|
},
|
|
1789
1839
|
{
|
|
1790
|
-
"text": "android
|
|
1840
|
+
"text": "android On base subscription offers (`offerId` null), lists promotional offers on\nthe same base plan. A promotional offer line itself returns an empty array; its pricing\nphases are not mapped here or on `introductoryPrice`.",
|
|
1791
1841
|
"name": "platform"
|
|
1792
1842
|
}
|
|
1793
1843
|
],
|