apps-sdk 1.0.52 → 1.0.54

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/config.js CHANGED
@@ -21,7 +21,10 @@ export var SPECIAL_EVENTS = ['picture_upload', 'write_prompt', 'picture_generate
21
21
  export var PAYWALL_DATA = {
22
22
  actions: {},
23
23
  scenes: {},
24
- others: {}
24
+ others: {},
25
+ products: {},
26
+ products_metadata: {},
27
+ paywall_info: {},
25
28
  }
26
29
 
27
30
  export const EVENT_TYPES = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apps-sdk",
3
- "version": "1.0.52",
3
+ "version": "1.0.54",
4
4
  "description": "Apps SDK",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,10 +1,11 @@
1
- import React from 'react';
1
+ import React, {useEffect} from 'react';
2
2
  import {BottomSheet} from 'react-native-btr';
3
3
  import {WebView} from 'react-native-webview';
4
4
  import {View} from "react-native";
5
5
  import Utils from "../libraries/Utils";
6
6
  import Networking from "../libraries/Networking";
7
7
  import PayWallLogic from "../libraries/PayWallLogic";
8
+ import Session from "../libraries/Session";
8
9
  import * as config from "../../config";
9
10
 
10
11
  class PayWall extends React.Component {
@@ -14,15 +15,23 @@ class PayWall extends React.Component {
14
15
  this.paywallData = {};
15
16
  }
16
17
 
17
- getURL = () => {
18
- // CP de prueba
19
- return "https://backend.ailandsapp.com/payment-card/ZLp_slash_QSy94h9aKdNJWvvvkE8dkHSyeiTGRxsZVQAaiiYveh2jTjeZVJnnIZ0WVKTgiRoAkEoVrB2leXjt_slash_l2g2MtLKRa_slash_30mL6tMu0L9IJxY=?dsn_id=6274";
18
+ initPayWall = async () => {
19
+ await PayWallLogic.initializePayWall();
20
20
  }
21
21
 
22
- getPayWallJS = () => {
23
- // return "window.subInfoInterval = setInterval(() => window.Appquiles && Appquiles.setSubscriptionPlans(" + JSON.stringify(information.subsPlansInfo) + "), 300);" : '';
24
- return "window.subInfoInterval = setInterval(() => window.Appquiles, 300);";
22
+ getURL = (type, keyword) => {
23
+ return config.PAYWALL_DATA[type][keyword].url || '';
24
+ }
25
+
26
+ getPayWallJS = async () => {
27
+ PayWallLogic.requestPaymentInfo().then((payWallInfo) => {
28
+ return "window.subInfoInterval = setInterval(() => window.Appquiles && Appquiles.setSubscriptionPlans(" + JSON.stringify(payWallInfo) + "), 300);";
29
+ });
30
+ }
25
31
 
32
+ getDesignIDFromURL = (url) => {
33
+ const urlObject = new URL(url);
34
+ return urlObject.searchParams.get('dsn_id') || '';
26
35
  }
27
36
 
28
37
  getPayWallData = (type, keyword) => {
@@ -30,7 +39,6 @@ class PayWall extends React.Component {
30
39
  console.log('No se encontraron datos para el paywall.');
31
40
  return;
32
41
  }
33
- console.log('PayWallData: ', JSON.stringify(config.PAYWALL_DATA[type][keyword]));
34
42
  this.paywallData = config.PAYWALL_DATA[type][keyword];
35
43
  }
36
44
 
@@ -44,12 +52,17 @@ class PayWall extends React.Component {
44
52
  }
45
53
  }
46
54
 
47
- componentDidUpdate(prevProps) {
55
+ async componentDidUpdate(prevProps) {
48
56
  if (this.props.visible && !prevProps.visible) {
49
- this.webviewRef.current.injectJavaScript(this.getPayWallJS());
57
+ this.webviewRef.current.injectJavaScript(await this.getPayWallJS());
58
+ Networking.sendEvent('scene', 'payment_card', { user_id: Session.getUserID(), card_id: this.getCardID(), scene: 'payment_card' });
50
59
  }
51
60
  }
52
61
 
62
+ getCardID = () => {
63
+ return this.getDesignIDFromURL(this.paywallData.url);
64
+ }
65
+
53
66
  // --------------------------------------- Eventos ---------------------------------------
54
67
  eventClickClose = (data) => {
55
68
  Networking.sendEvent('action', 'continue_free');
@@ -59,12 +72,13 @@ class PayWall extends React.Component {
59
72
  eventClickSubscribe = (data) => {
60
73
  Networking.sendEvent('action', 'cta');
61
74
  if (this.paywallData && this.paywallData.products_id && this.paywallData.products_id.length > 0) {
62
- let subscribed = PayWallLogic.executePurchase(this.paywallData.products_id[0]);
63
- console.log('subscribed',subscribed)
75
+ let subscribed = PayWallLogic.executePurchase(this.paywallData.products_id[0], this.hideSpinner).then((subscribed) => {
76
+ console.log('subscription result: ',subscribed);
77
+ if (subscribed) {
78
+ this.props.onSubscribe();
79
+ }
80
+ });
64
81
  }
65
- setTimeout(() => {
66
- this.hideSpinner();
67
- }, 3000);
68
82
  }
69
83
 
70
84
  eventClickFreeSubscription = (data) => {
@@ -27,6 +27,7 @@ class Networking {
27
27
  this.setEndpoints(initData.data.domains);
28
28
  this.setEvents(initData.data.attribution);
29
29
  this.setPayWallData(initData);
30
+ this.checkSubscription();
30
31
  }
31
32
  } catch (error) {
32
33
  console.error(error);
@@ -51,11 +52,7 @@ class Networking {
51
52
  async setToken(token) {
52
53
  try {
53
54
  const installID = await storage.getData('install_id');
54
- const response = await fetch(config.ENDPOINTS.EVENTS_PUSH.replace('[TOKEN]', token).replace('[INSTALL_ID]', installID));
55
- const json = await response.json();
56
- if(json.success){
57
- return true;
58
- }
55
+ const result = this.request(config.ENDPOINTS.NOTIFICATION_SET_TOKEN, { expo_id: token });
59
56
  } catch (error) {
60
57
  console.error(error);
61
58
  return null;
@@ -133,6 +130,16 @@ class Networking {
133
130
  return this.request(config.ENDPOINTS.SUB_NEW, data);
134
131
  }
135
132
 
133
+ checkSubscription = async () => {
134
+ let subsID = await storage.getData('userID');
135
+ let subStatus = await this.request(config.ENDPOINTS.SUB_STATUS, {...Session.sessionData, subs_id: subsID});
136
+ console.log('checkSubscription', subStatus);
137
+ if (subStatus && subStatus.success === 1) {
138
+ Session.setIsSubscribed(subStatus.data.subscription_active);
139
+ Session.setSubscriptionData(subStatus.data);
140
+ }
141
+ }
142
+
136
143
  setEvents(events) {
137
144
  events && (config.EVENTS = events);
138
145
  }
@@ -162,8 +169,11 @@ class Networking {
162
169
  }
163
170
  }
164
171
 
172
+ result.products = data.data.product_ids;
173
+
165
174
  if (result) {
166
175
  config.PAYWALL_DATA = result;
176
+ console.log('PAYWALL_DATA', config.PAYWALL_DATA);
167
177
  }
168
178
  }
169
179
 
@@ -176,10 +186,11 @@ class Networking {
176
186
  try {
177
187
  AdJust.trackEventIfExist(eventKeyword);
178
188
  let eventResponse = await this.request(config.ENDPOINTS.EVENTS_PUSH, {
179
- event_name: eventType,
189
+ event_name: eventKeyword,
180
190
  event_type: eventType,
181
- action: eventKeyword,
182
- data: eventData,
191
+ // action: eventKeyword,
192
+ appevent: eventKeyword,
193
+ payload: eventData,
183
194
  ...Session.sessionData,
184
195
  });
185
196
  if (eventResponse) {
@@ -2,6 +2,8 @@ import React from 'react';
2
2
  import {Platform} from "react-native";
3
3
  import Networking from "./Networking";
4
4
  import Session from "./Session";
5
+ import * as config from "../../config";
6
+
5
7
  import {
6
8
  finishTransaction,
7
9
  flushFailedPurchasesCachedAsPendingAndroid,
@@ -39,6 +41,7 @@ class PayWallLogic {
39
41
  const purchaseResponse = await Networking.createSubscription(data);
40
42
  if(purchaseResponse.success){
41
43
  Session.setIsSubscribed(true);
44
+ Session.setSubscriptionID(data.subs_id);
42
45
  Session.setSubscriptionData(purchaseResponse.data);
43
46
  }
44
47
  }
@@ -59,6 +62,7 @@ class PayWallLogic {
59
62
  const purchaseResponse = await Networking.createSubscription(data);
60
63
  if(purchaseResponse.success){
61
64
  Session.setIsSubscribed(true);
65
+ Session.setSubscriptionID(data.subs_id);
62
66
  Session.setSubscriptionData(purchaseResponse.data);
63
67
  } else {
64
68
  console.log('SDK checkSubscription fail')
@@ -87,8 +91,8 @@ class PayWallLogic {
87
91
  };
88
92
  }
89
93
 
90
- executePurchase = async (productID) => {
91
- let subscribe = false;
94
+ executePurchase = async (productID, hideLoaderCallback) => {
95
+ let subscribed = false;
92
96
  try {
93
97
  const subscriptionTemplates = await getSubscriptions({skus: [productID]});
94
98
  console.log('subscriptionTemplates', subscriptionTemplates);
@@ -96,16 +100,90 @@ class PayWallLogic {
96
100
  const subscription = subscriptionTemplates[0];
97
101
  const sku = subscription.productId;
98
102
  const offerToken = Platform.OS === 'android' ? subscription.subscriptionOfferDetails[0].offerToken : false;
103
+ if (hideLoaderCallback) {
104
+ setTimeout(() => {
105
+ hideLoaderCallback();
106
+ }, 15000);
107
+ }
99
108
  await requestSubscription({
100
109
  sku,
101
110
  ...(offerToken && {subscriptionOffers: [{sku, offerToken}]}),
102
111
  });
112
+ console.log('paso 2');
113
+ subscribed = true;
103
114
  }
104
115
  } catch (err) {
105
- console.warn(err.code, err.message);
116
+ console.log(err.code, err.message);
106
117
  }
107
- return subscribe;
118
+
119
+ return subscribed;
108
120
  };
121
+
122
+ getSubscriptionInfo = async (productIDs) => {
123
+ let subscriptionsData = {};
124
+ try {
125
+ const subscriptionTemplates = await getSubscriptions({skus: productIDs});
126
+ if (subscriptionTemplates.length > 0) {
127
+ subscriptionTemplates.forEach(product => {
128
+ subscriptionsData[product.productId] = product;
129
+ });
130
+ config.PAYWALL_DATA.products_metadata = subscriptionsData;
131
+ console.log('products_metadata', config.PAYWALL_DATA.products_metadata);
132
+ }
133
+ } catch (err) {
134
+ console.log(err.code, err.message);
135
+ return {};
136
+ }
137
+ console.log('subscription Metadata: ', subscriptionsData);
138
+ return subscriptionsData;
139
+ }
140
+
141
+ requestPaymentInfo = async () => {
142
+ await this.getSubscriptionInfo(this.getProductIDs());
143
+ return this.preparePayWallPurchaseInfo();
144
+ }
145
+
146
+ preparePayWallPurchaseInfo = () => {
147
+ let payWallInfo = [];
148
+
149
+ if (config.PAYWALL_DATA && config.PAYWALL_DATA.products_metadata) {
150
+ for (let key in config.PAYWALL_DATA.products_metadata) {
151
+ let product = config.PAYWALL_DATA.products_metadata[key];
152
+ payWallInfo.push({
153
+ productIdentifier: product.productId,
154
+ localizedTitle: product.title,
155
+ description: product.description,
156
+ localizedPrice: product.localizedPrice,
157
+ price: product.price,
158
+ type: product.type,
159
+ platform: product.platform,
160
+ currency: product.currency,
161
+ // duration: product.subscriptionPeriod,
162
+ freePeriod: '',
163
+ subscriptionUnits: product.subscriptionPeriodNumberIOS || product.subscriptionPeriodNumberAndroid || 1,
164
+ subscriptionPeriod: this.getPeriodInt(product.subscriptionPeriodUnitIOS || product.subscriptionPeriodUnitAndroid || 'M'),
165
+ units: product.subscriptionPeriodNumberIOS || product.subscriptionPeriodNumberAndroid || 1,
166
+ period: product.subscriptionPeriodUnitIOS || product.subscriptionPeriodUnitAndroid || 'MONTH',
167
+ });
168
+ }
169
+ config.PAYWALL_DATA.paywall_info = payWallInfo;
170
+ console.log('paywall_info', config.PAYWALL_DATA.paywall_info);
171
+ }
172
+ return payWallInfo;
173
+ }
174
+
175
+ getProductIDs = () => {
176
+ return config.PAYWALL_DATA.products;
177
+ }
178
+
179
+ getPeriodInt(period) {
180
+ return {
181
+ D: 0,
182
+ W: 1,
183
+ M: 2,
184
+ Y: 3,
185
+ }[period.charAt(0)];
186
+ }
109
187
  }
110
188
 
111
189
  export default new PayWallLogic();
@@ -114,13 +114,19 @@ class Session {
114
114
  }
115
115
 
116
116
  setIsSubscribed = (isSubscribed) => {
117
+ Storage.storeData("isSubscribed", isSubscribed);
117
118
  this.isSubscribed = isSubscribed;
118
119
  }
119
120
 
120
121
  setSubscriptionData = (subscriptionData) => {
122
+ Storage.storeData("subscriptionData", subscriptionData);
121
123
  this.subscriptionData = subscriptionData;
122
124
  }
123
125
 
126
+ setSubscriptionID = (subscriptionID) => {
127
+ Storage.storeData("subscriptionID", subscriptionID);
128
+ }
129
+
124
130
  setIsDevUser = (isDevUser) => {
125
131
  this.isDevUser = isDevUser;
126
132
  }
@@ -143,6 +149,28 @@ class Session {
143
149
  return null;
144
150
  }
145
151
  }
152
+
153
+ checkSubscription = async () => {
154
+ config.DEBUG_MODE && console.debug("checkSubscription");
155
+ try {
156
+ let result = Networking.checkSubscription();
157
+ config.DEBUG_MODE && console.debug("checkSubscription - result: ", result);
158
+ } catch (error) {
159
+ console.error(error);
160
+ return null;
161
+ }
162
+ }
163
+
164
+ checkSubscription24h = async () => {
165
+ config.DEBUG_MODE && console.debug("checkSubscription24h");
166
+ let lastCheck = await Storage.getData("lastSubscriptionCheck");
167
+ if (!lastCheck || (new Date().getTime() - lastCheck) > 86400000) {
168
+ await this.checkSubscription();
169
+ await Storage.storeData("lastSubscriptionCheck", new Date().getTime());
170
+ } else {
171
+ config.DEBUG_MODE && console.debug("checkSubscription24h - Not 24h yet");
172
+ }
173
+ }
146
174
  }
147
175
 
148
176
  export default new Session();
@@ -4,8 +4,10 @@ import * as FileSystem from 'expo-file-system';
4
4
  import * as Sharing from 'expo-sharing';
5
5
  import Networking from "./Networking";
6
6
  import utils from "./Utils";
7
+ import * as config from "../../config";
7
8
 
8
9
  const CREATIONS_DIR = `${FileSystem.documentDirectory}/creations`
10
+ const TMP_DIR = `${FileSystem.documentDirectory}/tmp`
9
11
 
10
12
  class Storage {
11
13
  async storeData(key, value) {
@@ -112,7 +114,7 @@ class Storage {
112
114
  try {
113
115
  const directoryUri = CREATIONS_DIR + '/' + fileName;
114
116
  console.log('handleDownloadImageToCreations directoryUri:', directoryUri);
115
- await this.createCreationsDir(directoryUri);
117
+ await this.createDir(directoryUri);
116
118
  const fileUri = directoryUri + '/image.jpg';
117
119
  console.log('handleDownloadImageToCreations fileUri:', fileUri);
118
120
  const fileData = directoryUri + '/data.json';
@@ -127,6 +129,22 @@ class Storage {
127
129
  }
128
130
  }
129
131
 
132
+ async handleDownloadImageToTMP(base64Image, fileName) {
133
+ try {
134
+ const directoryUri = TMP_DIR + '/' + fileName;
135
+ console.log('handleDownloadImageToTMP directoryUri:', directoryUri);
136
+ await this.createDir(directoryUri);
137
+ const fileUri = directoryUri + '/image.jpg';
138
+ console.log('handleDownloadImageToTMP fileUri:', fileUri);
139
+ console.log('handleDownloadImageToTMP base64Image:', base64Image.substring(0, 50) + '...');
140
+ const base64Data = base64Image.replace(/^data:image\/[a-z]+;base64,/, '');
141
+ await FileSystem.writeAsStringAsync(fileUri, base64Data, { encoding: FileSystem.EncodingType.Base64,})
142
+ return fileUri;
143
+ } catch (error) {
144
+ console.error('Error al guardar la imagen en FileSystem TMP:', error);
145
+ }
146
+ }
147
+
130
148
  async handleDownloadImageToGallery(imageURI) {
131
149
  try {
132
150
  const { status } = await MediaLibrary.requestPermissionsAsync();
@@ -143,7 +161,7 @@ class Storage {
143
161
  try {
144
162
  const info = await FileSystem.getInfoAsync(CREATIONS_DIR);
145
163
  if (!info.exists) {
146
- await this.createCreationsDir(CREATIONS_DIR);
164
+ await this.createDir(CREATIONS_DIR);
147
165
  return [];
148
166
  }
149
167
 
@@ -204,10 +222,10 @@ class Storage {
204
222
  }
205
223
  };
206
224
 
207
- async createCreationsDir (dirName) {
225
+ async createDir (dirName) {
208
226
  const directory = await FileSystem.getInfoAsync(dirName)
209
227
  if (!directory.exists) {
210
- console.log('createCreationsDir', dirName);
228
+ console.log('Creating Directory', dirName);
211
229
  await FileSystem.makeDirectoryAsync(dirName, { intermediates: true })
212
230
  const newDirectory = await FileSystem.getInfoAsync(dirName)
213
231
  }
@@ -220,6 +238,10 @@ class Storage {
220
238
  }
221
239
  return await Sharing.shareAsync(fileName);
222
240
  }
241
+
242
+ setTrackingPermissionGranted(value) {
243
+ config.TRACKING_ACTIVE = value;
244
+ }
223
245
  }
224
246
 
225
247
  export default new Storage();
package/types/index.d.ts CHANGED
@@ -35,6 +35,7 @@ declare module 'apps-sdk' {
35
35
  storeSessionStructure(): Promise<void>;
36
36
  checkFirstOpen(): Promise<void>;
37
37
  checkUserID(): Promise<void>;
38
+ setSubscriptionID(subscriptionID: string): void;
38
39
  generateSessionID(): string;
39
40
  getSessionData(): SessionData;
40
41
  getSessionID(): string | null;
@@ -46,6 +47,7 @@ declare module 'apps-sdk' {
46
47
  setUserID(userID: string): void;
47
48
  getUserID(): string | null;
48
49
  setSubscriptionData(subscriptionData: any): void;
50
+ checkSubscription24h(): Promise<void>;
49
51
  }
50
52
 
51
53
  export class Networking {
@@ -68,13 +70,15 @@ declare module 'apps-sdk' {
68
70
  removeData(key: string): Promise<void>;
69
71
  handleDownloadImage(url: string, filename: string): Promise<void>;
70
72
  handleShareFile(filename: string): Promise<boolean>;
71
- createCreationsDir(dirName: string): Promise<void>;
73
+ createDir(dirName: string): Promise<void>;
72
74
  handleDownloadImageToCreations(base64Image: string, fileName: string, data: object): Promise<{ directoryUri: string, fileUri: string, fileData: any }>;
75
+ handleDownloadImageToTMP(base64Image: string, fileName: string): Promise<string>;
73
76
  getCreations(): Promise<any>;
74
77
  deleteCreation(dirName: string): Promise<void>;
75
78
  deleteAllCreations(): Promise<void>;
76
79
  handleDownloadImageToGallery(imageURI: string): Promise<void>;
77
80
  handleRequestGalleryPermission(): Promise<string>;
81
+ setTrackingPermissionGranted(value: boolean): void;
78
82
  }
79
83
 
80
84
  export class Utils {