apps-sdk 1.0.112 → 1.0.114

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apps-sdk",
3
- "version": "1.0.112",
3
+ "version": "1.0.114",
4
4
  "description": "Apps SDK",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,7 +1,7 @@
1
- import React, {useEffect} from 'react';
2
- import {BottomSheet} from 'react-native-btr';
3
- import {WebView} from 'react-native-webview';
4
- import {View} from "react-native";
1
+ import React from 'react';
2
+ import { BottomSheet } from 'react-native-btr';
3
+ import { WebView } from 'react-native-webview';
4
+ import { View, Platform } from "react-native";
5
5
  import Utils from "../libraries/Utils";
6
6
  import Networking from "../libraries/Networking";
7
7
  import Storage from "../libraries/Storage";
@@ -16,6 +16,13 @@ class PayWall extends React.Component {
16
16
  this.webviewRef = React.createRef();
17
17
  this.paywallData = {};
18
18
  this.paywallJS = '';
19
+ this.state = {
20
+ htmlContent: null,
21
+ };
22
+ }
23
+
24
+ componentDidMount() {
25
+ this.initPayWall();
19
26
  }
20
27
 
21
28
  initPayWall = async () => {
@@ -49,11 +56,49 @@ class PayWall extends React.Component {
49
56
  }
50
57
  }
51
58
 
59
+ fetchAndModifyHTML = async () => {
60
+ try {
61
+ const response = await fetch(this.paywallData.url);
62
+ let html = await response.text();
63
+
64
+ for (let ind in config.PAYWALL_DATA.paywall_info) {
65
+ let paywallInfo = config.PAYWALL_DATA.paywall_info[ind];
66
+ let os = Platform.OS === 'ios' ? 'i' : 'a';
67
+ let product_id = paywallInfo.productIdentifier;
68
+ if (paywallInfo.localizedPriceYear) {
69
+ html = html.replace(new RegExp(`\\[PRICE_YEAR\\|[^\\]]*${os}:${product_id}[^\\]]*\\]`, 'g'), paywallInfo.localizedPrice);
70
+ }
71
+ if (paywallInfo.localizedPriceWeek) {
72
+ html = html.replace(new RegExp(`\\[PRICE_WEEK\\|[^\\]]*${os}:${product_id}[^\\]]*\\]`, 'g'), paywallInfo.localizedPriceWeek);
73
+ }
74
+ if (paywallInfo.localizedPriceMonth) {
75
+ html = html.replace(new RegExp(`\\[PRICE_MONTH\\|[^\\]]*${os}:${product_id}[^\\]]*\\]`, 'g'), paywallInfo.localizedPriceMonth);
76
+ }
77
+ if (paywallInfo.localizedPriceDay) {
78
+ html = html.replace(new RegExp(`\\[PRICE_DAY\\|[^\\]]*${os}:${product_id}[^\\]]*\\]`, 'g'), paywallInfo.localizedPriceDay);
79
+ }
80
+ }
81
+
82
+ let paywallJS = await PayWallLogic.getPayWallJS(this.props);
83
+ html = html.replace(
84
+ '</body>',
85
+ `<script>${paywallJS}</script></body>`
86
+ );
87
+
88
+ let tokens = html.match(/\[PRICE.*\]/g);
89
+ if (tokens) {
90
+ Networking.sendEvent('other', 'cp_price_token_not_replaced', { tokens: tokens, url: this.paywallData.url });
91
+ }
92
+
93
+ this.setState({ htmlContent: html });
94
+ } catch (error) {
95
+ console.log('Error al obtener el HTML:', error);
96
+ }
97
+ }
98
+
52
99
  async componentDidUpdate(prevProps) {
53
100
  if (this.props.visible && !prevProps.visible && this.paywallData.url) {
54
- this.webviewRef.current.injectJavaScript(PayWallLogic.paywallJS);
55
- Networking.sendEvent('scene', 'payment_card', { user_id: Session.getUserID(), card_id: this.getCardID(), scene: 'payment_card' });
56
- Storage.storeData('PAYWALL_DSNID', this.getCardID());
101
+ await this.fetchAndModifyHTML();
57
102
  }
58
103
  }
59
104
 
@@ -69,6 +114,15 @@ class PayWall extends React.Component {
69
114
 
70
115
  eventClickSubscribe = (data) => {
71
116
  Networking.sendEvent('other', 'cta_click_init');
117
+
118
+ if (Platform.OS === 'ios' && data.iid) {
119
+ data.id = data.iid;
120
+ } else {
121
+ if (data.aid) {
122
+ data.id = data.aid;
123
+ }
124
+ }
125
+
72
126
  if (this.paywallData && data.id && data.id.length > 0 && this.paywallData.products_id && this.paywallData.products_id.length > 0) {
73
127
  Storage.getData('PAYWALL_DSNID').then((dsn_id) => {
74
128
  Networking.sendEvent('action', 'cta', {product_id: data.id, dsn_id: dsn_id || ''});
@@ -150,21 +204,32 @@ class PayWall extends React.Component {
150
204
  Storage.storeData('PAYWALL_DSNID', this.getCardID());
151
205
  }
152
206
 
207
+ console.log('this.paywallData.url', this.paywallData.url);
208
+
153
209
  return (
154
210
  <BottomSheet visible={visible}>
155
211
  <View style={styles.bottomNavigationView}>
156
- <WebView style={{flex:1}} source={{ uri: this.paywallData.url }} javaScriptEnabled ref={this.webviewRef} onMessage={this.handleMessage} onError={(err) => {console.log('Error al cargar webview:',err)}} injectedJavaScript={PayWallLogic.paywallJS}
157
- onShouldStartLoadWithRequest={request => {
158
- console.log('request', request);
159
- if (request.url !== this.paywallData.url) {
160
- Networking.sendEvent('action', 'click_link', {url: request.url });
161
- Linking.openURL(request.url);
162
- return false;
163
- } else {
164
- return true;
165
- }
166
- }}
167
- />
212
+ {this.state.htmlContent ? (
213
+ <WebView
214
+ style={{ flex: 1 }}
215
+ originWhitelist={['*']}
216
+ source={{ html: this.state.htmlContent }}
217
+ javaScriptEnabled
218
+ ref={this.webviewRef}
219
+ onMessage={this.handleMessage}
220
+ onError={(err) => { console.log('Error al cargar webview:', err) }}
221
+ injectedJavaScript={PayWallLogic.paywallJS}
222
+ onShouldStartLoadWithRequest={request => {
223
+ if (request.url !== 'about:blank' && request.url !== this.paywallData.url) {
224
+ Networking.sendEvent('action', 'click_link', { url: request.url });
225
+ Linking.openURL(request.url);
226
+ return false;
227
+ } else {
228
+ return true;
229
+ }
230
+ }}
231
+ />
232
+ ) : null}
168
233
  </View>
169
234
  </BottomSheet>
170
235
  );
@@ -207,6 +207,7 @@ class PayWallLogic {
207
207
  payWallInfo['localizedPrice'] = "";
208
208
  this.paywallJS = "window.subInfoInterval = setInterval(() => window.Appquiles && Appquiles.setSubscriptionPlans(" + JSON.stringify(payWallInfo) + "), 300);";
209
209
  config.DEBUG_MODE && console.log('getPayWallJS', this.paywallJS);
210
+ return this.paywallJS;
210
211
  } catch (error) {
211
212
  console.error(error);
212
213
  }
@@ -218,22 +219,49 @@ class PayWallLogic {
218
219
  }
219
220
 
220
221
  preparePayWallPurchaseInfo = () => {
221
- let payWallInfo = [];
222
+ const payWallInfo = [];
222
223
 
223
224
  if (config.PAYWALL_DATA && config.PAYWALL_DATA.products_metadata) {
224
- for (let key in config.PAYWALL_DATA.products_metadata) {
225
- let product = config.PAYWALL_DATA.products_metadata[key];
225
+ for (const key in config.PAYWALL_DATA.products_metadata) {
226
+ const product = config.PAYWALL_DATA.products_metadata[key];
227
+ let price = 0;
228
+ let yearPrice = 0;
229
+ let monthPrice = 0;
230
+ let weekPrice = 0;
231
+ let dayPrice = 0;
226
232
  let period = 'M';
233
+ let currencySymbol = '';
234
+ let symbolPositionStart = false;
235
+ let localizedPrice = '';
236
+
227
237
  if (product.subscriptionPeriodUnitIOS) {
238
+ price = product.price;
239
+ currencySymbol = product.localizedPrice.replace(/[0-9,.\s]/g, '').trim();
240
+ localizedPrice = product.localizedPrice;
241
+ symbolPositionStart = product.localizedPrice.trim().startsWith(currencySymbol);
228
242
  if (product.subscriptionPeriodUnitIOS === 'DAY' && product.subscriptionPeriodNumberIOS == 7) {
229
243
  period = 'WEEK';
244
+ yearPrice = parseFloat(product.localizedPrice.replace(/[^\d,.-]/g, '').replace(',', '.')) * 52;
245
+ monthPrice = parseFloat(product.localizedPrice.replace(/[^\d,.-]/g, '').replace(',', '.')) * 4;
246
+ weekPrice = parseFloat(product.localizedPrice.replace(/[^\d,.-]/g, '').replace(',', '.'));
247
+ dayPrice = parseFloat(product.localizedPrice.replace(/[^\d,.-]/g, '').replace(',', '.')) / 7;
230
248
  } else {
231
249
  period = product.subscriptionPeriodUnitIOS;
250
+ yearPrice = parseFloat(product.localizedPrice.replace(/[^\d,.-]/g, '').replace(',', '.')) * 12;
251
+ monthPrice = parseFloat(product.localizedPrice.replace(/[^\d,.-]/g, '').replace(',', '.'));
252
+ weekPrice = parseFloat(product.localizedPrice.replace(/[^\d,.-]/g, '').replace(',', '.')) / product.subscriptionPeriodNumberIOS / 4;
253
+ dayPrice = parseFloat(product.localizedPrice.replace(/[^\d,.-]/g, '').replace(',', '.')) / product.subscriptionPeriodNumberIOS / 30;
232
254
  }
233
- } else {
234
- let offerDetail = product.subscriptionOfferDetails[0];
235
- let phase = offerDetail.pricingPhases.pricingPhaseList[0];
236
- let periodicity = phase.billingPeriod;
255
+ } else if (product.subscriptionOfferDetails) {
256
+ const offerDetail = product.subscriptionOfferDetails[0];
257
+ const phase = offerDetail.pricingPhases.pricingPhaseList[0];
258
+ const periodicity = phase.billingPeriod;
259
+ price = parseFloat(phase.priceAmountMicros) / 1000000;
260
+ localizedPrice = phase.formattedPrice;
261
+ weekPrice = phase.price / phase.billingPeriodLength;
262
+ currencySymbol = phase.formattedPrice.replace(/[0-9,.\s]/g, '').trim();
263
+ symbolPositionStart = phase.formattedPrice.trim().startsWith(currencySymbol);
264
+
237
265
  switch (periodicity) {
238
266
  case 'P1W':
239
267
  period = 'WEEK';
@@ -249,16 +277,56 @@ class PayWallLogic {
249
277
  break;
250
278
  }
251
279
  }
280
+
281
+ if (price) {
282
+ const periodNumber = product.subscriptionPeriodNumberIOS || product.subscriptionPeriodNumberAndroid || 1;
283
+ switch (period) {
284
+ case 'MONTH':
285
+ yearPrice = parseFloat(price) * 12;
286
+ monthPrice = parseFloat(price);
287
+ weekPrice = parseFloat(price) / parseFloat(periodNumber) / 4;
288
+ dayPrice = weekPrice / 7;
289
+ break;
290
+ case 'YEAR':
291
+ yearPrice = parseFloat(price);
292
+ monthPrice = parseFloat(price) / 12;
293
+ weekPrice = parseFloat(price) / parseFloat(periodNumber) / 52;
294
+ dayPrice = weekPrice / 7;
295
+ break;
296
+ case 'WEEK':
297
+ yearPrice = parseFloat(price) * 52;
298
+ monthPrice = parseFloat(price) * 4;
299
+ weekPrice = parseFloat(price);
300
+ dayPrice = parseFloat(price) / 7;
301
+ break;
302
+ }
303
+ }
304
+
305
+ yearPrice = parseFloat(yearPrice.toFixed(2));
306
+ monthPrice = parseFloat(monthPrice.toFixed(2));
307
+ weekPrice = parseFloat(weekPrice.toFixed(2));
308
+ dayPrice = parseFloat(dayPrice.toFixed(2));
309
+
310
+ const localizedPriceYear = symbolPositionStart ? `${currencySymbol} ${yearPrice}` : `${yearPrice} ${currencySymbol}`.trim();
311
+ const localizedPriceWeek = symbolPositionStart ? `${currencySymbol} ${weekPrice}` : `${weekPrice} ${currencySymbol}`.trim();
312
+ const localizedPriceDay = symbolPositionStart ? `${currencySymbol} ${dayPrice}` : `${dayPrice} ${currencySymbol}`.trim();
313
+
252
314
  payWallInfo.push({
253
315
  productIdentifier: product.productId,
254
316
  localizedTitle: product.title,
255
317
  description: product.description,
256
- localizedPrice: product.localizedPrice,
318
+ localizedPrice: localizedPrice,
319
+ localizedPriceYear: localizedPriceYear,
320
+ localizedPriceWeek: localizedPriceWeek,
321
+ localizedPriceDay: localizedPriceDay,
322
+ priceYear: yearPrice,
323
+ priceMonth: monthPrice,
324
+ priceWeek: weekPrice,
325
+ priceDay: dayPrice,
257
326
  price: product.price,
258
327
  type: product.type,
259
328
  platform: product.platform,
260
329
  currency: product.currency,
261
- // duration: product.subscriptionPeriod,
262
330
  freePeriod: '',
263
331
  subscriptionUnits: product.subscriptionPeriodNumberIOS || product.subscriptionPeriodNumberAndroid || 1,
264
332
  subscriptionPeriod: this.getPeriodInt(period),
@@ -267,11 +335,15 @@ class PayWallLogic {
267
335
  });
268
336
  }
269
337
  config.PAYWALL_DATA.paywall_info = payWallInfo;
270
- config.DEBUG_MODE && console.debug('paywall_info', config.PAYWALL_DATA.paywall_info);
338
+ if (config.DEBUG_MODE) {
339
+ console.debug('paywall_info', config.PAYWALL_DATA.paywall_info);
340
+ }
271
341
  }
272
342
  return payWallInfo;
273
343
  }
274
344
 
345
+
346
+
275
347
  getProductIDs = () => {
276
348
  return config.PAYWALL_DATA.products;
277
349
  }