@rebilly/framepay-react 2.0.1 → 2.2.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/.env.example +2 -0
- package/CHANGELOG.md +14 -0
- package/build/index.spec.js +2 -6
- package/build/lib/components/elements/applepay-element.js +3 -3
- package/build/lib/components/elements/bank-element.js +7 -10
- package/build/lib/components/elements/base-element.js +2 -6
- package/build/lib/components/elements/card-element.js +7 -10
- package/build/lib/components/elements/googlepay-element.js +3 -3
- package/build/lib/components/elements/iban-element.js +8 -15
- package/build/lib/components/elements/paypal-element.js +3 -3
- package/build/lib/components/injector.js +10 -30
- package/build/lib/components/provider.js +10 -14
- package/build/lib/constants.js +11 -15
- package/build/lib/context.js +3 -7
- package/env.js +7 -0
- package/package.json +25 -14
- package/src/index.spec.ts +19 -0
- package/src/index.ts +42 -0
- package/src/lib/components/elements/applepay-element.tsx +36 -0
- package/src/lib/components/elements/bank-element.spec.tsx +119 -0
- package/src/lib/components/elements/bank-element.tsx +77 -0
- package/src/lib/components/elements/base-element.tsx +100 -0
- package/src/lib/components/elements/card-element.spec.tsx +113 -0
- package/src/lib/components/elements/card-element.tsx +76 -0
- package/src/lib/components/elements/googlepay-element.tsx +36 -0
- package/src/lib/components/elements/iban-element.spec.tsx +104 -0
- package/src/lib/components/elements/iban-element.tsx +78 -0
- package/src/lib/components/elements/paypal-element.tsx +36 -0
- package/src/lib/components/injector.spec.tsx +162 -0
- package/src/lib/components/injector.tsx +495 -0
- package/src/lib/components/provider.spec.tsx +98 -0
- package/src/lib/components/provider.tsx +111 -0
- package/src/lib/constants.ts +43 -0
- package/src/lib/context.ts +24 -0
- package/src/lib/dom-util.ts +35 -0
- package/src/lib/framepay-error.ts +59 -0
- package/src/lib/get-rebilly-api.ts +11 -0
- package/test/e2e/assets/prop-types.js +849 -0
- package/test/e2e/assets/react-0.14.0.js +18759 -0
- package/test/e2e/assets/react-15.0.0.js +19309 -0
- package/test/e2e/assets/react-16.js +3318 -0
- package/test/e2e/assets/react-17.js +3357 -0
- package/test/e2e/assets/react-18.js +3342 -0
- package/test/e2e/assets/react-dom-0.14.0.js +42 -0
- package/test/e2e/assets/react-dom-15.0.0.js +42 -0
- package/test/e2e/assets/react-dom-16.js +25147 -0
- package/test/e2e/assets/react-dom-17.js +26292 -0
- package/test/e2e/assets/react-dom-18.js +29869 -0
- package/test/e2e/cypress-support.js +2 -0
- package/test/e2e/cypress.d.ts +1 -0
- package/test/e2e/fixtures/apple-pay.html +15 -0
- package/test/e2e/fixtures/apple-pay.js +63 -0
- package/test/e2e/fixtures/bank-separate.html +12 -0
- package/test/e2e/fixtures/bank-separate.js +323 -0
- package/test/e2e/fixtures/card-separate-brands.html +12 -0
- package/test/e2e/fixtures/card-separate-brands.js +260 -0
- package/test/e2e/fixtures/card-separate-rebilly-fields.html +12 -0
- package/test/e2e/fixtures/card-separate-rebilly-fields.js +281 -0
- package/test/e2e/fixtures/card-separate.html +12 -0
- package/test/e2e/fixtures/card-separate.js +227 -0
- package/test/e2e/fixtures/checkout-combined.html +12 -0
- package/test/e2e/fixtures/checkout-combined.js +199 -0
- package/test/e2e/fixtures/google-pay.html +15 -0
- package/test/e2e/fixtures/google-pay.js +63 -0
- package/test/e2e/fixtures/iban.html +12 -0
- package/test/e2e/fixtures/iban.js +239 -0
- package/test/e2e/fixtures/multiple-methods.html +12 -0
- package/test/e2e/fixtures/multiple-methods.js +470 -0
- package/test/e2e/fixtures/nav.js +20 -0
- package/test/e2e/fixtures/paypal.html +15 -0
- package/test/e2e/fixtures/paypal.js +62 -0
- package/test/e2e/fixtures/style.css +55 -0
- package/test/e2e/fixtures/util.js +71 -0
- package/test/e2e/local-server.mjs +12 -0
- package/test/e2e/server.mjs +43 -0
- package/test/e2e/specs/bank-separate.cy.ts +27 -0
- package/test/e2e/specs/card-separate-brands.cy.ts +68 -0
- package/test/e2e/specs/card-separate.cy.ts +27 -0
- package/test/e2e/specs/checkout-combined.cy.ts +24 -0
- package/test/e2e/specs/google-pay.cy.ts +13 -0
- package/test/e2e/specs/iban.cy.ts +17 -0
- package/test/e2e/specs/multiple-methods.cy.ts +128 -0
- package/test/e2e/specs/paypal.cy.ts +13 -0
- package/test/e2e/specs/react-version.cy.ts +12 -0
- package/test/e2e/switch-react-version.js +42 -0
- package/test/e2e/tsconfig.json +8 -0
- package/test/unit/jest.config.js +29 -0
- package/test/unit/specs/declaration-mock.spec.tsx +143 -0
- package/tsconfig.json +31 -0
- package/tsconfig.spec.json +13 -0
- package/tslint.json +36 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* Constants file.
|
|
6
|
+
* Links to the remote library FramePay and other settings.
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The ReactJS version 14+
|
|
12
|
+
* used in context.ts
|
|
13
|
+
*/
|
|
14
|
+
export const REACT_VERSION = React.version;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Remote FramePay library CDN link.
|
|
18
|
+
*/
|
|
19
|
+
export const FRAMEPAY_SCRIPT_LINK: string =
|
|
20
|
+
process.env.FRAMEPAY_SCRIPT_LINK ||
|
|
21
|
+
'https://framepay.rebilly.com/rebilly.js';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Remote FramePay style CDN link.
|
|
25
|
+
*/
|
|
26
|
+
export const FRAMEPAY_STYLE_LINK: string =
|
|
27
|
+
process.env.FRAMEPAY_STYLE_LINK ||
|
|
28
|
+
'https://framepay.rebilly.com/rebilly.css';
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Supported FramePay card types
|
|
32
|
+
*/
|
|
33
|
+
export const SUPPORTED_CARD_BRANDS: SupportedCardBrandsObject = {
|
|
34
|
+
Amex: SupportedCardBrands.Amex,
|
|
35
|
+
AstroPayCard: SupportedCardBrands.AstroPayCard,
|
|
36
|
+
Cup: SupportedCardBrands.Cup,
|
|
37
|
+
DinersClub: SupportedCardBrands.DinersClub,
|
|
38
|
+
Discover: SupportedCardBrands.Discover,
|
|
39
|
+
JCB: SupportedCardBrands.JCB,
|
|
40
|
+
Maestro: SupportedCardBrands.Maestro,
|
|
41
|
+
MasterCard: SupportedCardBrands.MasterCard,
|
|
42
|
+
Visa: SupportedCardBrands.Visa
|
|
43
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { REACT_VERSION } from './constants';
|
|
3
|
+
import getRebillyApi from './get-rebilly-api';
|
|
4
|
+
|
|
5
|
+
const defaultContextValue = {
|
|
6
|
+
api: getRebillyApi(),
|
|
7
|
+
error: null,
|
|
8
|
+
ready: false
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
// tslint:disable:no-let
|
|
12
|
+
let ProvidedContext;
|
|
13
|
+
if (/^15.*/.test(REACT_VERSION) || /^0.14.*/.test(REACT_VERSION)) {
|
|
14
|
+
// tslint:disable:no-var-requires
|
|
15
|
+
const createReactContext = require('create-react-context');
|
|
16
|
+
ProvidedContext = createReactContext(defaultContextValue);
|
|
17
|
+
} else {
|
|
18
|
+
ProvidedContext = React.createContext<FramePayContext>(defaultContextValue);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const ContextProvider = ProvidedContext.Provider;
|
|
22
|
+
const ContextConsumer = ProvidedContext.Consumer;
|
|
23
|
+
|
|
24
|
+
export { ContextProvider, ContextConsumer };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { FRAMEPAY_SCRIPT_LINK, FRAMEPAY_STYLE_LINK } from './constants';
|
|
2
|
+
|
|
3
|
+
interface ScriptProperties {
|
|
4
|
+
readonly onReady: () => void;
|
|
5
|
+
readonly onError: () => void;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const injectScript = ({ onReady, onError }: ScriptProperties) => {
|
|
9
|
+
// tslint:disable:no-expression-statement
|
|
10
|
+
const script = document.createElement('script');
|
|
11
|
+
const header = document.querySelector('head');
|
|
12
|
+
script.setAttribute('type', 'text/javascript');
|
|
13
|
+
script.setAttribute('async', 'true');
|
|
14
|
+
script.setAttribute('defer', 'true');
|
|
15
|
+
script.setAttribute('src', FRAMEPAY_SCRIPT_LINK);
|
|
16
|
+
script.setAttribute('defer', 'true');
|
|
17
|
+
script.addEventListener('load', () => onReady());
|
|
18
|
+
script.addEventListener('error', () => onError());
|
|
19
|
+
if (header) {
|
|
20
|
+
header.appendChild(script);
|
|
21
|
+
}
|
|
22
|
+
// tslint:enable:no-expression-statement
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const injectStyle = () => {
|
|
26
|
+
// tslint:disable:no-expression-statement
|
|
27
|
+
const style = document.createElement('link');
|
|
28
|
+
const header = document.querySelector('head');
|
|
29
|
+
style.setAttribute('rel', 'stylesheet');
|
|
30
|
+
style.setAttribute('href', FRAMEPAY_STYLE_LINK);
|
|
31
|
+
if (header) {
|
|
32
|
+
header.appendChild(style);
|
|
33
|
+
}
|
|
34
|
+
// tslint:enable:no-expression-statement
|
|
35
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export const ERROR_CODES = {
|
|
2
|
+
elementMountError: 'element-mount-error',
|
|
3
|
+
initializeError: 'initialize-error',
|
|
4
|
+
remoteScriptError: 'remote-script-error'
|
|
5
|
+
} as ErrorCodes;
|
|
6
|
+
|
|
7
|
+
export const defaultErrorMessages = {
|
|
8
|
+
[ERROR_CODES.remoteScriptError]: "Can't load the FramePay remote script",
|
|
9
|
+
[ERROR_CODES.elementMountError]: "Can't mount the element component",
|
|
10
|
+
[ERROR_CODES.initializeError]: `
|
|
11
|
+
FramePay initialize error\r\n
|
|
12
|
+
See https://github.com/Rebilly/framepay-react/tree/alpha#the-framepay-context-framepayprovider\r\n
|
|
13
|
+
See https://rebilly.github.io/framepay-docs/reference/rebilly.html#rebilly-initialize`
|
|
14
|
+
} as DefaultErrorMessages;
|
|
15
|
+
|
|
16
|
+
class ErrorBuilder {
|
|
17
|
+
make({
|
|
18
|
+
code,
|
|
19
|
+
details,
|
|
20
|
+
trace
|
|
21
|
+
}: {
|
|
22
|
+
readonly code: FramePayErrorCode;
|
|
23
|
+
readonly details: string;
|
|
24
|
+
readonly trace: any;
|
|
25
|
+
}): {
|
|
26
|
+
readonly code: FramePayErrorCode;
|
|
27
|
+
readonly details: string;
|
|
28
|
+
readonly message: DefaultErrorMessage;
|
|
29
|
+
readonly trace: any;
|
|
30
|
+
} {
|
|
31
|
+
return {
|
|
32
|
+
code,
|
|
33
|
+
details,
|
|
34
|
+
message: defaultErrorMessages[code],
|
|
35
|
+
trace: trace || null
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const handler = new ErrorBuilder();
|
|
41
|
+
|
|
42
|
+
const FramePayError = ({
|
|
43
|
+
code,
|
|
44
|
+
details = '',
|
|
45
|
+
trace = ''
|
|
46
|
+
}: {
|
|
47
|
+
readonly code: FramePayErrorCode;
|
|
48
|
+
readonly details?: string;
|
|
49
|
+
readonly trace?: any;
|
|
50
|
+
}) =>
|
|
51
|
+
handler.make({
|
|
52
|
+
code,
|
|
53
|
+
details,
|
|
54
|
+
trace
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
FramePayError.codes = ERROR_CODES;
|
|
58
|
+
|
|
59
|
+
export default FramePayError;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Just simple wrapper of remote FramePay api
|
|
3
|
+
*/
|
|
4
|
+
const remoteApi = (): RebillyApi => {
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
return typeof window !== 'undefined' ? window.Rebilly : undefined;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export default function getRebillyApi(): RebillyApi {
|
|
10
|
+
return remoteApi();
|
|
11
|
+
}
|