@purchasely/cordova-plugin-purchasely 1.2.0 → 2.1.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.
- package/README.md +16 -2
- package/VERSIONS.md +4 -0
- package/example/config.xml +10 -0
- package/example/package-lock.json +247 -75
- package/example/package.json +4 -3
- package/example/www/js/index.js +60 -16
- package/package.json +1 -1
- package/plugin.xml +6 -3
- package/src/android/.idea/workspace.xml +19 -1
- package/src/android/PLYProductActivity.java +19 -4
- package/src/android/PurchaselyPlugin.java +131 -70
- package/src/android/theme_purchasely_fullscreen.xml +6 -0
- package/src/android/theme_purchasely_fullscreen_v23.xml +6 -0
- package/src/android/theme_purchasely_fullscreen_v23_light_status_bar.xml +7 -0
- package/src/ios/CDVPurchasely.h +8 -11
- package/src/ios/CDVPurchasely.m +188 -89
- package/src/ios/Hybrid/PLYPlan+Hybrid.m +9 -0
- package/www/Purchasely.js +35 -28
package/example/www/js/index.js
CHANGED
|
@@ -27,16 +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");
|
|
31
|
-
|
|
32
30
|
Purchasely.setLanguage('en')
|
|
33
|
-
|
|
31
|
+
|
|
34
32
|
Purchasely.startWithAPIKey(
|
|
35
33
|
'afa96c76-1d8e-4e3c-a48f-204a3cd93a15',
|
|
36
34
|
['Google'],
|
|
37
35
|
null,
|
|
38
36
|
Purchasely.LogLevel.DEBUG,
|
|
39
|
-
|
|
37
|
+
Purchasely.RunningMode.full,
|
|
40
38
|
(isConfigured) => {
|
|
41
39
|
if(isConfigured) onPuchaselySdkReady();
|
|
42
40
|
},
|
|
@@ -88,6 +86,22 @@ function onPuchaselySdkReady() {
|
|
|
88
86
|
|
|
89
87
|
Purchasely.isReadyToPurchase(true);
|
|
90
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
|
+
|
|
91
105
|
Purchasely.setDefaultPresentationResultHandler(callback => {
|
|
92
106
|
console.log(callback);
|
|
93
107
|
if(callback.result == Purchasely.PurchaseResult.CANCELLED) {
|
|
@@ -96,26 +110,56 @@ function onPuchaselySdkReady() {
|
|
|
96
110
|
console.log("User purchased " + callback.plan.vendorId);
|
|
97
111
|
}
|
|
98
112
|
},
|
|
99
|
-
|
|
113
|
+
(error) => {
|
|
100
114
|
console.log("Error with purchase : " + error);
|
|
101
115
|
});
|
|
102
116
|
|
|
103
|
-
Purchasely.
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
Purchasely.
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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
|
+
}
|
|
113
155
|
});
|
|
114
156
|
}
|
|
115
157
|
|
|
116
158
|
function openPresentation() {
|
|
117
159
|
Purchasely.presentPresentationWithIdentifier(
|
|
118
160
|
null,
|
|
161
|
+
null,
|
|
162
|
+
true,
|
|
119
163
|
(callback) => {
|
|
120
164
|
console.log(callback);
|
|
121
165
|
if(callback.result == Purchasely.PurchaseResult.CANCELLED) {
|
|
@@ -140,7 +184,7 @@ function purchaseWithPlanVendorId() {
|
|
|
140
184
|
|
|
141
185
|
function processToPayment() {
|
|
142
186
|
// Call this method to process to payment
|
|
143
|
-
Purchasely.
|
|
187
|
+
Purchasely.onProcessAction(true);
|
|
144
188
|
}
|
|
145
189
|
|
|
146
190
|
function restore() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@purchasely/cordova-plugin-purchasely",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "2.1.1",
|
|
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.
|
|
2
|
+
<plugin id="@purchasely/cordova-plugin-purchasely" version="2.1.1" 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="
|
|
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:
|
|
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(
|
|
35
|
-
fragment = Purchasely.
|
|
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;
|
|
@@ -19,18 +22,22 @@ import org.w3c.dom.Attr;
|
|
|
19
22
|
import java.lang.ref.WeakReference;
|
|
20
23
|
import java.util.ArrayList;
|
|
21
24
|
import java.util.HashMap;
|
|
25
|
+
import java.util.Iterator;
|
|
22
26
|
import java.util.List;
|
|
23
27
|
import java.util.Locale;
|
|
24
28
|
import java.util.Map;
|
|
29
|
+
import java.util.function.BiConsumer;
|
|
25
30
|
|
|
26
31
|
import io.purchasely.billing.Store;
|
|
27
32
|
import io.purchasely.ext.Attribute;
|
|
28
|
-
import io.purchasely.ext.ContinuePurchaseListener;
|
|
29
33
|
import io.purchasely.ext.DistributionType;
|
|
30
34
|
import io.purchasely.ext.LogLevel;
|
|
31
|
-
import io.purchasely.ext.LoginClosedListener;
|
|
32
35
|
import io.purchasely.ext.PLYAppTechnology;
|
|
36
|
+
import io.purchasely.ext.PLYPaywallActionListener;
|
|
37
|
+
import io.purchasely.ext.PLYPresentationAction;
|
|
38
|
+
import io.purchasely.ext.PLYProcessActionListener;
|
|
33
39
|
import io.purchasely.ext.PLYProductViewResult;
|
|
40
|
+
import io.purchasely.ext.PLYRunningMode;
|
|
34
41
|
import io.purchasely.ext.PlanListener;
|
|
35
42
|
import io.purchasely.ext.ProductListener;
|
|
36
43
|
import io.purchasely.ext.ProductsListener;
|
|
@@ -52,8 +59,13 @@ public class PurchaselyPlugin extends CordovaPlugin {
|
|
|
52
59
|
static CallbackContext eventsCallback = null;
|
|
53
60
|
static ProductActivity productActivity = null;
|
|
54
61
|
|
|
55
|
-
private
|
|
56
|
-
|
|
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;
|
|
57
69
|
|
|
58
70
|
@Override
|
|
59
71
|
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
|
|
@@ -61,11 +73,11 @@ public class PurchaselyPlugin extends CordovaPlugin {
|
|
|
61
73
|
switch (action) {
|
|
62
74
|
case "startWithAPIKey":
|
|
63
75
|
startWithAPIKey(
|
|
64
|
-
args.getString(0),
|
|
76
|
+
getStringFromJson(args.getString(0)),
|
|
65
77
|
args.getJSONArray(1),
|
|
66
|
-
args.getString(2),
|
|
78
|
+
getStringFromJson(args.getString(2)),
|
|
67
79
|
args.getInt(3),
|
|
68
|
-
args.
|
|
80
|
+
args.getInt(4),
|
|
69
81
|
callbackContext);
|
|
70
82
|
break;
|
|
71
83
|
case "close":
|
|
@@ -81,19 +93,19 @@ public class PurchaselyPlugin extends CordovaPlugin {
|
|
|
81
93
|
getAnonymousUserId(callbackContext);
|
|
82
94
|
break;
|
|
83
95
|
case "userLogin":
|
|
84
|
-
userLogin(args.getString(0), callbackContext);
|
|
96
|
+
userLogin(getStringFromJson(args.getString(0)), callbackContext);
|
|
85
97
|
break;
|
|
86
98
|
case "userLogout":
|
|
87
99
|
userLogout();
|
|
88
100
|
break;
|
|
89
101
|
case "setLanguage":
|
|
90
|
-
setLanguage(args.getString(0));
|
|
102
|
+
setLanguage(getStringFromJson(args.getString(0)));
|
|
91
103
|
break;
|
|
92
104
|
case "setLogLevel":
|
|
93
105
|
setLogLevel(args.getInt(0));
|
|
94
106
|
break;
|
|
95
107
|
case "setAttribute":
|
|
96
|
-
setAttribute(args.getInt(0), args.getString(1));
|
|
108
|
+
setAttribute(args.getInt(0), getStringFromJson(args.getString(1)));
|
|
97
109
|
break;
|
|
98
110
|
case "setDefaultPresentationResultHandler":
|
|
99
111
|
setDefaultPresentationResultHandler(callbackContext);
|
|
@@ -109,24 +121,35 @@ public class PurchaselyPlugin extends CordovaPlugin {
|
|
|
109
121
|
break;
|
|
110
122
|
case "presentPresentationWithIdentifier":
|
|
111
123
|
presentPresentationWithIdentifier(
|
|
112
|
-
args.getString(0),
|
|
113
|
-
args.getString(1),
|
|
124
|
+
getStringFromJson(args.getString(0)),
|
|
125
|
+
getStringFromJson(args.getString(1)),
|
|
126
|
+
args.getBoolean(2),
|
|
114
127
|
callbackContext
|
|
115
128
|
);
|
|
116
129
|
break;
|
|
130
|
+
case "presentPresentationForPlacement":
|
|
131
|
+
presentPresentationForPlacement(
|
|
132
|
+
getStringFromJson(args.getString(0)),
|
|
133
|
+
getStringFromJson(args.getString(1)),
|
|
134
|
+
args.getBoolean(2),
|
|
135
|
+
callbackContext
|
|
136
|
+
);
|
|
137
|
+
break;
|
|
117
138
|
case "presentProductWithIdentifier":
|
|
118
139
|
presentProductWithIdentifier(
|
|
119
|
-
args.getString(0),
|
|
120
|
-
args.getString(1),
|
|
121
|
-
args.getString(2),
|
|
140
|
+
getStringFromJson(args.getString(0)),
|
|
141
|
+
getStringFromJson(args.getString(1)),
|
|
142
|
+
getStringFromJson(args.getString(2)),
|
|
143
|
+
args.getBoolean(3),
|
|
122
144
|
callbackContext
|
|
123
145
|
);
|
|
124
146
|
break;
|
|
125
147
|
case "presentPlanWithIdentifier":
|
|
126
148
|
presentPlanWithIdentifier(
|
|
127
|
-
args.getString(0),
|
|
128
|
-
args.getString(1),
|
|
129
|
-
args.getString(2),
|
|
149
|
+
getStringFromJson(args.getString(0)),
|
|
150
|
+
getStringFromJson(args.getString(1)),
|
|
151
|
+
getStringFromJson(args.getString(2)),
|
|
152
|
+
args.getBoolean(3),
|
|
130
153
|
callbackContext
|
|
131
154
|
);
|
|
132
155
|
break;
|
|
@@ -143,35 +166,32 @@ public class PurchaselyPlugin extends CordovaPlugin {
|
|
|
143
166
|
userSubscriptions(callbackContext);
|
|
144
167
|
break;
|
|
145
168
|
case "handle":
|
|
146
|
-
handle(args.getString(0), callbackContext);
|
|
169
|
+
handle(getStringFromJson(args.getString(0)), callbackContext);
|
|
147
170
|
break;
|
|
148
171
|
case "allProducts":
|
|
149
172
|
allProducts(callbackContext);
|
|
150
173
|
break;
|
|
151
174
|
case "productWithIdentifier":
|
|
152
|
-
productWithIdentifier(args.getString(0), callbackContext);
|
|
175
|
+
productWithIdentifier(getStringFromJson(args.getString(0)), callbackContext);
|
|
153
176
|
break;
|
|
154
177
|
case "planWithIdentifier":
|
|
155
|
-
planWithIdentifier(args.getString(0), callbackContext);
|
|
178
|
+
planWithIdentifier(getStringFromJson(args.getString(0)), callbackContext);
|
|
156
179
|
break;
|
|
157
180
|
case "purchaseWithPlanVendorId":
|
|
158
181
|
purchaseWithPlanVendorId(
|
|
159
|
-
args.getString(0),
|
|
160
|
-
args.getString(1),
|
|
182
|
+
getStringFromJson(args.getString(0)),
|
|
183
|
+
getStringFromJson(args.getString(1)),
|
|
161
184
|
callbackContext
|
|
162
185
|
);
|
|
163
186
|
break;
|
|
164
|
-
case "
|
|
165
|
-
|
|
187
|
+
case "setPaywallActionInterceptor":
|
|
188
|
+
setPaywallActionInterceptor(callbackContext);
|
|
166
189
|
break;
|
|
167
|
-
case "
|
|
168
|
-
|
|
190
|
+
case "onProcessAction":
|
|
191
|
+
onProcessAction(args.getBoolean(0));
|
|
169
192
|
break;
|
|
170
|
-
case "
|
|
171
|
-
|
|
172
|
-
break;
|
|
173
|
-
case "processToPayment":
|
|
174
|
-
processToPayment(args.getBoolean(0));
|
|
193
|
+
case "closePaywall":
|
|
194
|
+
closePaywall(callbackContext);
|
|
175
195
|
break;
|
|
176
196
|
default:
|
|
177
197
|
return false;
|
|
@@ -183,6 +203,14 @@ public class PurchaselyPlugin extends CordovaPlugin {
|
|
|
183
203
|
return true;
|
|
184
204
|
}
|
|
185
205
|
|
|
206
|
+
private String getStringFromJson(String value) {
|
|
207
|
+
if(value == null || value.equals("null") || value.isEmpty()) {
|
|
208
|
+
return null;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return value;
|
|
212
|
+
}
|
|
213
|
+
|
|
186
214
|
public static void sendPurchaseResult(PLYProductViewResult result, PLYPlan plan) {
|
|
187
215
|
int productViewResult = 0;
|
|
188
216
|
if(result == PLYProductViewResult.PURCHASED) {
|
|
@@ -211,7 +239,7 @@ public class PurchaselyPlugin extends CordovaPlugin {
|
|
|
211
239
|
JSONArray stores,
|
|
212
240
|
String userId,
|
|
213
241
|
int logLevel,
|
|
214
|
-
|
|
242
|
+
int runningMode,
|
|
215
243
|
CallbackContext callbackContext) {
|
|
216
244
|
ArrayList<String> list = new ArrayList<>();
|
|
217
245
|
for (int i=0; i< stores.length(); i++) {
|
|
@@ -223,11 +251,17 @@ public class PurchaselyPlugin extends CordovaPlugin {
|
|
|
223
251
|
}
|
|
224
252
|
ArrayList<Store> storesInstances = getStoresInstances(list);
|
|
225
253
|
|
|
254
|
+
PLYRunningMode plyRunningMode = PLYRunningMode.Full.INSTANCE;
|
|
255
|
+
if(runningMode == runningModeTransactionOnly) plyRunningMode = PLYRunningMode.TransactionOnly.INSTANCE;
|
|
256
|
+
else if(runningMode == runningModeObserver) plyRunningMode = PLYRunningMode.Observer.INSTANCE;
|
|
257
|
+
else if(runningMode == runningModePaywallOnly) plyRunningMode = PLYRunningMode.PaywallOnly.INSTANCE;
|
|
258
|
+
else if(runningMode == runningModePaywallObserver) plyRunningMode = PLYRunningMode.PaywallObserver.INSTANCE;
|
|
259
|
+
|
|
226
260
|
new Purchasely.Builder(cordova.getContext())
|
|
227
261
|
.apiKey(apiKey)
|
|
228
262
|
.stores(storesInstances)
|
|
229
263
|
.userId(userId)
|
|
230
|
-
.
|
|
264
|
+
.runningMode(plyRunningMode)
|
|
231
265
|
.logLevel(LogLevel.values()[logLevel])
|
|
232
266
|
.build();
|
|
233
267
|
|
|
@@ -275,8 +309,7 @@ public class PurchaselyPlugin extends CordovaPlugin {
|
|
|
275
309
|
private void close() {
|
|
276
310
|
defaultCallback = null;
|
|
277
311
|
presentationCallback = null;
|
|
278
|
-
|
|
279
|
-
continuePurchaseListener = null;
|
|
312
|
+
processActionListener = null;
|
|
280
313
|
productActivity = null;
|
|
281
314
|
Purchasely.close();
|
|
282
315
|
}
|
|
@@ -362,36 +395,54 @@ public class PurchaselyPlugin extends CordovaPlugin {
|
|
|
362
395
|
}
|
|
363
396
|
|
|
364
397
|
private void presentPresentationWithIdentifier(String presentationVendorId,
|
|
365
|
-
|
|
398
|
+
String contentId,
|
|
399
|
+
boolean isFullScreen,
|
|
366
400
|
CallbackContext callbackContext) {
|
|
367
401
|
presentationCallback = callbackContext;
|
|
368
402
|
Intent intent = PLYProductActivity.newIntent(cordova.getActivity());
|
|
369
403
|
intent.putExtra("presentationId", presentationVendorId);
|
|
370
404
|
intent.putExtra("contentId", contentId);
|
|
405
|
+
intent.putExtra("isFullScreen", isFullScreen);
|
|
406
|
+
cordova.getActivity().startActivity(intent);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
private void presentPresentationForPlacement(String placementVendorId,
|
|
410
|
+
String contentId,
|
|
411
|
+
boolean isFullScreen,
|
|
412
|
+
CallbackContext callbackContext) {
|
|
413
|
+
presentationCallback = callbackContext;
|
|
414
|
+
Intent intent = PLYProductActivity.newIntent(cordova.getActivity());
|
|
415
|
+
intent.putExtra("placementId", placementVendorId);
|
|
416
|
+
intent.putExtra("contentId", contentId);
|
|
417
|
+
intent.putExtra("isFullScreen", isFullScreen);
|
|
371
418
|
cordova.getActivity().startActivity(intent);
|
|
372
419
|
}
|
|
373
420
|
|
|
374
421
|
private void presentProductWithIdentifier(String productVendorId,
|
|
375
422
|
String presentationVendorId,
|
|
376
423
|
String contentId,
|
|
424
|
+
boolean isFullScreen,
|
|
377
425
|
CallbackContext callbackContext) {
|
|
378
426
|
presentationCallback = callbackContext;
|
|
379
427
|
Intent intent = PLYProductActivity.newIntent(cordova.getActivity());
|
|
380
428
|
intent.putExtra("presentationId", presentationVendorId);
|
|
381
429
|
intent.putExtra("productId", productVendorId);
|
|
382
430
|
intent.putExtra("contentId", contentId);
|
|
431
|
+
intent.putExtra("isFullScreen", isFullScreen);
|
|
383
432
|
cordova.getActivity().startActivity(intent);
|
|
384
433
|
}
|
|
385
434
|
|
|
386
435
|
private void presentPlanWithIdentifier(String planVendorId,
|
|
387
436
|
String presentationVendorId,
|
|
388
437
|
String contentId,
|
|
438
|
+
boolean isFullScreen,
|
|
389
439
|
CallbackContext callbackContext) {
|
|
390
440
|
presentationCallback = callbackContext;
|
|
391
441
|
Intent intent = PLYProductActivity.newIntent(cordova.getActivity());
|
|
392
442
|
intent.putExtra("presentationId", presentationVendorId);
|
|
393
443
|
intent.putExtra("planId", planVendorId);
|
|
394
444
|
intent.putExtra("contentId", contentId);
|
|
445
|
+
intent.putExtra("isFullScreen", isFullScreen);
|
|
395
446
|
cordova.getActivity().startActivity(intent);
|
|
396
447
|
}
|
|
397
448
|
|
|
@@ -469,7 +520,7 @@ public class PurchaselyPlugin extends CordovaPlugin {
|
|
|
469
520
|
}
|
|
470
521
|
|
|
471
522
|
private void productWithIdentifier(String vendorId, CallbackContext callbackContext) {
|
|
472
|
-
Purchasely.
|
|
523
|
+
Purchasely.product(vendorId, new ProductListener() {
|
|
473
524
|
@Override
|
|
474
525
|
public void onSuccess(@Nullable PLYProduct plyProduct) {
|
|
475
526
|
if(plyProduct != null) {
|
|
@@ -487,7 +538,7 @@ public class PurchaselyPlugin extends CordovaPlugin {
|
|
|
487
538
|
}
|
|
488
539
|
|
|
489
540
|
private void planWithIdentifier(String vendorId, CallbackContext callbackContext) {
|
|
490
|
-
Purchasely.
|
|
541
|
+
Purchasely.plan(vendorId, new PlanListener() {
|
|
491
542
|
@Override
|
|
492
543
|
public void onSuccess(@Nullable PLYPlan plyPlan) {
|
|
493
544
|
if(plyPlan != null) {
|
|
@@ -505,7 +556,7 @@ public class PurchaselyPlugin extends CordovaPlugin {
|
|
|
505
556
|
}
|
|
506
557
|
|
|
507
558
|
private void purchaseWithPlanVendorId(String planVendorId, String contentId, CallbackContext callbackContext) {
|
|
508
|
-
Purchasely.
|
|
559
|
+
Purchasely.plan(planVendorId, new PlanListener() {
|
|
509
560
|
@Override
|
|
510
561
|
public void onSuccess(@Nullable PLYPlan plyPlan) {
|
|
511
562
|
if(plyPlan != null) {
|
|
@@ -528,53 +579,63 @@ public class PurchaselyPlugin extends CordovaPlugin {
|
|
|
528
579
|
});
|
|
529
580
|
}
|
|
530
581
|
|
|
531
|
-
private void
|
|
532
|
-
Purchasely.
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
|
|
536
|
-
cordova.getActivity().startActivity(intent);
|
|
582
|
+
private void setPaywallActionInterceptor(CallbackContext callbackContext) {
|
|
583
|
+
Purchasely.setPaywallActionsInterceptor(
|
|
584
|
+
(info, plyPresentationAction, map, plyProcessActionListener) -> {
|
|
585
|
+
processActionListener = plyProcessActionListener;
|
|
537
586
|
|
|
538
|
-
|
|
587
|
+
String url = null;
|
|
588
|
+
if(map.getUrl() != null) {
|
|
589
|
+
url = map.getUrl().toString();
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
HashMap<String, Object> parametersForCordova = new HashMap<>();
|
|
593
|
+
parametersForCordova.put("title", map.getTitle());
|
|
594
|
+
parametersForCordova.put("url", url);
|
|
595
|
+
parametersForCordova.put("plan", transformPlanToMap(map.getPlan()));
|
|
596
|
+
parametersForCordova.put("presentation", map.getPresentation());
|
|
597
|
+
|
|
598
|
+
HashMap<String, Object> infoMap = new HashMap<>();
|
|
599
|
+
if(info.getContentId() != null) infoMap.put("contentId", info.getContentId());
|
|
600
|
+
if(info.getPresentationId() != null) infoMap.put("presentationId", info.getPresentationId());
|
|
601
|
+
if(info.getPlacementId() != null) infoMap.put("placementId", info.getPlacementId());
|
|
602
|
+
|
|
603
|
+
HashMap<String, Object> resultForCordova = new HashMap<>();
|
|
604
|
+
resultForCordova.put("info", infoMap);
|
|
605
|
+
resultForCordova.put("action", plyPresentationAction.getValue());
|
|
606
|
+
resultForCordova.put("parameters", parametersForCordova);
|
|
607
|
+
|
|
608
|
+
PluginResult result = new PluginResult(
|
|
609
|
+
PluginResult.Status.OK,
|
|
610
|
+
new JSONObject(resultForCordova)
|
|
611
|
+
);
|
|
539
612
|
result.setKeepCallback(true);
|
|
540
613
|
callbackContext.sendPluginResult(result);
|
|
541
614
|
});
|
|
542
615
|
}
|
|
543
616
|
|
|
544
|
-
private void
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
private void setConfirmPurchaseHandler(CallbackContext callbackContext) {
|
|
552
|
-
Purchasely.setConfirmPurchaseHandler((fragmentActivity, continuePurchaseListener) -> {
|
|
553
|
-
this.continuePurchaseListener = continuePurchaseListener;
|
|
554
|
-
Intent intent = new Intent(fragmentActivity, cordova.getActivity().getClass());
|
|
555
|
-
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
|
|
556
|
-
cordova.getActivity().startActivity(intent);
|
|
557
|
-
|
|
558
|
-
PluginResult result = new PluginResult(PluginResult.Status.OK);
|
|
559
|
-
result.setKeepCallback(true);
|
|
560
|
-
callbackContext.sendPluginResult(result);
|
|
561
|
-
});
|
|
617
|
+
private void closePaywall(CallbackContext callbackContext) {
|
|
618
|
+
Activity purchaselyActivity = productActivity.activity.get();
|
|
619
|
+
Activity activity = purchaselyActivity != null ? purchaselyActivity : cordova.getActivity();
|
|
620
|
+
Intent intent = new Intent(activity, cordova.getActivity().getClass());
|
|
621
|
+
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
|
|
622
|
+
cordova.getActivity().startActivity(intent);
|
|
562
623
|
}
|
|
563
624
|
|
|
564
|
-
private void
|
|
565
|
-
if(
|
|
625
|
+
private void onProcessAction(boolean processAction) {
|
|
626
|
+
if(processActionListener != null) {
|
|
566
627
|
if(productActivity != null) {
|
|
567
628
|
boolean softRelaunched = productActivity.relaunch(cordova);
|
|
568
629
|
if(softRelaunched) {
|
|
569
|
-
cordova.getActivity().runOnUiThread(() ->
|
|
630
|
+
cordova.getActivity().runOnUiThread(() -> processActionListener.processAction(processAction));
|
|
570
631
|
} else {
|
|
571
632
|
new Thread(() -> {
|
|
572
633
|
try {
|
|
573
634
|
Thread.sleep(500);
|
|
574
635
|
} catch (InterruptedException e) {
|
|
575
|
-
Log.e("Purchasely", "process
|
|
636
|
+
Log.e("Purchasely", "process action error", e);
|
|
576
637
|
} finally {
|
|
577
|
-
cordova.getActivity().runOnUiThread(() ->
|
|
638
|
+
cordova.getActivity().runOnUiThread(() -> processActionListener.processAction(processAction));
|
|
578
639
|
}
|
|
579
640
|
}).start();
|
|
580
641
|
}
|