apps-sdk 1.0.40 → 1.0.41
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.
|
|
3
|
+
"version": "1.0.41",
|
|
4
4
|
"description": "Apps SDK",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"expo-sharing": "^11.10.0",
|
|
21
21
|
"react-native": "^0.73.2",
|
|
22
22
|
"react-native-btr": "^2.2.1",
|
|
23
|
+
"react-native-iap": "^12.12.2",
|
|
23
24
|
"react-native-webview": "^13.8.1"
|
|
24
25
|
},
|
|
25
26
|
"types": "./types/index.d.ts"
|
|
@@ -150,6 +150,10 @@ class Networking {
|
|
|
150
150
|
return storage.getData("ENDPOINTS");
|
|
151
151
|
}
|
|
152
152
|
|
|
153
|
+
createSubscription = async (data) => {
|
|
154
|
+
return this.request(config.ENDPOINTS.SUB_NEW, data);
|
|
155
|
+
}
|
|
156
|
+
|
|
153
157
|
setEvents(events) {
|
|
154
158
|
events && (config.EVENTS = events);
|
|
155
159
|
}
|
package/src/libraries/PayWall.js
CHANGED
|
@@ -1,13 +1,25 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { View
|
|
2
|
+
import {BottomSheet} from 'react-native-btr';
|
|
3
|
+
import {WebView} from 'react-native-webview';
|
|
4
|
+
import {Platform, View} from "react-native";
|
|
5
5
|
import Utils from "./Utils";
|
|
6
6
|
import Networking from "./Networking";
|
|
7
7
|
import Session from "./Session";
|
|
8
8
|
import * as config from "../../config";
|
|
9
|
+
import {
|
|
10
|
+
finishTransaction,
|
|
11
|
+
flushFailedPurchasesCachedAsPendingAndroid,
|
|
12
|
+
getSubscriptions,
|
|
13
|
+
initConnection,
|
|
14
|
+
purchaseErrorListener,
|
|
15
|
+
purchaseUpdatedListener, requestSubscription,
|
|
16
|
+
} from 'react-native-iap';
|
|
17
|
+
import Constants from "expo-constants";
|
|
9
18
|
|
|
10
19
|
class PayWall extends React.Component {
|
|
20
|
+
purchaseUpdateSubscription;
|
|
21
|
+
purchaseErrorSubscription;
|
|
22
|
+
|
|
11
23
|
constructor(props) {
|
|
12
24
|
super(props);
|
|
13
25
|
this.webviewRef = React.createRef();
|
|
@@ -50,6 +62,89 @@ class PayWall extends React.Component {
|
|
|
50
62
|
}
|
|
51
63
|
}
|
|
52
64
|
|
|
65
|
+
// --------------------------------- Funciones para Pago ---------------------------------------
|
|
66
|
+
|
|
67
|
+
async initializePayWall() {
|
|
68
|
+
initConnection().then(async () => {
|
|
69
|
+
|
|
70
|
+
if(Platform.OS === 'android'){
|
|
71
|
+
flushFailedPurchasesCachedAsPendingAndroid()
|
|
72
|
+
.catch(() => {
|
|
73
|
+
console.log('flushFailedPurchasesCachedAsPendingAndroid')
|
|
74
|
+
})
|
|
75
|
+
.then(async () => {
|
|
76
|
+
this.purchaseUpdateSubscription = purchaseUpdatedListener(
|
|
77
|
+
async (purchase) => {
|
|
78
|
+
console.log('purchaseUpdatedListener', purchase);
|
|
79
|
+
const receipt = purchase.transactionReceipt;
|
|
80
|
+
if (receipt) {
|
|
81
|
+
const subscription = await getSubscriptions({skus: [purchase.productId]})
|
|
82
|
+
const s = subscription[0];
|
|
83
|
+
await finishTransaction({purchase: purchase});
|
|
84
|
+
let data = this.purchaseResp(s,purchase.purchaseToken)
|
|
85
|
+
const purchaseResponse = await Networking.createSubscription(data);
|
|
86
|
+
if(purchaseResponse.success){
|
|
87
|
+
Session.setIsSubscribed(true);
|
|
88
|
+
Session.setSubscriptionData(purchaseResponse.data);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
);
|
|
93
|
+
});
|
|
94
|
+
} else{
|
|
95
|
+
this.purchaseUpdateSubscription = purchaseUpdatedListener(
|
|
96
|
+
async (purchase) => {
|
|
97
|
+
console.log('SDK purchaseUpdatedListener purchase',purchase)
|
|
98
|
+
const subscription = await getSubscriptions({skus: [purchase.productId]})
|
|
99
|
+
const s = subscription[0];
|
|
100
|
+
await finishTransaction({purchase: purchase,isConsumable:true});
|
|
101
|
+
let data = this.purchaseResp(s,(purchase.originalTransactionIdentifierIOS ? purchase.originalTransactionIdentifierIOS : purchase.transactionId))
|
|
102
|
+
const purchaseResponse = await Networking.createSubscription(data);
|
|
103
|
+
if(purchaseResponse.success){
|
|
104
|
+
Session.setIsSubscribed(true);
|
|
105
|
+
Session.setSubscriptionData(purchaseResponse.data);
|
|
106
|
+
} else {
|
|
107
|
+
console.log('SDK checkSubscription fail')
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
this.purchaseErrorSubscription = purchaseErrorListener(
|
|
114
|
+
(error) => {
|
|
115
|
+
console.log('purchaseErrorListener', error);
|
|
116
|
+
},
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
purchaseResp = (subscription, purchaseToken) => {
|
|
123
|
+
return {
|
|
124
|
+
subs_id: purchaseToken,
|
|
125
|
+
product_id: subscription.productId,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
executePurchase = async (productID) => {
|
|
130
|
+
let subscribe = false;
|
|
131
|
+
try {
|
|
132
|
+
const subscriptionTemplates = await getSubscriptions({skus: [productID]});
|
|
133
|
+
if (subscriptionTemplates.length > 0) {
|
|
134
|
+
const subscription = subscriptionTemplates[0];
|
|
135
|
+
const sku = subscription.productId;
|
|
136
|
+
const offerToken = Platform.OS === 'android' ? subscription.subscriptionOfferDetails[0].offerToken : false;
|
|
137
|
+
await requestSubscription({
|
|
138
|
+
sku,
|
|
139
|
+
...(offerToken && {subscriptionOffers: [{sku, offerToken}]}),
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
} catch (err) {
|
|
143
|
+
console.warn(err.code, err.message);
|
|
144
|
+
}
|
|
145
|
+
return subscribe;
|
|
146
|
+
};
|
|
147
|
+
|
|
53
148
|
// --------------------------------------- Eventos ---------------------------------------
|
|
54
149
|
eventClickClose = (data) => {
|
|
55
150
|
Networking.sendEvent('action', 'continue_free');
|
|
@@ -57,6 +152,7 @@ class PayWall extends React.Component {
|
|
|
57
152
|
}
|
|
58
153
|
|
|
59
154
|
eventClickSubscribe = (data) => {
|
|
155
|
+
console.log(data);
|
|
60
156
|
Networking.sendEvent('action', 'cta');
|
|
61
157
|
setTimeout(() => {
|
|
62
158
|
this.hideSpinner();
|
package/src/libraries/Session.js
CHANGED
|
@@ -11,6 +11,7 @@ class Session {
|
|
|
11
11
|
sessionID = null;
|
|
12
12
|
isFirstOpen = false;
|
|
13
13
|
isSubscribed = false;
|
|
14
|
+
subscriptionData = {};
|
|
14
15
|
isDevUser = false;
|
|
15
16
|
|
|
16
17
|
init = async () => {
|
|
@@ -116,6 +117,10 @@ class Session {
|
|
|
116
117
|
this.isSubscribed = isSubscribed;
|
|
117
118
|
}
|
|
118
119
|
|
|
120
|
+
setSubscriptionData = (subscriptionData) => {
|
|
121
|
+
this.subscriptionData = subscriptionData;
|
|
122
|
+
}
|
|
123
|
+
|
|
119
124
|
setIsDevUser = (isDevUser) => {
|
|
120
125
|
this.isDevUser = isDevUser;
|
|
121
126
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -45,6 +45,7 @@ declare module 'apps-sdk' {
|
|
|
45
45
|
setIsDevUser(isDevUser: boolean): void;
|
|
46
46
|
setUserID(userID: string): void;
|
|
47
47
|
getUserID(): string | null;
|
|
48
|
+
setSubscriptionData(subscriptionData: any): void;
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
export class Networking {
|
|
@@ -58,6 +59,7 @@ declare module 'apps-sdk' {
|
|
|
58
59
|
getEndpoints(): any;
|
|
59
60
|
setEvents(events: any): void;
|
|
60
61
|
sendEvent(eventType: string, eventKeyword:string, eventData?: object): Promise<void>;
|
|
62
|
+
createSubscription()
|
|
61
63
|
}
|
|
62
64
|
|
|
63
65
|
export class Storage {
|
|
@@ -92,7 +94,10 @@ declare module 'apps-sdk' {
|
|
|
92
94
|
keyword: string;
|
|
93
95
|
}
|
|
94
96
|
|
|
95
|
-
export class PayWall
|
|
97
|
+
export class PayWall {
|
|
98
|
+
initializePayWall(): Promise<void>;
|
|
99
|
+
executePurchase(productID: string): Promise<void>;
|
|
100
|
+
}
|
|
96
101
|
|
|
97
102
|
export class AppsSDK {
|
|
98
103
|
initializePushNotifications(): Promise<string>;
|