@purchasely/cordova-plugin-purchasely 2.3.1 → 4.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.
@@ -14,15 +14,16 @@
14
14
  "license": "Apache-2.0",
15
15
  "devDependencies": {
16
16
  "@purchasely/cordova-plugin-puchasely-google": "file:../../purchasely-google",
17
- "cordova-android": "^11.0.0",
18
- "cordova-ios": "^6.2.0",
17
+ "@purchasely/cordova-plugin-purchasely": "file:..",
18
+ "cordova-android": "^12.0.1",
19
+ "cordova-ios": "^7.0.1",
19
20
  "cordova-plugin-puchasely-google": "file:../../purchasely-google",
20
21
  "cordova-plugin-purchasely": "file:.."
21
22
  },
22
23
  "cordova": {
23
24
  "plugins": {
24
- "cordova-plugin-puchasely-google": {},
25
- "@purchasely/cordova-plugin-puchasely-google": {}
25
+ "@purchasely/cordova-plugin-puchasely-google": {},
26
+ "@purchasely/cordova-plugin-purchasely": {}
26
27
  },
27
28
  "platforms": [
28
29
  "android",
@@ -47,9 +47,21 @@
47
47
  <div style="margin-top: 20px;">
48
48
  <button id="openPresentation">Open Presentation</button>
49
49
  </div>
50
+ <div style="margin-top: 20px;">
51
+ <button id="fetchPresentation">Fetch Presentation</button>
52
+ </div>
50
53
  <div style="margin-top: 20px;">
51
54
  <button id="processToPayment">Continue payment</button>
52
55
  </div>
56
+ <div style="margin-top: 20px;">
57
+ <button id="showPresentation">Show hidden presentation</button>
58
+ </div>
59
+ <div style="margin-top: 20px;">
60
+ <button id="hidePresentation">Hide presentation</button>
61
+ </div>
62
+ <div style="margin-top: 20px;">
63
+ <button id="closePresentation">Close presentation</button>
64
+ </div>
53
65
  <div style="margin-top: 20px;">
54
66
  <button id="presentSubscriptions">Open Subscriptions</button>
55
67
  </div>
@@ -27,13 +27,10 @@ function onDeviceReady() {
27
27
  console.log('Running cordova-' + cordova.platformId + '@' + cordova.version);
28
28
  document.getElementById('deviceready').classList.add('ready');
29
29
 
30
- Purchasely.setLanguage('en');
31
-
32
- Purchasely.userDidConsumeSubscriptionContent();
33
-
34
- Purchasely.startWithAPIKey(
30
+ Purchasely.start(
35
31
  'fcb39be4-2ba4-4db7-bde3-2a5a1e20745d',
36
32
  ['Google'],
33
+ false,
37
34
  null,
38
35
  Purchasely.LogLevel.DEBUG,
39
36
  Purchasely.RunningMode.full,
@@ -44,8 +41,14 @@ function onDeviceReady() {
44
41
  console.log(error);
45
42
  });
46
43
 
44
+ Purchasely.setLanguage('en');
45
+
47
46
  document.getElementById("openPresentation").addEventListener("click", openPresentation);
47
+ document.getElementById("fetchPresentation").addEventListener("click", fetchPresentation);
48
48
  document.getElementById("presentSubscriptions").addEventListener("click", presentSubscriptions);
49
+ document.getElementById("showPresentation").addEventListener("click", showPresentation);
50
+ document.getElementById("hidePresentation").addEventListener("click", hidePresentation);
51
+ document.getElementById("closePresentation").addEventListener("click", closePresentation);
49
52
  document.getElementById("purchaseWithPlanVendorId").addEventListener("click", purchaseWithPlanVendorId);
50
53
  document.getElementById("restore").addEventListener("click", restore);
51
54
  document.getElementById("silentRestore").addEventListener("click", silentRestore);
@@ -86,7 +89,7 @@ function onPuchaselySdkReady() {
86
89
  Purchasely.setAttribute(Purchasely.Attribute.FIREBASE_APP_INSTANCE_ID, "1");
87
90
  Purchasely.setAttribute(Purchasely.Attribute.BATCH_INSTALLATION_ID, "testBatch1");
88
91
 
89
- Purchasely.isReadyToPurchase(true);
92
+ Purchasely.readyToOpenDeeplink(true);
90
93
 
91
94
  Purchasely.planWithIdentifier('PURCHASELY_PLUS_MONTHLY', (plan) => {
92
95
  console.log(' ==> Plan');
@@ -100,7 +103,6 @@ function onPuchaselySdkReady() {
100
103
  console.log(plan.introPrice);
101
104
  console.log(plan.introAmount);
102
105
  console.log(plan.introDuration);
103
- console.log('Eligible for intro offer ? ' + plan.isEligibleForIntroOffer);
104
106
  }, (error) => {
105
107
  console.log(error);
106
108
  });
@@ -117,6 +119,42 @@ function onPuchaselySdkReady() {
117
119
  console.log("Error with purchase : " + error);
118
120
  });
119
121
 
122
+ Purchasely.setUserAttributeWithString("key_string", "value_string");
123
+ Purchasely.setUserAttributeWithBoolean("key_boolean", true);
124
+ Purchasely.setUserAttributeWithInt("key_int", 7);
125
+ Purchasely.setUserAttributeWithDouble("key_double", 4.5);
126
+ Purchasely.setUserAttributeWithDate("key_date", new Date().toISOString());
127
+
128
+ Purchasely.userAttribute("key_string", value => {
129
+ console.log("User attribute string " + value);
130
+ });
131
+
132
+ Purchasely.userAttribute("key_boolean", value => {
133
+ console.log("User attribute boolean " + value);
134
+ });
135
+
136
+ Purchasely.userAttribute("key_int", value => {
137
+ console.log("User attribute int " + value);
138
+ });
139
+
140
+ Purchasely.userAttribute("key_double", value => {
141
+ console.log("User attribute double " + value);
142
+ });
143
+
144
+ Purchasely.userAttribute("key_date", value => {
145
+ console.log("User attribute date " + value);
146
+
147
+ Purchasely.clearUserAttribute("key_string");
148
+ Purchasely.userAttribute("key_string",{}, error => {
149
+ console.log("User attribute string cleared ? " + error);
150
+
151
+ Purchasely.clearUserAttributes();
152
+ Purchasely.userAttribute("key_double", {}, error => {
153
+ console.log("User attribute double empty? " + error);
154
+ });
155
+ });
156
+ });
157
+
120
158
  Purchasely.setPaywallActionInterceptor((result) => {
121
159
  console.log(result);
122
160
  console.log('Received action from paywall ' + result.info.presentationId);
@@ -146,7 +184,7 @@ function onPuchaselySdkReady() {
146
184
  } else if (result.action === Purchasely.PaywallAction.purchase) {
147
185
  console.log('User wants to purchase');
148
186
  //If you want to intercept it, close paywall and display your screen
149
- Purchasely.closePaywall();
187
+ Purchasely.hidePresentation();
150
188
  } else if (result.action === Purchasely.PaywallAction.restore) {
151
189
  console.log('User wants to restore his purchases');
152
190
  Purchasely.onProcessAction(true);
@@ -176,6 +214,30 @@ function openPresentation() {
176
214
  );
177
215
  }
178
216
 
217
+ function fetchPresentation() {
218
+ Purchasely.fetchPresentationForPlacement(
219
+ 'onboarding', //placementId
220
+ null, //contentId
221
+ (presentation) => {
222
+ console.log(presentation);
223
+ Purchasely.presentPresentation(presentation, false, null,
224
+ (callback) => {
225
+ console.log(callback);
226
+ if(callback.result == Purchasely.PurchaseResult.CANCELLED) {
227
+ console.log("User cancelled purchased");
228
+ } else {
229
+ console.log("User purchased " + callback.plan.name);
230
+ }
231
+ }, (error) => {
232
+ console.log("Error with present : " + error);
233
+ });
234
+ },
235
+ (error) => {
236
+ console.log("Error with purchase : " + error);
237
+ }
238
+ );
239
+ }
240
+
179
241
  function presentSubscriptions() {
180
242
  Purchasely.presentSubscriptions();
181
243
  }
@@ -185,10 +247,25 @@ function purchaseWithPlanVendorId() {
185
247
  }
186
248
 
187
249
  function processToPayment() {
250
+ // Call this method open paywall again
251
+ Purchasely.showPresentation();
252
+
188
253
  // Call this method to process to payment
189
254
  Purchasely.onProcessAction(true);
190
255
  }
191
256
 
257
+ function showPresentation() {
258
+ Purchasely.showPresentation();
259
+ }
260
+
261
+ function hidePresentation() {
262
+ Purchasely.hidePresentation();
263
+ }
264
+
265
+ function closePresentation() {
266
+ Purchasely.closePresentation();
267
+ }
268
+
192
269
  function restore() {
193
270
  Purchasely.restoreAllProducts(
194
271
  (plan) => {
@@ -213,8 +290,35 @@ function silentRestore() {
213
290
  );
214
291
  }
215
292
 
293
+ function isEligibleForIntroOffer() {
294
+ console.log("isEligibleForIntroOffer");
295
+ Purchasely.isEligibleForIntroOffer(
296
+ 'PURCHASELY_PLUS_YEARLY', // planVendorId
297
+ (isEligible) => {
298
+ console.log("isEligibleForIntroOffer result: " + isEligible);
299
+ },
300
+ (error) => {
301
+ console.log("Error with isEligibleForIntroOffer : " + error);
302
+ }
303
+ );
304
+ }
305
+
306
+ function signPromotionalOffer() {
307
+ console.log("signPromotionalOffer");
308
+ Purchasely.signPromotionalOffer(
309
+ 'com.purchasely.plus.yearly', // storeProductId
310
+ 'com.purchasely.plus.yearly.winback.test', // storeOfferId
311
+ (signature) => {
312
+ console.log("signPromotionalOffer result: " + signature);
313
+ },
314
+ (error) => {
315
+ console.log("Error with signPromotionalOffer : " + error);
316
+ }
317
+ );
318
+ }
319
+
216
320
  function openDeeplink() {
217
- Purchasely.handle(
321
+ Purchasely.isDeeplinkHandled(
218
322
  "purchasely://ply/presentations/CAROUSEL",
219
323
  isHandled => {
220
324
  console.log("Deeplink is handled ? " + isHandled)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@purchasely/cordova-plugin-purchasely",
3
- "version": "2.3.1",
3
+ "version": "4.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",
@@ -30,6 +30,14 @@
30
30
  "hms",
31
31
  "amazon"
32
32
  ],
33
+ "engines": {
34
+ "cordovaDependencies": {
35
+ "1.0.0": {
36
+ "cordova": ">=11.0.0",
37
+ "cordova-android": ">=12.0.0"
38
+ }
39
+ }
40
+ },
33
41
  "author": "Purchasely",
34
42
  "license": "ISC",
35
43
  "main": "index.js",
package/plugin.xml CHANGED
@@ -1,9 +1,13 @@
1
1
  <?xml version='1.0' encoding='utf-8'?>
2
- <plugin id="@purchasely/cordova-plugin-purchasely" version="2.3.1" 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="4.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" />
6
6
  </js-module>
7
+ <engines>
8
+ <engine name="cordova" version=">=11.0.0"/>
9
+ <engine name="cordova-android" version=">=12.0.0"/>
10
+ </engines>
7
11
  <platform name="ios">
8
12
  <config-file parent="/*" target="config.xml">
9
13
  <feature name="Purchasely">
@@ -23,12 +27,16 @@
23
27
  <source-file src="src/ios/Hybrid/PLYPlan+Hybrid.m" />
24
28
  <header-file src="src/ios/Hybrid/PLYSubscription+Hybrid.h" />
25
29
  <source-file src="src/ios/Hybrid/PLYSubscription+Hybrid.m" />
30
+ <header-file src="src/ios/Hybrid/PLYPresentationPlan+Hybrid.h" />
31
+ <source-file src="src/ios/Hybrid/PLYPresentationPlan+Hybrid.m" />
32
+ <header-file src="src/ios/Hybrid/UIColor+PLYHelper.h" />
33
+ <source-file src="src/ios/Hybrid/UIColor+PLYHelper.m" />
26
34
  <podspec>
27
35
  <config>
28
36
  <source url="https://github.com/CocoaPods/Specs.git"/>
29
37
  </config>
30
38
  <pods use-frameworks="true">
31
- <pod name="Purchasely" spec="3.3.3"/>
39
+ <pod name="Purchasely" spec="4.1.4"/>
32
40
  </pods>
33
41
  </podspec>
34
42
  </platform>
@@ -38,6 +46,8 @@
38
46
  <param name="android-package" value="cordova.plugin.purchasely.PurchaselyPlugin" />
39
47
  </feature>
40
48
  <preference name="AndroidXEnabled" value="true" />
49
+ <preference name="GradlePluginKotlinEnabled" value="true" />
50
+ <preference name="GradlePluginKotlinCodeStyle" value="official" />
41
51
  </config-file>
42
52
  <config-file parent="/manifest/application" target="AndroidManifest.xml">
43
53
  <activity
@@ -51,11 +61,12 @@
51
61
  android:theme="@style/Theme.AppCompat.Light.NoActionBar">
52
62
  </activity>
53
63
  </config-file>
54
- <framework src="io.purchasely:core:3.3.2" />
55
- <source-file src="src/android/PurchaselyPlugin.java" target-dir="src/cordova/plugin/purchasely" />
56
- <source-file src="src/android/PLYProductActivity.java" target-dir="src/cordova/plugin/purchasely" />
64
+ <framework src="io.purchasely:core:4.1.1" />
65
+ <source-file src="src/android/PurchaselyPlugin.kt" target-dir="java/cordova/plugin/purchasely" />
66
+ <source-file src="src/android/PLYProductActivity.kt" target-dir="java/cordova/plugin/purchasely" />
57
67
  <source-file src="src/android/PLYSubscriptionsActivity.java" target-dir="src/cordova/plugin/purchasely" />
58
68
  <source-file src="src/android/activity_ply_product_activity.xml" target-dir="res/layout"/>
69
+ <source-file src="src/android/activity_ply_subscriptions_activity.xml" target-dir="res/layout"/>
59
70
  <source-file src="src/android/theme_purchasely_fullscreen.xml" target-dir="res/values"/>
60
71
  <source-file src="src/android/theme_purchasely_fullscreen_v23_light_status_bar.xml" target-dir="res/values-v23"/>
61
72
  <source-file src="src/android/theme_purchasely_fullscreen_v23.xml" target-dir="res/values-v23"/>
package/purchasely.iml ADDED
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="JAVA_MODULE" version="4">
3
+ <component name="NewModuleRootManager" inherit-compiler-output="true">
4
+ <exclude-output />
5
+ <content url="file://$MODULE_DIR$">
6
+ <sourceFolder url="file://$MODULE_DIR$/src/android" isTestSource="false" packagePrefix="cordova.plugin.purchasely" />
7
+ </content>
8
+ <orderEntry type="inheritedJdk" />
9
+ <orderEntry type="sourceFolder" forTests="false" />
10
+ </component>
11
+ </module>
@@ -0,0 +1,171 @@
1
+ package cordova.plugin.purchasely
2
+
3
+ import android.app.Activity
4
+ import android.content.Intent
5
+ import android.graphics.Color
6
+ import android.os.Bundle
7
+ import android.view.View
8
+ import android.widget.FrameLayout
9
+ import androidx.appcompat.app.AppCompatActivity
10
+ import androidx.core.view.WindowCompat
11
+ import cordova.plugin.purchasely.PurchaselyPlugin.ProductActivity
12
+ import io.purchasely.ext.PLYPresentation
13
+ import io.purchasely.ext.PLYPresentationViewProperties
14
+ import io.purchasely.ext.PLYProductViewResult
15
+ import io.purchasely.ext.Purchasely
16
+ import io.purchasely.models.PLYPlan
17
+ import io.purchasely.views.parseColor
18
+ import java.lang.ref.WeakReference
19
+
20
+ class PLYProductActivity : AppCompatActivity() {
21
+
22
+ private var presentationId: String? = null
23
+ private var placementId: String? = null
24
+ private var productId: String? = null
25
+ private var planId: String? = null
26
+ private var contentId: String? = null
27
+
28
+ private var presentation: PLYPresentation? = null
29
+
30
+ private var isFullScreen: Boolean = false
31
+ private var backgroundColor: String? = null
32
+
33
+ private var paywallView: View? = null
34
+
35
+ override fun onCreate(savedInstanceState: Bundle?) {
36
+ super.onCreate(savedInstanceState)
37
+
38
+ isFullScreen = intent.extras?.getBoolean("isFullScreen") ?: false
39
+ backgroundColor = intent.extras?.getString("background_color")
40
+
41
+ if(isFullScreen) {
42
+ WindowCompat.setDecorFitsSystemWindows(window, false)
43
+ }
44
+
45
+ val package_name = application.packageName
46
+
47
+ setContentView(
48
+ application.resources
49
+ .getIdentifier(
50
+ "activity_ply_product_activity",
51
+ "layout",
52
+ package_name
53
+ )
54
+ )
55
+
56
+ val container = findViewById<View>(
57
+ resources.getIdentifier(
58
+ "container",
59
+ "id",
60
+ package_name
61
+ )
62
+ ) as FrameLayout
63
+
64
+ try {
65
+ val loadingBackgroundColor = backgroundColor.parseColor(Color.WHITE)
66
+ container.setBackgroundColor(loadingBackgroundColor)
67
+ } catch (e: Exception) {
68
+ //do nothing
69
+ }
70
+
71
+ presentationId = intent.extras?.getString("presentationId")
72
+ placementId = intent.extras?.getString("placementId")
73
+ productId = intent.extras?.getString("productId")
74
+ planId = intent.extras?.getString("planId")
75
+ contentId = intent.extras?.getString("contentId")
76
+
77
+ presentation = intent.extras?.getParcelable("presentation")
78
+
79
+ paywallView = if(presentation != null) {
80
+ presentation?.buildView(this, viewProperties = PLYPresentationViewProperties(onClose = {
81
+ container.removeAllViews()
82
+ supportFinishAfterTransition()
83
+ }), callback)
84
+ } else {
85
+ Purchasely.presentationView(
86
+ this@PLYProductActivity,
87
+ PLYPresentationViewProperties(
88
+ placementId = placementId,
89
+ contentId = contentId,
90
+ presentationId = presentationId,
91
+ planId = planId,
92
+ productId = productId,
93
+ onLoaded = { isLoaded ->
94
+ if(!isLoaded) return@PLYPresentationViewProperties
95
+
96
+ val backgroundPaywall = paywallView?.findViewById<FrameLayout>(io.purchasely.R.id.content)?.background
97
+ if(backgroundPaywall != null) {
98
+ container.background = backgroundPaywall
99
+ }
100
+ },
101
+ onClose = {
102
+ container.removeAllViews()
103
+ supportFinishAfterTransition()
104
+ }
105
+ ),
106
+ callback
107
+ )
108
+ }
109
+
110
+ if(paywallView == null) {
111
+ finish()
112
+ return
113
+ }
114
+
115
+ container.addView(paywallView)
116
+ }
117
+
118
+ override fun onStart() {
119
+ super.onStart()
120
+
121
+ val productActivity = ProductActivity()
122
+ productActivity.presentation = presentation
123
+ productActivity.presentationId = presentationId
124
+ productActivity.placementId = placementId
125
+ productActivity.productId = productId
126
+ productActivity.planId = planId
127
+ productActivity.contentId = contentId
128
+ productActivity.isFullScreen = isFullScreen
129
+ productActivity.loadingBackgroundColor = backgroundColor
130
+ productActivity.activity = WeakReference(this)
131
+ PurchaselyPlugin.productActivity = productActivity
132
+ }
133
+
134
+ override fun onDestroy() {
135
+ PurchaselyPlugin.productActivity?.activity = null
136
+ super.onDestroy()
137
+ }
138
+
139
+ private val callback: (PLYProductViewResult, PLYPlan?) -> Unit = { result, plan ->
140
+ PurchaselyPlugin.sendPurchaseResult(
141
+ result,
142
+ plan
143
+ )
144
+ //supportFinishAfterTransition()
145
+ }
146
+
147
+ companion object {
148
+ @JvmStatic
149
+ fun newIntent(activity: Activity?,
150
+ properties: PLYPresentationViewProperties = PLYPresentationViewProperties(),
151
+ isFullScreen: Boolean = false,
152
+ backgroundColor: String? = null) = Intent(activity, PLYProductActivity::class.java).apply {
153
+ //remove old activity if still referenced to avoid issues
154
+ val oldActivity = PurchaselyPlugin.productActivity?.activity?.get()
155
+ oldActivity?.finish()
156
+ PurchaselyPlugin.productActivity?.activity = null
157
+ PurchaselyPlugin.productActivity = null
158
+ //flags = Intent.FLAG_ACTIVITY_NEW_TASK xor Intent.FLAG_ACTIVITY_MULTIPLE_TASK
159
+
160
+ putExtra("background_color", backgroundColor)
161
+ putExtra("isFullScreen", isFullScreen)
162
+
163
+ putExtra("presentationId", properties.presentationId)
164
+ putExtra("contentId", properties.contentId)
165
+ putExtra("placementId", properties.placementId)
166
+ putExtra("productId", properties.productId)
167
+ putExtra("planId", properties.planId)
168
+ }
169
+ }
170
+
171
+ }
@@ -14,7 +14,7 @@ public class PLYSubscriptionsActivity extends AppCompatActivity {
14
14
  super.onCreate(savedInstanceState);
15
15
  String package_name = getApplication().getPackageName();
16
16
  setContentView(getApplication().getResources()
17
- .getIdentifier("activity_ply_product_activity",
17
+ .getIdentifier("activity_ply_subscriptions_activity",
18
18
  "layout",
19
19
  package_name)
20
20
  );