@inflow_pay/sdk 0.0.1 → 0.1.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.
@@ -0,0 +1,310 @@
1
+ import { JSX as JSX_2 } from 'react/jsx-runtime';
2
+ import { ReactNode } from 'react';
3
+
4
+ declare interface ButtonBaseStyles {
5
+ backgroundColor?: string;
6
+ textColor?: string;
7
+ borderRadius?: string;
8
+ borderColor?: string;
9
+ borderEnabled?: boolean;
10
+ fontSize?: string;
11
+ fontWeight?: string;
12
+ opacity?: string;
13
+ }
14
+
15
+ declare interface ButtonStyles extends ButtonBaseStyles {
16
+ hover?: ButtonBaseStyles;
17
+ disabled?: ButtonBaseStyles;
18
+ loaderColor?: string;
19
+ }
20
+
21
+ /**
22
+ * CardElement - React component
23
+ *
24
+ * Same API as the original React SDK
25
+ *
26
+ * @example
27
+ * ```tsx
28
+ * <CardElement
29
+ * paymentId="pay_xxx"
30
+ * onComplete={(result) => {
31
+ * if (result.status === 'CHECKOUT_SUCCESS') {
32
+ * window.location.href = '/success';
33
+ * }
34
+ * }}
35
+ * />
36
+ * ```
37
+ */
38
+ export declare function CardElement({ paymentId, onReady, onChange, onComplete, onError, style, buttonText, placeholders, config: propConfig, }: CardElementProps & {
39
+ config?: SDKConfig;
40
+ }): JSX_2.Element;
41
+
42
+ declare class CardElement_2 {
43
+ private sdk;
44
+ private container;
45
+ private mounted;
46
+ constructor(config: InternalSDKConfig, options: CardElementOptions);
47
+ /**
48
+ * Mount the CardElement to the DOM
49
+ * This will create and display the iframe
50
+ */
51
+ mount(): void;
52
+ /**
53
+ * Destroy the CardElement and cleanup
54
+ */
55
+ destroy(): void;
56
+ }
57
+
58
+ declare interface CardElementOptions {
59
+ /** Container element or CSS selector where the iframe will be mounted */
60
+ container: string | HTMLElement;
61
+ /** Payment ID for this transaction */
62
+ paymentId: string;
63
+ /** Callback when payment completes */
64
+ onComplete?: (result: {
65
+ status: string;
66
+ data?: any;
67
+ error?: any;
68
+ }) => void;
69
+ /** Callback when payment fails */
70
+ onError?: (error: any) => void;
71
+ /** Callback when user closes the payment */
72
+ onClose?: () => void;
73
+ /** Custom styling for the card element */
74
+ style?: CSSProperties;
75
+ /** Custom button text (default: "Complete Payment") */
76
+ buttonText?: string;
77
+ /** Custom placeholder text for inputs */
78
+ placeholders?: {
79
+ cardNumber?: string;
80
+ expiry?: string;
81
+ cvc?: string;
82
+ };
83
+ }
84
+
85
+ export declare interface CardElementProps {
86
+ paymentId: string;
87
+ onReady?: () => void;
88
+ onChange?: (state: CardElementState) => void;
89
+ onComplete?: (result: PaymentResult) => void;
90
+ onError?: (error: PaymentError) => void;
91
+ style?: CSSProperties;
92
+ buttonText?: string;
93
+ placeholders?: {
94
+ cardNumber?: string;
95
+ expiry?: string;
96
+ cvc?: string;
97
+ };
98
+ }
99
+
100
+ export declare interface CardElementState {
101
+ complete: boolean;
102
+ }
103
+
104
+ declare interface CSSProperties {
105
+ fontFamily?: FontFamily;
106
+ fillParent?: boolean;
107
+ inputContainer?: InputContainerStyles;
108
+ input?: InputStyles;
109
+ button?: ButtonStyles;
110
+ disclaimerColor?: string;
111
+ fieldErrorColor?: string;
112
+ generalError?: GeneralMessageStyles;
113
+ generalSuccess?: GeneralMessageStyles;
114
+ light?: ThemeStyles;
115
+ dark?: ThemeStyles;
116
+ }
117
+
118
+ /**
119
+ * Type definitions for SDK v2
120
+ */
121
+ declare type FontFamily = 'DM Sans' | 'Inter' | 'Poppins' | 'Nunito' | 'Work Sans' | 'Manrope' | 'Rubik' | 'Karla' | 'Figtree' | 'Outfit' | 'Space Grotesk' | 'Urbanist';
122
+
123
+ declare interface GeneralMessageStyles {
124
+ textColor?: string;
125
+ backgroundColor?: string;
126
+ borderEnabled?: boolean;
127
+ borderRadius?: string;
128
+ borderColor?: string;
129
+ }
130
+
131
+ /**
132
+ * InflowPayProvider - React component
133
+ *
134
+ * Same API as the original React SDK
135
+ *
136
+ * @example
137
+ * ```tsx
138
+ * <InflowPayProvider config={{ apiKey: 'inflow_pub_xxx' }}>
139
+ * <CardElement
140
+ * paymentId="pay_xxx"
141
+ * onComplete={(result) => {
142
+ * if (result.status === 'CHECKOUT_SUCCESS') {
143
+ * window.location.href = '/success';
144
+ * }
145
+ * }}
146
+ * />
147
+ * </InflowPayProvider>
148
+ * ```
149
+ */
150
+ export declare function InflowPayProvider({ config, children, }: {
151
+ config: SDKConfig;
152
+ children: ReactNode;
153
+ }): JSX_2.Element;
154
+
155
+ declare interface InputContainerStyles {
156
+ backgroundColor?: string;
157
+ borderColor?: string;
158
+ borderEnabled?: boolean;
159
+ borderRadius?: string;
160
+ }
161
+
162
+ declare interface InputStyles {
163
+ backgroundColor?: string;
164
+ borderColor?: string;
165
+ borderEnabled?: boolean;
166
+ borderRadius?: string;
167
+ textColor?: string;
168
+ placeholderColor?: string;
169
+ }
170
+
171
+ declare interface InternalSDKConfig {
172
+ apiKey: string;
173
+ iframeUrl: string;
174
+ timeout: number;
175
+ debug: boolean;
176
+ }
177
+
178
+ export declare interface PaymentError {
179
+ code: string;
180
+ message: string;
181
+ retryable: boolean;
182
+ }
183
+
184
+ export declare interface PaymentResult {
185
+ status: string;
186
+ data?: any;
187
+ error?: {
188
+ code: string;
189
+ message: string;
190
+ retryable: boolean;
191
+ };
192
+ }
193
+
194
+ declare class PaymentSDK {
195
+ private config;
196
+ /**
197
+ * Initialize the InflowPay Payment SDK
198
+ *
199
+ * @param config - SDK configuration
200
+ *
201
+ * @example
202
+ * ```typescript
203
+ * const sdk = new PaymentSDK({
204
+ * apiKey: 'inflow_pub_local_xxx'
205
+ * });
206
+ * ```
207
+ */
208
+ constructor(config: PaymentSDKConfig);
209
+ /**
210
+ * Create a CardElement for iframe-based payment UI
211
+ *
212
+ * @param options - CardElement configuration
213
+ * @returns CardElement instance
214
+ *
215
+ * @example
216
+ * ```typescript
217
+ * const cardElement = sdk.createCardElement({
218
+ * container: '#card-container',
219
+ * paymentId: 'pay_123',
220
+ * onComplete: (result) => {
221
+ * if (result.status === 'CHECKOUT_SUCCESS') {
222
+ * window.location.href = '/success';
223
+ * }
224
+ * }
225
+ * });
226
+ *
227
+ * cardElement.mount();
228
+ * ```
229
+ */
230
+ createCardElement(options: {
231
+ container: string | HTMLElement;
232
+ paymentId: string;
233
+ style?: CSSProperties;
234
+ buttonText?: string;
235
+ placeholders?: {
236
+ cardNumber?: string;
237
+ expiry?: string;
238
+ cvc?: string;
239
+ };
240
+ onComplete?: (result: {
241
+ status: string;
242
+ data?: any;
243
+ error?: any;
244
+ }) => void;
245
+ onError?: (error: any) => void;
246
+ onClose?: () => void;
247
+ }): CardElement_2;
248
+ /**
249
+ * Get the iframe URL being used
250
+ */
251
+ getIframeUrl(): string;
252
+ /**
253
+ * Get the API key
254
+ */
255
+ getApiKey(): string;
256
+ /**
257
+ * Auto-detect environment from API key
258
+ */
259
+ private getEnvironmentFromApiKey;
260
+ }
261
+
262
+ declare interface PaymentSDKConfig {
263
+ /** Public API key */
264
+ apiKey: string;
265
+ /** Backend API URL (optional, auto-detected from API key) */
266
+ iframeUrl?: string;
267
+ /** Request timeout in milliseconds (default: 30000) */
268
+ timeout?: number;
269
+ /** Enable debug logging (default: false, only allowed in local/dev environments) */
270
+ debug?: boolean;
271
+ }
272
+
273
+ export declare interface SDKConfig {
274
+ apiKey: string;
275
+ iframeUrl?: string;
276
+ timeout?: number;
277
+ /** Enable debug logging (default: false, only allowed in local/dev environments) */
278
+ debug?: boolean;
279
+ }
280
+
281
+ declare interface ThemeStyles {
282
+ inputContainer?: InputContainerStyles;
283
+ input?: InputStyles;
284
+ button?: ButtonStyles;
285
+ disclaimerColor?: string;
286
+ fieldErrorColor?: string;
287
+ generalError?: GeneralMessageStyles;
288
+ generalSuccess?: GeneralMessageStyles;
289
+ }
290
+
291
+ /**
292
+ * useInflowPay - Hook to access InflowPay SDK instance
293
+ *
294
+ * @example
295
+ * ```tsx
296
+ * function CustomComponent() {
297
+ * const inflow = useInflowPay();
298
+ *
299
+ * const checkStatus = async () => {
300
+ * const status = await inflow.getPaymentStatus('pay_xxx');
301
+ * console.log(status);
302
+ * };
303
+ *
304
+ * return <button onClick={checkStatus}>Check Status</button>;
305
+ * }
306
+ * ```
307
+ */
308
+ export declare function useInflowPay(): PaymentSDK;
309
+
310
+ export { }
package/dist/react.cjs ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const E=require("react/jsx-runtime"),t=require("react"),v=require("./payment-sdk-BWb7DDT1.js"),P=t.createContext(null);function b({config:e,children:u}){const[i]=t.useState(()=>{const r={apiKey:e.apiKey,iframeUrl:e.iframeUrl,timeout:e.timeout,debug:e.debug};return new v.PaymentSDK(r)});return E.jsx(P.Provider,{value:{sdk:i},children:u})}function k(){const e=t.useContext(P);if(!e)throw new Error("useInflowPay must be used within InflowPayProvider");return e.sdk}function K({paymentId:e,onReady:u,onChange:i,onComplete:r,onError:f,style:o,buttonText:l,placeholders:d,config:s}){const x=t.useContext(P),c=t.useRef(null),a=t.useRef(null),[m,I]=t.useState(!1),w=x?.sdk||(s?new v.PaymentSDK({apiKey:s.apiKey,iframeUrl:s.iframeUrl,timeout:s.timeout,debug:s.debug}):null);if(!w)throw new Error("CardElement must be used within InflowPayProvider or have a config prop");return t.useEffect(()=>{if(!c.current)return;c.current.id||(c.current.id=`inflowpay-card-element-${Date.now()}`);const S={container:c.current,paymentId:e,...o&&{style:o},...l&&{buttonText:l},...d&&{placeholders:d},onComplete:n=>{r&&r(n)},onError:n=>{f?f(n):r&&r({status:"PAYMENT_FAILED",error:n})},onClose:()=>{}},y=w.createCardElement(S);if(a.current=y,y.mount(),I(!0),u){const n=setTimeout(()=>{u()},100);return()=>clearTimeout(n)}},[e,w,m,r,f,u,o,l,d]),t.useEffect(()=>{i&&m&&i({complete:!1})},[m,i]),t.useEffect(()=>()=>{a.current&&(a.current.destroy(),a.current=null)},[]),E.jsx("div",{ref:c,style:{width:o?.fillParent?"100%":"344px"}})}exports.CardElement=K;exports.InflowPayProvider=b;exports.useInflowPay=k;
2
+ //# sourceMappingURL=react.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react.cjs","sources":["../src/react/index.tsx"],"sourcesContent":["/**\n * InflowPay React SDK v2 - React Components\n * \n * React components that use the iframe-based SDK v2\n * Same API as the original React SDK for easy migration\n */\n\nimport React, { createContext, useContext, useEffect, useRef, useState } from 'react';\nimport type { ReactNode } from 'react';\nimport { PaymentSDK } from '../payment-sdk';\nimport type { PaymentSDKConfig } from '../payment-sdk';\nimport type { CardElement as CardElementClass } from '../card-element';\nimport type { CardElementOptions } from '../card-element';\nimport type { CSSProperties } from '../types';\n\nexport interface SDKConfig {\n apiKey: string;\n iframeUrl?: string;\n timeout?: number;\n /** Enable debug logging (default: false, only allowed in local/dev environments) */\n debug?: boolean;\n}\n\nexport interface PaymentResult {\n status: string;\n data?: any;\n error?: {\n code: string;\n message: string;\n retryable: boolean;\n };\n}\n\nexport interface PaymentError {\n code: string;\n message: string;\n retryable: boolean;\n}\n\nexport interface CardElementState {\n complete: boolean;\n}\n\nexport interface CardElementProps {\n paymentId: string;\n onReady?: () => void;\n onChange?: (state: CardElementState) => void;\n onComplete?: (result: PaymentResult) => void;\n onError?: (error: PaymentError) => void;\n style?: CSSProperties;\n buttonText?: string;\n placeholders?: {\n cardNumber?: string;\n expiry?: string;\n cvc?: string;\n };\n}\n\ninterface InflowPayContextValue {\n sdk: PaymentSDK;\n}\n\nconst InflowPayContext = createContext<InflowPayContextValue | null>(null);\n\n/**\n * InflowPayProvider - React component\n * \n * Same API as the original React SDK\n * \n * @example\n * ```tsx\n * <InflowPayProvider config={{ apiKey: 'inflow_pub_xxx' }}>\n * <CardElement\n * paymentId=\"pay_xxx\"\n * onComplete={(result) => {\n * if (result.status === 'CHECKOUT_SUCCESS') {\n * window.location.href = '/success';\n * }\n * }}\n * />\n * </InflowPayProvider>\n * ```\n */\nexport function InflowPayProvider({\n config,\n children,\n}: {\n config: SDKConfig;\n children: ReactNode;\n}) {\n const [sdk] = useState(() => {\n const sdkConfig: PaymentSDKConfig = {\n apiKey: config.apiKey,\n iframeUrl: config.iframeUrl,\n timeout: config.timeout,\n debug: config.debug,\n };\n return new PaymentSDK(sdkConfig);\n });\n\n return (\n <InflowPayContext.Provider value={{ sdk }}>\n {children}\n </InflowPayContext.Provider>\n );\n}\n\n/**\n * useInflowPay - Hook to access InflowPay SDK instance\n * \n * @example\n * ```tsx\n * function CustomComponent() {\n * const inflow = useInflowPay();\n * \n * const checkStatus = async () => {\n * const status = await inflow.getPaymentStatus('pay_xxx');\n * console.log(status);\n * };\n * \n * return <button onClick={checkStatus}>Check Status</button>;\n * }\n * ```\n */\nexport function useInflowPay(): PaymentSDK {\n const context = useContext(InflowPayContext);\n if (!context) {\n throw new Error('useInflowPay must be used within InflowPayProvider');\n }\n return context.sdk;\n}\n\n/**\n * CardElement - React component\n * \n * Same API as the original React SDK\n * \n * @example\n * ```tsx\n * <CardElement\n * paymentId=\"pay_xxx\"\n * onComplete={(result) => {\n * if (result.status === 'CHECKOUT_SUCCESS') {\n * window.location.href = '/success';\n * }\n * }}\n * />\n * ```\n */\nexport function CardElement({\n paymentId,\n onReady,\n onChange,\n onComplete,\n onError,\n style,\n buttonText,\n placeholders,\n config: propConfig,\n}: CardElementProps & { config?: SDKConfig }) {\n const context = useContext(InflowPayContext);\n const containerRef = useRef<HTMLDivElement>(null);\n const cardElementRef = useRef<CardElementClass | null>(null);\n const [mounted, setMounted] = useState(false);\n\n const sdk = context?.sdk || (propConfig ? new PaymentSDK({\n apiKey: propConfig.apiKey,\n iframeUrl: propConfig.iframeUrl,\n timeout: propConfig.timeout,\n debug: propConfig.debug,\n }) : null);\n\n if (!sdk) {\n throw new Error('CardElement must be used within InflowPayProvider or have a config prop');\n }\n\n useEffect(() => {\n if (!containerRef.current) {\n return;\n }\n\n if (!containerRef.current.id) {\n containerRef.current.id = `inflowpay-card-element-${Date.now()}`;\n }\n\n const cardElementOptions: CardElementOptions = {\n container: containerRef.current,\n paymentId: paymentId,\n ...(style && { style }),\n ...(buttonText && { buttonText }),\n ...(placeholders && { placeholders }),\n onComplete: (result) => {\n if (onComplete) {\n onComplete(result);\n }\n },\n onError: (error) => {\n if (onError) {\n onError(error);\n } else if (onComplete) {\n onComplete({\n status: 'PAYMENT_FAILED',\n error: error,\n });\n }\n },\n onClose: () => {\n },\n };\n\n const cardElement = sdk.createCardElement(cardElementOptions);\n cardElementRef.current = cardElement;\n cardElement.mount();\n setMounted(true);\n\n if (onReady) {\n const timer = setTimeout(() => {\n onReady();\n }, 100);\n return () => clearTimeout(timer);\n }\n }, [paymentId, sdk, mounted, onComplete, onError, onReady, style, buttonText, placeholders]);\n\n useEffect(() => {\n if (onChange && mounted) {\n onChange({ complete: false });\n }\n }, [mounted, onChange]);\n\n useEffect(() => {\n return () => {\n if (cardElementRef.current) {\n cardElementRef.current.destroy();\n cardElementRef.current = null;\n }\n };\n }, []);\n\n return (\n <div\n ref={containerRef}\n style={{\n width: style?.fillParent ? \"100%\" : \"344px\"\n }}\n />\n );\n}\n"],"names":["InflowPayContext","createContext","InflowPayProvider","config","children","sdk","useState","sdkConfig","PaymentSDK","jsx","useInflowPay","context","useContext","CardElement","paymentId","onReady","onChange","onComplete","onError","style","buttonText","placeholders","propConfig","containerRef","useRef","cardElementRef","mounted","setMounted","useEffect","cardElementOptions","result","error","cardElement","timer"],"mappings":"+KA8DMA,EAAmBC,EAAAA,cAA4C,IAAI,EAqBlE,SAASC,EAAkB,CAChC,OAAAC,EACA,SAAAC,CACF,EAGG,CACD,KAAM,CAACC,CAAG,EAAIC,EAAAA,SAAS,IAAM,CAC3B,MAAMC,EAA8B,CAClC,OAAQJ,EAAO,OACf,UAAWA,EAAO,UAClB,QAASA,EAAO,QAChB,MAAOA,EAAO,KAAA,EAEhB,OAAO,IAAIK,EAAAA,WAAWD,CAAS,CACjC,CAAC,EAED,OACEE,EAAAA,IAACT,EAAiB,SAAjB,CAA0B,MAAO,CAAE,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