@deuna/react-native-sdk 2.0.4 → 2.1.0-beta.1
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/DeunaWalletsModule.podspec +19 -0
- package/README.md +141 -2
- package/android/build.gradle +43 -0
- package/android/src/main/AndroidManifest.xml +8 -0
- package/android/src/main/java/com/deuna/wallets/DeunaWalletsModule.kt +103 -0
- package/app.plugin.js +1 -0
- package/expo-module.config.json +10 -0
- package/ios/DeunaWalletsModule.swift +56 -0
- package/lib/module/DeunaSDK.js +44 -3
- package/lib/module/DeunaSDK.js.map +1 -1
- package/lib/module/components/DeunaWebView.js +3 -0
- package/lib/module/components/DeunaWebView.js.map +1 -1
- package/lib/module/components/DeunaWidget.js +1 -0
- package/lib/module/components/DeunaWidget.js.map +1 -1
- package/lib/module/controllers/BaseWebViewController.js +17 -4
- package/lib/module/controllers/BaseWebViewController.js.map +1 -1
- package/lib/module/controllers/ElementsWidgetController.js +9 -1
- package/lib/module/controllers/ElementsWidgetController.js.map +1 -1
- package/lib/module/helpers/ExternalUrlHelper.js +4 -1
- package/lib/module/helpers/ExternalUrlHelper.js.map +1 -1
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/plugin/index.js +25 -0
- package/lib/module/plugin/index.js.map +1 -0
- package/lib/module/plugin/withAndroidGooglePay.js +20 -0
- package/lib/module/plugin/withAndroidGooglePay.js.map +1 -0
- package/lib/module/plugin/withIosApplePay.js +10 -0
- package/lib/module/plugin/withIosApplePay.js.map +1 -0
- package/lib/module/plugin/withIosFmtFix.js +34 -0
- package/lib/module/plugin/withIosFmtFix.js.map +1 -0
- package/lib/module/types/base.js +16 -0
- package/lib/module/types/base.js.map +1 -1
- package/lib/module/types/envs.js +12 -0
- package/lib/module/types/envs.js.map +1 -1
- package/lib/module/wallets/WalletModule.js +218 -0
- package/lib/module/wallets/WalletModule.js.map +1 -0
- package/lib/module/wallets/index.js +4 -0
- package/lib/module/wallets/index.js.map +1 -0
- package/lib/module/wallets/tokenize/applePay.js +24 -0
- package/lib/module/wallets/tokenize/applePay.js.map +1 -0
- package/lib/module/wallets/tokenize/googlePay.js +24 -0
- package/lib/module/wallets/tokenize/googlePay.js.map +1 -0
- package/lib/module/wallets/tokenize/index.js +12 -0
- package/lib/module/wallets/tokenize/index.js.map +1 -0
- package/lib/module/wallets/types.js +4 -0
- package/lib/module/wallets/types.js.map +1 -0
- package/lib/module/wallets/vaultApi.js +121 -0
- package/lib/module/wallets/vaultApi.js.map +1 -0
- package/lib/typescript/deuna-sdk-react-native/src/DeunaSDK.d.ts +12 -3
- package/lib/typescript/deuna-sdk-react-native/src/DeunaSDK.d.ts.map +1 -1
- package/lib/typescript/deuna-sdk-react-native/src/components/DeunaWebView.d.ts +1 -0
- package/lib/typescript/deuna-sdk-react-native/src/components/DeunaWebView.d.ts.map +1 -1
- package/lib/typescript/deuna-sdk-react-native/src/controllers/BaseWebViewController.d.ts +7 -0
- package/lib/typescript/deuna-sdk-react-native/src/controllers/BaseWebViewController.d.ts.map +1 -1
- package/lib/typescript/deuna-sdk-react-native/src/controllers/ElementsWidgetController.d.ts.map +1 -1
- package/lib/typescript/deuna-sdk-react-native/src/helpers/ExternalUrlHelper.d.ts +1 -0
- package/lib/typescript/deuna-sdk-react-native/src/helpers/ExternalUrlHelper.d.ts.map +1 -1
- package/lib/typescript/deuna-sdk-react-native/src/index.d.ts +1 -0
- package/lib/typescript/deuna-sdk-react-native/src/index.d.ts.map +1 -1
- package/lib/typescript/deuna-sdk-react-native/src/plugin/index.d.ts +8 -0
- package/lib/typescript/deuna-sdk-react-native/src/plugin/index.d.ts.map +1 -0
- package/lib/typescript/deuna-sdk-react-native/src/plugin/withAndroidGooglePay.d.ts +3 -0
- package/lib/typescript/deuna-sdk-react-native/src/plugin/withAndroidGooglePay.d.ts.map +1 -0
- package/lib/typescript/deuna-sdk-react-native/src/plugin/withIosApplePay.d.ts +5 -0
- package/lib/typescript/deuna-sdk-react-native/src/plugin/withIosApplePay.d.ts.map +1 -0
- package/lib/typescript/deuna-sdk-react-native/src/plugin/withIosFmtFix.d.ts +3 -0
- package/lib/typescript/deuna-sdk-react-native/src/plugin/withIosFmtFix.d.ts.map +1 -0
- package/lib/typescript/deuna-sdk-react-native/src/types/base.d.ts +78 -14
- package/lib/typescript/deuna-sdk-react-native/src/types/base.d.ts.map +1 -1
- package/lib/typescript/deuna-sdk-react-native/src/types/envs.d.ts +12 -0
- package/lib/typescript/deuna-sdk-react-native/src/types/envs.d.ts.map +1 -1
- package/lib/typescript/deuna-sdk-react-native/src/types/helpers/urlConfig.d.ts +1 -1
- package/lib/typescript/deuna-sdk-react-native/src/types/helpers/urlConfig.d.ts.map +1 -1
- package/lib/typescript/deuna-sdk-react-native/src/types/interfaces/callbacks.d.ts +11 -0
- package/lib/typescript/deuna-sdk-react-native/src/types/interfaces/callbacks.d.ts.map +1 -1
- package/lib/typescript/deuna-sdk-react-native/src/types/interfaces/initWidgetBase.d.ts +3 -3
- package/lib/typescript/deuna-sdk-react-native/src/types/interfaces/initWidgetBase.d.ts.map +1 -1
- package/lib/typescript/deuna-sdk-react-native/src/wallets/WalletModule.d.ts +29 -0
- package/lib/typescript/deuna-sdk-react-native/src/wallets/WalletModule.d.ts.map +1 -0
- package/lib/typescript/deuna-sdk-react-native/src/wallets/index.d.ts +3 -0
- package/lib/typescript/deuna-sdk-react-native/src/wallets/index.d.ts.map +1 -0
- package/lib/typescript/deuna-sdk-react-native/src/wallets/tokenize/applePay.d.ts +2 -0
- package/lib/typescript/deuna-sdk-react-native/src/wallets/tokenize/applePay.d.ts.map +1 -0
- package/lib/typescript/deuna-sdk-react-native/src/wallets/tokenize/googlePay.d.ts +2 -0
- package/lib/typescript/deuna-sdk-react-native/src/wallets/tokenize/googlePay.d.ts.map +1 -0
- package/lib/typescript/deuna-sdk-react-native/src/wallets/tokenize/index.d.ts +3 -0
- package/lib/typescript/deuna-sdk-react-native/src/wallets/tokenize/index.d.ts.map +1 -0
- package/lib/typescript/deuna-sdk-react-native/src/wallets/types.d.ts +15 -0
- package/lib/typescript/deuna-sdk-react-native/src/wallets/types.d.ts.map +1 -0
- package/lib/typescript/deuna-sdk-react-native/src/wallets/vaultApi.d.ts +38 -0
- package/lib/typescript/deuna-sdk-react-native/src/wallets/vaultApi.d.ts.map +1 -0
- package/package.json +14 -2
- package/react-native.config.js +8 -0
- package/src/DeunaSDK.ts +65 -4
- package/src/components/DeunaWebView.tsx +4 -0
- package/src/components/DeunaWidget.tsx +2 -0
- package/src/controllers/BaseWebViewController.ts +15 -4
- package/src/controllers/ElementsWidgetController.ts +16 -1
- package/src/helpers/ExternalUrlHelper.ts +5 -1
- package/src/index.tsx +1 -0
- package/src/plugin/index.ts +29 -0
- package/src/plugin/withAndroidGooglePay.ts +15 -0
- package/src/plugin/withIosApplePay.ts +10 -0
- package/src/plugin/withIosFmtFix.ts +49 -0
- package/src/types/base.ts +92 -14
- package/src/types/envs.ts +14 -0
- package/src/types/helpers/urlConfig.ts +1 -1
- package/src/types/interfaces/callbacks.ts +15 -0
- package/src/types/interfaces/initWidgetBase.ts +3 -3
- package/src/wallets/WalletModule.ts +255 -0
- package/src/wallets/index.ts +13 -0
- package/src/wallets/tokenize/applePay.ts +22 -0
- package/src/wallets/tokenize/googlePay.ts +27 -0
- package/src/wallets/tokenize/index.ts +12 -0
- package/src/wallets/types.ts +17 -0
- package/src/wallets/vaultApi.ts +229 -0
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import { ELEMENTS_URLS } from '../types/helpers/buildElementsLink';
|
|
2
|
+
import type { UserInfo } from '../types/interfaces/initWidgetBase';
|
|
3
|
+
|
|
4
|
+
const DEFAULT_CARD_NETWORKS = ['VISA', 'MASTERCARD', 'AMEX', 'DISCOVER'];
|
|
5
|
+
const DEFAULT_AUTH_METHODS_APPLE = ['CRYPTOGRAM_3DS'];
|
|
6
|
+
const DEFAULT_AUTH_METHODS_GOOGLE = ['PAN_ONLY', 'CRYPTOGRAM_3DS'];
|
|
7
|
+
|
|
8
|
+
export interface ApplePayCredentials {
|
|
9
|
+
merchantIdentifier: string;
|
|
10
|
+
displayName: string;
|
|
11
|
+
supportedNetworks: string[];
|
|
12
|
+
merchantCapabilities: string[];
|
|
13
|
+
transactionInfo?: {
|
|
14
|
+
amount: string;
|
|
15
|
+
currencyCode: string;
|
|
16
|
+
countryCode: string;
|
|
17
|
+
label: string;
|
|
18
|
+
};
|
|
19
|
+
credentialId?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface GooglePayCredentials {
|
|
23
|
+
merchantId: string;
|
|
24
|
+
merchantName: string;
|
|
25
|
+
gateway: string;
|
|
26
|
+
gatewayMerchantId: string;
|
|
27
|
+
tokenizationType: 'PAYMENT_GATEWAY' | 'DIRECT';
|
|
28
|
+
publicKey?: string;
|
|
29
|
+
allowedCardNetworks: string[];
|
|
30
|
+
allowedAuthMethods: string[];
|
|
31
|
+
transactionInfo?: {
|
|
32
|
+
totalPrice: string;
|
|
33
|
+
currencyCode: string;
|
|
34
|
+
countryCode: string;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type WalletCredentials = ApplePayCredentials | GooglePayCredentials;
|
|
39
|
+
|
|
40
|
+
export interface VaultFetchResult {
|
|
41
|
+
providers: string[];
|
|
42
|
+
credentials: Record<string, WalletCredentials>;
|
|
43
|
+
userToken?: string;
|
|
44
|
+
userId?: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export async function fetchVaultResult(
|
|
48
|
+
environment: string,
|
|
49
|
+
publicApiKey: string,
|
|
50
|
+
orderToken?: string,
|
|
51
|
+
userInfo?: Partial<UserInfo>
|
|
52
|
+
): Promise<VaultFetchResult> {
|
|
53
|
+
const base =
|
|
54
|
+
ELEMENTS_URLS[environment as keyof typeof ELEMENTS_URLS] ??
|
|
55
|
+
ELEMENTS_URLS.develop;
|
|
56
|
+
const url = orderToken
|
|
57
|
+
? `${base}/api/vault?orderToken=${encodeURIComponent(orderToken)}`
|
|
58
|
+
: `${base}/api/vault`;
|
|
59
|
+
|
|
60
|
+
const body = userInfo ? buildUserInfoBody(userInfo) : undefined;
|
|
61
|
+
console.log(
|
|
62
|
+
'[Wallets] fetchVaultResult — url:',
|
|
63
|
+
url,
|
|
64
|
+
'body:',
|
|
65
|
+
JSON.stringify(body)
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
const response = await fetch(url, {
|
|
69
|
+
method: 'POST',
|
|
70
|
+
headers: { 'x-api-key': publicApiKey, 'Content-Type': 'application/json' },
|
|
71
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
if (!response.ok) {
|
|
75
|
+
console.error('[Wallets] Vault API error:', response.status);
|
|
76
|
+
console.error('[Wallets] Vault API error message:', response.statusText);
|
|
77
|
+
console.error('[Wallets] Vault API error response:', response);
|
|
78
|
+
throw {
|
|
79
|
+
code: 'VAULT_FETCH_FAILED',
|
|
80
|
+
message: `Vault API error: ${response.status}`,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return parseVaultResponse(await response.json());
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function parseVaultResponse(json: Record<string, unknown>): VaultFetchResult {
|
|
88
|
+
console.log(
|
|
89
|
+
'[Wallets] parseVaultResponse result:',
|
|
90
|
+
JSON.stringify(json, null, 2)
|
|
91
|
+
);
|
|
92
|
+
const paymentMethods = (json['paymentMethods'] as unknown[]) ?? [];
|
|
93
|
+
const checkout = json['checkout'] as Record<string, unknown> | undefined;
|
|
94
|
+
const merchant = checkout?.['merchant'] as
|
|
95
|
+
| Record<string, unknown>
|
|
96
|
+
| undefined;
|
|
97
|
+
const order = (checkout?.['order'] as Record<string, unknown> | undefined)?.[
|
|
98
|
+
'order'
|
|
99
|
+
] as Record<string, unknown> | undefined;
|
|
100
|
+
const userAuthData = (
|
|
101
|
+
json['userAuthResponse'] as Record<string, unknown> | undefined
|
|
102
|
+
)?.['data'] as Record<string, unknown> | undefined;
|
|
103
|
+
|
|
104
|
+
const credentialParser = {
|
|
105
|
+
apple_pay: parseApplePayCredentials,
|
|
106
|
+
google_pay: parseGooglePayCredentials,
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const providers: string[] = [];
|
|
110
|
+
const credentials: Record<string, WalletCredentials> = {};
|
|
111
|
+
|
|
112
|
+
for (const rawMethod of paymentMethods) {
|
|
113
|
+
const method = rawMethod as Record<string, unknown>;
|
|
114
|
+
const processorName = method['processor_name'] as string | undefined;
|
|
115
|
+
if (!processorName || providers.includes(processorName)) continue;
|
|
116
|
+
|
|
117
|
+
providers.push(processorName);
|
|
118
|
+
|
|
119
|
+
const parse =
|
|
120
|
+
credentialParser[processorName as keyof typeof credentialParser];
|
|
121
|
+
if (parse) {
|
|
122
|
+
credentials[processorName] = parse(method, merchant, order);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return {
|
|
127
|
+
providers,
|
|
128
|
+
credentials,
|
|
129
|
+
userToken:
|
|
130
|
+
(userAuthData?.['user_token'] as string | undefined) || undefined,
|
|
131
|
+
userId: (userAuthData?.['user_id'] as string | undefined) || undefined,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function parseApplePayCredentials(
|
|
136
|
+
method: Record<string, unknown>,
|
|
137
|
+
merchant: Record<string, unknown> | undefined,
|
|
138
|
+
order: Record<string, unknown> | undefined
|
|
139
|
+
): ApplePayCredentials {
|
|
140
|
+
const extra = (method['extra_params'] as Record<string, unknown>) ?? {};
|
|
141
|
+
const displayName =
|
|
142
|
+
(extra['merchant_name'] as string | undefined) ??
|
|
143
|
+
(merchant?.['name'] as string | undefined) ??
|
|
144
|
+
'';
|
|
145
|
+
|
|
146
|
+
return {
|
|
147
|
+
merchantIdentifier:
|
|
148
|
+
(extra['mobile_merchant_id'] as string | undefined) ?? '',
|
|
149
|
+
displayName,
|
|
150
|
+
supportedNetworks:
|
|
151
|
+
(extra['allowed_card_networks'] as string[] | undefined) ??
|
|
152
|
+
DEFAULT_CARD_NETWORKS,
|
|
153
|
+
merchantCapabilities:
|
|
154
|
+
(extra['allowed_auth_methods'] as string[] | undefined) ??
|
|
155
|
+
DEFAULT_AUTH_METHODS_APPLE,
|
|
156
|
+
transactionInfo: buildApplePayTransactionInfo(order, merchant, displayName),
|
|
157
|
+
credentialId: (method['id'] as string | undefined) || undefined,
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function buildApplePayTransactionInfo(
|
|
162
|
+
order: Record<string, unknown> | undefined,
|
|
163
|
+
merchant: Record<string, unknown> | undefined,
|
|
164
|
+
label: string
|
|
165
|
+
): ApplePayCredentials['transactionInfo'] {
|
|
166
|
+
const currency = order?.['currency'] as string | undefined;
|
|
167
|
+
const country = merchant?.['country'] as string | undefined;
|
|
168
|
+
if (!currency || !country) return undefined;
|
|
169
|
+
const totalCents = (order?.['total_amount'] as number | undefined) ?? 0;
|
|
170
|
+
return {
|
|
171
|
+
amount: (totalCents / 100).toFixed(2),
|
|
172
|
+
currencyCode: currency.toUpperCase(),
|
|
173
|
+
countryCode: country.toUpperCase(),
|
|
174
|
+
label,
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function parseGooglePayCredentials(
|
|
179
|
+
method: Record<string, unknown>,
|
|
180
|
+
merchant: Record<string, unknown> | undefined,
|
|
181
|
+
order: Record<string, unknown> | undefined
|
|
182
|
+
): GooglePayCredentials {
|
|
183
|
+
const creds = (method['credentials'] as Record<string, unknown>) ?? {};
|
|
184
|
+
const extra = (method['extra_params'] as Record<string, unknown>) ?? {};
|
|
185
|
+
const gateway = (extra['gateway'] as string | undefined) ?? '';
|
|
186
|
+
|
|
187
|
+
return {
|
|
188
|
+
merchantId: (extra['mobile_merchant_id'] as string | undefined) ?? '',
|
|
189
|
+
merchantName: (merchant?.['name'] as string | undefined) ?? '',
|
|
190
|
+
gateway,
|
|
191
|
+
gatewayMerchantId:
|
|
192
|
+
(extra['mobile_merchant_id'] as string | undefined) ?? '',
|
|
193
|
+
tokenizationType:
|
|
194
|
+
gateway.toUpperCase() === 'DIRECT' ? 'DIRECT' : 'PAYMENT_GATEWAY',
|
|
195
|
+
publicKey: (creds['public_api_key'] as string | undefined) || undefined,
|
|
196
|
+
allowedCardNetworks:
|
|
197
|
+
(extra['allowed_card_networks'] as string[] | undefined) ??
|
|
198
|
+
DEFAULT_CARD_NETWORKS,
|
|
199
|
+
allowedAuthMethods:
|
|
200
|
+
(extra['allowed_auth_methods'] as string[] | undefined) ??
|
|
201
|
+
DEFAULT_AUTH_METHODS_GOOGLE,
|
|
202
|
+
transactionInfo: buildGooglePayTransactionInfo(order, merchant),
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function buildGooglePayTransactionInfo(
|
|
207
|
+
order: Record<string, unknown> | undefined,
|
|
208
|
+
merchant: Record<string, unknown> | undefined
|
|
209
|
+
): GooglePayCredentials['transactionInfo'] {
|
|
210
|
+
const currency = order?.['currency'] as string | undefined;
|
|
211
|
+
const country = merchant?.['country'] as string | undefined;
|
|
212
|
+
if (!currency || !country) return undefined;
|
|
213
|
+
const totalCents = (order?.['total_amount'] as number | undefined) ?? 0;
|
|
214
|
+
return {
|
|
215
|
+
totalPrice: (totalCents / 100).toFixed(2),
|
|
216
|
+
currencyCode: currency.toUpperCase(),
|
|
217
|
+
countryCode: country.toUpperCase(),
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function buildUserInfoBody(
|
|
222
|
+
userInfo: Partial<UserInfo>
|
|
223
|
+
): Record<string, unknown> | undefined {
|
|
224
|
+
if (!userInfo.email) return undefined;
|
|
225
|
+
const body: Record<string, unknown> = { email: userInfo.email };
|
|
226
|
+
if (userInfo.firstName) body['firstName'] = userInfo.firstName;
|
|
227
|
+
if (userInfo.lastName) body['lastName'] = userInfo.lastName;
|
|
228
|
+
return body;
|
|
229
|
+
}
|