@getopenpay/openpay-js-react 0.0.2-beta.1 → 0.0.3-alpha.de11edb

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 CHANGED
@@ -1,14 +1,65 @@
1
1
  # openpay-js-react
2
2
 
3
- React components for OpenPay.JS
3
+ ## Installation
4
4
 
5
- ## Development
5
+ ```shell npm
6
+ npm install @getopenpay/openpay-js-react
7
+ ```
6
8
 
7
- 1. Install dependencies using `make install`
8
- 2. Run `make dev` to start Vite in watch mode
9
- 3. In another terminal, `cd` into the `example` directory and run `make dev` to start the example app
10
- 4. Open [http://localhost:3032](http://localhost:3032) to see the example app
9
+ ```shell yarn
10
+ yarn add @getopenpay/openpay-js-react
11
+ ```
11
12
 
12
- When you make changes to the library, Vite will automatically recompile it and NextJS will automatically reload the page.
13
+ ```shell pnpm
14
+ pnpm add @getopenpay/openpay-js-react
15
+ ```
13
16
 
14
- If NextJS doesn't reload, you can try manually refreshing the page, or reinstalling the library using `npm install ../` in the `example` directory.
17
+ ## Usage
18
+
19
+ See example usage here ([example usages](https://dash.readme.com/go/getopenpay?redirect=%2Fv1.0%2Fdocs%2Fexamples))
20
+
21
+ ## Concepts
22
+
23
+ ### Elements
24
+
25
+ Elements are the embeds of secure web pages hosted on our servers. Elements must be used within the provider,`<ElementsForm />`, which provides context required by the elements.
26
+
27
+ `<ElementsForm />` needs `checkoutSecureToken` which can be generated by creating a checkout session via OpenPay Python SDK. [Create Checkout Session](ref:create_checkout_session)
28
+
29
+ The library provides separate card elements (Card number, expiry, CVV) and a combination these elements in a single line input field.
30
+
31
+ - `<CardNumberElement />`
32
+ - `<CardExpiryElement />`
33
+ - `<CardCvcElement />`
34
+ - `<CardElement />` (Combined)
35
+
36
+ ### Billing information
37
+
38
+ Customer billing information is required to proceed checkout. You can implement the input fields for billing information in your own way. Since you're in control of these fields, you can perform custom validations, custom styling and auto-fill with user account information.
39
+ For OpenPay to access the input fields, please include `data-opid` attribute with predefined field names which can be accessed via `FieldName`.
40
+
41
+ Available field names:
42
+
43
+ - `FieldName.FIRST_NAME`
44
+ - `FieldName.LAST_NAME`
45
+ - `FieldName.EMAIL`
46
+ - `FieldName.ZIP_CODE`
47
+ - `FieldName.CITY`
48
+ - `FieldName.STATE`
49
+ - `FieldName.COUNTRY`
50
+ - `FieldName.ADDRESS`
51
+ - `FieldName.PHONE`
52
+
53
+ ### Styling
54
+
55
+ By default, the elements provided are "Unstyled". They will have transparent background and text color adaptive to system's color scheme. You can wrap an element inside a container to which you can apply customized styling ([Examples](doc:examples)).
56
+
57
+ If you want to customize the styling of the element itself you can apply via the optional `styles` prop. The following are supported properties. These support any valid CSS values.
58
+
59
+ - `backgroundColor`
60
+ - `color`
61
+ - `fontFamily`
62
+ - `fontSize`
63
+ - `fontWeight`
64
+ - `margin`
65
+ - `padding`
package/dist/index.d.ts CHANGED
@@ -1,147 +1,9 @@
1
1
  import { FC } from 'react';
2
2
  import { z } from 'zod';
3
3
 
4
- export declare const Appearance: z.ZodObject<{
5
- theme: z.ZodEnum<[AppearanceTheme.UNSTYLED, AppearanceTheme.LIGHT, AppearanceTheme.DARK]>;
6
- variables: z.ZodOptional<z.ZodObject<{
7
- colorPrimary: z.ZodOptional<z.ZodString>;
8
- colorBackground: z.ZodOptional<z.ZodString>;
9
- colorForeground: z.ZodOptional<z.ZodString>;
10
- colorText: z.ZodOptional<z.ZodString>;
11
- colorDanger: z.ZodOptional<z.ZodString>;
12
- fontFamily: z.ZodOptional<z.ZodString>;
13
- fontSize: z.ZodOptional<z.ZodString>;
14
- spacing: z.ZodOptional<z.ZodString>;
15
- borderRadius: z.ZodOptional<z.ZodString>;
16
- borderColor: z.ZodOptional<z.ZodString>;
17
- borderWidth: z.ZodOptional<z.ZodString>;
18
- focusRingColor: z.ZodOptional<z.ZodString>;
19
- padding: z.ZodOptional<z.ZodString>;
20
- }, "strip", z.ZodTypeAny, {
21
- colorPrimary?: string | undefined;
22
- colorBackground?: string | undefined;
23
- colorForeground?: string | undefined;
24
- colorText?: string | undefined;
25
- colorDanger?: string | undefined;
26
- fontFamily?: string | undefined;
27
- fontSize?: string | undefined;
28
- spacing?: string | undefined;
29
- borderRadius?: string | undefined;
30
- borderColor?: string | undefined;
31
- borderWidth?: string | undefined;
32
- focusRingColor?: string | undefined;
33
- padding?: string | undefined;
34
- }, {
35
- colorPrimary?: string | undefined;
36
- colorBackground?: string | undefined;
37
- colorForeground?: string | undefined;
38
- colorText?: string | undefined;
39
- colorDanger?: string | undefined;
40
- fontFamily?: string | undefined;
41
- fontSize?: string | undefined;
42
- spacing?: string | undefined;
43
- borderRadius?: string | undefined;
44
- borderColor?: string | undefined;
45
- borderWidth?: string | undefined;
46
- focusRingColor?: string | undefined;
47
- padding?: string | undefined;
48
- }>>;
49
- }, "strip", z.ZodTypeAny, {
50
- theme: AppearanceTheme;
51
- variables?: {
52
- colorPrimary?: string | undefined;
53
- colorBackground?: string | undefined;
54
- colorForeground?: string | undefined;
55
- colorText?: string | undefined;
56
- colorDanger?: string | undefined;
57
- fontFamily?: string | undefined;
58
- fontSize?: string | undefined;
59
- spacing?: string | undefined;
60
- borderRadius?: string | undefined;
61
- borderColor?: string | undefined;
62
- borderWidth?: string | undefined;
63
- focusRingColor?: string | undefined;
64
- padding?: string | undefined;
65
- } | undefined;
66
- }, {
67
- theme: AppearanceTheme;
68
- variables?: {
69
- colorPrimary?: string | undefined;
70
- colorBackground?: string | undefined;
71
- colorForeground?: string | undefined;
72
- colorText?: string | undefined;
73
- colorDanger?: string | undefined;
74
- fontFamily?: string | undefined;
75
- fontSize?: string | undefined;
76
- spacing?: string | undefined;
77
- borderRadius?: string | undefined;
78
- borderColor?: string | undefined;
79
- borderWidth?: string | undefined;
80
- focusRingColor?: string | undefined;
81
- padding?: string | undefined;
82
- } | undefined;
83
- }>;
4
+ declare const AllFieldNames: z.ZodUnion<[z.ZodNativeEnum<typeof FieldName>, z.ZodNativeEnum<typeof PrivateFieldName>]>;
84
5
 
85
- export declare type Appearance = z.infer<typeof Appearance>;
86
-
87
- /**
88
- * Models shared between CDE and OpenPay.js
89
- * Don't forget to update shared-models.ts in the other repo's utils folder too!
90
- */
91
- /**
92
- * Styles and appearance
93
- */
94
- export declare enum AppearanceTheme {
95
- UNSTYLED = "unstyled",
96
- LIGHT = "light",
97
- DARK = "dark"
98
- }
99
-
100
- export declare const AppearanceVariables: z.ZodObject<{
101
- colorPrimary: z.ZodOptional<z.ZodString>;
102
- colorBackground: z.ZodOptional<z.ZodString>;
103
- colorForeground: z.ZodOptional<z.ZodString>;
104
- colorText: z.ZodOptional<z.ZodString>;
105
- colorDanger: z.ZodOptional<z.ZodString>;
106
- fontFamily: z.ZodOptional<z.ZodString>;
107
- fontSize: z.ZodOptional<z.ZodString>;
108
- spacing: z.ZodOptional<z.ZodString>;
109
- borderRadius: z.ZodOptional<z.ZodString>;
110
- borderColor: z.ZodOptional<z.ZodString>;
111
- borderWidth: z.ZodOptional<z.ZodString>;
112
- focusRingColor: z.ZodOptional<z.ZodString>;
113
- padding: z.ZodOptional<z.ZodString>;
114
- }, "strip", z.ZodTypeAny, {
115
- colorPrimary?: string | undefined;
116
- colorBackground?: string | undefined;
117
- colorForeground?: string | undefined;
118
- colorText?: string | undefined;
119
- colorDanger?: string | undefined;
120
- fontFamily?: string | undefined;
121
- fontSize?: string | undefined;
122
- spacing?: string | undefined;
123
- borderRadius?: string | undefined;
124
- borderColor?: string | undefined;
125
- borderWidth?: string | undefined;
126
- focusRingColor?: string | undefined;
127
- padding?: string | undefined;
128
- }, {
129
- colorPrimary?: string | undefined;
130
- colorBackground?: string | undefined;
131
- colorForeground?: string | undefined;
132
- colorText?: string | undefined;
133
- colorDanger?: string | undefined;
134
- fontFamily?: string | undefined;
135
- fontSize?: string | undefined;
136
- spacing?: string | undefined;
137
- borderRadius?: string | undefined;
138
- borderColor?: string | undefined;
139
- borderWidth?: string | undefined;
140
- focusRingColor?: string | undefined;
141
- padding?: string | undefined;
142
- }>;
143
-
144
- export declare type AppearanceVariables = z.infer<typeof AppearanceVariables>;
6
+ declare type AllFieldNames = z.infer<typeof AllFieldNames>;
145
7
 
146
8
  export declare const CardCvcElement: FC<ElementProps>;
147
9
 
@@ -151,16 +13,16 @@ export declare const CardExpiryElement: FC<ElementProps>;
151
13
 
152
14
  export declare const CardNumberElement: FC<ElementProps>;
153
15
 
154
- declare type ElementProps = {
16
+ export declare type ElementProps = {
155
17
  styles?: ElementsStyle;
156
18
  };
157
19
 
158
20
  declare type ElementsContextValue = {
159
- contextId: string;
21
+ formId: string;
160
22
  formHeight: string;
161
23
  referer?: string;
162
24
  checkoutSecureToken?: string;
163
- appearance?: Appearance;
25
+ registerIframe: (iframe: HTMLIFrameElement) => void;
164
26
  };
165
27
 
166
28
  export declare const ElementsForm: FC<ElementsFormProps>;
@@ -169,22 +31,24 @@ declare type ElementsFormChildrenProps = {
169
31
  submit: () => void;
170
32
  };
171
33
 
172
- declare type ElementsFormProps = {
34
+ export declare type ElementsFormProps = {
173
35
  className?: string;
174
- appearance?: Appearance;
175
36
  checkoutSecureToken?: string;
176
37
  children: (props: ElementsFormChildrenProps) => JSX.Element;
177
38
  onFocus?: (elementId: string) => void;
178
39
  onBlur?: (elementId: string) => void;
179
40
  onChange?: (elementId: string) => void;
180
- onLoad?: (totalAmountAtoms: number) => void;
41
+ onLoad?: (totalAmountAtoms: number, currency?: string) => void;
181
42
  onLoadError?: (message: string) => void;
182
- onValidationError?: (message: string, elementId?: string) => void;
43
+ onValidationError?: (field: AllFieldNames, errors: string[], elementId?: string) => void;
183
44
  onCheckoutStarted?: () => void;
184
45
  onCheckoutSuccess?: (invoiceUrls: string[]) => void;
185
46
  onCheckoutError?: (message: string) => void;
186
47
  };
187
48
 
49
+ /**
50
+ * Styles
51
+ */
188
52
  declare const ElementsStyle: z.ZodObject<{
189
53
  backgroundColor: z.ZodOptional<z.ZodString>;
190
54
  color: z.ZodOptional<z.ZodString>;
@@ -194,27 +58,27 @@ declare const ElementsStyle: z.ZodObject<{
194
58
  margin: z.ZodOptional<z.ZodString>;
195
59
  padding: z.ZodOptional<z.ZodString>;
196
60
  }, "strip", z.ZodTypeAny, {
197
- fontFamily?: string | undefined;
198
- fontSize?: string | undefined;
199
- padding?: string | undefined;
200
61
  backgroundColor?: string | undefined;
201
62
  color?: string | undefined;
202
- fontWeight?: string | undefined;
203
- margin?: string | undefined;
204
- }, {
205
63
  fontFamily?: string | undefined;
206
64
  fontSize?: string | undefined;
65
+ fontWeight?: string | undefined;
66
+ margin?: string | undefined;
207
67
  padding?: string | undefined;
68
+ }, {
208
69
  backgroundColor?: string | undefined;
209
70
  color?: string | undefined;
71
+ fontFamily?: string | undefined;
72
+ fontSize?: string | undefined;
210
73
  fontWeight?: string | undefined;
211
74
  margin?: string | undefined;
75
+ padding?: string | undefined;
212
76
  }>;
213
77
 
214
78
  declare type ElementsStyle = z.infer<typeof ElementsStyle>;
215
79
 
216
80
  /**
217
- * Form field names
81
+ * Expected input fields
218
82
  */
219
83
  export declare enum FieldName {
220
84
  FIRST_NAME = "firstName",
@@ -228,6 +92,12 @@ export declare enum FieldName {
228
92
  PHONE = "phone"
229
93
  }
230
94
 
95
+ declare enum PrivateFieldName {
96
+ CARD_NUMBER = "cardNumber",
97
+ CARD_EXPIRY = "cardExpiry",
98
+ CARD_CVC = "cardCvc"
99
+ }
100
+
231
101
  export declare const useOpenPayElements: () => ElementsContextValue;
232
102
 
233
103
  export { }