@purchasely/cordova-plugin-purchasely 1.1.8 → 2.1.0

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.
@@ -27,14 +27,14 @@ function onDeviceReady() {
27
27
  console.log('Running cordova-' + cordova.platformId + '@' + cordova.version);
28
28
  document.getElementById('deviceready').classList.add('ready');
29
29
 
30
- console.log("Hi");
30
+ Purchasely.setLanguage('en')
31
31
 
32
32
  Purchasely.startWithAPIKey(
33
33
  'afa96c76-1d8e-4e3c-a48f-204a3cd93a15',
34
34
  ['Google'],
35
35
  null,
36
36
  Purchasely.LogLevel.DEBUG,
37
- false,
37
+ Purchasely.RunningMode.full,
38
38
  (isConfigured) => {
39
39
  if(isConfigured) onPuchaselySdkReady();
40
40
  },
@@ -46,6 +46,7 @@ function onDeviceReady() {
46
46
  document.getElementById("presentSubscriptions").addEventListener("click", presentSubscriptions);
47
47
  document.getElementById("purchaseWithPlanVendorId").addEventListener("click", purchaseWithPlanVendorId);
48
48
  document.getElementById("restore").addEventListener("click", restore);
49
+ document.getElementById("silentRestore").addEventListener("click", silentRestore);
49
50
  document.getElementById("processToPayment").addEventListener("click", processToPayment);
50
51
 
51
52
  }
@@ -81,9 +82,26 @@ function onPuchaselySdkReady() {
81
82
  Purchasely.setLogLevel(Purchasely.LogLevel.DEBUG);
82
83
 
83
84
  Purchasely.setAttribute(Purchasely.Attribute.FIREBASE_APP_INSTANCE_ID, "1");
85
+ Purchasely.setAttribute(Purchasely.Attribute.BATCH_INSTALLATION_ID, "testBatch1");
84
86
 
85
87
  Purchasely.isReadyToPurchase(true);
86
88
 
89
+ Purchasely.planWithIdentifier('PURCHASELY_PLUS_MONTHLY', (plan) => {
90
+ console.log(' ==> Plan');
91
+ console.log(plan.vendorId);
92
+ console.log(plan.productId);
93
+ console.log(plan.name);
94
+ console.log(plan.price);
95
+ console.log(plan.amount);
96
+ console.log(plan.period);
97
+ console.log(plan.hasIntroductoryPrice);
98
+ console.log(plan.introPrice);
99
+ console.log(plan.introAmount);
100
+ console.log(plan.introDuration);
101
+ }, (error) => {
102
+ console.log(error);
103
+ });
104
+
87
105
  Purchasely.setDefaultPresentationResultHandler(callback => {
88
106
  console.log(callback);
89
107
  if(callback.result == Purchasely.PurchaseResult.CANCELLED) {
@@ -92,26 +110,56 @@ function onPuchaselySdkReady() {
92
110
  console.log("User purchased " + callback.plan.vendorId);
93
111
  }
94
112
  },
95
- (error) => {
113
+ (error) => {
96
114
  console.log("Error with purchase : " + error);
97
115
  });
98
116
 
99
- Purchasely.setLoginTappedHandler(onLoginTapped => {
100
- // Present your own screen for user to log in
101
-
102
- // Call this method to update Purchasely Paywall
103
- Purchasely.userLogin('my_user_id');
104
- Purchasely.onUserLoggedIn(true);
105
- });
106
-
107
- Purchasely.setConfirmPurchaseHandler(onPurchaseTapped => {
108
- // Present your own screen before purchase
117
+ Purchasely.setPaywallActionInterceptor((result) => {
118
+ console.log(result);
119
+ console.log('Received action from paywall ' + result.info.presentationId);
120
+
121
+ if (result.action === Purchasely.PaywallAction.navigate) {
122
+ console.log(
123
+ 'User wants to navigate to website ' +
124
+ result.parameters.title +
125
+ ' ' +
126
+ result.parameters.url
127
+ );
128
+ console.log('prevent Purchasely SDK to navigate to website');
129
+ Purchasely.onProcessAction(false);
130
+ } else if (result.action === Purchasely.PaywallAction.close) {
131
+ console.log('User wants to close paywall');
132
+ Purchasely.onProcessAction(true);
133
+ } else if (result.action === Purchasely.PaywallAction.login) {
134
+ console.log('User wants to login');
135
+ //Present your own screen for user to log in
136
+ Purchasely.closePaywall();
137
+ Purchasely.userLogin('MY_USER_ID');
138
+ //Call this method to update Purchasely Paywall
139
+ Purchasely.onProcessAction(true);
140
+ } else if (result.action === Purchasely.PaywallAction.open_presentation) {
141
+ console.log('User wants to open a new paywall');
142
+ Purchasely.onProcessAction(true);
143
+ } else if (result.action === Purchasely.PaywallAction.purchase) {
144
+ console.log('User wants to purchase');
145
+ //If you want to intercept it, close paywall and display your screen
146
+ Purchasely.closePaywall();
147
+ Purchasely.onProcessAction(true);
148
+ } else if (result.action === Purchasely.PaywallAction.restore) {
149
+ console.log('User wants to restore his purchases');
150
+ Purchasely.onProcessAction(true);
151
+ } else {
152
+ console.log('Action unknown ' + result.action);
153
+ Purchasely.onProcessAction(true);
154
+ }
109
155
  });
110
156
  }
111
157
 
112
158
  function openPresentation() {
113
159
  Purchasely.presentPresentationWithIdentifier(
114
160
  null,
161
+ null,
162
+ true,
115
163
  (callback) => {
116
164
  console.log(callback);
117
165
  if(callback.result == Purchasely.PurchaseResult.CANCELLED) {
@@ -136,7 +184,7 @@ function purchaseWithPlanVendorId() {
136
184
 
137
185
  function processToPayment() {
138
186
  // Call this method to process to payment
139
- Purchasely.processToPayment(true);
187
+ Purchasely.onProcessAction(true);
140
188
  }
141
189
 
142
190
  function restore() {
@@ -151,6 +199,18 @@ function restore() {
151
199
  );
152
200
  }
153
201
 
202
+ function silentRestore() {
203
+ Purchasely.silentRestoreAllProducts(
204
+ (plan) => {
205
+ if(plan) console.log("Silent restore " + plan.vendorId);
206
+ else console.log("Nothing to restore");
207
+ },
208
+ (error) => {
209
+ console.log("Silent Restore failed " + error);
210
+ },
211
+ );
212
+ }
213
+
154
214
  function openDeeplink() {
155
215
  Purchasely.handle(
156
216
  "purchasely://ply/presentations/CAROUSEL",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@purchasely/cordova-plugin-purchasely",
3
- "version": "1.1.8",
3
+ "version": "2.1.0",
4
4
  "description": "Purchasely is a solution to ease the integration and boost your In-App Purchases & Subscriptions on the App Store, Google Play Store, Amazon Appstore and Huawei App Gallery.",
5
5
  "cordova": {
6
6
  "id": "@purchasely/cordova-plugin-purchasely",
package/plugin.xml CHANGED
@@ -1,5 +1,5 @@
1
1
  <?xml version='1.0' encoding='utf-8'?>
2
- <plugin id="@purchasely/cordova-plugin-purchasely" version="1.1.8" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
2
+ <plugin id="@purchasely/cordova-plugin-purchasely" version="2.1.0" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
3
3
  <name>Purchasely</name>
4
4
  <js-module name="Purchasely" src="www/Purchasely.js">
5
5
  <clobbers target="Purchasely" />
@@ -28,7 +28,7 @@
28
28
  <source url="https://github.com/CocoaPods/Specs.git"/>
29
29
  </config>
30
30
  <pods use-frameworks="true">
31
- <pod name="Purchasely" spec="2.7.3"/>
31
+ <pod name="Purchasely" spec="3.1.0"/>
32
32
  </pods>
33
33
  </podspec>
34
34
  </platform>
@@ -51,10 +51,13 @@
51
51
  android:theme="@style/Theme.AppCompat.Light.NoActionBar">
52
52
  </activity>
53
53
  </config-file>
54
- <framework src="io.purchasely:core:2.7.6" />
54
+ <framework src="io.purchasely:core:3.1.0" />
55
55
  <source-file src="src/android/PurchaselyPlugin.java" target-dir="src/cordova/plugin/purchasely" />
56
56
  <source-file src="src/android/PLYProductActivity.java" target-dir="src/cordova/plugin/purchasely" />
57
57
  <source-file src="src/android/PLYSubscriptionsActivity.java" target-dir="src/cordova/plugin/purchasely" />
58
58
  <source-file src="src/android/activity_ply_product_activity.xml" target-dir="res/layout"/>
59
+ <source-file src="src/android/theme_purchasely_fullscreen.xml" target-dir="res/values"/>
60
+ <source-file src="src/android/theme_purchasely_fullscreen_v23_light_status_bar.xml" target-dir="res/values-v23"/>
61
+ <source-file src="src/android/theme_purchasely_fullscreen_v23.xml" target-dir="res/values-v23"/>
59
62
  </platform>
60
63
  </plugin>
@@ -4,12 +4,17 @@
4
4
  <option name="autoReloadType" value="NONE" />
5
5
  </component>
6
6
  <component name="ChangeListManager">
7
- <list default="true" id="ad0a27bd-64f4-4852-98a1-a7dc8e28a72f" name="Default Changelist" comment="" />
7
+ <list default="true" id="ad0a27bd-64f4-4852-98a1-a7dc8e28a72f" name="Default Changelist" comment="">
8
+ <change beforePath="$PROJECT_DIR$/../../plugin.xml" beforeDir="false" afterPath="$PROJECT_DIR$/../../plugin.xml" afterDir="false" />
9
+ </list>
8
10
  <option name="SHOW_DIALOG" value="false" />
9
11
  <option name="HIGHLIGHT_CONFLICTS" value="true" />
10
12
  <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
11
13
  <option name="LAST_RESOLUTION" value="IGNORE" />
12
14
  </component>
15
+ <component name="Git.Settings">
16
+ <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/../.." />
17
+ </component>
13
18
  <component name="ProjectId" id="1uz33TZxRidCdjXlE00OtDvw6mD" />
14
19
  <component name="ProjectViewState">
15
20
  <option name="hideEmptyMiddlePackages" value="true" />
@@ -18,7 +23,9 @@
18
23
  <component name="PropertiesComponent">
19
24
  <property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
20
25
  <property name="android.sdk.path" value="$USER_HOME$/Android/Sdk" />
26
+ <property name="dart.analysis.tool.window.visible" value="false" />
21
27
  <property name="last_opened_file_path" value="$PROJECT_DIR$" />
28
+ <property name="show.migrate.to.gradle.popup" value="false" />
22
29
  </component>
23
30
  <component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
24
31
  <component name="TaskManager">
@@ -31,4 +38,15 @@
31
38
  </task>
32
39
  <servers />
33
40
  </component>
41
+ <component name="Vcs.Log.Tabs.Properties">
42
+ <option name="TAB_STATES">
43
+ <map>
44
+ <entry key="MAIN">
45
+ <value>
46
+ <State />
47
+ </value>
48
+ </entry>
49
+ </map>
50
+ </option>
51
+ </component>
34
52
  </project>
@@ -6,6 +6,7 @@ import android.os.Bundle;
6
6
 
7
7
  import androidx.annotation.Nullable;
8
8
  import androidx.appcompat.app.AppCompatActivity;
9
+ import androidx.core.view.WindowCompat;
9
10
  import androidx.fragment.app.Fragment;
10
11
 
11
12
  import java.lang.ref.WeakReference;
@@ -18,6 +19,12 @@ public class PLYProductActivity extends AppCompatActivity {
18
19
  @Override
19
20
  protected void onCreate(@Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
20
21
  super.onCreate(savedInstanceState);
22
+
23
+ boolean isFullScreen = getIntent().getExtras().getBoolean("isFullScreen");
24
+ if(isFullScreen) {
25
+ WindowCompat.setDecorFitsSystemWindows(getWindow(), false);
26
+ }
27
+
21
28
  String package_name = getApplication().getPackageName();
22
29
  setContentView(getApplication().getResources()
23
30
  .getIdentifier("activity_ply_product_activity",
@@ -26,17 +33,25 @@ public class PLYProductActivity extends AppCompatActivity {
26
33
  );
27
34
 
28
35
  String presentationId = getIntent().getExtras().getString("presentationId");
36
+ String placementId = getIntent().getExtras().getString("placementId");
29
37
  String productId = getIntent().getExtras().getString("productId");
30
38
  String planId = getIntent().getExtras().getString("planId");
31
39
  String contentId = getIntent().getExtras().getString("contentId");
32
40
 
33
41
  Fragment fragment;
34
- if(planId != null && !planId.isEmpty()) {
35
- fragment = Purchasely.planFragment(planId, presentationId, contentId, listener);
42
+ if(placementId != null && !placementId.isEmpty()) {
43
+ fragment = Purchasely.presentationFragmentForPlacement(placementId, contentId, null, listener);
44
+ } else if(planId != null && !planId.isEmpty()) {
45
+ fragment = Purchasely.planFragment(planId, presentationId, contentId, null, listener);
36
46
  } else if(productId != null && !productId.isEmpty()) {
37
- fragment = Purchasely.productFragment(productId, presentationId, contentId, listener);
47
+ fragment = Purchasely.productFragment(productId, presentationId, contentId, null, listener);
38
48
  } else {
39
- fragment = Purchasely.presentationFragment(presentationId, contentId, listener);
49
+ fragment = Purchasely.presentationFragment(presentationId, contentId, null, listener);
50
+ }
51
+
52
+ if(fragment == null) {
53
+ supportFinishAfterTransition();
54
+ return;
40
55
  }
41
56
 
42
57
  getSupportFragmentManager().beginTransaction()
@@ -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,14 +123,24 @@ 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;
130
+ case "presentPresentationForPlacement":
131
+ presentPresentationForPlacement(
132
+ args.getString(0),
133
+ args.getString(1),
134
+ args.getBoolean(2),
135
+ callbackContext
136
+ );
137
+ break;
112
138
  case "presentProductWithIdentifier":
113
139
  presentProductWithIdentifier(
114
140
  args.getString(0),
115
141
  args.getString(1),
116
142
  args.getString(2),
143
+ args.getBoolean(3),
117
144
  callbackContext
118
145
  );
119
146
  break;
@@ -122,6 +149,7 @@ public class PurchaselyPlugin extends CordovaPlugin {
122
149
  args.getString(0),
123
150
  args.getString(1),
124
151
  args.getString(2),
152
+ args.getBoolean(3),
125
153
  callbackContext
126
154
  );
127
155
  break;
@@ -131,6 +159,9 @@ public class PurchaselyPlugin extends CordovaPlugin {
131
159
  case "restoreAllProducts":
132
160
  restoreAllProducts(callbackContext);
133
161
  break;
162
+ case "silentRestoreAllProducts":
163
+ restoreAllProducts(callbackContext);
164
+ break;
134
165
  case "userSubscriptions":
135
166
  userSubscriptions(callbackContext);
136
167
  break;
@@ -153,17 +184,14 @@ public class PurchaselyPlugin extends CordovaPlugin {
153
184
  callbackContext
154
185
  );
155
186
  break;
156
- case "setLoginTappedHandler":
157
- setLoginTappedHandler(callbackContext);
187
+ case "setPaywallActionInterceptor":
188
+ setPaywallActionInterceptor(callbackContext);
158
189
  break;
159
- case "onUserLoggedIn":
160
- onUserLoggedIn(args.getBoolean(0));
190
+ case "onProcessAction":
191
+ onProcessAction(args.getBoolean(0));
161
192
  break;
162
- case "setConfirmPurchaseHandler":
163
- setConfirmPurchaseHandler(callbackContext);
164
- break;
165
- case "processToPayment":
166
- processToPayment(args.getBoolean(0));
193
+ case "closePaywall":
194
+ closePaywall(callbackContext);
167
195
  break;
168
196
  default:
169
197
  return false;
@@ -203,7 +231,7 @@ public class PurchaselyPlugin extends CordovaPlugin {
203
231
  JSONArray stores,
204
232
  String userId,
205
233
  int logLevel,
206
- boolean observerMode,
234
+ int runningMode,
207
235
  CallbackContext callbackContext) {
208
236
  ArrayList<String> list = new ArrayList<>();
209
237
  for (int i=0; i< stores.length(); i++) {
@@ -215,11 +243,17 @@ public class PurchaselyPlugin extends CordovaPlugin {
215
243
  }
216
244
  ArrayList<Store> storesInstances = getStoresInstances(list);
217
245
 
246
+ PLYRunningMode plyRunningMode = PLYRunningMode.Full.INSTANCE;
247
+ if(runningMode == runningModeTransactionOnly) plyRunningMode = PLYRunningMode.TransactionOnly.INSTANCE;
248
+ else if(runningMode == runningModeObserver) plyRunningMode = PLYRunningMode.Observer.INSTANCE;
249
+ else if(runningMode == runningModePaywallOnly) plyRunningMode = PLYRunningMode.PaywallOnly.INSTANCE;
250
+ else if(runningMode == runningModePaywallObserver) plyRunningMode = PLYRunningMode.PaywallObserver.INSTANCE;
251
+
218
252
  new Purchasely.Builder(cordova.getContext())
219
253
  .apiKey(apiKey)
220
254
  .stores(storesInstances)
221
255
  .userId(userId)
222
- .observerMode(observerMode)
256
+ .runningMode(plyRunningMode)
223
257
  .logLevel(LogLevel.values()[logLevel])
224
258
  .build();
225
259
 
@@ -267,8 +301,7 @@ public class PurchaselyPlugin extends CordovaPlugin {
267
301
  private void close() {
268
302
  defaultCallback = null;
269
303
  presentationCallback = null;
270
- loginClosedListener = null;
271
- continuePurchaseListener = null;
304
+ processActionListener = null;
272
305
  productActivity = null;
273
306
  Purchasely.close();
274
307
  }
@@ -318,6 +351,14 @@ public class PurchaselyPlugin extends CordovaPlugin {
318
351
  Purchasely.setLogLevel(LogLevel.values()[logLevel]);
319
352
  }
320
353
 
354
+ private void setLanguage(String language) {
355
+ try {
356
+ Purchasely.setLanguage(new Locale(language));
357
+ } catch (Exception e) {
358
+ Purchasely.setLanguage(Locale.getDefault());
359
+ }
360
+ }
361
+
321
362
  private void isReadyToPurchase(boolean isReadyToPurchase) {
322
363
  Purchasely.setReadyToPurchase(isReadyToPurchase);
323
364
  }
@@ -346,36 +387,54 @@ public class PurchaselyPlugin extends CordovaPlugin {
346
387
  }
347
388
 
348
389
  private void presentPresentationWithIdentifier(String presentationVendorId,
349
- String contentId,
390
+ String contentId,
391
+ boolean isFullScreen,
350
392
  CallbackContext callbackContext) {
351
393
  presentationCallback = callbackContext;
352
394
  Intent intent = PLYProductActivity.newIntent(cordova.getActivity());
353
395
  intent.putExtra("presentationId", presentationVendorId);
354
396
  intent.putExtra("contentId", contentId);
397
+ intent.putExtra("isFullScreen", isFullScreen);
398
+ cordova.getActivity().startActivity(intent);
399
+ }
400
+
401
+ private void presentPresentationForPlacement(String placementVendorId,
402
+ String contentId,
403
+ boolean isFullScreen,
404
+ CallbackContext callbackContext) {
405
+ presentationCallback = callbackContext;
406
+ Intent intent = PLYProductActivity.newIntent(cordova.getActivity());
407
+ intent.putExtra("placementId", placementVendorId);
408
+ intent.putExtra("contentId", contentId);
409
+ intent.putExtra("isFullScreen", isFullScreen);
355
410
  cordova.getActivity().startActivity(intent);
356
411
  }
357
412
 
358
413
  private void presentProductWithIdentifier(String productVendorId,
359
414
  String presentationVendorId,
360
415
  String contentId,
416
+ boolean isFullScreen,
361
417
  CallbackContext callbackContext) {
362
418
  presentationCallback = callbackContext;
363
419
  Intent intent = PLYProductActivity.newIntent(cordova.getActivity());
364
420
  intent.putExtra("presentationId", presentationVendorId);
365
421
  intent.putExtra("productId", productVendorId);
366
422
  intent.putExtra("contentId", contentId);
423
+ intent.putExtra("isFullScreen", isFullScreen);
367
424
  cordova.getActivity().startActivity(intent);
368
425
  }
369
426
 
370
427
  private void presentPlanWithIdentifier(String planVendorId,
371
428
  String presentationVendorId,
372
429
  String contentId,
430
+ boolean isFullScreen,
373
431
  CallbackContext callbackContext) {
374
432
  presentationCallback = callbackContext;
375
433
  Intent intent = PLYProductActivity.newIntent(cordova.getActivity());
376
434
  intent.putExtra("presentationId", presentationVendorId);
377
435
  intent.putExtra("planId", planVendorId);
378
436
  intent.putExtra("contentId", contentId);
437
+ intent.putExtra("isFullScreen", isFullScreen);
379
438
  cordova.getActivity().startActivity(intent);
380
439
  }
381
440
 
@@ -453,7 +512,7 @@ public class PurchaselyPlugin extends CordovaPlugin {
453
512
  }
454
513
 
455
514
  private void productWithIdentifier(String vendorId, CallbackContext callbackContext) {
456
- Purchasely.getProduct(vendorId, new ProductListener() {
515
+ Purchasely.product(vendorId, new ProductListener() {
457
516
  @Override
458
517
  public void onSuccess(@Nullable PLYProduct plyProduct) {
459
518
  if(plyProduct != null) {
@@ -471,7 +530,7 @@ public class PurchaselyPlugin extends CordovaPlugin {
471
530
  }
472
531
 
473
532
  private void planWithIdentifier(String vendorId, CallbackContext callbackContext) {
474
- Purchasely.getPlan(vendorId, new PlanListener() {
533
+ Purchasely.plan(vendorId, new PlanListener() {
475
534
  @Override
476
535
  public void onSuccess(@Nullable PLYPlan plyPlan) {
477
536
  if(plyPlan != null) {
@@ -489,7 +548,7 @@ public class PurchaselyPlugin extends CordovaPlugin {
489
548
  }
490
549
 
491
550
  private void purchaseWithPlanVendorId(String planVendorId, String contentId, CallbackContext callbackContext) {
492
- Purchasely.getPlan(planVendorId, new PlanListener() {
551
+ Purchasely.plan(planVendorId, new PlanListener() {
493
552
  @Override
494
553
  public void onSuccess(@Nullable PLYPlan plyPlan) {
495
554
  if(plyPlan != null) {
@@ -512,53 +571,63 @@ public class PurchaselyPlugin extends CordovaPlugin {
512
571
  });
513
572
  }
514
573
 
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);
574
+ private void setPaywallActionInterceptor(CallbackContext callbackContext) {
575
+ Purchasely.setPaywallActionsInterceptor(
576
+ (info, plyPresentationAction, map, plyProcessActionListener) -> {
577
+ processActionListener = plyProcessActionListener;
578
+
579
+ String url = null;
580
+ if(map.getUrl() != null) {
581
+ url = map.getUrl().toString();
582
+ }
521
583
 
522
- PluginResult result = new PluginResult(PluginResult.Status.OK);
584
+ HashMap<String, Object> parametersForCordova = new HashMap<>();
585
+ parametersForCordova.put("title", map.getTitle());
586
+ parametersForCordova.put("url", url);
587
+ parametersForCordova.put("plan", transformPlanToMap(map.getPlan()));
588
+ parametersForCordova.put("presentation", map.getPresentation());
589
+
590
+ HashMap<String, Object> infoMap = new HashMap<>();
591
+ if(info.getContentId() != null) infoMap.put("contentId", info.getContentId());
592
+ if(info.getPresentationId() != null) infoMap.put("presentationId", info.getPresentationId());
593
+ if(info.getPlacementId() != null) infoMap.put("placementId", info.getPlacementId());
594
+
595
+ HashMap<String, Object> resultForCordova = new HashMap<>();
596
+ resultForCordova.put("info", infoMap);
597
+ resultForCordova.put("action", plyPresentationAction.getValue());
598
+ resultForCordova.put("parameters", parametersForCordova);
599
+
600
+ PluginResult result = new PluginResult(
601
+ PluginResult.Status.OK,
602
+ new JSONObject(resultForCordova)
603
+ );
523
604
  result.setKeepCallback(true);
524
605
  callbackContext.sendPluginResult(result);
525
606
  });
526
607
  }
527
608
 
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
- }
534
-
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);
541
-
542
- PluginResult result = new PluginResult(PluginResult.Status.OK);
543
- result.setKeepCallback(true);
544
- callbackContext.sendPluginResult(result);
545
- });
609
+ private void closePaywall(CallbackContext callbackContext) {
610
+ Activity purchaselyActivity = productActivity.activity.get();
611
+ Activity activity = purchaselyActivity != null ? purchaselyActivity : cordova.getActivity();
612
+ Intent intent = new Intent(activity, cordova.getActivity().getClass());
613
+ intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
614
+ cordova.getActivity().startActivity(intent);
546
615
  }
547
616
 
548
- private void processToPayment(boolean continueToPayment) {
549
- if(continuePurchaseListener != null) {
617
+ private void onProcessAction(boolean processAction) {
618
+ if(processActionListener != null) {
550
619
  if(productActivity != null) {
551
620
  boolean softRelaunched = productActivity.relaunch(cordova);
552
621
  if(softRelaunched) {
553
- cordova.getActivity().runOnUiThread(() -> continuePurchaseListener.processToPayment(continueToPayment));
622
+ cordova.getActivity().runOnUiThread(() -> processActionListener.processAction(processAction));
554
623
  } else {
555
624
  new Thread(() -> {
556
625
  try {
557
626
  Thread.sleep(500);
558
627
  } catch (InterruptedException e) {
559
- Log.e("Purchasely", "process to payment error", e);
628
+ Log.e("Purchasely", "process action error", e);
560
629
  } finally {
561
- cordova.getActivity().runOnUiThread(() -> continuePurchaseListener.processToPayment(continueToPayment));
630
+ cordova.getActivity().runOnUiThread(() -> processActionListener.processAction(processAction));
562
631
  }
563
632
  }).start();
564
633
  }
@@ -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>