@getopenpay/openpay-js-react 0.0.2 → 0.0.3-alpha.4e3a3ab
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 +59 -8
- package/dist/index.d.ts +103 -0
- package/dist/index.js +3145 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,14 +1,65 @@
|
|
|
1
1
|
# openpay-js-react
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## Installation
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
```shell npm
|
|
6
|
+
npm install @getopenpay/openpay-js-react
|
|
7
|
+
```
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
13
|
+
```shell pnpm
|
|
14
|
+
pnpm add @getopenpay/openpay-js-react
|
|
15
|
+
```
|
|
13
16
|
|
|
14
|
-
|
|
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
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
declare const AllFieldNames: z.ZodUnion<[z.ZodNativeEnum<typeof FieldName>, z.ZodNativeEnum<typeof PrivateFieldName>]>;
|
|
5
|
+
|
|
6
|
+
declare type AllFieldNames = z.infer<typeof AllFieldNames>;
|
|
7
|
+
|
|
8
|
+
export declare const CardCvcElement: FC<ElementProps>;
|
|
9
|
+
|
|
10
|
+
export declare const CardElement: FC<ElementProps>;
|
|
11
|
+
|
|
12
|
+
export declare const CardExpiryElement: FC<ElementProps>;
|
|
13
|
+
|
|
14
|
+
export declare const CardNumberElement: FC<ElementProps>;
|
|
15
|
+
|
|
16
|
+
export declare type ElementProps = {
|
|
17
|
+
styles?: ElementsStyle;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
declare type ElementsContextValue = {
|
|
21
|
+
formId: string;
|
|
22
|
+
formHeight: string;
|
|
23
|
+
referer?: string;
|
|
24
|
+
checkoutSecureToken?: string;
|
|
25
|
+
registerIframe: (iframe: HTMLIFrameElement) => void;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export declare const ElementsForm: FC<ElementsFormProps>;
|
|
29
|
+
|
|
30
|
+
declare type ElementsFormChildrenProps = {
|
|
31
|
+
submit: () => void;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export declare type ElementsFormProps = {
|
|
35
|
+
className?: string;
|
|
36
|
+
checkoutSecureToken?: string;
|
|
37
|
+
children: (props: ElementsFormChildrenProps) => JSX.Element;
|
|
38
|
+
onFocus?: (elementId: string) => void;
|
|
39
|
+
onBlur?: (elementId: string) => void;
|
|
40
|
+
onChange?: (elementId: string) => void;
|
|
41
|
+
onLoad?: (totalAmountAtoms: number, currency?: string) => void;
|
|
42
|
+
onLoadError?: (message: string) => void;
|
|
43
|
+
onValidationError?: (field: AllFieldNames, errors: string[], elementId?: string) => void;
|
|
44
|
+
onCheckoutStarted?: () => void;
|
|
45
|
+
onCheckoutSuccess?: (invoiceUrls: string[]) => void;
|
|
46
|
+
onCheckoutError?: (message: string) => void;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Styles
|
|
51
|
+
*/
|
|
52
|
+
declare const ElementsStyle: z.ZodObject<{
|
|
53
|
+
backgroundColor: z.ZodOptional<z.ZodString>;
|
|
54
|
+
color: z.ZodOptional<z.ZodString>;
|
|
55
|
+
fontFamily: z.ZodOptional<z.ZodString>;
|
|
56
|
+
fontSize: z.ZodOptional<z.ZodString>;
|
|
57
|
+
fontWeight: z.ZodOptional<z.ZodString>;
|
|
58
|
+
margin: z.ZodOptional<z.ZodString>;
|
|
59
|
+
padding: z.ZodOptional<z.ZodString>;
|
|
60
|
+
}, "strip", z.ZodTypeAny, {
|
|
61
|
+
backgroundColor?: string | undefined;
|
|
62
|
+
color?: string | undefined;
|
|
63
|
+
fontFamily?: string | undefined;
|
|
64
|
+
fontSize?: string | undefined;
|
|
65
|
+
fontWeight?: string | undefined;
|
|
66
|
+
margin?: string | undefined;
|
|
67
|
+
padding?: string | undefined;
|
|
68
|
+
}, {
|
|
69
|
+
backgroundColor?: string | undefined;
|
|
70
|
+
color?: string | undefined;
|
|
71
|
+
fontFamily?: string | undefined;
|
|
72
|
+
fontSize?: string | undefined;
|
|
73
|
+
fontWeight?: string | undefined;
|
|
74
|
+
margin?: string | undefined;
|
|
75
|
+
padding?: string | undefined;
|
|
76
|
+
}>;
|
|
77
|
+
|
|
78
|
+
declare type ElementsStyle = z.infer<typeof ElementsStyle>;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Expected input fields
|
|
82
|
+
*/
|
|
83
|
+
export declare enum FieldName {
|
|
84
|
+
FIRST_NAME = "firstName",
|
|
85
|
+
LAST_NAME = "lastName",
|
|
86
|
+
EMAIL = "email",
|
|
87
|
+
ZIP_CODE = "zipCode",
|
|
88
|
+
CITY = "city",
|
|
89
|
+
STATE = "state",
|
|
90
|
+
COUNTRY = "country",
|
|
91
|
+
ADDRESS = "address",
|
|
92
|
+
PHONE = "phone"
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
declare enum PrivateFieldName {
|
|
96
|
+
CARD_NUMBER = "cardNumber",
|
|
97
|
+
CARD_EXPIRY = "cardExpiry",
|
|
98
|
+
CARD_CVC = "cardCvc"
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export declare const useOpenPayElements: () => ElementsContextValue;
|
|
102
|
+
|
|
103
|
+
export { }
|