com.amanotes.gdk 0.2.19 → 0.2.20

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/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.2.20 - 2023-10-05]
4
+ ### Update RevenueCat 5.3.0
5
+
3
6
  ## [0.2.19 - 2023-09-12]
4
7
  ### Add `ama_device_id` to all events
5
8
 
@@ -1,5 +1,5 @@
1
1
  fileFormatVersion: 2
2
- guid: 1ea28b311cdc648ef9cd322abd1797b5
2
+ guid: 293341d9acee543a8b692edae57f0aa8
3
3
  MonoImporter:
4
4
  externalObjects: {}
5
5
  serializedVersion: 2
@@ -1,5 +1,5 @@
1
1
  fileFormatVersion: 2
2
- guid: 2e155e09a97324557b3803886b0dcfd7
2
+ guid: 55c96ab69ed9b471ebc383f02b0e4538
3
3
  TextScriptImporter:
4
4
  externalObjects: {}
5
5
  userData:
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -1,5 +1,5 @@
1
1
  fileFormatVersion: 2
2
- guid: ec14a271afdcc4c72b0d1305fbd9db8c
2
+ guid: 7549d4283e5844b68b594b1dcb4add02
3
3
  DefaultImporter:
4
4
  externalObjects: {}
5
5
  userData:
@@ -1,6 +1,7 @@
1
1
  using System;
2
2
  using System.Collections;
3
3
  using System.Collections.Generic;
4
+ using System.Globalization;
4
5
  using UnityEngine;
5
6
  using Amanotes.Core.Internal;
6
7
 
@@ -14,15 +15,21 @@ namespace Amanotes.Core
14
15
  public partial class IAP //Public
15
16
  {
16
17
  public static bool IsVIP => !string.IsNullOrEmpty(localData.activeSubscriptionId);
17
-
18
18
  public static string ActiveSubscriptionId => localData.activeSubscriptionId;
19
-
19
+ public static string SubscriptionPeriodType => localData.subscriptionPeriodType;
20
+ public static DateTime? SubscriptionLastPurchaseDate => localData.SubscriptionLastPurchaseDate;
21
+ public static DateTime? SubscriptionExpiredDate => localData.SubscriptionExpiredDate;
22
+ public static DateTime? UnsubscribedDate => localData.UnsubscribedDate;
20
23
  public static Dictionary<string, ProductInfo> AllProducts => dicProducts;
21
-
22
- public static ISetupBuilder GetProducts()
24
+ private const string DATE_FORMAT = "yyyy/MM/yy HH:mm:ss";
25
+
26
+ public static ISetupBuilder GetProducts(bool appendExistingList = false)
23
27
  {
24
- IAPExtension.isCleanUpConfig = false;
25
- dicProducts.Clear();
28
+ if (!appendExistingList)
29
+ {
30
+ IAPExtension.isCleanUpConfig = false;
31
+ dicProducts.Clear();
32
+ }
26
33
  var result = new SetupContext();
27
34
  ExecuteInNextFrame(result.GetProducts);
28
35
  return result;
@@ -31,7 +38,13 @@ namespace Amanotes.Core
31
38
  public static IPurchaseBuilder Purchase(string productId)
32
39
  {
33
40
  var result = new PurchaseContext();
34
- ExecuteInNextFrame(() => result.Purchase(productId));
41
+ if (!dicProducts.ContainsKey(productId))
42
+ {
43
+ LogWarning($"[IAP] Product {productId} is not found");
44
+ result.onFail?.Invoke(new PurchaseError($"Product {productId} is not found"));
45
+ return result;
46
+ }
47
+ ExecuteInNextFrame(() => result.Purchase(dicProducts[productId]));
35
48
  return result;
36
49
  }
37
50
 
@@ -46,7 +59,7 @@ namespace Amanotes.Core
46
59
  {
47
60
  if (!dicProducts.ContainsKey(productId))
48
61
  {
49
- LogWarning($"[IAP] Not found product with id <{productId}>. Make sure you have called Setup() first.");
62
+ LogWarning($"[IAP] Not found product with id <{productId}>. Make sure you have called GetProducts() first.");
50
63
  return null;
51
64
  }
52
65
 
@@ -73,6 +86,13 @@ namespace Amanotes.Core
73
86
  {
74
87
  return Adapter?.GetPurchaseHistory();
75
88
  }
89
+
90
+ public static DateTime? GetLastPurchaseDate(string productId)
91
+ {
92
+ var product = GetProduct(productId);
93
+ if (product == null) return null;
94
+ return Adapter?.GetLastPurchaseDate(product.productAndPlanId);
95
+ }
76
96
  }
77
97
 
78
98
  public partial class IAP //Internal
@@ -134,12 +154,68 @@ namespace Amanotes.Core
134
154
  internal class IAPData : IJsonFile
135
155
  {
136
156
  public string activeSubscriptionId;
157
+ public string subscriptionPeriodType;
158
+ public string subscriptionLastPurchaseDate;
159
+ public string subscriptionExpiredDate;
160
+ public string unsubscribedDate;
137
161
  public List<string> purchasedProducts;
162
+
163
+ private DateTime? _subscriptionLastPurchaseDate;
164
+ public DateTime? SubscriptionLastPurchaseDate
165
+ {
166
+ get
167
+ {
168
+ if (_subscriptionLastPurchaseDate != null) return _subscriptionLastPurchaseDate;
169
+ if (DateTime.TryParseExact(subscriptionLastPurchaseDate, DATE_FORMAT,
170
+ CultureInfo.InvariantCulture, DateTimeStyles.None, out var pd))
171
+ {
172
+ _subscriptionLastPurchaseDate = pd;
173
+ }
174
+ return _subscriptionLastPurchaseDate;
175
+ }
176
+ }
177
+
178
+ private DateTime? _subscriptionExpiredDate;
179
+ public DateTime? SubscriptionExpiredDate
180
+ {
181
+ get
182
+ {
183
+ if (_subscriptionExpiredDate != null) return _subscriptionExpiredDate;
184
+ if (DateTime.TryParseExact(subscriptionExpiredDate, DATE_FORMAT,
185
+ CultureInfo.InvariantCulture, DateTimeStyles.None, out var pd))
186
+ {
187
+ _subscriptionExpiredDate = pd;
188
+ }
189
+ return _subscriptionExpiredDate;
190
+ }
191
+ }
192
+
193
+ private DateTime? _unsubscribedDate;
194
+ public DateTime? UnsubscribedDate
195
+ {
196
+ get
197
+ {
198
+ if (_unsubscribedDate != null) return _unsubscribedDate;
199
+ if (DateTime.TryParseExact(unsubscribedDate, DATE_FORMAT,
200
+ CultureInfo.InvariantCulture, DateTimeStyles.None, out var pd))
201
+ {
202
+ _unsubscribedDate = pd;
203
+ }
204
+ return _unsubscribedDate;
205
+ }
206
+ }
138
207
 
139
208
  public void Sync()
140
209
  {
141
210
  activeSubscriptionId = Adapter?.GetActiveSubscriptionId();
211
+ subscriptionPeriodType = Adapter?.GetSubscriptionPeriodType();
142
212
  purchasedProducts = Adapter?.GetPurchasedProducts();
213
+ _subscriptionLastPurchaseDate = Adapter?.GetSubscriptionLastPurchaseDate();
214
+ subscriptionLastPurchaseDate = _subscriptionLastPurchaseDate?.ToString(DATE_FORMAT);
215
+ _subscriptionExpiredDate = Adapter?.GetSubscriptionExpiredDate();
216
+ subscriptionExpiredDate = _subscriptionExpiredDate?.ToString(DATE_FORMAT);
217
+ _unsubscribedDate = Adapter?.GetUnsubscribedDate();
218
+ unsubscribedDate = _unsubscribedDate?.ToString(DATE_FORMAT);
143
219
  this.SaveJsonToFile();
144
220
  }
145
221
  }
@@ -158,6 +234,7 @@ namespace Amanotes.Core
158
234
  {
159
235
  public string id;
160
236
  public ProductType type;
237
+ [HideInInspector] public string productAndPlanId;
161
238
  [HideInInspector] public string title;
162
239
  [HideInInspector] public string description;
163
240
  [HideInInspector] public float price;
@@ -186,8 +263,9 @@ namespace Amanotes.Core
186
263
  {
187
264
  }
188
265
 
189
- public PurchaseError(string errorMessage)
266
+ public PurchaseError(string errorMessage, string productId = null)
190
267
  {
268
+ this.productId = productId;
191
269
  error = errorMessage;
192
270
  }
193
271
  }
@@ -241,9 +319,11 @@ namespace Amanotes.Core
241
319
  {
242
320
  if (sc == null) return null;
243
321
  ClearOldProductConfig();
322
+ var ls = AdapterConfig?.products;
323
+ if (ls == null) return null;
244
324
  foreach (var pId in subs)
245
325
  {
246
- AdapterConfig?.products.Add(new ProductInfo { id = pId, type = ProductType.Subscription });
326
+ ls.Add(new ProductInfo { id = pId, type = ProductType.Subscription });
247
327
  }
248
328
  return sc;
249
329
  }
@@ -252,9 +332,11 @@ namespace Amanotes.Core
252
332
  {
253
333
  if (sc == null) return null;
254
334
  ClearOldProductConfig();
335
+ var ls = AdapterConfig?.products;
336
+ if (ls == null) return null;
255
337
  foreach (var pId in cons)
256
338
  {
257
- AdapterConfig?.products.Add(new ProductInfo { id = pId, type = ProductType.Consumable });
339
+ ls.Add(new ProductInfo { id = pId, type = ProductType.Consumable });
258
340
  }
259
341
  return sc;
260
342
  }
@@ -263,9 +345,11 @@ namespace Amanotes.Core
263
345
  {
264
346
  if (sc == null) return null;
265
347
  ClearOldProductConfig();
348
+ var ls = AdapterConfig?.products;
349
+ if (ls == null) return null;
266
350
  foreach (var pId in nons)
267
351
  {
268
- AdapterConfig?.products.Add(new ProductInfo { id = pId, type = ProductType.NonConsumable });
352
+ ls.Add(new ProductInfo { id = pId, type = ProductType.NonConsumable });
269
353
  }
270
354
  return sc;
271
355
  }
@@ -339,18 +423,29 @@ namespace Amanotes.Core.Internal
339
423
 
340
424
  public void GetProducts()
341
425
  {
342
- if (AdapterConfig?.products.Count == 0)
426
+ var ls = AdapterConfig?.products;
427
+ if (ls == null || ls.Count == 0)
343
428
  {
344
429
  LogWarning("There is no IAP product");
345
430
  return;
346
- }
431
+ }
432
+
433
+ #if UNITY_EDITOR
434
+ foreach (var p in ls)
435
+ {
436
+ if (dicProducts.ContainsKey(p.id)) dicProducts[p.id] = p;
437
+ else dicProducts.Add(p.id, p);
438
+ }
439
+ onSuccess?.Invoke(dicProducts);
440
+ return;
441
+ #endif
347
442
 
348
443
  getProdQueue.Clear();
349
444
  var subs = new List<string>();
350
445
  var cons = new List<string>();
351
446
  var nons = new List<string>();
352
447
 
353
- foreach (var p in AdapterConfig.products)
448
+ foreach (var p in ls)
354
449
  {
355
450
  switch (p.type)
356
451
  {
@@ -393,9 +488,10 @@ namespace Amanotes.Core.Internal
393
488
  {
394
489
  AmaGDK.IAP.Adapter?.GetProducts(lsProduct.ToArray(), type, (pList) =>
395
490
  {
396
- foreach (var pI in pList)
491
+ foreach (var p in pList)
397
492
  {
398
- dicProducts.Add(pI.id, pI);
493
+ if (dicProducts.ContainsKey(p.id)) dicProducts[p.id] = p;
494
+ else dicProducts.Add(p.id, p);
399
495
  }
400
496
  ExecuteInNextFrame(GetNextProductsInQueue);
401
497
  }, error => onFail?.Invoke(error));
@@ -416,20 +512,14 @@ namespace Amanotes.Core.Internal
416
512
  public Action<PurchaseError> onFail;
417
513
  public string discountId;
418
514
 
419
- public void Purchase(string productId)
515
+ public void Purchase(ProductInfo productInfo)
420
516
  {
421
- if (!dicProducts.ContainsKey(productId))
422
- {
423
- LogWarning($"[IAP] Product {productId} is not found");
424
- return;
425
- }
426
-
427
517
  #if UNITY_EDITOR
428
518
  if (AdapterConfig.allPurchaseSuccessInEditor)
429
519
  {
430
520
  DoOnSuccess(new PurchaseSuccess
431
521
  {
432
- productIds = new[] { productId },
522
+ productIds = new[] { productInfo.id },
433
523
  isSandbox = true
434
524
  });
435
525
  return;
@@ -438,11 +528,11 @@ namespace Amanotes.Core.Internal
438
528
 
439
529
  if (!string.IsNullOrWhiteSpace(discountId))
440
530
  {
441
- AmaGDK.IAP.Adapter?.PurchaseDiscount(productId, dicProducts[productId].type, discountId, DoOnSuccess, DoOnFail);
531
+ AmaGDK.IAP.Adapter?.PurchaseDiscount(productInfo, discountId, DoOnSuccess, DoOnFail);
442
532
  return;
443
533
  }
444
534
 
445
- AmaGDK.IAP.Adapter?.Purchase(productId, dicProducts[productId].type, DoOnSuccess, DoOnFail);
535
+ AmaGDK.IAP.Adapter?.Purchase(productInfo, DoOnSuccess, DoOnFail);
446
536
  }
447
537
 
448
538
  public void RestorePurchase()
@@ -465,12 +555,17 @@ namespace Amanotes.Core.Internal
465
555
  public interface IIAPAdapter
466
556
  {
467
557
  void GetProducts(string[] productIds, ProductType productType, Action<ProductInfo[]> onSuccess = null, Action<string> onFail = null);
468
- void Purchase(string productId, ProductType productType, Action<PurchaseSuccess> onSuccess = null, Action<PurchaseError> onFail = null);
469
- void PurchaseDiscount(string productId, ProductType productType, string discountId, Action<PurchaseSuccess> onSuccess = null, Action<PurchaseError> onFail = null);
558
+ void Purchase(ProductInfo productInfo, Action<PurchaseSuccess> onSuccess = null, Action<PurchaseError> onFail = null);
559
+ void PurchaseDiscount(ProductInfo productInfo, string discountId, Action<PurchaseSuccess> onSuccess = null, Action<PurchaseError> onFail = null);
470
560
  void RestorePurchase(Action<PurchaseSuccess> onSuccess = null, Action<PurchaseError> onFail = null);
471
561
  List<string> GetActiveSubscriptions();
472
562
  List<string> GetPurchasedProducts();
473
563
  string GetActiveSubscriptionId();
564
+ string GetSubscriptionPeriodType();
565
+ DateTime? GetSubscriptionLastPurchaseDate();
566
+ DateTime? GetSubscriptionExpiredDate();
567
+ DateTime? GetUnsubscribedDate();
474
568
  HashSet<PurchaseRecord> GetPurchaseHistory();
569
+ DateTime? GetLastPurchaseDate(string productAndPlanId);
475
570
  }
476
- }
571
+ }
package/Runtime/AmaGDK.cs CHANGED
@@ -14,7 +14,7 @@ namespace Amanotes.Core
14
14
  {
15
15
  public partial class AmaGDK : MonoBehaviour
16
16
  {
17
- public const string VERSION = "0.2.19";
17
+ public const string VERSION = "0.2.20";
18
18
 
19
19
  internal static AmaGDK _instance;
20
20
  internal static Status _status = Status.None;
@@ -62,7 +62,7 @@ namespace Amanotes.Core
62
62
  }
63
63
 
64
64
  float time = 0;
65
- float timeout = 3;
65
+ float timeout = 10;
66
66
 
67
67
  var counter = 0;
68
68
  const int INIT_TOLERANCE = 10 * 60;
@@ -1,5 +1,5 @@
1
1
  fileFormatVersion: 2
2
- guid: 703161d03cf9f4dc9a95125c44430ebe
2
+ guid: abf1efb2d0f644148901211ecbce462f
3
3
  PluginImporter:
4
4
  externalObjects: {}
5
5
  serializedVersion: 2
@@ -1,5 +1,5 @@
1
1
  fileFormatVersion: 2
2
- guid: e9aa069386a2746d2affa79fe86ce7a6
2
+ guid: 0d9bff6463df741a099d04c5694bc689
3
3
  folderAsset: yes
4
4
  DefaultImporter:
5
5
  externalObjects: {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "com.amanotes.gdk",
3
- "version": "0.2.19",
3
+ "version": "0.2.20",
4
4
  "displayName": "AmaGDK",
5
5
  "description": "Amanotes Game Development Kit",
6
6
  "unity": "2019.4",