@purchasely/cordova-plugin-purchasely 1.1.7 → 2.0.1

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.
@@ -5,6 +5,9 @@ import android.content.Intent;
5
5
  import android.net.Uri;
6
6
  import android.util.Log;
7
7
 
8
+ import androidx.annotation.NonNull;
9
+ import androidx.fragment.app.FragmentActivity;
10
+
8
11
  import org.apache.cordova.CallbackContext;
9
12
  import org.apache.cordova.CordovaInterface;
10
13
  import org.apache.cordova.CordovaPlugin;
@@ -14,21 +17,27 @@ import org.jetbrains.annotations.Nullable;
14
17
  import org.json.JSONArray;
15
18
  import org.json.JSONException;
16
19
  import org.json.JSONObject;
20
+ import org.w3c.dom.Attr;
17
21
 
18
22
  import java.lang.ref.WeakReference;
19
23
  import java.util.ArrayList;
20
24
  import java.util.HashMap;
25
+ import java.util.Iterator;
21
26
  import java.util.List;
27
+ import java.util.Locale;
22
28
  import java.util.Map;
29
+ import java.util.function.BiConsumer;
23
30
 
24
31
  import io.purchasely.billing.Store;
25
32
  import io.purchasely.ext.Attribute;
26
- import io.purchasely.ext.ContinuePurchaseListener;
27
33
  import io.purchasely.ext.DistributionType;
28
34
  import io.purchasely.ext.LogLevel;
29
- import io.purchasely.ext.LoginClosedListener;
30
35
  import io.purchasely.ext.PLYAppTechnology;
36
+ import io.purchasely.ext.PLYPaywallActionListener;
37
+ import io.purchasely.ext.PLYPresentationAction;
38
+ import io.purchasely.ext.PLYProcessActionListener;
31
39
  import io.purchasely.ext.PLYProductViewResult;
40
+ import io.purchasely.ext.PLYRunningMode;
32
41
  import io.purchasely.ext.PlanListener;
33
42
  import io.purchasely.ext.ProductListener;
34
43
  import io.purchasely.ext.ProductsListener;
@@ -50,8 +59,13 @@ public class PurchaselyPlugin extends CordovaPlugin {
50
59
  static CallbackContext eventsCallback = null;
51
60
  static ProductActivity productActivity = null;
52
61
 
53
- private LoginClosedListener loginClosedListener = null;
54
- private ContinuePurchaseListener continuePurchaseListener = null;
62
+ private PLYProcessActionListener processActionListener;
63
+
64
+ private static int runningModeTransactionOnly = 0;
65
+ private static int runningModeObserver = 1;
66
+ private static int runningModePaywallOnly = 2;
67
+ private static int runningModePaywallObserver = 3;
68
+ private static int runningModeFull = 4;
55
69
 
56
70
  @Override
57
71
  public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
@@ -63,7 +77,7 @@ public class PurchaselyPlugin extends CordovaPlugin {
63
77
  args.getJSONArray(1),
64
78
  args.getString(2),
65
79
  args.getInt(3),
66
- args.getBoolean(4),
80
+ args.getInt(4),
67
81
  callbackContext);
68
82
  break;
69
83
  case "close":
@@ -84,6 +98,9 @@ public class PurchaselyPlugin extends CordovaPlugin {
84
98
  case "userLogout":
85
99
  userLogout();
86
100
  break;
101
+ case "setLanguage":
102
+ setLanguage(args.getString(0));
103
+ break;
87
104
  case "setLogLevel":
88
105
  setLogLevel(args.getInt(0));
89
106
  break;
@@ -106,6 +123,7 @@ public class PurchaselyPlugin extends CordovaPlugin {
106
123
  presentPresentationWithIdentifier(
107
124
  args.getString(0),
108
125
  args.getString(1),
126
+ args.getBoolean(2),
109
127
  callbackContext
110
128
  );
111
129
  break;
@@ -114,6 +132,7 @@ public class PurchaselyPlugin extends CordovaPlugin {
114
132
  args.getString(0),
115
133
  args.getString(1),
116
134
  args.getString(2),
135
+ args.getBoolean(3),
117
136
  callbackContext
118
137
  );
119
138
  break;
@@ -122,6 +141,7 @@ public class PurchaselyPlugin extends CordovaPlugin {
122
141
  args.getString(0),
123
142
  args.getString(1),
124
143
  args.getString(2),
144
+ args.getBoolean(3),
125
145
  callbackContext
126
146
  );
127
147
  break;
@@ -131,6 +151,9 @@ public class PurchaselyPlugin extends CordovaPlugin {
131
151
  case "restoreAllProducts":
132
152
  restoreAllProducts(callbackContext);
133
153
  break;
154
+ case "silentRestoreAllProducts":
155
+ restoreAllProducts(callbackContext);
156
+ break;
134
157
  case "userSubscriptions":
135
158
  userSubscriptions(callbackContext);
136
159
  break;
@@ -153,17 +176,14 @@ public class PurchaselyPlugin extends CordovaPlugin {
153
176
  callbackContext
154
177
  );
155
178
  break;
156
- case "setLoginTappedHandler":
157
- setLoginTappedHandler(callbackContext);
179
+ case "setPaywallActionInterceptor":
180
+ setPaywallActionInterceptor(callbackContext);
158
181
  break;
159
- case "onUserLoggedIn":
160
- onUserLoggedIn(args.getBoolean(0));
182
+ case "onProcessAction":
183
+ onProcessAction(args.getBoolean(0));
161
184
  break;
162
- case "setConfirmPurchaseHandler":
163
- setConfirmPurchaseHandler(callbackContext);
164
- break;
165
- case "processToPayment":
166
- processToPayment(args.getBoolean(0));
185
+ case "closePaywall":
186
+ closePaywall(callbackContext);
167
187
  break;
168
188
  default:
169
189
  return false;
@@ -203,7 +223,7 @@ public class PurchaselyPlugin extends CordovaPlugin {
203
223
  JSONArray stores,
204
224
  String userId,
205
225
  int logLevel,
206
- boolean observerMode,
226
+ int runningMode,
207
227
  CallbackContext callbackContext) {
208
228
  ArrayList<String> list = new ArrayList<>();
209
229
  for (int i=0; i< stores.length(); i++) {
@@ -215,11 +235,17 @@ public class PurchaselyPlugin extends CordovaPlugin {
215
235
  }
216
236
  ArrayList<Store> storesInstances = getStoresInstances(list);
217
237
 
238
+ PLYRunningMode plyRunningMode = PLYRunningMode.Full.INSTANCE;
239
+ if(runningMode == runningModeTransactionOnly) plyRunningMode = PLYRunningMode.TransactionOnly.INSTANCE;
240
+ else if(runningMode == runningModeObserver) plyRunningMode = PLYRunningMode.Observer.INSTANCE;
241
+ else if(runningMode == runningModePaywallOnly) plyRunningMode = PLYRunningMode.PaywallOnly.INSTANCE;
242
+ else if(runningMode == runningModePaywallObserver) plyRunningMode = PLYRunningMode.PaywallObserver.INSTANCE;
243
+
218
244
  new Purchasely.Builder(cordova.getContext())
219
245
  .apiKey(apiKey)
220
246
  .stores(storesInstances)
221
247
  .userId(userId)
222
- .observerMode(observerMode)
248
+ .runningMode(plyRunningMode)
223
249
  .logLevel(LogLevel.values()[logLevel])
224
250
  .build();
225
251
 
@@ -267,8 +293,7 @@ public class PurchaselyPlugin extends CordovaPlugin {
267
293
  private void close() {
268
294
  defaultCallback = null;
269
295
  presentationCallback = null;
270
- loginClosedListener = null;
271
- continuePurchaseListener = null;
296
+ processActionListener = null;
272
297
  productActivity = null;
273
298
  Purchasely.close();
274
299
  }
@@ -318,6 +343,14 @@ public class PurchaselyPlugin extends CordovaPlugin {
318
343
  Purchasely.setLogLevel(LogLevel.values()[logLevel]);
319
344
  }
320
345
 
346
+ private void setLanguage(String language) {
347
+ try {
348
+ Purchasely.setLanguage(new Locale(language));
349
+ } catch (Exception e) {
350
+ Purchasely.setLanguage(Locale.getDefault());
351
+ }
352
+ }
353
+
321
354
  private void isReadyToPurchase(boolean isReadyToPurchase) {
322
355
  Purchasely.setReadyToPurchase(isReadyToPurchase);
323
356
  }
@@ -346,36 +379,42 @@ public class PurchaselyPlugin extends CordovaPlugin {
346
379
  }
347
380
 
348
381
  private void presentPresentationWithIdentifier(String presentationVendorId,
349
- String contentId,
382
+ String contentId,
383
+ boolean isFullScreen,
350
384
  CallbackContext callbackContext) {
351
385
  presentationCallback = callbackContext;
352
386
  Intent intent = PLYProductActivity.newIntent(cordova.getActivity());
353
387
  intent.putExtra("presentationId", presentationVendorId);
354
388
  intent.putExtra("contentId", contentId);
389
+ intent.putExtra("isFullScreen", isFullScreen);
355
390
  cordova.getActivity().startActivity(intent);
356
391
  }
357
392
 
358
393
  private void presentProductWithIdentifier(String productVendorId,
359
394
  String presentationVendorId,
360
395
  String contentId,
396
+ boolean isFullScreen,
361
397
  CallbackContext callbackContext) {
362
398
  presentationCallback = callbackContext;
363
399
  Intent intent = PLYProductActivity.newIntent(cordova.getActivity());
364
400
  intent.putExtra("presentationId", presentationVendorId);
365
401
  intent.putExtra("productId", productVendorId);
366
402
  intent.putExtra("contentId", contentId);
403
+ intent.putExtra("isFullScreen", isFullScreen);
367
404
  cordova.getActivity().startActivity(intent);
368
405
  }
369
406
 
370
407
  private void presentPlanWithIdentifier(String planVendorId,
371
408
  String presentationVendorId,
372
409
  String contentId,
410
+ boolean isFullScreen,
373
411
  CallbackContext callbackContext) {
374
412
  presentationCallback = callbackContext;
375
413
  Intent intent = PLYProductActivity.newIntent(cordova.getActivity());
376
414
  intent.putExtra("presentationId", presentationVendorId);
377
415
  intent.putExtra("planId", planVendorId);
378
416
  intent.putExtra("contentId", contentId);
417
+ intent.putExtra("isFullScreen", isFullScreen);
379
418
  cordova.getActivity().startActivity(intent);
380
419
  }
381
420
 
@@ -453,7 +492,7 @@ public class PurchaselyPlugin extends CordovaPlugin {
453
492
  }
454
493
 
455
494
  private void productWithIdentifier(String vendorId, CallbackContext callbackContext) {
456
- Purchasely.getProduct(vendorId, new ProductListener() {
495
+ Purchasely.product(vendorId, new ProductListener() {
457
496
  @Override
458
497
  public void onSuccess(@Nullable PLYProduct plyProduct) {
459
498
  if(plyProduct != null) {
@@ -471,7 +510,7 @@ public class PurchaselyPlugin extends CordovaPlugin {
471
510
  }
472
511
 
473
512
  private void planWithIdentifier(String vendorId, CallbackContext callbackContext) {
474
- Purchasely.getPlan(vendorId, new PlanListener() {
513
+ Purchasely.plan(vendorId, new PlanListener() {
475
514
  @Override
476
515
  public void onSuccess(@Nullable PLYPlan plyPlan) {
477
516
  if(plyPlan != null) {
@@ -489,7 +528,7 @@ public class PurchaselyPlugin extends CordovaPlugin {
489
528
  }
490
529
 
491
530
  private void purchaseWithPlanVendorId(String planVendorId, String contentId, CallbackContext callbackContext) {
492
- Purchasely.getPlan(planVendorId, new PlanListener() {
531
+ Purchasely.plan(planVendorId, new PlanListener() {
493
532
  @Override
494
533
  public void onSuccess(@Nullable PLYPlan plyPlan) {
495
534
  if(plyPlan != null) {
@@ -512,53 +551,57 @@ public class PurchaselyPlugin extends CordovaPlugin {
512
551
  });
513
552
  }
514
553
 
515
- private void setLoginTappedHandler(CallbackContext callbackContext) {
516
- Purchasely.setLoginTappedHandler((fragmentActivity, loginClosedListener) -> {
517
- this.loginClosedListener = loginClosedListener;
518
- Intent intent = new Intent(fragmentActivity, cordova.getActivity().getClass());
519
- intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
520
- cordova.getActivity().startActivity(intent);
554
+ private void setPaywallActionInterceptor(CallbackContext callbackContext) {
555
+ Purchasely.setPaywallActionsInterceptor(
556
+ (info, plyPresentationAction, map, plyProcessActionListener) -> {
557
+ processActionListener = plyProcessActionListener;
521
558
 
522
- PluginResult result = new PluginResult(PluginResult.Status.OK);
523
- result.setKeepCallback(true);
524
- callbackContext.sendPluginResult(result);
525
- });
526
- }
559
+ HashMap<String, Object> parametersForCordova = new HashMap<>();
560
+ parametersForCordova.put("title", map.getTitle());
561
+ parametersForCordova.put("url", map.getUrl());
562
+ parametersForCordova.put("plan", transformPlanToMap(map.getPlan()));
563
+ parametersForCordova.put("presentation", map.getPresentation());
527
564
 
528
- private void onUserLoggedIn(boolean userLoggedIn) {
529
- if(loginClosedListener != null) {
530
- if(productActivity != null) productActivity.relaunch(cordova);
531
- cordova.getActivity().runOnUiThread(() -> loginClosedListener.userLoggedIn(userLoggedIn));
532
- }
533
- }
565
+ HashMap<String, Object> infoMap = new HashMap<>();
566
+ if(info.getContentId() != null) infoMap.put("contentId", info.getContentId());
567
+ if(info.getPresentationId() != null) infoMap.put("presentationId", info.getPresentationId());
534
568
 
535
- private void setConfirmPurchaseHandler(CallbackContext callbackContext) {
536
- Purchasely.setConfirmPurchaseHandler((fragmentActivity, continuePurchaseListener) -> {
537
- this.continuePurchaseListener = continuePurchaseListener;
538
- Intent intent = new Intent(fragmentActivity, cordova.getActivity().getClass());
539
- intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
540
- cordova.getActivity().startActivity(intent);
569
+ HashMap<String, Object> resultForCordova = new HashMap<>();
570
+ resultForCordova.put("info", infoMap);
571
+ resultForCordova.put("action", plyPresentationAction.getValue());
572
+ resultForCordova.put("parameters", parametersForCordova);
541
573
 
542
- PluginResult result = new PluginResult(PluginResult.Status.OK);
574
+ PluginResult result = new PluginResult(
575
+ PluginResult.Status.OK,
576
+ new JSONObject(resultForCordova)
577
+ );
543
578
  result.setKeepCallback(true);
544
579
  callbackContext.sendPluginResult(result);
545
580
  });
546
581
  }
547
582
 
548
- private void processToPayment(boolean continueToPayment) {
549
- if(continuePurchaseListener != null) {
583
+ private void closePaywall(CallbackContext callbackContext) {
584
+ Activity purchaselyActivity = productActivity.activity.get();
585
+ Activity activity = purchaselyActivity != null ? purchaselyActivity : cordova.getActivity();
586
+ Intent intent = new Intent(activity, cordova.getActivity().getClass());
587
+ intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
588
+ cordova.getActivity().startActivity(intent);
589
+ }
590
+
591
+ private void onProcessAction(boolean processAction) {
592
+ if(processActionListener != null) {
550
593
  if(productActivity != null) {
551
594
  boolean softRelaunched = productActivity.relaunch(cordova);
552
595
  if(softRelaunched) {
553
- cordova.getActivity().runOnUiThread(() -> continuePurchaseListener.processToPayment(continueToPayment));
596
+ cordova.getActivity().runOnUiThread(() -> processActionListener.processAction(processAction));
554
597
  } else {
555
598
  new Thread(() -> {
556
599
  try {
557
600
  Thread.sleep(500);
558
601
  } catch (InterruptedException e) {
559
- Log.e("Purchasely", "process to payment error", e);
602
+ Log.e("Purchasely", "process action error", e);
560
603
  } finally {
561
- cordova.getActivity().runOnUiThread(() -> continuePurchaseListener.processToPayment(continueToPayment));
604
+ cordova.getActivity().runOnUiThread(() -> processActionListener.processAction(processAction));
562
605
  }
563
606
  }).start();
564
607
  }
@@ -0,0 +1,6 @@
1
+ <resources>
2
+ <style name="Theme.Purchasely.Fullscreen" parent="Theme.AppCompat.Light.NoActionBar">
3
+ <item name="android:navigationBarColor">@android:color/transparent</item>
4
+ <item name="android:statusBarColor">@android:color/transparent</item>
5
+ </style>
6
+ </resources>
@@ -0,0 +1,6 @@
1
+ <resources>
2
+ <style name="Theme.Purchasely.Fullscreen" parent="Theme.AppCompat.Light.NoActionBar">
3
+ <item name="android:navigationBarColor">@android:color/transparent</item>
4
+ <item name="android:statusBarColor">@android:color/transparent</item>
5
+ </style>
6
+ </resources>
@@ -0,0 +1,7 @@
1
+ <resources>
2
+ <style name="Theme.Purchasely.Fullscreen.Light" parent="Theme.AppCompat.Light.NoActionBar">
3
+ <item name="android:navigationBarColor">@android:color/transparent</item>
4
+ <item name="android:statusBarColor">@android:color/transparent</item>
5
+ <item name="android:windowLightStatusBar">true</item>
6
+ </style>
7
+ </resources>
@@ -11,16 +11,13 @@
11
11
  @interface CDVPurchasely<PLYEventDelegate> : CDVPlugin {
12
12
  }
13
13
 
14
- @property (nonatomic, retain) UIViewController* presentedPresentationViewController;
14
+ @property (nonatomic, assign) UIViewController* presentedPresentationViewController;
15
15
 
16
16
  @property CDVInvokedUrlCommand* purchasedCommand;
17
17
  @property CDVInvokedUrlCommand* eventCommand;
18
18
 
19
- @property CDVInvokedUrlCommand* loginTappedCommand;
20
- @property void (^loginClosedHandler)(BOOL loggedIn);
21
-
22
- @property CDVInvokedUrlCommand* authorizePurchaseCommand;
23
- @property void (^authorizePurchaseHandler)(BOOL authorizePurchase);
19
+ @property CDVInvokedUrlCommand* paywallActionInterceptorCommand;
20
+ @property void (^onProcessActionHandler)(BOOL proceed);
24
21
 
25
22
  - (void)startWithAPIKey:(CDVInvokedUrlCommand*)command;
26
23
  - (void)setLogLevel:(CDVInvokedUrlCommand*)command;
@@ -36,6 +33,7 @@
36
33
  - (void)presentSubscriptions:(CDVInvokedUrlCommand*)command;
37
34
  - (void)purchaseWithPlanVendorId:(CDVInvokedUrlCommand*)command;
38
35
  - (void)restoreAllProducts:(CDVInvokedUrlCommand*)command;
36
+ - (void)silentRestoreAllProducts:(CDVInvokedUrlCommand*)command;
39
37
  - (void)purchasedSubscription:(CDVInvokedUrlCommand*)command;
40
38
  - (void)allProducts:(CDVInvokedUrlCommand*)command;
41
39
  - (void)productWithIdentifier:(CDVInvokedUrlCommand*)command;
@@ -45,10 +43,8 @@
45
43
  - (void)removeEventsListener:(CDVInvokedUrlCommand*)command;
46
44
  - (void)handle:(CDVInvokedUrlCommand*)command;
47
45
  - (void)close:(CDVInvokedUrlCommand*)command;
48
- - (void)setLoginTappedHandler:(CDVInvokedUrlCommand*)command;
49
- - (void)onUserLoggedIn:(CDVInvokedUrlCommand*)command;
50
- - (void)setConfirmPurchaseHandler:(CDVInvokedUrlCommand*)command;
51
- - (void)processToPayment:(CDVInvokedUrlCommand*)command;
52
-
46
+ - (void)setPaywallActionInterceptor:(CDVInvokedUrlCommand*)command;
47
+ - (void)onProcessAction:(CDVInvokedUrlCommand*)command;
48
+ - (void)closePaywall:(CDVInvokedUrlCommand*)command;
53
49
 
54
50
  @end