@capgo/native-purchases 0.0.1 → 0.0.3
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.
|
@@ -3,7 +3,7 @@ require 'json'
|
|
|
3
3
|
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
|
|
4
4
|
|
|
5
5
|
Pod::Spec.new do |s|
|
|
6
|
-
s.name = '
|
|
6
|
+
s.name = 'CapgoNativePurchases'
|
|
7
7
|
s.version = package['version']
|
|
8
8
|
s.summary = package['description']
|
|
9
9
|
s.license = package['license']
|
|
@@ -115,17 +115,82 @@ public class NativePurchasesPlugin extends Plugin {
|
|
|
115
115
|
|
|
116
116
|
@PluginMethod
|
|
117
117
|
public void restorePurchases(PluginCall call) {
|
|
118
|
-
|
|
119
|
-
|
|
118
|
+
Log.d("NativePurchases", "restorePurchases");
|
|
119
|
+
|
|
120
|
+
if (billingClient.isReady()) {
|
|
121
|
+
Purchase.PurchasesResult purchasesResult = billingClient.queryPurchases(BillingClient.SkuType.INAPP);
|
|
122
|
+
|
|
123
|
+
if (purchasesResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
|
|
124
|
+
List<Purchase> purchasesList = purchasesResult.getPurchasesList();
|
|
125
|
+
|
|
126
|
+
JSObject ret = new JSObject();
|
|
127
|
+
JSONArray purchases = new JSONArray();
|
|
128
|
+
|
|
129
|
+
for (Purchase purchase : purchasesList) {
|
|
130
|
+
JSObject purchaseObject = new JSObject();
|
|
131
|
+
purchaseObject.put("productId", purchase.getSku());
|
|
132
|
+
purchaseObject.put("transactionId", purchase.getPurchaseToken());
|
|
133
|
+
purchaseObject.put("purchaseTime", purchase.getPurchaseTime());
|
|
134
|
+
purchases.put(purchaseObject);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
ret.put("purchases", purchases);
|
|
138
|
+
call.resolve(ret);
|
|
139
|
+
} else {
|
|
140
|
+
// Handle any other error codes.
|
|
141
|
+
call.reject("Unknown error")
|
|
142
|
+
}
|
|
143
|
+
}
|
|
120
144
|
}
|
|
121
145
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
146
|
+
|
|
147
|
+
@PluginMethod
|
|
148
|
+
public void getProducts(PluginCall call) {
|
|
125
149
|
JSONArray productIdentifiersArray = call.getArray("productIdentifiers");
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
150
|
+
List<String> productIdentifiers = new ArrayList<>();
|
|
151
|
+
|
|
152
|
+
for (int i = 0; i < productIdentifiersArray.length(); i++) {
|
|
153
|
+
try {
|
|
154
|
+
productIdentifiers.add(productIdentifiersArray.getString(i));
|
|
155
|
+
} catch (JSONException e) {
|
|
156
|
+
e.printStackTrace();
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
Log.d("NativePurchases", "getProducts: " + productIdentifiers);
|
|
161
|
+
|
|
162
|
+
if (billingClient.isReady()) {
|
|
163
|
+
SkuDetailsParams.Builder params = SkuDetailsParams.newBuilder();
|
|
164
|
+
params.setSkusList(productIdentifiers).setType(BillingClient.SkuType.INAPP);
|
|
165
|
+
|
|
166
|
+
billingClient.querySkuDetailsAsync(params.build(), new SkuDetailsResponseListener() {
|
|
167
|
+
@Override
|
|
168
|
+
public void onSkuDetailsResponse(BillingResult billingResult, List<SkuDetails> skuDetailsList) {
|
|
169
|
+
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK && skuDetailsList != null) {
|
|
170
|
+
JSObject ret = new JSObject();
|
|
171
|
+
JSONArray products = new JSONArray();
|
|
172
|
+
|
|
173
|
+
for (SkuDetails skuDetails : skuDetailsList) {
|
|
174
|
+
JSObject product = new JSObject();
|
|
175
|
+
product.put("productId", skuDetails.getSku());
|
|
176
|
+
product.put("title", skuDetails.getTitle());
|
|
177
|
+
product.put("description", skuDetails.getDescription());
|
|
178
|
+
product.put("price", skuDetails.getPrice());
|
|
179
|
+
product.put("priceAmountMicros", skuDetails.getPriceAmountMicros());
|
|
180
|
+
product.put("priceCurrencyCode", skuDetails.getPriceCurrencyCode());
|
|
181
|
+
product.put("type", skuDetails.getType());
|
|
182
|
+
products.put(product);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
ret.put("products", products);
|
|
186
|
+
call.resolve(ret);
|
|
187
|
+
} else {
|
|
188
|
+
// Handle any other error codes.
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
}
|
|
129
194
|
|
|
130
195
|
//================================================================================
|
|
131
196
|
// Private methods
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capgo/native-purchases",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "In-app Subscriptions Made Easy",
|
|
5
5
|
"main": "dist/plugin.cjs.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"android/build.gradle",
|
|
12
12
|
"dist/",
|
|
13
13
|
"ios/Plugin/",
|
|
14
|
-
"
|
|
14
|
+
"CapgoNativePurchases.podspec"
|
|
15
15
|
],
|
|
16
16
|
"author": "Martin donadieu",
|
|
17
17
|
"license": "MIT",
|