@idonatedev/idonate-sdk 1.1.0-dev12 → 1.1.0-dev14

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 (54) hide show
  1. package/README.md +27 -0
  2. package/dist/esm/apple-pay.d.ts +12 -0
  3. package/dist/esm/apple-pay.js +74 -0
  4. package/dist/esm/cloudflare-challenge-handler.d.ts +5 -0
  5. package/dist/esm/cloudflare-challenge-handler.js +77 -0
  6. package/dist/esm/config-handler.d.ts +22 -0
  7. package/dist/esm/config-handler.js +47 -0
  8. package/dist/esm/constants.d.ts +18 -0
  9. package/dist/esm/constants.js +82 -0
  10. package/dist/esm/google-pay.d.ts +18 -0
  11. package/dist/esm/google-pay.js +140 -0
  12. package/dist/esm/idonate-client.d.ts +28 -0
  13. package/dist/esm/idonate-client.js +256 -0
  14. package/dist/esm/index.d.ts +11 -0
  15. package/dist/esm/index.js +11 -0
  16. package/dist/esm/recaptcha.d.ts +12 -0
  17. package/dist/esm/recaptcha.js +89 -0
  18. package/dist/esm/shared.d.ts +3 -0
  19. package/dist/esm/shared.js +13 -0
  20. package/dist/esm/test-utils.d.ts +81 -0
  21. package/dist/esm/test-utils.js +94 -0
  22. package/dist/esm/tokenize/CardConnectTokenizer.d.ts +51 -0
  23. package/dist/esm/tokenize/CardConnectTokenizer.js +706 -0
  24. package/dist/esm/tokenize/SpreedlyTokenizer.d.ts +92 -0
  25. package/dist/esm/tokenize/SpreedlyTokenizer.js +1140 -0
  26. package/dist/esm/tokenize/Tokenizer.d.ts +37 -0
  27. package/dist/esm/tokenize/Tokenizer.js +146 -0
  28. package/dist/esm/tokenize/iats.d.ts +3 -0
  29. package/dist/esm/tokenize/iats.js +48 -0
  30. package/dist/esm/tokenize/index.d.ts +6 -0
  31. package/dist/esm/tokenize/index.js +6 -0
  32. package/dist/esm/tokenize/spreedly-secure.d.ts +8 -0
  33. package/dist/esm/tokenize/spreedly-secure.js +40 -0
  34. package/dist/esm/tokenize/styles.d.ts +4 -0
  35. package/dist/esm/tokenize/styles.js +46 -0
  36. package/dist/esm/tokenize/tokenizer-constants.d.ts +62 -0
  37. package/dist/esm/tokenize/tokenizer-constants.js +62 -0
  38. package/dist/esm/tokenize/tokenizer-utils.d.ts +19 -0
  39. package/dist/esm/tokenize/tokenizer-utils.js +139 -0
  40. package/dist/esm/tokenize/types.d.ts +144 -0
  41. package/dist/esm/tokenize/types.js +26 -0
  42. package/dist/esm/typeAdapters.d.ts +29 -0
  43. package/dist/esm/typeAdapters.js +188 -0
  44. package/dist/esm/types.d.ts +367 -0
  45. package/dist/esm/types.js +14 -0
  46. package/dist/esm/util.d.ts +17 -0
  47. package/dist/esm/util.js +113 -0
  48. package/dist/typeAdapters.js +0 -9
  49. package/package.json +52 -23
  50. package/umd/idonate-sdk.js +1 -1
  51. package/dist/tokenize/cardconnect.d.ts +0 -3
  52. package/dist/tokenize/cardconnect.js +0 -16
  53. package/dist/tokenize/spreedly.d.ts +0 -48
  54. package/dist/tokenize/spreedly.js +0 -208
@@ -0,0 +1,144 @@
1
+ export type PaymentMethodType = 'credit_card' | 'bank_account' | 'paypal' | 'apple_pay' | 'google_pay';
2
+ export type PaymentMethodMode = 'credit_card' | 'bank_account';
3
+ export interface PaymentGateway {
4
+ id: string;
5
+ backend_name: string;
6
+ gateway_type?: string;
7
+ name: string;
8
+ config?: {
9
+ environment_key?: string;
10
+ base_url?: string;
11
+ merchant_id?: string;
12
+ [key: string]: any;
13
+ };
14
+ }
15
+ export interface TokenizerContainer {
16
+ containerId: string;
17
+ styling?: TokenizerStyling;
18
+ mode?: PaymentMethodMode;
19
+ bankCountry?: 'US' | 'CA';
20
+ enableTestMode?: boolean;
21
+ layout?: 'single-line' | 'two-line';
22
+ }
23
+ export interface TokenizerStylingComplete {
24
+ input: {
25
+ height: string;
26
+ padding: string;
27
+ fontSize: string;
28
+ fontFamily: string;
29
+ border: string;
30
+ borderRadius: string;
31
+ backgroundColor: string;
32
+ color: string;
33
+ boxSizing: string;
34
+ width: string;
35
+ lineHeight?: string;
36
+ transition: string;
37
+ };
38
+ focus: {
39
+ borderColor: string;
40
+ outline: string;
41
+ boxShadow: string;
42
+ };
43
+ error: {
44
+ borderColor: string;
45
+ color?: string;
46
+ backgroundColor?: string;
47
+ };
48
+ container: {
49
+ display: string;
50
+ gap: string;
51
+ alignItems: string;
52
+ flexWrap?: string;
53
+ rowGap?: string;
54
+ };
55
+ }
56
+ type DeepPartial<T> = T extends object ? {
57
+ [P in keyof T]?: DeepPartial<T[P]>;
58
+ } : T;
59
+ export type TokenizerStyling = DeepPartial<TokenizerStylingComplete>;
60
+ export interface CardData {
61
+ firstName: string;
62
+ lastName: string;
63
+ email?: string;
64
+ phone?: string;
65
+ address?: {
66
+ line1?: string;
67
+ line2?: string;
68
+ city?: string;
69
+ state?: string;
70
+ postalCode?: string;
71
+ country?: string;
72
+ };
73
+ }
74
+ export interface BankAccountData {
75
+ firstName: string;
76
+ lastName: string;
77
+ email?: string;
78
+ phone?: string;
79
+ address?: {
80
+ line1?: string;
81
+ line2?: string;
82
+ city?: string;
83
+ state?: string;
84
+ postalCode?: string;
85
+ country?: string;
86
+ };
87
+ }
88
+ export interface CanadianBankAccountData extends BankAccountData {
89
+ }
90
+ export type PaymentData = CardData | BankAccountData | CanadianBankAccountData;
91
+ export interface PaymentToken {
92
+ token: string;
93
+ lastFour: string;
94
+ cardType?: CardType;
95
+ accountType?: 'checking' | 'savings';
96
+ paymentMethodType?: PaymentMethodMode;
97
+ expiresAt?: Date;
98
+ provider?: string;
99
+ }
100
+ export type CardType = 'visa' | 'mastercard' | 'amex' | 'discover' | 'diners' | 'jcb' | 'unknown';
101
+ export type TokenizerEvent = 'ready' | 'focus' | 'blur' | 'change' | 'validation' | 'cardTypeChange' | 'error' | 'tokenization' | 'tokenReady';
102
+ export interface ValidationState {
103
+ isValid: boolean;
104
+ cardNumber?: {
105
+ isValid: boolean;
106
+ isEmpty: boolean;
107
+ error?: string;
108
+ };
109
+ cvv?: {
110
+ isValid: boolean;
111
+ isEmpty: boolean;
112
+ error?: string;
113
+ };
114
+ expiry?: {
115
+ isValid: boolean;
116
+ isEmpty: boolean;
117
+ error?: string;
118
+ };
119
+ routingNumber?: {
120
+ isValid: boolean;
121
+ isEmpty: boolean;
122
+ error?: string;
123
+ };
124
+ accountNumber?: {
125
+ isValid: boolean;
126
+ isEmpty: boolean;
127
+ error?: string;
128
+ };
129
+ }
130
+ export interface ValidationResult {
131
+ isValid: boolean;
132
+ errors: ValidationError[];
133
+ }
134
+ export interface ValidationError {
135
+ field: 'cardNumber' | 'cvv' | 'expiry' | 'routingNumber' | 'accountNumber';
136
+ message: string;
137
+ code?: string;
138
+ }
139
+ export declare class TokenizationError extends Error {
140
+ errors: ValidationError[];
141
+ code?: string;
142
+ constructor(errors: any[] | string, code?: string);
143
+ }
144
+ export {};
@@ -0,0 +1,26 @@
1
+ export class TokenizationError extends Error {
2
+ constructor(errors, code) {
3
+ const message = typeof errors === 'string'
4
+ ? errors
5
+ : errors.map((e) => e.message || e).join(', ');
6
+ super(message);
7
+ this.name = 'TokenizationError';
8
+ this.code = code;
9
+ if (Array.isArray(errors)) {
10
+ this.errors = errors.map((e) => ({
11
+ field: e.field || e.attribute || 'unknown',
12
+ message: e.message || e.error || String(e),
13
+ code: e.code || e.key,
14
+ }));
15
+ }
16
+ else {
17
+ this.errors = [
18
+ {
19
+ field: 'cardNumber',
20
+ message: errors,
21
+ code,
22
+ },
23
+ ];
24
+ }
25
+ }
26
+ }
@@ -0,0 +1,29 @@
1
+ import { CreatePaymentMethodRequest, CreatePaymentMethodResult, CreateDonationRequest, CreateDonationResult, ClientResponse, ClientError, CashPaymentPayload } from './types';
2
+ export declare function buildCashPaymentPayload(organizationId: string, input: CreateDonationRequest): CashPaymentPayload;
3
+ export declare function buildDonationResult(response: ClientResponse): CreateDonationResult;
4
+ export declare function buildCreatePaymentMethodPayload(input: CreatePaymentMethodRequest): {
5
+ gateway_id: string | undefined;
6
+ backend_name: import("./types").BackendName | undefined;
7
+ payment_method_type: import("./types").PaymentMethodType;
8
+ payment_method_token: string;
9
+ donor_id: string | undefined;
10
+ first_name: string;
11
+ last_name: string;
12
+ company: string;
13
+ email: string | undefined;
14
+ phone: string;
15
+ country: string;
16
+ address1: string;
17
+ address2: string | undefined;
18
+ city: string;
19
+ state: string;
20
+ zip_code: string;
21
+ embed_id: string | undefined;
22
+ recaptcha_token: string;
23
+ recaptcha_type: import("./types").RecaptchaType;
24
+ };
25
+ export declare function collapseClientErrors(errors: ClientError[]): ClientError;
26
+ export declare function buildCreatePaymentMethodResult(response: ClientResponse): CreatePaymentMethodResult;
27
+ export type SpreedlyResponse = any;
28
+ export declare function unpackSpreedlyResponse(response: any): Promise<SpreedlyResponse>;
29
+ export declare function extractSpreedlyToken(spreedlyData: SpreedlyResponse): string;
@@ -0,0 +1,188 @@
1
+ import { ClientError, } from './types';
2
+ export function buildCashPaymentPayload(organizationId, input) {
3
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
4
+ const billingAddress = {
5
+ country: input.billingAddress.country,
6
+ address1: input.billingAddress.address1,
7
+ address2: input.billingAddress.address2,
8
+ city: input.billingAddress.city,
9
+ state: input.billingAddress.state,
10
+ zip_code: input.billingAddress.zip,
11
+ };
12
+ const billingContact = {
13
+ title: input.billingContact.salutation,
14
+ first_name: input.billingContact.firstName,
15
+ middle_name: input.billingContact.middleName,
16
+ last_name: input.billingContact.lastName,
17
+ company_name: input.billingContact.company,
18
+ email: input.billingContact.email,
19
+ home_phone: input.billingContact.primaryPhone,
20
+ timezone: new Intl.DateTimeFormat().resolvedOptions().timeZone,
21
+ };
22
+ const payment = {
23
+ payment_method_id: input.paymentMethodId,
24
+ gateway_id: input.paymentGatewayId,
25
+ amount: input.paymentAmount,
26
+ type: 'cash',
27
+ frequency: input.recurringFrequency,
28
+ start_date: input.recurringStart,
29
+ end_date: input.recurringEnd,
30
+ retain_on_success: input.retainPaymentMethod,
31
+ };
32
+ const donationOptions = {
33
+ organization_id: organizationId,
34
+ campaign_id: input.campaignId,
35
+ reference_code: input.referenceCode,
36
+ double_the_donation_company_id: input.corporateMatchingId,
37
+ donor_id: input.donorId,
38
+ hide_name: input.anonymousOptIn,
39
+ show_name_to_fundraiser: input.showNameToFundraiserOptIn,
40
+ email_opt_in: input.emailOptIn,
41
+ donor_paid_fee: input.donorPaidFeeAmount,
42
+ designation_note: input.designationNote,
43
+ gift_id: input.giftId,
44
+ gift_extra: input.giftExtra,
45
+ gift_skipped: input.giftSkipped,
46
+ p2p_fundraiser_id: input.p2pFundraiserId,
47
+ p2p_fundraiser_comment: input.p2pFundraiserComment,
48
+ organization_event_id: input.organizationEventId,
49
+ advocate_id: input.advocateId,
50
+ advocacy_program_id: input.advocacyProgramId,
51
+ advocacy_team_id: input.advocacyTeamId,
52
+ page_id: input.landingPageId,
53
+ embed_id: input.embedId,
54
+ tribute_definition_id: (_a = input.tribute) === null || _a === void 0 ? void 0 : _a.tributeDefinitionId,
55
+ tribute_recipient_first_name: (_b = input.tribute) === null || _b === void 0 ? void 0 : _b.tributeFirstName,
56
+ tribute_recipient_last_name: (_c = input.tribute) === null || _c === void 0 ? void 0 : _c.tributeLastName,
57
+ tribute_address1: (_d = input.tribute) === null || _d === void 0 ? void 0 : _d.tributeAddress1,
58
+ tribute_address2: (_e = input.tribute) === null || _e === void 0 ? void 0 : _e.tributeAddress2,
59
+ tribute_city: (_f = input.tribute) === null || _f === void 0 ? void 0 : _f.tributeCity,
60
+ tribute_state: (_g = input.tribute) === null || _g === void 0 ? void 0 : _g.tributeState,
61
+ tribute_postal_code: (_h = input.tribute) === null || _h === void 0 ? void 0 : _h.tributePostalCode,
62
+ tribute_country: (_j = input.tribute) === null || _j === void 0 ? void 0 : _j.tributeCountry,
63
+ tribute_from_name: (_k = input.tribute) === null || _k === void 0 ? void 0 : _k.tributeFromName,
64
+ tribute_recipient_email: (_l = input.tribute) === null || _l === void 0 ? void 0 : _l.tributeRecipientEmail,
65
+ honorees: (_m = input.tribute) === null || _m === void 0 ? void 0 : _m.honorees,
66
+ tribute_send_card: (_o = input.tribute) === null || _o === void 0 ? void 0 : _o.tributeSendCard,
67
+ tribute_include_amount: (_p = input.tribute) === null || _p === void 0 ? void 0 : _p.tributeIncludeAmount,
68
+ tribute_skipped: (_q = input.tribute) === null || _q === void 0 ? void 0 : _q.tributeSkipped,
69
+ tribute_type: (_r = input.tribute) === null || _r === void 0 ? void 0 : _r.tributeType,
70
+ useOnBillingAddress: (_s = input.tribute) === null || _s === void 0 ? void 0 : _s.useOnBillingAddress,
71
+ embed_referer: window.location.href,
72
+ converted_to_recurring: input.convertedToRecurring,
73
+ };
74
+ if (input.designations) {
75
+ donationOptions.designations = input.designations;
76
+ }
77
+ else {
78
+ donationOptions.designations = [];
79
+ }
80
+ if (input.designationId) {
81
+ donationOptions.designations.push({
82
+ id: input.designationId,
83
+ amount: input.paymentAmount,
84
+ });
85
+ }
86
+ const utmFields = {};
87
+ if (input.utm) {
88
+ if (input.utm.campaign) {
89
+ utmFields.utm_campaign = input.utm.campaign;
90
+ }
91
+ if (input.utm.content) {
92
+ utmFields.utm_content = input.utm.content;
93
+ }
94
+ if (input.utm.medium) {
95
+ utmFields.utm_medium = input.utm.medium;
96
+ }
97
+ if (input.utm.source) {
98
+ utmFields.utm_source = input.utm.source;
99
+ }
100
+ if (input.utm.term) {
101
+ utmFields.utm_term = input.utm.term;
102
+ }
103
+ }
104
+ if (input.customerMeta) {
105
+ [1, 2, 3, 4, 5].forEach((customNoteIndex) => {
106
+ const key = `custom_note_${customNoteIndex}`;
107
+ if (input.customerMeta[key]) {
108
+ donationOptions[key] = input.customerMeta[key];
109
+ delete input.customerMeta[key];
110
+ }
111
+ });
112
+ }
113
+ return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, donationOptions), billingAddress), billingContact), payment), utmFields), { customer_meta: input.customerMeta || {}, recaptcha_token: input.recaptchaToken, recaptcha_type: input.recaptchaType });
114
+ }
115
+ export function buildDonationResult(response) {
116
+ let campaign;
117
+ let designation;
118
+ let donor;
119
+ let schedule;
120
+ let transaction;
121
+ if (response._raw_response.transaction) {
122
+ transaction = response._raw_response.transaction;
123
+ }
124
+ if (response._raw_response.schedule) {
125
+ schedule = response._raw_response.schedule;
126
+ }
127
+ if (response._raw_response.donor) {
128
+ donor = response._raw_response.donor;
129
+ }
130
+ if (response._raw_response.designation) {
131
+ designation = response._raw_response.designation;
132
+ }
133
+ if (response._raw_response.campaign) {
134
+ campaign = response._raw_response.campaign;
135
+ }
136
+ return Object.assign(Object.assign({}, response), { campaign,
137
+ designation,
138
+ donor,
139
+ schedule,
140
+ transaction });
141
+ }
142
+ export function buildCreatePaymentMethodPayload(input) {
143
+ return {
144
+ gateway_id: input.paymentGatewayId,
145
+ backend_name: input.backendName,
146
+ payment_method_type: input.paymentMethodType,
147
+ payment_method_token: input.paymentMethodToken,
148
+ donor_id: input.donorId,
149
+ first_name: input.contact.firstName,
150
+ last_name: input.contact.lastName,
151
+ company: input.contact.company,
152
+ email: input.contact.email,
153
+ phone: input.contact.primaryPhone,
154
+ country: input.address.country,
155
+ address1: input.address.address1,
156
+ address2: input.address.address2,
157
+ city: input.address.city,
158
+ state: input.address.state,
159
+ zip_code: input.address.zip,
160
+ embed_id: input.embedId,
161
+ recaptcha_token: input.recaptchaToken,
162
+ recaptcha_type: input.recaptchaType,
163
+ };
164
+ }
165
+ export function collapseClientErrors(errors) {
166
+ return new ClientError(errors.map((err) => err.message).join(`\n `), {
167
+ _rawPayload: errors,
168
+ });
169
+ }
170
+ export function buildCreatePaymentMethodResult(response) {
171
+ return Object.assign(Object.assign({}, response), { paymentMethodId: response._raw_response.result.id });
172
+ }
173
+ export function unpackSpreedlyResponse(response) {
174
+ return response.json().then((data) => {
175
+ if (data.errors) {
176
+ throw new ClientError(data.errors
177
+ .map((spreedlyError) => spreedlyError.message)
178
+ .join(`\n `), data);
179
+ }
180
+ return data;
181
+ });
182
+ }
183
+ export function extractSpreedlyToken(spreedlyData) {
184
+ if (!spreedlyData.transaction || !spreedlyData.transaction.payment_method) {
185
+ throw new ClientError('Payment Method not tokenized.');
186
+ }
187
+ return spreedlyData.transaction.payment_method.token;
188
+ }