@idonatedev/idonate-sdk 1.1.0-dev8 → 1.2.0-dev0

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 (72) hide show
  1. package/README.md +308 -7
  2. package/dist/constants.d.ts +1 -1
  3. package/dist/constants.js +2 -6
  4. package/dist/esm/apple-pay.d.ts +12 -0
  5. package/dist/esm/apple-pay.js +74 -0
  6. package/dist/esm/cloudflare-challenge-handler.d.ts +5 -0
  7. package/dist/esm/cloudflare-challenge-handler.js +77 -0
  8. package/dist/esm/config-handler.d.ts +22 -0
  9. package/dist/esm/config-handler.js +47 -0
  10. package/dist/esm/constants.d.ts +18 -0
  11. package/dist/esm/constants.js +81 -0
  12. package/dist/esm/google-pay.d.ts +18 -0
  13. package/dist/esm/google-pay.js +140 -0
  14. package/dist/esm/idonate-client.d.ts +32 -0
  15. package/dist/esm/idonate-client.js +294 -0
  16. package/dist/esm/index.d.ts +11 -0
  17. package/dist/esm/index.js +11 -0
  18. package/dist/esm/recaptcha.d.ts +12 -0
  19. package/dist/esm/recaptcha.js +89 -0
  20. package/dist/esm/shared.d.ts +4 -0
  21. package/dist/esm/shared.js +21 -0
  22. package/dist/esm/test-utils.d.ts +81 -0
  23. package/dist/esm/test-utils.js +94 -0
  24. package/dist/esm/tokenize/CardConnectTokenizer.d.ts +51 -0
  25. package/dist/esm/tokenize/CardConnectTokenizer.js +712 -0
  26. package/dist/esm/tokenize/PayPalTokenizer.d.ts +77 -0
  27. package/dist/esm/tokenize/PayPalTokenizer.js +268 -0
  28. package/dist/esm/tokenize/SpreedlyTokenizer.d.ts +92 -0
  29. package/dist/esm/tokenize/SpreedlyTokenizer.js +1140 -0
  30. package/dist/esm/tokenize/Tokenizer.d.ts +37 -0
  31. package/dist/esm/tokenize/Tokenizer.js +150 -0
  32. package/dist/esm/tokenize/iats.d.ts +3 -0
  33. package/dist/esm/tokenize/iats.js +48 -0
  34. package/dist/esm/tokenize/index.d.ts +7 -0
  35. package/dist/esm/tokenize/index.js +7 -0
  36. package/dist/esm/tokenize/spreedly-secure.d.ts +8 -0
  37. package/dist/esm/tokenize/spreedly-secure.js +40 -0
  38. package/dist/esm/tokenize/styles.d.ts +4 -0
  39. package/dist/esm/tokenize/styles.js +46 -0
  40. package/dist/esm/tokenize/tokenizer-constants.d.ts +62 -0
  41. package/dist/esm/tokenize/tokenizer-constants.js +62 -0
  42. package/dist/esm/tokenize/tokenizer-utils.d.ts +19 -0
  43. package/dist/esm/tokenize/tokenizer-utils.js +139 -0
  44. package/dist/esm/tokenize/types.d.ts +146 -0
  45. package/dist/esm/tokenize/types.js +26 -0
  46. package/dist/esm/typeAdapters.d.ts +29 -0
  47. package/dist/esm/typeAdapters.js +189 -0
  48. package/dist/esm/types.d.ts +378 -0
  49. package/dist/esm/types.js +14 -0
  50. package/dist/esm/util.d.ts +17 -0
  51. package/dist/esm/util.js +113 -0
  52. package/dist/idonate-client.d.ts +6 -2
  53. package/dist/idonate-client.js +40 -2
  54. package/dist/shared.d.ts +2 -1
  55. package/dist/shared.js +9 -0
  56. package/dist/tokenize/CardConnectTokenizer.d.ts +1 -0
  57. package/dist/tokenize/CardConnectTokenizer.js +127 -104
  58. package/dist/tokenize/PayPalTokenizer.d.ts +77 -0
  59. package/dist/tokenize/PayPalTokenizer.js +272 -0
  60. package/dist/tokenize/SpreedlyTokenizer.d.ts +1 -0
  61. package/dist/tokenize/SpreedlyTokenizer.js +276 -135
  62. package/dist/tokenize/Tokenizer.js +6 -2
  63. package/dist/tokenize/index.d.ts +1 -0
  64. package/dist/tokenize/index.js +3 -1
  65. package/dist/tokenize/styles.d.ts +1 -0
  66. package/dist/tokenize/styles.js +9 -0
  67. package/dist/tokenize/tokenizer-utils.js +1 -1
  68. package/dist/tokenize/types.d.ts +6 -7
  69. package/dist/typeAdapters.js +3 -2
  70. package/dist/types.d.ts +16 -5
  71. package/package.json +14 -3
  72. package/umd/idonate-sdk.js +1 -1
@@ -0,0 +1,378 @@
1
+ export declare const ApplePaySessionStatus: {
2
+ readonly STATUS_SUCCESS: number;
3
+ readonly STATUS_FAILURE: number;
4
+ };
5
+ export type ApplePayPaymentRequest = ApplePayJS.ApplePayPaymentRequest;
6
+ export type ClientOptions = {
7
+ enableSandboxMode?: boolean;
8
+ spreedlyEnvironmentKey?: string;
9
+ overrideBaseUrl?: string;
10
+ overrideAuthApiBaseUrl?: string;
11
+ overrideEmbedApiBaseUrl?: string;
12
+ overrideDonorApiBaseUrl?: string;
13
+ overrideCardConnectBaseUrl?: string;
14
+ overrideApplePayUrl?: string;
15
+ pcScriptBase?: string;
16
+ pcScriptId?: string;
17
+ enableDelay: boolean;
18
+ secondsToDelay: number;
19
+ turnstileCdnUrl?: string;
20
+ turnstileSiteKey?: string;
21
+ sdkClientName?: string;
22
+ enableSpreedlySecureTokenization?: boolean;
23
+ organizationId?: number;
24
+ embedId?: string;
25
+ };
26
+ export type Address = {
27
+ address1: string;
28
+ address2?: string;
29
+ country: string;
30
+ city: string;
31
+ state: string;
32
+ zip: string;
33
+ };
34
+ export type Contact = {
35
+ salutation?: string;
36
+ firstName: string;
37
+ middleName?: string;
38
+ lastName: string;
39
+ fullName?: string;
40
+ company: string;
41
+ email?: string;
42
+ primaryPhone: string;
43
+ };
44
+ export type CreditCard = {
45
+ cardNumber: string;
46
+ verificationValue?: string;
47
+ expirationMonth: string;
48
+ expirationYear: string;
49
+ };
50
+ export type ACHAccount = {
51
+ accountNumber: string;
52
+ routingNumber: string;
53
+ accountHolderType: 'personal' | 'business';
54
+ accountType: 'checking' | 'savings';
55
+ };
56
+ export type PaymentMethodType = 'credit_card' | 'bank_account' | 'paypal' | 'apple_pay' | 'google_pay';
57
+ export type RecaptchaType = 'v2' | 'v3' | 'invisible' | 'organization' | 'nonce' | 'bypass';
58
+ export type RecaptchaSecuredRequest = {
59
+ recaptchaType: RecaptchaType;
60
+ recaptchaToken: string;
61
+ };
62
+ export type RecurringFrequency = 'once' | 'weekly' | 'twicemonthly' | 'biweekly' | 'monthly' | 'quarterly' | 'semiannually' | 'annually';
63
+ export type UTMData = {
64
+ campaign?: string;
65
+ content?: string;
66
+ medium?: string;
67
+ source?: string;
68
+ term?: string;
69
+ };
70
+ export type TributeData = {
71
+ tributeDefinitionId: string;
72
+ tributeFirstName: string;
73
+ tributeLastName: string;
74
+ tributeAddress1: string;
75
+ tributeAddress2: string;
76
+ tributeCity: string;
77
+ tributeState: string;
78
+ tributePostalCode: string;
79
+ tributeCountry: string;
80
+ tributeFromName: string;
81
+ tributeType: string;
82
+ tributeRecipientEmail: string;
83
+ honorees: {
84
+ firstname: string;
85
+ lastname: string;
86
+ message: string;
87
+ }[];
88
+ tributeSendCard: boolean;
89
+ tributeIncludeAmount: boolean;
90
+ tributeSkipped: boolean;
91
+ useOnBillingAddress: boolean;
92
+ };
93
+ export type CreateDonationRequest = RecaptchaSecuredRequest & {
94
+ paymentGatewayId: string;
95
+ donorId?: string;
96
+ paymentMethodId: string;
97
+ paymentTransactionId?: string;
98
+ retainPaymentMethod?: boolean;
99
+ paymentAmount: number;
100
+ currency: string;
101
+ billingContact: Contact;
102
+ billingAddress: Address;
103
+ referenceCode?: string;
104
+ designationId?: string;
105
+ designations?: {
106
+ id: string;
107
+ amount: number;
108
+ }[];
109
+ designationNote?: string;
110
+ campaignId?: string;
111
+ p2pFundraiserId?: string;
112
+ p2pFundraiserComment?: string;
113
+ p2pProgramId?: string;
114
+ organizationEventId?: string;
115
+ corporateMatchingId?: string;
116
+ advocateId?: string;
117
+ advocacyProgramId?: string;
118
+ advocacyTeamId?: string;
119
+ landingPageId?: number;
120
+ customerMeta?: {
121
+ [key: string]: string;
122
+ };
123
+ utm?: UTMData;
124
+ tribute?: TributeData;
125
+ recurringFrequency: RecurringFrequency;
126
+ recurringStart?: Date;
127
+ recurringEnd?: Date;
128
+ donorPaidFeeAmount?: number;
129
+ emailOptIn?: boolean;
130
+ anonymousOptIn?: boolean;
131
+ showNameToFundraiserOptIn?: boolean;
132
+ giftId?: string;
133
+ giftExtra?: string;
134
+ giftSkipped?: boolean;
135
+ embedId?: string;
136
+ convertedToRecurring?: boolean | undefined;
137
+ };
138
+ export type UtmFields = {
139
+ utm_campaign?: string;
140
+ utm_content?: string;
141
+ utm_medium?: string;
142
+ utm_source?: string;
143
+ utm_term?: string;
144
+ };
145
+ export type CashPaymentPayload = {
146
+ organization_id: string;
147
+ campaign_id: string;
148
+ reference_code: string;
149
+ double_the_donation_company_id: string;
150
+ donor_id: string;
151
+ hide_name: boolean;
152
+ show_name_to_fundraiser: boolean;
153
+ email_opt_in: boolean;
154
+ donor_paid_fee: number;
155
+ designation_note: string;
156
+ gift_id: string;
157
+ gift_extra: string;
158
+ gift_skipped: boolean;
159
+ p2p_fundraiser_id: string;
160
+ p2p_fundraiser_comment: string;
161
+ organization_event_id: string;
162
+ advocate_id: string;
163
+ advocacy_program_id: string;
164
+ advocacy_team_id: string;
165
+ page_id: number;
166
+ embed_id: string;
167
+ tribute_definition_id: string;
168
+ tribute_recipient_first_name: string;
169
+ tribute_recipient_last_name: string;
170
+ tribute_address1: string;
171
+ tribute_address2: string;
172
+ tribute_city: string;
173
+ tribute_state: string;
174
+ tribute_postal_code: string;
175
+ tribute_country: string;
176
+ tribute_from_name: string;
177
+ tribute_recipient_email: string;
178
+ honorees: {
179
+ firstname: string;
180
+ lastname: string;
181
+ message: string;
182
+ }[];
183
+ tribute_send_card: boolean;
184
+ tribute_include_amount: boolean;
185
+ tribute_skipped: boolean;
186
+ tribute_type: string;
187
+ useOnBillingAddress: boolean;
188
+ embed_referer: string;
189
+ converted_to_recurring: boolean;
190
+ customer_meta: Record<string, string>;
191
+ recaptcha_token: string;
192
+ recaptcha_type: string;
193
+ designations: {
194
+ id: string;
195
+ amount: number;
196
+ }[];
197
+ country: string;
198
+ address1: string;
199
+ address2: string | undefined;
200
+ city: string;
201
+ state: string;
202
+ zip_code: string;
203
+ title?: string;
204
+ first_name: string;
205
+ middle_name?: string | undefined;
206
+ last_name: string;
207
+ company_name: string;
208
+ email?: string;
209
+ home_phone: string;
210
+ timezone: string;
211
+ payment_method_id: string;
212
+ gateway_id: string;
213
+ amount: number;
214
+ type: 'cash';
215
+ frequency: RecurringFrequency;
216
+ start_date: Date | undefined;
217
+ end_date: Date | undefined;
218
+ retain_on_success: boolean | undefined;
219
+ } & UtmFields;
220
+ export type ClientErrorDetails = {
221
+ field?: string;
222
+ code?: string;
223
+ suggestion?: string;
224
+ _rawPayload?: any;
225
+ };
226
+ export declare class ClientError extends Error {
227
+ message: string;
228
+ details?: ClientErrorDetails | undefined;
229
+ constructor(message: string, details?: ClientErrorDetails | undefined);
230
+ }
231
+ export type ClientResponse = {
232
+ errors: ClientError[];
233
+ _raw_response?: any;
234
+ };
235
+ export type CreateDonationResult = ClientResponse & {
236
+ transaction?: Transaction;
237
+ schedule?: Schedule;
238
+ donor?: Donor;
239
+ designation?: Designation;
240
+ campaign?: Campaign;
241
+ };
242
+ export type CreatePaymentMethodRequest = RecaptchaSecuredRequest & {
243
+ paymentMethodType: PaymentMethodType;
244
+ paymentMethodToken: string;
245
+ donorId?: string;
246
+ paymentGatewayId?: string;
247
+ backendName?: BackendName;
248
+ embedId?: string;
249
+ contact: Contact;
250
+ address: Address;
251
+ };
252
+ export type CreatePaymentMethodResult = ClientResponse & {
253
+ paymentMethodId: string;
254
+ };
255
+ export type Campaign = {
256
+ title: string;
257
+ };
258
+ export type Designation = {
259
+ id: string;
260
+ title: string;
261
+ };
262
+ export type Donor = {
263
+ id: string;
264
+ created: string;
265
+ contact: {
266
+ created: string;
267
+ updated: string;
268
+ title: string;
269
+ };
270
+ };
271
+ export type TokenizeCardConnectResult = {
272
+ token: string;
273
+ message: string;
274
+ errorcode: number;
275
+ };
276
+ export type BackendName = 'spreedly' | 'card_connect' | 'iats' | 'paypal_checkout';
277
+ export type PaymentGateway = {
278
+ id: string;
279
+ name: string;
280
+ backend_name: BackendName;
281
+ gateway_type?: string;
282
+ config?: {
283
+ [key: string]: any;
284
+ };
285
+ };
286
+ export interface EmbedConfig {
287
+ embed_id?: string;
288
+ organization_id?: string;
289
+ available_gateways: PaymentGateway[];
290
+ }
291
+ export type PaymentMethod = {
292
+ id: string;
293
+ type: PaymentMethodType;
294
+ };
295
+ export type Schedule = {
296
+ id: string;
297
+ recurringFrequency: RecurringFrequency;
298
+ };
299
+ export type Transaction = {
300
+ id: string;
301
+ };
302
+ export type Donation = {
303
+ id: string;
304
+ transaction?: Transaction;
305
+ schedule?: Schedule;
306
+ };
307
+ export type TokenizeCardConnectBankAccountResult = TokenizeCardConnectResult;
308
+ export type TokenizeCardConnectApplePayResult = TokenizeCardConnectResult;
309
+ export type TokenizeCardConnectGooglePayResult = TokenizeCardConnectResult;
310
+ export type ApplePayContact = ApplePayJS.ApplePayPaymentContact & {
311
+ email?: string;
312
+ phone?: string;
313
+ };
314
+ export type TokenizeApplePayResult = {
315
+ applePaySession: ApplePaySession;
316
+ cardConnectResponse: TokenizeCardConnectApplePayResult;
317
+ billingContact?: ApplePayContact;
318
+ merchantSessionId?: string;
319
+ };
320
+ export type MerchantSession = any;
321
+ export type ApplePayMerchantValidationPayload = {
322
+ apple_pay_url: string;
323
+ organization_id: string;
324
+ };
325
+ export type GooglePayBaseCardPaymentMethodType = {
326
+ type: google.payments.api.PaymentMethodType;
327
+ parameters: google.payments.api.CardParameters;
328
+ };
329
+ export type GooglePayConfig = {
330
+ paymentDataRequest: Partial<Omit<google.payments.api.PaymentDataRequest, 'transactionInfo'>> & {
331
+ transactionInfo: Partial<google.payments.api.PaymentDataRequest['transactionInfo']>;
332
+ };
333
+ paymentOptions: google.payments.api.PaymentOptions;
334
+ cardConnectMerchantId: string;
335
+ baseCardPaymentMethodParameters?: Partial<GooglePayBaseCardPaymentMethodType['parameters']>;
336
+ };
337
+ export interface SpreedlyPaymentMethodPayload {
338
+ retained?: boolean;
339
+ metadata?: Record<string, string>;
340
+ }
341
+ export interface SpreedlyPaymentMethodBankAccountPayload extends SpreedlyPaymentMethodPayload {
342
+ payment_method: {
343
+ bank_account: ({
344
+ first_name: string;
345
+ last_name: string;
346
+ } | {
347
+ full_name: string;
348
+ }) & {
349
+ bank_routing_number: string;
350
+ bank_account_number: string;
351
+ bank_name?: string;
352
+ bank_account_type?: 'checking' | 'savings';
353
+ bank_account_holder_type?: 'business' | 'personal';
354
+ };
355
+ };
356
+ }
357
+ export interface SpreedlyInstance {
358
+ init(key: string, opts: {
359
+ numberEl: string;
360
+ cvvEl: string;
361
+ }): void;
362
+ on(key: string, func: (param1: any | null, param2: any | null, param3: any | null, param4: any | null) => void): void;
363
+ validate(): void;
364
+ setPlaceholder(fields: string, placeholder: string): void;
365
+ setFieldType(fields: string, placeholder: string): void;
366
+ setStyle(fields: string, placeholder: string): void;
367
+ setNumberFormat(fields: string): void;
368
+ reload(): void;
369
+ tokenizeCreditCard(fields: {
370
+ first_name: string;
371
+ last_name: string;
372
+ month: string;
373
+ year: string;
374
+ email?: string;
375
+ zip?: string;
376
+ }): void;
377
+ removeHandlers(): void;
378
+ }
@@ -0,0 +1,14 @@
1
+ export const ApplePaySessionStatus = {
2
+ STATUS_SUCCESS: typeof ApplePaySession !== 'undefined' ? ApplePaySession.STATUS_SUCCESS : 1,
3
+ STATUS_FAILURE: typeof ApplePaySession !== 'undefined' ? ApplePaySession.STATUS_FAILURE : 0,
4
+ };
5
+ export class ClientError extends Error {
6
+ constructor(message, details) {
7
+ super(message);
8
+ this.message = message;
9
+ this.details = details;
10
+ if (Error.captureStackTrace) {
11
+ Error.captureStackTrace(this, ClientError);
12
+ }
13
+ }
14
+ }
@@ -0,0 +1,17 @@
1
+ import { ClientResponse } from './types';
2
+ export declare function receiveEmbedData(): Promise<any>;
3
+ export declare function sanitizeString(value: string): string;
4
+ type SanitizeableObject = {
5
+ [key: string]: SanitizeableObject;
6
+ } | string | boolean | number | SanitizeableObject[];
7
+ export declare function sanitizeArray(array: SanitizeableObject[]): SanitizeableObject[];
8
+ export declare function sanitizeObject(object: SanitizeableObject): SanitizeableObject;
9
+ type Name = {
10
+ firstName: string;
11
+ lastName: string;
12
+ };
13
+ export declare function splitName(fullname: string): Name;
14
+ export declare function parseResponse(response: Response, opts?: {
15
+ throwErrors?: boolean;
16
+ }): Promise<ClientResponse>;
17
+ export {};
@@ -0,0 +1,113 @@
1
+ import { ClientError } from './types';
2
+ import { collapseClientErrors } from './typeAdapters';
3
+ export function receiveEmbedData() {
4
+ let handler;
5
+ return new Promise((resolve, reject) => {
6
+ if (!window.parent) {
7
+ reject('Cannot receive data without parent');
8
+ }
9
+ handler = (evt) => {
10
+ let data;
11
+ try {
12
+ data = JSON.parse(evt.data);
13
+ }
14
+ catch (error) {
15
+ return;
16
+ }
17
+ if (data.embedData) {
18
+ resolve(data.embedData);
19
+ }
20
+ };
21
+ window.addEventListener('message', handler);
22
+ }).then((data) => {
23
+ window.removeEventListener('message', handler);
24
+ return data;
25
+ });
26
+ }
27
+ export function sanitizeString(value) {
28
+ if (!value) {
29
+ return value;
30
+ }
31
+ const tmp = document.createElement('div');
32
+ tmp.innerHTML = value;
33
+ const scripts = Array.from(tmp.getElementsByTagName('script'));
34
+ for (const script of scripts) {
35
+ if (script.parentNode) {
36
+ script.parentNode.removeChild(script);
37
+ }
38
+ }
39
+ return tmp.innerHTML;
40
+ }
41
+ export function sanitizeArray(array) {
42
+ return array.map(sanitizeObject);
43
+ }
44
+ export function sanitizeObject(object) {
45
+ if (object === null || object === undefined) {
46
+ return object;
47
+ }
48
+ else if (Array.isArray(object)) {
49
+ return sanitizeArray(object);
50
+ }
51
+ else if (typeof object === 'string') {
52
+ return sanitizeString(object);
53
+ }
54
+ else if (typeof object === 'object') {
55
+ const newObject = {};
56
+ for (const [key, value] of Object.entries(object)) {
57
+ if (Array.isArray(value)) {
58
+ newObject[key] = sanitizeArray(value);
59
+ }
60
+ else if (typeof value === 'string') {
61
+ newObject[key] = sanitizeString(value);
62
+ }
63
+ else {
64
+ newObject[key] = sanitizeObject(value);
65
+ }
66
+ }
67
+ return newObject;
68
+ }
69
+ else {
70
+ return object;
71
+ }
72
+ }
73
+ export function splitName(fullname) {
74
+ const nameParts = fullname.split(' ');
75
+ const firstName = nameParts.slice(0, -1).join(' ') || 'NOT GIVEN';
76
+ const lastName = nameParts.slice(-1).join(' ');
77
+ const nameObj = {
78
+ firstName,
79
+ lastName,
80
+ };
81
+ return nameObj;
82
+ }
83
+ export function parseResponse(response, opts) {
84
+ return response.json().then((json) => {
85
+ const errors = [];
86
+ if (response.status !== 200) {
87
+ if (json.result !== undefined) {
88
+ Object.keys(json.result).forEach((key) => {
89
+ errors.push(new ClientError(key + ': ' + json.result[key].join('\n '), {
90
+ field: key,
91
+ }));
92
+ });
93
+ }
94
+ if (json.messages !== undefined) {
95
+ json.messages.forEach((msg) => {
96
+ if (msg.category === 'error') {
97
+ errors.push(new ClientError(msg.message));
98
+ }
99
+ });
100
+ }
101
+ else {
102
+ errors.push(new ClientError(json.message));
103
+ }
104
+ }
105
+ if (opts && opts.throwErrors && errors.length) {
106
+ throw collapseClientErrors(errors);
107
+ }
108
+ return {
109
+ errors,
110
+ _raw_response: json,
111
+ };
112
+ });
113
+ }
@@ -1,4 +1,4 @@
1
- import { ClientOptions, Contact, Address, CreatePaymentMethodRequest, CreatePaymentMethodResult, CreateDonationRequest, CreateDonationResult, TokenizeApplePayResult } from './types';
1
+ import { ClientOptions, Contact, Address, CreatePaymentMethodRequest, CreatePaymentMethodResult, CreateDonationRequest, CreateDonationResult, TokenizeApplePayResult, EmbedConfig } from './types';
2
2
  import ConfigHandler from './config-handler';
3
3
  import { Tokenizer, PaymentMethodType, PaymentGateway, TokenizerContainer } from './tokenize';
4
4
  export default class iDonateClient {
@@ -6,10 +6,12 @@ export default class iDonateClient {
6
6
  private readonly embedId;
7
7
  private currentOrganizationId;
8
8
  private allowTransaction;
9
+ private embedConfigCache?;
10
+ private embedConfigPromise?;
9
11
  get organizationId(): string;
10
12
  readonly options: ClientOptions;
11
13
  readonly config: ConfigHandler;
12
- constructor(clientKey: string, embedId: string, options?: Partial<ClientOptions>);
14
+ constructor(clientKey: string, embedId: string | EmbedConfig, options?: Partial<ClientOptions>);
13
15
  createDonation(donation: CreateDonationRequest): Promise<CreateDonationResult>;
14
16
  createTransaction(donation: CreateDonationRequest): Promise<{
15
17
  transactionId: string | undefined;
@@ -25,4 +27,6 @@ export default class iDonateClient {
25
27
  address: Address;
26
28
  }): Promise<string>;
27
29
  selectGateway(availableGateways: PaymentGateway[], paymentType: PaymentMethodType, preferredGatewayId?: string): PaymentGateway | undefined;
30
+ getEmbedConfig(): Promise<EmbedConfig>;
31
+ getGateway(gatewayId: string): Promise<PaymentGateway>;
28
32
  }
@@ -72,8 +72,19 @@ class iDonateClient {
72
72
  constructor(clientKey, embedId, options) {
73
73
  var _a;
74
74
  this.clientKey = clientKey;
75
- this.embedId = embedId;
76
- this.currentOrganizationId = clientKey;
75
+ if (typeof embedId === 'string') {
76
+ this.embedId = embedId;
77
+ }
78
+ else {
79
+ this.embedConfigCache = embedId;
80
+ this.embedId = embedId.embed_id || '';
81
+ if (embedId.organization_id) {
82
+ this.currentOrganizationId = embedId.organization_id;
83
+ }
84
+ }
85
+ if (!this.currentOrganizationId) {
86
+ this.currentOrganizationId = clientKey;
87
+ }
77
88
  this.options = Object.assign({}, clientDefaults, options);
78
89
  this.allowTransaction = false;
79
90
  this.config = new config_handler_1.default(this.options);
@@ -291,5 +302,32 @@ class iDonateClient {
291
302
  }
292
303
  return availableGateways[0];
293
304
  }
305
+ getEmbedConfig() {
306
+ return __awaiter(this, void 0, void 0, function* () {
307
+ if (this.embedConfigCache) {
308
+ return this.embedConfigCache;
309
+ }
310
+ if (this.embedConfigPromise) {
311
+ return this.embedConfigPromise;
312
+ }
313
+ this.embedConfigPromise = shared
314
+ .fetchEmbedConfig(this.embedId, this.config)
315
+ .then((config) => {
316
+ this.embedConfigCache = config;
317
+ return config;
318
+ });
319
+ return this.embedConfigPromise;
320
+ });
321
+ }
322
+ getGateway(gatewayId) {
323
+ return __awaiter(this, void 0, void 0, function* () {
324
+ const config = yield this.getEmbedConfig();
325
+ const gateway = config.available_gateways.find((g) => g.id === gatewayId);
326
+ if (!gateway) {
327
+ throw new Error(`Gateway ${gatewayId} not found in embed configuration. Available: ${config.available_gateways.map((g) => g.id).join(', ')}`);
328
+ }
329
+ return gateway;
330
+ });
331
+ }
294
332
  }
295
333
  exports.default = iDonateClient;
package/dist/shared.d.ts CHANGED
@@ -1,3 +1,4 @@
1
- import { CreatePaymentMethodRequest, CreatePaymentMethodResult } from './types';
1
+ import { CreatePaymentMethodRequest, CreatePaymentMethodResult, EmbedConfig } from './types';
2
2
  import ConfigHandler from './config-handler';
3
3
  export declare function createPaymentMethod(paymentMethod: CreatePaymentMethodRequest, config: ConfigHandler): Promise<CreatePaymentMethodResult>;
4
+ export declare function fetchEmbedConfig(embedId: string, config: ConfigHandler): Promise<EmbedConfig>;
package/dist/shared.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createPaymentMethod = createPaymentMethod;
4
+ exports.fetchEmbedConfig = fetchEmbedConfig;
4
5
  const typeAdapters_1 = require("./typeAdapters");
5
6
  const constants_1 = require("./constants");
6
7
  const util_1 = require("./util");
@@ -14,3 +15,11 @@ function createPaymentMethod(paymentMethod, config) {
14
15
  .then((response) => (0, util_1.parseResponse)(response, { throwErrors: true }))
15
16
  .then((response) => (0, typeAdapters_1.buildCreatePaymentMethodResult)(response));
16
17
  }
18
+ function fetchEmbedConfig(embedId, config) {
19
+ return fetch(`${config.embedApiBaseUrl}/config/${embedId}`, {
20
+ method: 'GET',
21
+ headers: constants_1.CLIENT_HEADERS,
22
+ })
23
+ .then((response) => (0, util_1.parseResponse)(response, { throwErrors: true }))
24
+ .then((response) => response._raw_response.result);
25
+ }
@@ -5,6 +5,7 @@ import ConfigHandler from '../config-handler';
5
5
  export declare class CardConnectTokenizer extends Tokenizer {
6
6
  private iframeUrl;
7
7
  private containerId;
8
+ private layout;
8
9
  private iframe;
9
10
  private messageHandler?;
10
11
  private expectedOrigin;