apps-sdk 1.0.67 → 1.0.69

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.67",
3
+ "version": "1.0.69",
4
4
  "description": "Apps SDK",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -13,6 +13,7 @@ class PayWall extends React.Component {
13
13
  super(props);
14
14
  this.webviewRef = React.createRef();
15
15
  this.paywallData = {};
16
+ this.paywallJS = '';
16
17
  }
17
18
 
18
19
  initPayWall = async () => {
@@ -23,12 +24,6 @@ class PayWall extends React.Component {
23
24
  return config.PAYWALL_DATA[type][keyword].url || '';
24
25
  }
25
26
 
26
- getPayWallJS = async () => {
27
- PayWallLogic.requestPaymentInfo().then((payWallInfo) => {
28
- return "window.subInfoInterval = setInterval(() => window.Appquiles && Appquiles.setSubscriptionPlans(" + JSON.stringify(payWallInfo) + "), 300);";
29
- });
30
- }
31
-
32
27
  getDesignIDFromURL = (url) => {
33
28
  const urlObject = new URL(url);
34
29
  return urlObject.searchParams.get('dsn_id') || '';
@@ -54,7 +49,7 @@ class PayWall extends React.Component {
54
49
 
55
50
  async componentDidUpdate(prevProps) {
56
51
  if (this.props.visible && !prevProps.visible) {
57
- this.webviewRef.current.injectJavaScript(await this.getPayWallJS());
52
+ this.webviewRef.current.injectJavaScript(PayWallLogic.paywallJS);
58
53
  Networking.sendEvent('scene', 'payment_card', { user_id: Session.getUserID(), card_id: this.getCardID(), scene: 'payment_card' });
59
54
  }
60
55
  }
@@ -91,6 +86,16 @@ class PayWall extends React.Component {
91
86
  this.props.acceptTerms();
92
87
  }
93
88
 
89
+ eventClickRestore = (data) => {
90
+ Networking.sendEvent('action', 'subscription_restore');
91
+ let subscribed = PayWallLogic.restorePurchase(this.hideSpinner, this.hidePayWall).then((subscribed) => {
92
+ console.log('subscription result: ',subscribed);
93
+ if (subscribed) {
94
+ this.props.onSubscribe();
95
+ }
96
+ });
97
+ }
98
+
94
99
  hideSpinner = () => {
95
100
  const event = {
96
101
  event: 'hideLoader',
@@ -99,9 +104,8 @@ class PayWall extends React.Component {
99
104
  }
100
105
  }
101
106
  console.log('SDK setHideLoaderAppquiles',event);
102
- this.webviewRef.current.injectJavaScript(
103
- `Appquiles.emitAppEvent(${JSON.stringify(event)});$('.spinner').hide();`
104
- );
107
+ const jsHideSpinner = `Appquiles.emitAppEvent(${JSON.stringify(event)});$('.spinner').hide(); true;`;
108
+ this.webviewRef.current.injectJavaScript(jsHideSpinner);
105
109
  }
106
110
 
107
111
  hidePayWall = () => {
@@ -112,10 +116,12 @@ class PayWall extends React.Component {
112
116
  render() {
113
117
  const { visible, onClose, type, keyword } = this.props;
114
118
  this.getPayWallData(type, keyword);
119
+ config.DEBUG_MODE && console.log('PayWallLogic.paywallJS:', PayWallLogic.paywallJS);
120
+ config.DEBUG_MODE && console.log('PayWallLogic.paywallJS type:', typeof PayWallLogic.paywallJS);
115
121
  return (
116
122
  <BottomSheet visible={visible} onBackButtonPress={onClose} onBackdropPress={onClose}>
117
123
  <View style={styles.bottomNavigationView}>
118
- <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={this.getPayWallJS()}/>
124
+ <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}/>
119
125
  </View>
120
126
  </BottomSheet>
121
127
  );
@@ -19,7 +19,7 @@ class AdJust {
19
19
  self.attribution = attribution;
20
20
  setTimeout(() => {
21
21
  self.sendAttributionData(attribution);
22
- }, 60000);
22
+ }, 30000);
23
23
  });
24
24
  Adjust.create(adjustConfig)
25
25
  this.updateAttributionInfo();
@@ -7,13 +7,19 @@ import * as config from "../../config";
7
7
  import {
8
8
  finishTransaction,
9
9
  flushFailedPurchasesCachedAsPendingAndroid,
10
+ getAvailablePurchases,
10
11
  getSubscriptions,
11
12
  initConnection,
12
13
  purchaseErrorListener,
13
- purchaseUpdatedListener, requestSubscription,
14
+ purchaseUpdatedListener,
15
+ requestSubscription,
14
16
  } from 'react-native-iap';
15
17
 
16
18
  class PayWallLogic {
19
+ constructor(props) {
20
+ this.paywallJS = '';
21
+ }
22
+
17
23
  purchaseUpdateSubscription;
18
24
  purchaseErrorSubscription;
19
25
 
@@ -79,6 +85,8 @@ class PayWallLogic {
79
85
  console.log('purchaseErrorListener', error);
80
86
  },
81
87
  );
88
+
89
+ await this.getPayWallJS();
82
90
  } catch (error) {
83
91
  console.log('Error en initializePayWall', error);
84
92
  }
@@ -119,6 +127,42 @@ class PayWallLogic {
119
127
  return subscribed;
120
128
  };
121
129
 
130
+ restorePurchase = async (hideLoaderCallback, hidePayWallCallback) => {
131
+ let subscribed = false;
132
+ try {
133
+ const purchases = await getAvailablePurchases();
134
+ let restorePurchaseData = {};
135
+ if(purchases){
136
+ for(let i in purchases){
137
+ if(purchases[i].productId ){
138
+ restorePurchaseData = this.purchaseData(purchases[i], Platform.OS === 'android' ? purchases[i].purchaseToken : purchases[i].originalTransactionIdentifierIOS);
139
+ break;
140
+ }
141
+ }
142
+ }
143
+ subscribed = true;
144
+ Session.setIsSubscribed(true);
145
+ Session.setSubscriptionID(restorePurchaseData.subs_id);
146
+ if (hidePayWallCallback) {
147
+ hidePayWallCallback();
148
+ }
149
+ config.DEBUG_MODE && console.log('Purchase restored successfully', restorePurchaseData);
150
+ } catch (error) {
151
+ console.warn(error);
152
+ }
153
+ if (hideLoaderCallback) {
154
+ hideLoaderCallback();
155
+ }
156
+ return subscribed;
157
+ }
158
+
159
+ purchaseData = (subscription, purchaseToken) => {
160
+ return {
161
+ subs_id: purchaseToken,
162
+ product_id: subscription.productId,
163
+ };
164
+ }
165
+
122
166
  getSubscriptionInfo = async (productIDs) => {
123
167
  let subscriptionsData = {};
124
168
  try {
@@ -138,6 +182,17 @@ class PayWallLogic {
138
182
  return subscriptionsData;
139
183
  }
140
184
 
185
+ getPayWallJS = async () => {
186
+ try {
187
+ const payWallInfo = await this.requestPaymentInfo();
188
+ payWallInfo['localizedPrice'] = "";
189
+ this.paywallJS = "window.subInfoInterval = setInterval(() => window.Appquiles && Appquiles.setSubscriptionPlans(" + JSON.stringify(payWallInfo) + "), 300);";
190
+ config.DEBUG_MODE && console.log('getPayWallJS', this.paywallJS);
191
+ } catch (error) {
192
+ console.error(error);
193
+ }
194
+ }
195
+
141
196
  requestPaymentInfo = async () => {
142
197
  await this.getSubscriptionInfo(this.getProductIDs());
143
198
  return this.preparePayWallPurchaseInfo();
package/types/index.d.ts CHANGED
@@ -121,6 +121,7 @@ declare module 'apps-sdk' {
121
121
  export class PayWallLogic {
122
122
  initializePayWall(): Promise<void>;
123
123
  executePurchase(productID: string): Promise<void>;
124
+ restorePurchase(): Promise<void>;
124
125
  }
125
126
 
126
127
  export class AdJust {