@capgo/native-purchases 0.0.15 → 0.0.16
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.
|
@@ -12,6 +12,9 @@ import com.android.billingclient.api.ProductDetailsResponseListener;
|
|
|
12
12
|
import com.android.billingclient.api.Purchase;
|
|
13
13
|
import com.android.billingclient.api.PurchasesUpdatedListener;
|
|
14
14
|
import com.android.billingclient.api.QueryProductDetailsParams;
|
|
15
|
+
import com.android.billingclient.api.SkuDetails;
|
|
16
|
+
import com.android.billingclient.api.SkuDetailsParams;
|
|
17
|
+
import com.android.billingclient.api.SkuDetailsResponseListener;
|
|
15
18
|
import com.getcapacitor.JSObject;
|
|
16
19
|
import com.getcapacitor.Plugin;
|
|
17
20
|
import com.getcapacitor.PluginCall;
|
|
@@ -148,6 +151,7 @@ public class NativePurchasesPlugin extends Plugin {
|
|
|
148
151
|
public void purchaseProduct(PluginCall call) {
|
|
149
152
|
String productIdentifier = call.getString("productIdentifier");
|
|
150
153
|
String productType = call.getString("productType", "inapp");
|
|
154
|
+
Number quantity = call.getInt("quantity", 1);
|
|
151
155
|
// cannot use quantity, because it's done in native modal
|
|
152
156
|
Log.d("CapacitorPurchases", "purchaseProduct: " + productIdentifier);
|
|
153
157
|
if (productIdentifier.isEmpty()) {
|
|
@@ -155,12 +159,42 @@ public class NativePurchasesPlugin extends Plugin {
|
|
|
155
159
|
call.reject("productIdentifier is empty");
|
|
156
160
|
return;
|
|
157
161
|
}
|
|
162
|
+
// List<String> skuList = new ArrayList<>();
|
|
163
|
+
// skuList.add(productIdentifier);
|
|
164
|
+
// SkuDetailsParams params = SkuDetailsParams.newBuilder().setSkusList(skuList).setType(productType == "inapp"
|
|
165
|
+
// ? BillingClient.SkuType.INAPP
|
|
166
|
+
// : BillingClient.SkuType.SUBS).build();
|
|
167
|
+
//
|
|
168
|
+
// billingClient.querySkuDetailsAsync(params, new SkuDetailsResponseListener() {
|
|
169
|
+
// @Override
|
|
170
|
+
// public void onSkuDetailsResponse(BillingResult billingResult, List<com.android.billingclient.api.SkuDetails> skuDetailsList) {
|
|
171
|
+
// if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK && skuDetailsList != null) {
|
|
172
|
+
// for (SkuDetails skuDetails : skuDetailsList) {
|
|
173
|
+
// if (skuDetails.getSku().equals(productIdentifier)) {
|
|
174
|
+
// BillingFlowParams flowParams = BillingFlowParams.newBuilder()
|
|
175
|
+
// .setSkuDetails(skuDetails)
|
|
176
|
+
// // set quantity here
|
|
177
|
+
//
|
|
178
|
+
// .setQuantity(quantity) // Set the quantity here
|
|
179
|
+
// .build();
|
|
180
|
+
// BillingResult billingResult2 = billingClient.launchBillingFlow(getActivity(), flowParams);
|
|
181
|
+
// Log.i(
|
|
182
|
+
// "NativePurchases",
|
|
183
|
+
// "onProductDetailsResponse2" + billingResult2
|
|
184
|
+
// );
|
|
185
|
+
// }
|
|
186
|
+
// }
|
|
187
|
+
// } else {
|
|
188
|
+
// // Handle error: unable to query SKU details
|
|
189
|
+
// }
|
|
190
|
+
// }
|
|
191
|
+
// });
|
|
158
192
|
ImmutableList<QueryProductDetailsParams.Product> productList = ImmutableList.of(
|
|
159
193
|
QueryProductDetailsParams.Product
|
|
160
194
|
.newBuilder()
|
|
161
195
|
.setProductId(productIdentifier)
|
|
162
196
|
.setProductType(
|
|
163
|
-
productType
|
|
197
|
+
productType.equals("inapp")
|
|
164
198
|
? BillingClient.ProductType.INAPP
|
|
165
199
|
: BillingClient.ProductType.SUBS
|
|
166
200
|
)
|
|
@@ -178,24 +212,25 @@ public class NativePurchasesPlugin extends Plugin {
|
|
|
178
212
|
BillingResult billingResult,
|
|
179
213
|
List<ProductDetails> productDetailsList
|
|
180
214
|
) {
|
|
181
|
-
Log.i(
|
|
182
|
-
"NativePurchases",
|
|
183
|
-
"onProductDetailsResponse" + billingResult + productDetailsList
|
|
184
|
-
);
|
|
185
215
|
// Process the result
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
BillingFlowParams.ProductDetailsParams
|
|
216
|
+
List<BillingFlowParams.ProductDetailsParams> productDetailsParamsList = new ArrayList<>();
|
|
217
|
+
for (ProductDetails productDetailsItem : productDetailsList) {
|
|
218
|
+
BillingFlowParams.ProductDetailsParams.Builder productDetailsParams = BillingFlowParams.ProductDetailsParams
|
|
189
219
|
.newBuilder()
|
|
190
|
-
.setProductDetails(
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
220
|
+
.setProductDetails(productDetailsItem);
|
|
221
|
+
if (productType.equals("subs")) {
|
|
222
|
+
String offertoken = productDetailsItem
|
|
223
|
+
.getSubscriptionOfferDetails()
|
|
224
|
+
.get(0)
|
|
225
|
+
.getOfferToken();
|
|
226
|
+
productDetailsParams.setOfferToken(offertoken);
|
|
227
|
+
}
|
|
228
|
+
productDetailsParamsList.add(productDetailsParams.build());
|
|
229
|
+
}
|
|
194
230
|
BillingFlowParams billingFlowParams = BillingFlowParams
|
|
195
231
|
.newBuilder()
|
|
196
232
|
.setProductDetailsParamsList(productDetailsParamsList)
|
|
197
233
|
.build();
|
|
198
|
-
|
|
199
234
|
// Launch the billing flow
|
|
200
235
|
BillingResult billingResult2 = billingClient.launchBillingFlow(
|
|
201
236
|
getActivity(),
|
|
@@ -239,7 +274,7 @@ public class NativePurchasesPlugin extends Plugin {
|
|
|
239
274
|
.newBuilder()
|
|
240
275
|
.setProductId(productIdentifier)
|
|
241
276
|
.setProductType(
|
|
242
|
-
productType
|
|
277
|
+
productType.equals("inapp")
|
|
243
278
|
? BillingClient.ProductType.INAPP
|
|
244
279
|
: BillingClient.ProductType.SUBS
|
|
245
280
|
)
|