@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.
Files changed (116) hide show
  1. package/DeunaWalletsModule.podspec +19 -0
  2. package/README.md +141 -2
  3. package/android/build.gradle +43 -0
  4. package/android/src/main/AndroidManifest.xml +8 -0
  5. package/android/src/main/java/com/deuna/wallets/DeunaWalletsModule.kt +103 -0
  6. package/app.plugin.js +1 -0
  7. package/expo-module.config.json +10 -0
  8. package/ios/DeunaWalletsModule.swift +56 -0
  9. package/lib/module/DeunaSDK.js +44 -3
  10. package/lib/module/DeunaSDK.js.map +1 -1
  11. package/lib/module/components/DeunaWebView.js +3 -0
  12. package/lib/module/components/DeunaWebView.js.map +1 -1
  13. package/lib/module/components/DeunaWidget.js +1 -0
  14. package/lib/module/components/DeunaWidget.js.map +1 -1
  15. package/lib/module/controllers/BaseWebViewController.js +17 -4
  16. package/lib/module/controllers/BaseWebViewController.js.map +1 -1
  17. package/lib/module/controllers/ElementsWidgetController.js +9 -1
  18. package/lib/module/controllers/ElementsWidgetController.js.map +1 -1
  19. package/lib/module/helpers/ExternalUrlHelper.js +4 -1
  20. package/lib/module/helpers/ExternalUrlHelper.js.map +1 -1
  21. package/lib/module/index.js +1 -0
  22. package/lib/module/index.js.map +1 -1
  23. package/lib/module/plugin/index.js +25 -0
  24. package/lib/module/plugin/index.js.map +1 -0
  25. package/lib/module/plugin/withAndroidGooglePay.js +20 -0
  26. package/lib/module/plugin/withAndroidGooglePay.js.map +1 -0
  27. package/lib/module/plugin/withIosApplePay.js +10 -0
  28. package/lib/module/plugin/withIosApplePay.js.map +1 -0
  29. package/lib/module/plugin/withIosFmtFix.js +34 -0
  30. package/lib/module/plugin/withIosFmtFix.js.map +1 -0
  31. package/lib/module/types/base.js +16 -0
  32. package/lib/module/types/base.js.map +1 -1
  33. package/lib/module/types/envs.js +12 -0
  34. package/lib/module/types/envs.js.map +1 -1
  35. package/lib/module/wallets/WalletModule.js +218 -0
  36. package/lib/module/wallets/WalletModule.js.map +1 -0
  37. package/lib/module/wallets/index.js +4 -0
  38. package/lib/module/wallets/index.js.map +1 -0
  39. package/lib/module/wallets/tokenize/applePay.js +24 -0
  40. package/lib/module/wallets/tokenize/applePay.js.map +1 -0
  41. package/lib/module/wallets/tokenize/googlePay.js +24 -0
  42. package/lib/module/wallets/tokenize/googlePay.js.map +1 -0
  43. package/lib/module/wallets/tokenize/index.js +12 -0
  44. package/lib/module/wallets/tokenize/index.js.map +1 -0
  45. package/lib/module/wallets/types.js +4 -0
  46. package/lib/module/wallets/types.js.map +1 -0
  47. package/lib/module/wallets/vaultApi.js +121 -0
  48. package/lib/module/wallets/vaultApi.js.map +1 -0
  49. package/lib/typescript/deuna-sdk-react-native/src/DeunaSDK.d.ts +12 -3
  50. package/lib/typescript/deuna-sdk-react-native/src/DeunaSDK.d.ts.map +1 -1
  51. package/lib/typescript/deuna-sdk-react-native/src/components/DeunaWebView.d.ts +1 -0
  52. package/lib/typescript/deuna-sdk-react-native/src/components/DeunaWebView.d.ts.map +1 -1
  53. package/lib/typescript/deuna-sdk-react-native/src/controllers/BaseWebViewController.d.ts +7 -0
  54. package/lib/typescript/deuna-sdk-react-native/src/controllers/BaseWebViewController.d.ts.map +1 -1
  55. package/lib/typescript/deuna-sdk-react-native/src/controllers/ElementsWidgetController.d.ts.map +1 -1
  56. package/lib/typescript/deuna-sdk-react-native/src/helpers/ExternalUrlHelper.d.ts +1 -0
  57. package/lib/typescript/deuna-sdk-react-native/src/helpers/ExternalUrlHelper.d.ts.map +1 -1
  58. package/lib/typescript/deuna-sdk-react-native/src/index.d.ts +1 -0
  59. package/lib/typescript/deuna-sdk-react-native/src/index.d.ts.map +1 -1
  60. package/lib/typescript/deuna-sdk-react-native/src/plugin/index.d.ts +8 -0
  61. package/lib/typescript/deuna-sdk-react-native/src/plugin/index.d.ts.map +1 -0
  62. package/lib/typescript/deuna-sdk-react-native/src/plugin/withAndroidGooglePay.d.ts +3 -0
  63. package/lib/typescript/deuna-sdk-react-native/src/plugin/withAndroidGooglePay.d.ts.map +1 -0
  64. package/lib/typescript/deuna-sdk-react-native/src/plugin/withIosApplePay.d.ts +5 -0
  65. package/lib/typescript/deuna-sdk-react-native/src/plugin/withIosApplePay.d.ts.map +1 -0
  66. package/lib/typescript/deuna-sdk-react-native/src/plugin/withIosFmtFix.d.ts +3 -0
  67. package/lib/typescript/deuna-sdk-react-native/src/plugin/withIosFmtFix.d.ts.map +1 -0
  68. package/lib/typescript/deuna-sdk-react-native/src/types/base.d.ts +78 -14
  69. package/lib/typescript/deuna-sdk-react-native/src/types/base.d.ts.map +1 -1
  70. package/lib/typescript/deuna-sdk-react-native/src/types/envs.d.ts +12 -0
  71. package/lib/typescript/deuna-sdk-react-native/src/types/envs.d.ts.map +1 -1
  72. package/lib/typescript/deuna-sdk-react-native/src/types/helpers/urlConfig.d.ts +1 -1
  73. package/lib/typescript/deuna-sdk-react-native/src/types/helpers/urlConfig.d.ts.map +1 -1
  74. package/lib/typescript/deuna-sdk-react-native/src/types/interfaces/callbacks.d.ts +11 -0
  75. package/lib/typescript/deuna-sdk-react-native/src/types/interfaces/callbacks.d.ts.map +1 -1
  76. package/lib/typescript/deuna-sdk-react-native/src/types/interfaces/initWidgetBase.d.ts +3 -3
  77. package/lib/typescript/deuna-sdk-react-native/src/types/interfaces/initWidgetBase.d.ts.map +1 -1
  78. package/lib/typescript/deuna-sdk-react-native/src/wallets/WalletModule.d.ts +29 -0
  79. package/lib/typescript/deuna-sdk-react-native/src/wallets/WalletModule.d.ts.map +1 -0
  80. package/lib/typescript/deuna-sdk-react-native/src/wallets/index.d.ts +3 -0
  81. package/lib/typescript/deuna-sdk-react-native/src/wallets/index.d.ts.map +1 -0
  82. package/lib/typescript/deuna-sdk-react-native/src/wallets/tokenize/applePay.d.ts +2 -0
  83. package/lib/typescript/deuna-sdk-react-native/src/wallets/tokenize/applePay.d.ts.map +1 -0
  84. package/lib/typescript/deuna-sdk-react-native/src/wallets/tokenize/googlePay.d.ts +2 -0
  85. package/lib/typescript/deuna-sdk-react-native/src/wallets/tokenize/googlePay.d.ts.map +1 -0
  86. package/lib/typescript/deuna-sdk-react-native/src/wallets/tokenize/index.d.ts +3 -0
  87. package/lib/typescript/deuna-sdk-react-native/src/wallets/tokenize/index.d.ts.map +1 -0
  88. package/lib/typescript/deuna-sdk-react-native/src/wallets/types.d.ts +15 -0
  89. package/lib/typescript/deuna-sdk-react-native/src/wallets/types.d.ts.map +1 -0
  90. package/lib/typescript/deuna-sdk-react-native/src/wallets/vaultApi.d.ts +38 -0
  91. package/lib/typescript/deuna-sdk-react-native/src/wallets/vaultApi.d.ts.map +1 -0
  92. package/package.json +14 -2
  93. package/react-native.config.js +8 -0
  94. package/src/DeunaSDK.ts +65 -4
  95. package/src/components/DeunaWebView.tsx +4 -0
  96. package/src/components/DeunaWidget.tsx +2 -0
  97. package/src/controllers/BaseWebViewController.ts +15 -4
  98. package/src/controllers/ElementsWidgetController.ts +16 -1
  99. package/src/helpers/ExternalUrlHelper.ts +5 -1
  100. package/src/index.tsx +1 -0
  101. package/src/plugin/index.ts +29 -0
  102. package/src/plugin/withAndroidGooglePay.ts +15 -0
  103. package/src/plugin/withIosApplePay.ts +10 -0
  104. package/src/plugin/withIosFmtFix.ts +49 -0
  105. package/src/types/base.ts +92 -14
  106. package/src/types/envs.ts +14 -0
  107. package/src/types/helpers/urlConfig.ts +1 -1
  108. package/src/types/interfaces/callbacks.ts +15 -0
  109. package/src/types/interfaces/initWidgetBase.ts +3 -3
  110. package/src/wallets/WalletModule.ts +255 -0
  111. package/src/wallets/index.ts +13 -0
  112. package/src/wallets/tokenize/applePay.ts +22 -0
  113. package/src/wallets/tokenize/googlePay.ts +27 -0
  114. package/src/wallets/tokenize/index.ts +12 -0
  115. package/src/wallets/types.ts +17 -0
  116. 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
+ }