apps-sdk 1.0.112 → 1.0.115
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 +1 -1
- package/src/components/PayWall.js +98 -31
- package/src/libraries/PayWallLogic.js +84 -12
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import 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,55 @@ 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.localizedPriceMonth) {
|
|
72
|
+
html = html.replace(new RegExp(`\\[PRICE_MONTH\\|[^\\]]*${os}:${product_id}[^\\]]*\\]`, 'g'), paywallInfo.localizedPriceMonth);
|
|
73
|
+
}
|
|
74
|
+
if (paywallInfo.localizedPriceWeek) {
|
|
75
|
+
html = html.replace(new RegExp(`\\[PRICE_WEEK\\|[^\\]]*${os}:${product_id}[^\\]]*\\]`, 'g'), paywallInfo.localizedPriceWeek);
|
|
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.
|
|
55
|
-
|
|
56
|
-
|
|
101
|
+
await this.fetchAndModifyHTML();
|
|
102
|
+
setTimeout(() => {
|
|
103
|
+
Networking.sendEvent('scene', 'payment_card', {
|
|
104
|
+
user_id: Session.getUserID(),
|
|
105
|
+
scene: 'payment_card'
|
|
106
|
+
});
|
|
107
|
+
}, 3000);
|
|
57
108
|
}
|
|
58
109
|
}
|
|
59
110
|
|
|
@@ -69,17 +120,24 @@ class PayWall extends React.Component {
|
|
|
69
120
|
|
|
70
121
|
eventClickSubscribe = (data) => {
|
|
71
122
|
Networking.sendEvent('other', 'cta_click_init');
|
|
123
|
+
|
|
124
|
+
if (Platform.OS === 'ios' && data.iid) {
|
|
125
|
+
data.id = data.iid;
|
|
126
|
+
} else {
|
|
127
|
+
if (data.aid) {
|
|
128
|
+
data.id = data.aid;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
72
132
|
if (this.paywallData && data.id && data.id.length > 0 && this.paywallData.products_id && this.paywallData.products_id.length > 0) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
});
|
|
133
|
+
Networking.sendEvent('action', 'cta', {product_id: data.id});
|
|
134
|
+
let subscribed = PayWallLogic.executePurchase(data.id, this.hideSpinner, this.hidePayWall).then((subscribed) => {
|
|
135
|
+
console.log('subscription result: ', subscribed);
|
|
136
|
+
if (subscribed) {
|
|
137
|
+
this.props.onSubscribe(false);
|
|
138
|
+
} else {
|
|
139
|
+
this.props.onPaymentError();
|
|
140
|
+
}
|
|
83
141
|
});
|
|
84
142
|
} else {
|
|
85
143
|
Networking.sendEvent('other', 'cta_click_error_paywall_data');
|
|
@@ -146,25 +204,34 @@ class PayWall extends React.Component {
|
|
|
146
204
|
if (!this.paywallData.url) {
|
|
147
205
|
config.DEBUG_MODE && console.log('PayWallLogic: paywallData no tiene url para este type / keyword -> ' + type + ' / ' + keyword);
|
|
148
206
|
return null;
|
|
149
|
-
} else {
|
|
150
|
-
Storage.storeData('PAYWALL_DSNID', this.getCardID());
|
|
151
207
|
}
|
|
152
208
|
|
|
209
|
+
console.log('this.paywallData.url', this.paywallData.url);
|
|
210
|
+
|
|
153
211
|
return (
|
|
154
212
|
<BottomSheet visible={visible}>
|
|
155
213
|
<View style={styles.bottomNavigationView}>
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
214
|
+
{this.state.htmlContent ? (
|
|
215
|
+
<WebView
|
|
216
|
+
style={{ flex: 1 }}
|
|
217
|
+
originWhitelist={['*']}
|
|
218
|
+
source={{ html: this.state.htmlContent }}
|
|
219
|
+
javaScriptEnabled
|
|
220
|
+
ref={this.webviewRef}
|
|
221
|
+
onMessage={this.handleMessage}
|
|
222
|
+
onError={(err) => { console.log('Error al cargar webview:', err) }}
|
|
223
|
+
injectedJavaScript={PayWallLogic.paywallJS}
|
|
224
|
+
onShouldStartLoadWithRequest={request => {
|
|
225
|
+
if (request.url !== 'about:blank' && request.url !== this.paywallData.url) {
|
|
226
|
+
Networking.sendEvent('action', 'click_link', { url: request.url });
|
|
227
|
+
Linking.openURL(request.url);
|
|
228
|
+
return false;
|
|
229
|
+
} else {
|
|
230
|
+
return true;
|
|
231
|
+
}
|
|
232
|
+
}}
|
|
233
|
+
/>
|
|
234
|
+
) : null}
|
|
168
235
|
</View>
|
|
169
236
|
</BottomSheet>
|
|
170
237
|
);
|
|
@@ -105,12 +105,10 @@ class PayWallLogic {
|
|
|
105
105
|
if (source) {
|
|
106
106
|
final_source = source;
|
|
107
107
|
}
|
|
108
|
-
const dns_id = await Storage.getData('PAYWALL_DSNID');
|
|
109
108
|
config.DEBUG_MODE && console.log('purchaseResp final_source', final_source);
|
|
110
109
|
return {
|
|
111
110
|
subs_id: purchaseToken,
|
|
112
111
|
product_id: subscription.productId,
|
|
113
|
-
dns_id: dns_id || '',
|
|
114
112
|
source: final_source,
|
|
115
113
|
};
|
|
116
114
|
}
|
|
@@ -207,6 +205,7 @@ class PayWallLogic {
|
|
|
207
205
|
payWallInfo['localizedPrice'] = "";
|
|
208
206
|
this.paywallJS = "window.subInfoInterval = setInterval(() => window.Appquiles && Appquiles.setSubscriptionPlans(" + JSON.stringify(payWallInfo) + "), 300);";
|
|
209
207
|
config.DEBUG_MODE && console.log('getPayWallJS', this.paywallJS);
|
|
208
|
+
return this.paywallJS;
|
|
210
209
|
} catch (error) {
|
|
211
210
|
console.error(error);
|
|
212
211
|
}
|
|
@@ -218,22 +217,49 @@ class PayWallLogic {
|
|
|
218
217
|
}
|
|
219
218
|
|
|
220
219
|
preparePayWallPurchaseInfo = () => {
|
|
221
|
-
|
|
220
|
+
const payWallInfo = [];
|
|
222
221
|
|
|
223
222
|
if (config.PAYWALL_DATA && config.PAYWALL_DATA.products_metadata) {
|
|
224
|
-
for (
|
|
225
|
-
|
|
223
|
+
for (const key in config.PAYWALL_DATA.products_metadata) {
|
|
224
|
+
const product = config.PAYWALL_DATA.products_metadata[key];
|
|
225
|
+
let price = 0;
|
|
226
|
+
let yearPrice = 0;
|
|
227
|
+
let monthPrice = 0;
|
|
228
|
+
let weekPrice = 0;
|
|
229
|
+
let dayPrice = 0;
|
|
226
230
|
let period = 'M';
|
|
231
|
+
let currencySymbol = '';
|
|
232
|
+
let symbolPositionStart = false;
|
|
233
|
+
let localizedPrice = '';
|
|
234
|
+
|
|
227
235
|
if (product.subscriptionPeriodUnitIOS) {
|
|
236
|
+
price = product.price;
|
|
237
|
+
currencySymbol = product.localizedPrice.replace(/[0-9,.\s]/g, '').trim();
|
|
238
|
+
localizedPrice = product.localizedPrice;
|
|
239
|
+
symbolPositionStart = product.localizedPrice.trim().startsWith(currencySymbol);
|
|
228
240
|
if (product.subscriptionPeriodUnitIOS === 'DAY' && product.subscriptionPeriodNumberIOS == 7) {
|
|
229
241
|
period = 'WEEK';
|
|
242
|
+
yearPrice = parseFloat(product.localizedPrice.replace(/[^\d,.-]/g, '').replace(',', '.')) * 52;
|
|
243
|
+
monthPrice = parseFloat(product.localizedPrice.replace(/[^\d,.-]/g, '').replace(',', '.')) * 4;
|
|
244
|
+
weekPrice = parseFloat(product.localizedPrice.replace(/[^\d,.-]/g, '').replace(',', '.'));
|
|
245
|
+
dayPrice = parseFloat(product.localizedPrice.replace(/[^\d,.-]/g, '').replace(',', '.')) / 7;
|
|
230
246
|
} else {
|
|
231
247
|
period = product.subscriptionPeriodUnitIOS;
|
|
248
|
+
yearPrice = parseFloat(product.localizedPrice.replace(/[^\d,.-]/g, '').replace(',', '.')) * 12;
|
|
249
|
+
monthPrice = parseFloat(product.localizedPrice.replace(/[^\d,.-]/g, '').replace(',', '.'));
|
|
250
|
+
weekPrice = parseFloat(product.localizedPrice.replace(/[^\d,.-]/g, '').replace(',', '.')) / product.subscriptionPeriodNumberIOS / 4;
|
|
251
|
+
dayPrice = parseFloat(product.localizedPrice.replace(/[^\d,.-]/g, '').replace(',', '.')) / product.subscriptionPeriodNumberIOS / 30;
|
|
232
252
|
}
|
|
233
|
-
} else {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
253
|
+
} else if (product.subscriptionOfferDetails) {
|
|
254
|
+
const offerDetail = product.subscriptionOfferDetails[0];
|
|
255
|
+
const phase = offerDetail.pricingPhases.pricingPhaseList[0];
|
|
256
|
+
const periodicity = phase.billingPeriod;
|
|
257
|
+
price = parseFloat(phase.priceAmountMicros) / 1000000;
|
|
258
|
+
localizedPrice = phase.formattedPrice;
|
|
259
|
+
weekPrice = phase.price / phase.billingPeriodLength;
|
|
260
|
+
currencySymbol = phase.formattedPrice.replace(/[0-9,.\s]/g, '').trim();
|
|
261
|
+
symbolPositionStart = phase.formattedPrice.trim().startsWith(currencySymbol);
|
|
262
|
+
|
|
237
263
|
switch (periodicity) {
|
|
238
264
|
case 'P1W':
|
|
239
265
|
period = 'WEEK';
|
|
@@ -249,16 +275,58 @@ class PayWallLogic {
|
|
|
249
275
|
break;
|
|
250
276
|
}
|
|
251
277
|
}
|
|
278
|
+
|
|
279
|
+
if (price) {
|
|
280
|
+
const periodNumber = product.subscriptionPeriodNumberIOS || product.subscriptionPeriodNumberAndroid || 1;
|
|
281
|
+
switch (period) {
|
|
282
|
+
case 'MONTH':
|
|
283
|
+
yearPrice = parseFloat(price) * 12;
|
|
284
|
+
monthPrice = parseFloat(price);
|
|
285
|
+
weekPrice = parseFloat(price) / parseFloat(periodNumber) / 4;
|
|
286
|
+
dayPrice = weekPrice / 7;
|
|
287
|
+
break;
|
|
288
|
+
case 'YEAR':
|
|
289
|
+
yearPrice = parseFloat(price);
|
|
290
|
+
monthPrice = parseFloat(price) / 12;
|
|
291
|
+
weekPrice = parseFloat(price) / parseFloat(periodNumber) / 52;
|
|
292
|
+
dayPrice = weekPrice / 7;
|
|
293
|
+
break;
|
|
294
|
+
case 'WEEK':
|
|
295
|
+
yearPrice = parseFloat(price) * 52;
|
|
296
|
+
monthPrice = parseFloat(price) * 4;
|
|
297
|
+
weekPrice = parseFloat(price);
|
|
298
|
+
dayPrice = parseFloat(price) / 7;
|
|
299
|
+
break;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
yearPrice = parseFloat(yearPrice.toFixed(2));
|
|
304
|
+
monthPrice = parseFloat(monthPrice.toFixed(2));
|
|
305
|
+
weekPrice = parseFloat(weekPrice.toFixed(2));
|
|
306
|
+
dayPrice = parseFloat(dayPrice.toFixed(2));
|
|
307
|
+
|
|
308
|
+
const localizedPriceYear = symbolPositionStart ? `${currencySymbol} ${yearPrice}` : `${yearPrice} ${currencySymbol}`.trim();
|
|
309
|
+
const localizedPriceMonth = symbolPositionStart ? `${currencySymbol} ${monthPrice}` : `${monthPrice} ${currencySymbol}`.trim();
|
|
310
|
+
const localizedPriceWeek = symbolPositionStart ? `${currencySymbol} ${weekPrice}` : `${weekPrice} ${currencySymbol}`.trim();
|
|
311
|
+
const localizedPriceDay = symbolPositionStart ? `${currencySymbol} ${dayPrice}` : `${dayPrice} ${currencySymbol}`.trim();
|
|
312
|
+
|
|
252
313
|
payWallInfo.push({
|
|
253
314
|
productIdentifier: product.productId,
|
|
254
315
|
localizedTitle: product.title,
|
|
255
316
|
description: product.description,
|
|
256
|
-
localizedPrice:
|
|
317
|
+
localizedPrice: localizedPrice,
|
|
318
|
+
localizedPriceYear: localizedPriceYear,
|
|
319
|
+
localizedPriceMonth: localizedPriceMonth,
|
|
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
|
-
|
|
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
|
}
|