@payconductor/react 1.0.0
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/README.md +253 -0
- package/dist/index.cjs.js +2 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.es.js +476 -0
- package/dist/index.es.js.map +1 -0
- package/dist/payconductor/constants.d.ts +30 -0
- package/dist/payconductor/hooks/index.d.ts +3 -0
- package/dist/payconductor/hooks/use-element.d.ts +30 -0
- package/dist/payconductor/hooks/use-payconductor.d.ts +6 -0
- package/dist/payconductor/iframe/constants.d.ts +8 -0
- package/dist/payconductor/iframe/types.d.ts +241 -0
- package/dist/payconductor/internal.d.ts +11 -0
- package/dist/payconductor/payconductor-element.d.ts +5 -0
- package/dist/payconductor/payconductor.d.ts +14 -0
- package/dist/payconductor/types.d.ts +44 -0
- package/dist/payconductor/utils.d.ts +5 -0
- package/package.json +58 -0
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
export declare enum PaymentMethod {
|
|
2
|
+
Pix = "Pix",
|
|
3
|
+
CreditCard = "CreditCard",
|
|
4
|
+
DebitCard = "DebitCard",
|
|
5
|
+
BankSlip = "BankSlip",
|
|
6
|
+
Crypto = "Crypto",
|
|
7
|
+
ApplePay = "ApplePay",
|
|
8
|
+
NuPay = "NuPay",
|
|
9
|
+
PicPay = "PicPay",
|
|
10
|
+
AmazonPay = "AmazonPay",
|
|
11
|
+
SepaDebit = "SepaDebit",
|
|
12
|
+
GooglePay = "GooglePay"
|
|
13
|
+
}
|
|
14
|
+
export declare enum PaymentMethodLayout {
|
|
15
|
+
Grid = "grid",
|
|
16
|
+
Vertical = "vertical",
|
|
17
|
+
Horizontal = "horizontal"
|
|
18
|
+
}
|
|
19
|
+
export declare enum PaymentStatus {
|
|
20
|
+
Succeeded = "succeeded",
|
|
21
|
+
Pending = "pending",
|
|
22
|
+
Failed = "failed"
|
|
23
|
+
}
|
|
24
|
+
export declare enum DeviceType {
|
|
25
|
+
Android = "android",
|
|
26
|
+
IOS = "ios",
|
|
27
|
+
Web = "web"
|
|
28
|
+
}
|
|
29
|
+
export declare enum InputStyleKey {
|
|
30
|
+
Padding = "padding",
|
|
31
|
+
Radius = "radius",
|
|
32
|
+
Color = "color",
|
|
33
|
+
Background = "background",
|
|
34
|
+
Shadow = "shadow"
|
|
35
|
+
}
|
|
36
|
+
export declare enum OutgoingMessage {
|
|
37
|
+
Init = "Init",
|
|
38
|
+
Config = "Config",
|
|
39
|
+
Update = "Update",
|
|
40
|
+
ConfirmPayment = "ConfirmPayment",
|
|
41
|
+
Validate = "Validate",
|
|
42
|
+
Reset = "Reset"
|
|
43
|
+
}
|
|
44
|
+
export declare enum IncomingMessage {
|
|
45
|
+
Ready = "Ready",
|
|
46
|
+
Error = "Error",
|
|
47
|
+
PaymentComplete = "PaymentComplete",
|
|
48
|
+
PaymentFailed = "PaymentFailed",
|
|
49
|
+
PaymentPending = "PaymentPending",
|
|
50
|
+
ValidationError = "ValidationError",
|
|
51
|
+
PaymentMethodSelected = "PaymentMethodSelected"
|
|
52
|
+
}
|
|
53
|
+
export declare enum ErrorCode {
|
|
54
|
+
InvalidClient = "InvalidClient",
|
|
55
|
+
InvalidToken = "InvalidToken",
|
|
56
|
+
NetworkError = "NetworkError",
|
|
57
|
+
IframeNotReady = "IframeNotReady",
|
|
58
|
+
PaymentDeclined = "PaymentDeclined",
|
|
59
|
+
ValidationError = "ValidationError",
|
|
60
|
+
Timeout = "Timeout"
|
|
61
|
+
}
|
|
62
|
+
export type InputStyleConfig = {
|
|
63
|
+
padding?: string;
|
|
64
|
+
radius?: string;
|
|
65
|
+
color?: string;
|
|
66
|
+
background?: string;
|
|
67
|
+
shadow?: string;
|
|
68
|
+
};
|
|
69
|
+
export type PaymentMethodsConfig = {
|
|
70
|
+
layout?: PaymentMethodLayout;
|
|
71
|
+
gap?: string;
|
|
72
|
+
inputStyle?: InputStyleConfig;
|
|
73
|
+
};
|
|
74
|
+
export type PaymentMethodConfig = {
|
|
75
|
+
method: PaymentMethod;
|
|
76
|
+
discount?: number;
|
|
77
|
+
showBrands?: boolean;
|
|
78
|
+
installments?: {
|
|
79
|
+
count: number;
|
|
80
|
+
amount: number;
|
|
81
|
+
}[];
|
|
82
|
+
};
|
|
83
|
+
export type PaymentMethodsResponse = {
|
|
84
|
+
methods: PaymentMethod[];
|
|
85
|
+
config: PaymentMethodsConfig;
|
|
86
|
+
};
|
|
87
|
+
export type PayConductorTheme = {
|
|
88
|
+
primaryColor?: string;
|
|
89
|
+
secondaryColor?: string;
|
|
90
|
+
backgroundColor?: string;
|
|
91
|
+
surfaceColor?: string;
|
|
92
|
+
textColor?: string;
|
|
93
|
+
textSecondaryColor?: string;
|
|
94
|
+
errorColor?: string;
|
|
95
|
+
successColor?: string;
|
|
96
|
+
warningColor?: string;
|
|
97
|
+
borderColor?: string;
|
|
98
|
+
disabledColor?: string;
|
|
99
|
+
fontFamily?: string;
|
|
100
|
+
fontSize?: {
|
|
101
|
+
xs?: string;
|
|
102
|
+
sm?: string;
|
|
103
|
+
md?: string;
|
|
104
|
+
lg?: string;
|
|
105
|
+
xl?: string;
|
|
106
|
+
};
|
|
107
|
+
fontWeight?: {
|
|
108
|
+
normal?: number;
|
|
109
|
+
medium?: number;
|
|
110
|
+
bold?: number;
|
|
111
|
+
};
|
|
112
|
+
lineHeight?: string;
|
|
113
|
+
spacing?: {
|
|
114
|
+
xs?: string;
|
|
115
|
+
sm?: string;
|
|
116
|
+
md?: string;
|
|
117
|
+
lg?: string;
|
|
118
|
+
xl?: string;
|
|
119
|
+
};
|
|
120
|
+
borderRadius?: string;
|
|
121
|
+
borderWidth?: string;
|
|
122
|
+
boxShadow?: string;
|
|
123
|
+
boxShadowHover?: string;
|
|
124
|
+
inputBackground?: string;
|
|
125
|
+
inputBorderColor?: string;
|
|
126
|
+
inputBorderRadius?: string;
|
|
127
|
+
inputHeight?: string;
|
|
128
|
+
inputPadding?: string;
|
|
129
|
+
buttonHeight?: string;
|
|
130
|
+
buttonPadding?: string;
|
|
131
|
+
buttonBorderRadius?: string;
|
|
132
|
+
transitionDuration?: string;
|
|
133
|
+
transitionTimingFunction?: string;
|
|
134
|
+
};
|
|
135
|
+
export declare const defaultTheme: PayConductorTheme;
|
|
136
|
+
export type PayConductorConfig = {
|
|
137
|
+
publicKey: string;
|
|
138
|
+
orderId?: string;
|
|
139
|
+
theme?: PayConductorTheme;
|
|
140
|
+
locale?: string;
|
|
141
|
+
paymentMethods?: PaymentMethod[] | "all";
|
|
142
|
+
defaultPaymentMethod?: PaymentMethod;
|
|
143
|
+
paymentMethodsConfig?: PaymentMethodConfig[];
|
|
144
|
+
methodsDirection?: "vertical" | "horizontal";
|
|
145
|
+
showPaymentButtons?: boolean;
|
|
146
|
+
/** Required when NuPay is an available payment method */
|
|
147
|
+
nuPayConfig?: NuPayData;
|
|
148
|
+
};
|
|
149
|
+
export type BillingDetails = {
|
|
150
|
+
name: string;
|
|
151
|
+
email?: string;
|
|
152
|
+
phone?: string;
|
|
153
|
+
address?: {
|
|
154
|
+
line1: string;
|
|
155
|
+
line2?: string;
|
|
156
|
+
city: string;
|
|
157
|
+
state: string;
|
|
158
|
+
postalCode: string;
|
|
159
|
+
country: string;
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
export type CardData = {
|
|
163
|
+
number: string;
|
|
164
|
+
expMonth: string;
|
|
165
|
+
expYear: string;
|
|
166
|
+
cvc: string;
|
|
167
|
+
};
|
|
168
|
+
export type CreatePaymentMethodOptions = {
|
|
169
|
+
billingDetails: BillingDetails;
|
|
170
|
+
card?: CardData;
|
|
171
|
+
};
|
|
172
|
+
export type PaymentMethodResult = {
|
|
173
|
+
id: string;
|
|
174
|
+
type: PaymentMethod;
|
|
175
|
+
card?: {
|
|
176
|
+
brand: string;
|
|
177
|
+
last4: string;
|
|
178
|
+
expMonth: number;
|
|
179
|
+
expYear: number;
|
|
180
|
+
};
|
|
181
|
+
billingDetails?: BillingDetails;
|
|
182
|
+
};
|
|
183
|
+
export type PaymentResult = {
|
|
184
|
+
orderId: string;
|
|
185
|
+
status: PaymentStatus;
|
|
186
|
+
amount: number;
|
|
187
|
+
currency: string;
|
|
188
|
+
message?: string;
|
|
189
|
+
};
|
|
190
|
+
export interface MessagePayload {
|
|
191
|
+
type: OutgoingMessage | IncomingMessage;
|
|
192
|
+
data?: unknown;
|
|
193
|
+
requestId?: string;
|
|
194
|
+
error?: {
|
|
195
|
+
code: string;
|
|
196
|
+
message: string;
|
|
197
|
+
field?: string;
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
export type CardTokenData = {
|
|
201
|
+
token: string;
|
|
202
|
+
firstSixCardNumber?: string;
|
|
203
|
+
};
|
|
204
|
+
export type CardFullData = {
|
|
205
|
+
number: string;
|
|
206
|
+
holderName: string;
|
|
207
|
+
cvv: string;
|
|
208
|
+
expiration: {
|
|
209
|
+
month: number;
|
|
210
|
+
year: number;
|
|
211
|
+
};
|
|
212
|
+
};
|
|
213
|
+
export type CardPaymentData = CardTokenData | CardFullData;
|
|
214
|
+
export type PixPaymentData = {
|
|
215
|
+
paymentMethod: PaymentMethod.Pix;
|
|
216
|
+
expirationInSeconds?: number;
|
|
217
|
+
};
|
|
218
|
+
export type CreditCardPaymentData = {
|
|
219
|
+
paymentMethod: PaymentMethod.CreditCard;
|
|
220
|
+
card: CardPaymentData;
|
|
221
|
+
installments: number;
|
|
222
|
+
softDescriptor?: string;
|
|
223
|
+
};
|
|
224
|
+
export type BankSlipPaymentData = {
|
|
225
|
+
paymentMethod: PaymentMethod.BankSlip;
|
|
226
|
+
expirationInDays?: number;
|
|
227
|
+
};
|
|
228
|
+
export type NuPayData = {
|
|
229
|
+
cancelUrl: string;
|
|
230
|
+
merchantName: string;
|
|
231
|
+
returnUrl: string;
|
|
232
|
+
storeName?: string;
|
|
233
|
+
};
|
|
234
|
+
export type NuPayPaymentData = {
|
|
235
|
+
paymentMethod: PaymentMethod.NuPay;
|
|
236
|
+
nuPay: NuPayData;
|
|
237
|
+
};
|
|
238
|
+
export type PicPayPaymentData = {
|
|
239
|
+
paymentMethod: PaymentMethod.PicPay;
|
|
240
|
+
};
|
|
241
|
+
export type PaymentConfirmData = PixPaymentData | CreditCardPaymentData | BankSlipPaymentData | NuPayPaymentData | PicPayPaymentData;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IncomingMessage, OutgoingMessage, PayConductorConfig, PaymentMethod, PaymentResult } from './iframe/types';
|
|
2
|
+
import { ConfirmPaymentOptions, PendingRequest } from './types';
|
|
3
|
+
|
|
4
|
+
export declare function createPendingRequestsMap(): Map<string, PendingRequest>;
|
|
5
|
+
export declare function sendMessageToIframe(iframe: HTMLIFrameElement | Element | undefined, pendingMap: Map<string, PendingRequest> | null, type: OutgoingMessage | IncomingMessage, data?: unknown): Promise<unknown>;
|
|
6
|
+
export declare function confirmPayment(iframe: HTMLIFrameElement | Element | undefined, pendingMap: Map<string, PendingRequest> | null, options: ConfirmPaymentOptions): Promise<PaymentResult>;
|
|
7
|
+
export declare function validatePayment(iframe: HTMLIFrameElement | Element | undefined, pendingMap: Map<string, PendingRequest> | null, data: unknown): Promise<boolean>;
|
|
8
|
+
export declare function resetPayment(iframe: HTMLIFrameElement | Element | undefined, pendingMap: Map<string, PendingRequest> | null): Promise<void>;
|
|
9
|
+
export declare function sendConfig(iframe: HTMLIFrameElement | Element | undefined, pendingMap: Map<string, PendingRequest> | null, config: Pick<PayConductorConfig, "theme" | "locale" | "paymentMethods" | "defaultPaymentMethod" | "showPaymentButtons" | "nuPayConfig">): Promise<void>;
|
|
10
|
+
export declare function sendInit(iframe: HTMLIFrameElement | Element | undefined, pendingMap: Map<string, PendingRequest> | null, config: PayConductorConfig): Promise<void>;
|
|
11
|
+
export declare function handleMessageEvent(event: MessageEvent, pendingMap: Map<string, PendingRequest> | null, setIsReady: (value: boolean) => void, setError: (value: string | null) => void, onReady?: () => void, onError?: (error: Error) => void, onPaymentComplete?: (data: PaymentResult) => void, onPaymentFailed?: (data: PaymentResult) => void, onPaymentPending?: (data: PaymentResult) => void, onPaymentMethodSelected?: (method: PaymentMethod) => void): void;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { PayConductorConfig, PaymentMethod, PaymentResult } from './iframe/types';
|
|
2
|
+
export interface PayConductorEmbedProps extends Omit<PayConductorConfig, "orderId"> {
|
|
3
|
+
children?: any;
|
|
4
|
+
showActionButtons?: boolean;
|
|
5
|
+
debug?: boolean;
|
|
6
|
+
onReady?: () => void;
|
|
7
|
+
onError?: (error: Error) => void;
|
|
8
|
+
onPaymentComplete?: (result: PaymentResult) => void;
|
|
9
|
+
onPaymentFailed?: (result: PaymentResult) => void;
|
|
10
|
+
onPaymentPending?: (result: PaymentResult) => void;
|
|
11
|
+
onPaymentMethodSelected?: (method: PaymentMethod) => void;
|
|
12
|
+
}
|
|
13
|
+
declare function PayConductor(props: PayConductorEmbedProps): import("react/jsx-runtime").JSX.Element;
|
|
14
|
+
export default PayConductor;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { PayConductorConfig, PaymentMethod, PaymentResult } from './iframe/types';
|
|
2
|
+
|
|
3
|
+
export type * from './iframe/types';
|
|
4
|
+
export type ConfirmPaymentOptions = {
|
|
5
|
+
orderId: string;
|
|
6
|
+
returnUrl?: string;
|
|
7
|
+
};
|
|
8
|
+
export type SubmitResult = {
|
|
9
|
+
error?: {
|
|
10
|
+
message: string;
|
|
11
|
+
code?: string;
|
|
12
|
+
type?: "validation_error" | "payment_error";
|
|
13
|
+
};
|
|
14
|
+
paymentMethod?: PaymentMethod;
|
|
15
|
+
};
|
|
16
|
+
export type PayConductorApi = {
|
|
17
|
+
confirmPayment: (options: ConfirmPaymentOptions) => Promise<PaymentResult>;
|
|
18
|
+
validate: (data: unknown) => Promise<boolean>;
|
|
19
|
+
reset: () => Promise<void>;
|
|
20
|
+
getSelectedPaymentMethod: () => PaymentMethod | null;
|
|
21
|
+
};
|
|
22
|
+
export type PayConductorFrame = {
|
|
23
|
+
iframe: HTMLIFrameElement | Element | unknown | null;
|
|
24
|
+
iframeUrl?: string;
|
|
25
|
+
isReady: boolean;
|
|
26
|
+
error: string | null;
|
|
27
|
+
};
|
|
28
|
+
export type PayConductorContextValue = {
|
|
29
|
+
frame: PayConductorFrame | null;
|
|
30
|
+
config: PayConductorConfig | null;
|
|
31
|
+
api: PayConductorApi;
|
|
32
|
+
selectedPaymentMethod?: PaymentMethod | null;
|
|
33
|
+
};
|
|
34
|
+
export type PayConductorState = {
|
|
35
|
+
isLoaded: boolean;
|
|
36
|
+
isReady: boolean;
|
|
37
|
+
error: string | null;
|
|
38
|
+
iframeUrl: string;
|
|
39
|
+
selectedPaymentMethod: PaymentMethod | null;
|
|
40
|
+
};
|
|
41
|
+
export type PendingRequest = {
|
|
42
|
+
resolve: (value: unknown) => void;
|
|
43
|
+
reject: (error: unknown) => void;
|
|
44
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { PayConductorConfig } from './iframe/types';
|
|
2
|
+
|
|
3
|
+
export declare function buildIframeUrl(config: PayConductorConfig): string;
|
|
4
|
+
export declare function generateRequestId(): string;
|
|
5
|
+
export declare function isValidOrigin(origin: string, allowedOrigins: string[]): boolean;
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@payconductor/react",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "React SDK for PayConductor",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.cjs.js",
|
|
7
|
+
"module": "dist/index.es.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "tsc -b && vite build",
|
|
14
|
+
"build:watch": "vite build --watch",
|
|
15
|
+
"dev": "vite build --watch"
|
|
16
|
+
},
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"import": "./dist/index.es.js",
|
|
20
|
+
"require": "./dist/index.cjs.js",
|
|
21
|
+
"types": "./dist/index.d.ts"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "http://github.com/payconductor-ai/payconductor-sdk-web"
|
|
27
|
+
},
|
|
28
|
+
"bugs": {
|
|
29
|
+
"url": "https://github.com/payconductor-ai/payconductor-sdk-web/issues"
|
|
30
|
+
},
|
|
31
|
+
"homepage": "https://github.com/payconductor-ai/payconductor-sdk-web#readme",
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"author": "PayConductor",
|
|
34
|
+
"keywords": [
|
|
35
|
+
"payconductor",
|
|
36
|
+
"payment",
|
|
37
|
+
"gateway",
|
|
38
|
+
"react",
|
|
39
|
+
"sdk",
|
|
40
|
+
"checkout"
|
|
41
|
+
],
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public"
|
|
44
|
+
},
|
|
45
|
+
"peerDependencies": {
|
|
46
|
+
"react": ">=16.8.0",
|
|
47
|
+
"react-dom": ">=16.8.0"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@types/react": "^18.0.0",
|
|
51
|
+
"@types/react-dom": "^18.0.0",
|
|
52
|
+
"react": "^18.0.0",
|
|
53
|
+
"react-dom": "^18.0.0",
|
|
54
|
+
"typescript": "^5.0.0",
|
|
55
|
+
"vite": "^5.0.0",
|
|
56
|
+
"vite-plugin-dts": "^3.9.0"
|
|
57
|
+
}
|
|
58
|
+
}
|