mobilyflow-react-native-sdk 0.1.0-alpha.1 → 0.1.0-alpha.2
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/MobilyPurchaseSDK.tsx +175 -0
- package/src/index.tsx +24 -175
package/package.json
CHANGED
@@ -0,0 +1,175 @@
|
|
1
|
+
import MobilyflowReactNativeSdk, { type MobilyPurchaseSDKOptions } from './NativeMobilyflowReactNativeSdk';
|
2
|
+
import { MobilyProduct } from './entities/mobily-product';
|
3
|
+
import type { WebhookStatus } from './enums/webhook-status';
|
4
|
+
import type { MobilySubscriptionOffer } from './entities/mobily-subscription-offer';
|
5
|
+
import { MobilySubscriptionGroup } from './entities/mobily-subscription-group';
|
6
|
+
import { MobilyCustomerEntitlement } from './entities/mobily-customer-entitlement';
|
7
|
+
import { Platform as RNPlatform } from 'react-native';
|
8
|
+
import { MobilyError } from './errors/mobily-error';
|
9
|
+
import { MobilyPurchaseError } from './errors/mobily-purchase-error';
|
10
|
+
import { MobilyTransferOwnershipError } from './errors/mobily-transfer-ownership-error';
|
11
|
+
|
12
|
+
export type PurchaseOptions = {
|
13
|
+
offer?: MobilySubscriptionOffer;
|
14
|
+
quantity?: number;
|
15
|
+
};
|
16
|
+
|
17
|
+
export class MobilyPurchaseSDK {
|
18
|
+
private _uuid: string;
|
19
|
+
|
20
|
+
constructor(appId: string, apiKey: string, environment: number, options?: MobilyPurchaseSDKOptions) {
|
21
|
+
this._uuid = MobilyflowReactNativeSdk.instantiate(appId, apiKey, environment, options ?? {});
|
22
|
+
}
|
23
|
+
|
24
|
+
private throwError(error: any) {
|
25
|
+
if (RNPlatform.OS === 'android') {
|
26
|
+
switch (error.name) {
|
27
|
+
case 'com.mobilyflow.mobilypurchasesdk.Exceptions.MobilyException':
|
28
|
+
return new MobilyError(parseInt(error.code, 10), error.message, error.nativeStackAndroid);
|
29
|
+
case 'com.mobilyflow.mobilypurchasesdk.Exceptions.MobilyPurchaseException':
|
30
|
+
return new MobilyPurchaseError(parseInt(error.code, 10), error.message, error.nativeStackAndroid);
|
31
|
+
case 'com.mobilyflow.mobilypurchasesdk.Exceptions.MobilyTransferOwnershipException':
|
32
|
+
return new MobilyTransferOwnershipError(parseInt(error.code, 10), error.message, error.nativeStackAndroid);
|
33
|
+
}
|
34
|
+
} else {
|
35
|
+
switch (error.domain) {
|
36
|
+
case 'MobilyflowSDK.MobilyError':
|
37
|
+
return new MobilyError(parseInt(error.code, 10), error.message, error.nativeStackIOS);
|
38
|
+
case 'MobilyflowSDK.MobilyPurchaseError':
|
39
|
+
return new MobilyPurchaseError(parseInt(error.code, 10), error.message, error.nativeStackIOS);
|
40
|
+
case 'MobilyflowSDK.MobilyTransferOwnershipError':
|
41
|
+
return new MobilyTransferOwnershipError(parseInt(error.code, 10), error.message, error.nativeStackIOS);
|
42
|
+
}
|
43
|
+
}
|
44
|
+
|
45
|
+
return error;
|
46
|
+
}
|
47
|
+
|
48
|
+
close() {
|
49
|
+
try {
|
50
|
+
MobilyflowReactNativeSdk.close(this._uuid);
|
51
|
+
} catch (error: any) {
|
52
|
+
throw this.throwError(error);
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
56
|
+
async login(externalId: string) {
|
57
|
+
try {
|
58
|
+
await MobilyflowReactNativeSdk.login(this._uuid, externalId);
|
59
|
+
} catch (error: any) {
|
60
|
+
throw this.throwError(error);
|
61
|
+
}
|
62
|
+
}
|
63
|
+
|
64
|
+
async getProducts(identifiers?: string[], onlyAvailable = false): Promise<MobilyProduct[]> {
|
65
|
+
try {
|
66
|
+
const products = await MobilyflowReactNativeSdk.getProducts(this._uuid, identifiers, onlyAvailable);
|
67
|
+
return products.map(MobilyProduct.parseFromAPI);
|
68
|
+
} catch (error: any) {
|
69
|
+
throw this.throwError(error);
|
70
|
+
}
|
71
|
+
}
|
72
|
+
|
73
|
+
async getSubscriptionGroups(identifiers?: string[], onlyAvailable = false) {
|
74
|
+
try {
|
75
|
+
const groups = await MobilyflowReactNativeSdk.getSubscriptionGroups(this._uuid, identifiers, onlyAvailable);
|
76
|
+
return groups.map(MobilySubscriptionGroup.parseFromAPI);
|
77
|
+
} catch (error: any) {
|
78
|
+
throw this.throwError(error);
|
79
|
+
}
|
80
|
+
}
|
81
|
+
|
82
|
+
async getEntitlementForSubscription(subscriptionGroupId: string) {
|
83
|
+
try {
|
84
|
+
const entitlement = await MobilyflowReactNativeSdk.getEntitlementForSubscription(this._uuid, subscriptionGroupId);
|
85
|
+
return MobilyCustomerEntitlement.parseFromAPI(entitlement);
|
86
|
+
} catch (error: any) {
|
87
|
+
throw this.throwError(error);
|
88
|
+
}
|
89
|
+
}
|
90
|
+
|
91
|
+
async getEntitlement(productId: string) {
|
92
|
+
try {
|
93
|
+
const entitlement = await MobilyflowReactNativeSdk.getEntitlement(this._uuid, productId);
|
94
|
+
return MobilyCustomerEntitlement.parseFromAPI(entitlement);
|
95
|
+
} catch (error: any) {
|
96
|
+
throw this.throwError(error);
|
97
|
+
}
|
98
|
+
}
|
99
|
+
|
100
|
+
async getEntitlements(productIds: string[]) {
|
101
|
+
try {
|
102
|
+
const entitlements = await MobilyflowReactNativeSdk.getEntitlements(this._uuid, productIds);
|
103
|
+
return entitlements.map(MobilyCustomerEntitlement.parseFromAPI);
|
104
|
+
} catch (error: any) {
|
105
|
+
throw this.throwError(error);
|
106
|
+
}
|
107
|
+
}
|
108
|
+
|
109
|
+
async requestTransferOwnership() {
|
110
|
+
try {
|
111
|
+
return await MobilyflowReactNativeSdk.requestTransferOwnership(this._uuid);
|
112
|
+
} catch (error: any) {
|
113
|
+
throw this.throwError(error);
|
114
|
+
}
|
115
|
+
}
|
116
|
+
|
117
|
+
async openManageSubscription() {
|
118
|
+
try {
|
119
|
+
return await MobilyflowReactNativeSdk.openManageSubscription(this._uuid);
|
120
|
+
} catch (error: any) {
|
121
|
+
throw this.throwError(error);
|
122
|
+
}
|
123
|
+
}
|
124
|
+
|
125
|
+
async openRefundDialog(transactionId: string): Promise<boolean> {
|
126
|
+
if (RNPlatform.OS === 'android') {
|
127
|
+
throw new Error('openRefundDialog not implemented on Android');
|
128
|
+
} else {
|
129
|
+
try {
|
130
|
+
return await MobilyflowReactNativeSdk.openRefundDialog(this._uuid, transactionId);
|
131
|
+
} catch (error: any) {
|
132
|
+
throw this.throwError(error);
|
133
|
+
}
|
134
|
+
}
|
135
|
+
}
|
136
|
+
|
137
|
+
async purchaseProduct(product: MobilyProduct, options?: PurchaseOptions): Promise<WebhookStatus> {
|
138
|
+
try {
|
139
|
+
return await MobilyflowReactNativeSdk.purchaseProduct(this._uuid, product.id, {
|
140
|
+
offerId: options?.offer?.id || null,
|
141
|
+
quantity: options?.quantity || null,
|
142
|
+
});
|
143
|
+
} catch (error: any) {
|
144
|
+
throw this.throwError(error);
|
145
|
+
}
|
146
|
+
}
|
147
|
+
|
148
|
+
sendDiagnotic() {
|
149
|
+
try {
|
150
|
+
return MobilyflowReactNativeSdk.sendDiagnotic(this._uuid);
|
151
|
+
} catch (error: any) {
|
152
|
+
throw this.throwError(error);
|
153
|
+
}
|
154
|
+
}
|
155
|
+
|
156
|
+
async getStoreCountry() {
|
157
|
+
if (RNPlatform.OS === 'android') {
|
158
|
+
throw new Error('getStoreCountry not implemented on Android');
|
159
|
+
} else {
|
160
|
+
try {
|
161
|
+
return await MobilyflowReactNativeSdk.getStoreCountry(this._uuid);
|
162
|
+
} catch (error: any) {
|
163
|
+
throw this.throwError(error);
|
164
|
+
}
|
165
|
+
}
|
166
|
+
}
|
167
|
+
|
168
|
+
async isForwardingEnable() {
|
169
|
+
try {
|
170
|
+
return await MobilyflowReactNativeSdk.isForwardingEnable(this._uuid);
|
171
|
+
} catch (error: any) {
|
172
|
+
throw this.throwError(error);
|
173
|
+
}
|
174
|
+
}
|
175
|
+
}
|
package/src/index.tsx
CHANGED
@@ -1,175 +1,24 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
export
|
13
|
-
|
14
|
-
|
15
|
-
};
|
16
|
-
|
17
|
-
export
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
if (RNPlatform.OS === 'android') {
|
26
|
-
switch (error.name) {
|
27
|
-
case 'com.mobilyflow.mobilypurchasesdk.Exceptions.MobilyException':
|
28
|
-
return new MobilyError(parseInt(error.code, 10), error.message, error.nativeStackAndroid);
|
29
|
-
case 'com.mobilyflow.mobilypurchasesdk.Exceptions.MobilyPurchaseException':
|
30
|
-
return new MobilyPurchaseError(parseInt(error.code, 10), error.message, error.nativeStackAndroid);
|
31
|
-
case 'com.mobilyflow.mobilypurchasesdk.Exceptions.MobilyTransferOwnershipException':
|
32
|
-
return new MobilyTransferOwnershipError(parseInt(error.code, 10), error.message, error.nativeStackAndroid);
|
33
|
-
}
|
34
|
-
} else {
|
35
|
-
switch (error.domain) {
|
36
|
-
case 'MobilyflowSDK.MobilyError':
|
37
|
-
return new MobilyError(parseInt(error.code, 10), error.message, error.nativeStackIOS);
|
38
|
-
case 'MobilyflowSDK.MobilyPurchaseError':
|
39
|
-
return new MobilyPurchaseError(parseInt(error.code, 10), error.message, error.nativeStackIOS);
|
40
|
-
case 'MobilyflowSDK.MobilyTransferOwnershipError':
|
41
|
-
return new MobilyTransferOwnershipError(parseInt(error.code, 10), error.message, error.nativeStackIOS);
|
42
|
-
}
|
43
|
-
}
|
44
|
-
|
45
|
-
return error;
|
46
|
-
}
|
47
|
-
|
48
|
-
close() {
|
49
|
-
try {
|
50
|
-
MobilyflowReactNativeSdk.close(this._uuid);
|
51
|
-
} catch (error: any) {
|
52
|
-
throw this.throwError(error);
|
53
|
-
}
|
54
|
-
}
|
55
|
-
|
56
|
-
async login(externalId: string) {
|
57
|
-
try {
|
58
|
-
await MobilyflowReactNativeSdk.login(this._uuid, externalId);
|
59
|
-
} catch (error: any) {
|
60
|
-
throw this.throwError(error);
|
61
|
-
}
|
62
|
-
}
|
63
|
-
|
64
|
-
async getProducts(identifiers?: string[], onlyAvailable = false): Promise<MobilyProduct[]> {
|
65
|
-
try {
|
66
|
-
const products = await MobilyflowReactNativeSdk.getProducts(this._uuid, identifiers, onlyAvailable);
|
67
|
-
return products.map(MobilyProduct.parseFromAPI);
|
68
|
-
} catch (error: any) {
|
69
|
-
throw this.throwError(error);
|
70
|
-
}
|
71
|
-
}
|
72
|
-
|
73
|
-
async getSubscriptionGroups(identifiers?: string[], onlyAvailable = false) {
|
74
|
-
try {
|
75
|
-
const groups = await MobilyflowReactNativeSdk.getSubscriptionGroups(this._uuid, identifiers, onlyAvailable);
|
76
|
-
return groups.map(MobilySubscriptionGroup.parseFromAPI);
|
77
|
-
} catch (error: any) {
|
78
|
-
throw this.throwError(error);
|
79
|
-
}
|
80
|
-
}
|
81
|
-
|
82
|
-
async getEntitlementForSubscription(subscriptionGroupId: string) {
|
83
|
-
try {
|
84
|
-
const entitlement = await MobilyflowReactNativeSdk.getEntitlementForSubscription(this._uuid, subscriptionGroupId);
|
85
|
-
return MobilyCustomerEntitlement.parseFromAPI(entitlement);
|
86
|
-
} catch (error: any) {
|
87
|
-
throw this.throwError(error);
|
88
|
-
}
|
89
|
-
}
|
90
|
-
|
91
|
-
async getEntitlement(productId: string) {
|
92
|
-
try {
|
93
|
-
const entitlement = await MobilyflowReactNativeSdk.getEntitlement(this._uuid, productId);
|
94
|
-
return MobilyCustomerEntitlement.parseFromAPI(entitlement);
|
95
|
-
} catch (error: any) {
|
96
|
-
throw this.throwError(error);
|
97
|
-
}
|
98
|
-
}
|
99
|
-
|
100
|
-
async getEntitlements(productIds: string[]) {
|
101
|
-
try {
|
102
|
-
const entitlements = await MobilyflowReactNativeSdk.getEntitlements(this._uuid, productIds);
|
103
|
-
return entitlements.map(MobilyCustomerEntitlement.parseFromAPI);
|
104
|
-
} catch (error: any) {
|
105
|
-
throw this.throwError(error);
|
106
|
-
}
|
107
|
-
}
|
108
|
-
|
109
|
-
async requestTransferOwnership() {
|
110
|
-
try {
|
111
|
-
return await MobilyflowReactNativeSdk.requestTransferOwnership(this._uuid);
|
112
|
-
} catch (error: any) {
|
113
|
-
throw this.throwError(error);
|
114
|
-
}
|
115
|
-
}
|
116
|
-
|
117
|
-
async openManageSubscription() {
|
118
|
-
try {
|
119
|
-
return await MobilyflowReactNativeSdk.openManageSubscription(this._uuid);
|
120
|
-
} catch (error: any) {
|
121
|
-
throw this.throwError(error);
|
122
|
-
}
|
123
|
-
}
|
124
|
-
|
125
|
-
async openRefundDialog(transactionId: string): Promise<boolean> {
|
126
|
-
if (RNPlatform.OS === 'android') {
|
127
|
-
throw new Error('openRefundDialog not implemented on Android');
|
128
|
-
} else {
|
129
|
-
try {
|
130
|
-
return await MobilyflowReactNativeSdk.openRefundDialog(this._uuid, transactionId);
|
131
|
-
} catch (error: any) {
|
132
|
-
throw this.throwError(error);
|
133
|
-
}
|
134
|
-
}
|
135
|
-
}
|
136
|
-
|
137
|
-
async purchaseProduct(product: MobilyProduct, options?: PurchaseOptions): Promise<WebhookStatus> {
|
138
|
-
try {
|
139
|
-
return await MobilyflowReactNativeSdk.purchaseProduct(this._uuid, product.id, {
|
140
|
-
offerId: options?.offer?.id || null,
|
141
|
-
quantity: options?.quantity || null,
|
142
|
-
});
|
143
|
-
} catch (error: any) {
|
144
|
-
throw this.throwError(error);
|
145
|
-
}
|
146
|
-
}
|
147
|
-
|
148
|
-
sendDiagnotic() {
|
149
|
-
try {
|
150
|
-
return MobilyflowReactNativeSdk.sendDiagnotic(this._uuid);
|
151
|
-
} catch (error: any) {
|
152
|
-
throw this.throwError(error);
|
153
|
-
}
|
154
|
-
}
|
155
|
-
|
156
|
-
async getStoreCountry() {
|
157
|
-
if (RNPlatform.OS === 'android') {
|
158
|
-
throw new Error('getStoreCountry not implemented on Android');
|
159
|
-
} else {
|
160
|
-
try {
|
161
|
-
return await MobilyflowReactNativeSdk.getStoreCountry(this._uuid);
|
162
|
-
} catch (error: any) {
|
163
|
-
throw this.throwError(error);
|
164
|
-
}
|
165
|
-
}
|
166
|
-
}
|
167
|
-
|
168
|
-
async isForwardingEnable() {
|
169
|
-
try {
|
170
|
-
return await MobilyflowReactNativeSdk.isForwardingEnable(this._uuid);
|
171
|
-
} catch (error: any) {
|
172
|
-
throw this.throwError(error);
|
173
|
-
}
|
174
|
-
}
|
175
|
-
}
|
1
|
+
export type { PurchaseOptions } from './MobilyPurchaseSDK';
|
2
|
+
export { MobilyPurchaseSDK } from './MobilyPurchaseSDK';
|
3
|
+
|
4
|
+
export { MobilyProduct } from './entities/mobily-product';
|
5
|
+
export {
|
6
|
+
MobilyCustomerEntitlement,
|
7
|
+
ItemEntitlement,
|
8
|
+
SubscriptionEntitlement,
|
9
|
+
} from './entities/mobily-customer-entitlement';
|
10
|
+
export { MobilyOneTimeProduct } from './entities/mobily-one-time-product';
|
11
|
+
export { MobilySubscriptionProduct } from './entities/mobily-subscription-product';
|
12
|
+
export { MobilySubscriptionGroup } from './entities/mobily-subscription-group';
|
13
|
+
export { MobilySubscriptionOffer } from './entities/mobily-subscription-offer';
|
14
|
+
|
15
|
+
export { MobilyEnvironment } from './enums/mobily-environment';
|
16
|
+
export { PeriodUnit } from './enums/period-unit';
|
17
|
+
export { Platform } from './enums/platform';
|
18
|
+
export { ProductStatus } from './enums/product-status';
|
19
|
+
export { ProductType } from './enums/product-type';
|
20
|
+
export { WebhookStatus } from './enums/webhook-status';
|
21
|
+
|
22
|
+
export { MobilyError } from './errors/mobily-error';
|
23
|
+
export { MobilyPurchaseError } from './errors/mobily-purchase-error';
|
24
|
+
export { MobilyTransferOwnershipError } from './errors/mobily-transfer-ownership-error';
|