@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.
Files changed (91) hide show
  1. package/.env.example +2 -0
  2. package/CHANGELOG.md +14 -0
  3. package/build/index.spec.js +2 -6
  4. package/build/lib/components/elements/applepay-element.js +3 -3
  5. package/build/lib/components/elements/bank-element.js +7 -10
  6. package/build/lib/components/elements/base-element.js +2 -6
  7. package/build/lib/components/elements/card-element.js +7 -10
  8. package/build/lib/components/elements/googlepay-element.js +3 -3
  9. package/build/lib/components/elements/iban-element.js +8 -15
  10. package/build/lib/components/elements/paypal-element.js +3 -3
  11. package/build/lib/components/injector.js +10 -30
  12. package/build/lib/components/provider.js +10 -14
  13. package/build/lib/constants.js +11 -15
  14. package/build/lib/context.js +3 -7
  15. package/env.js +7 -0
  16. package/package.json +25 -14
  17. package/src/index.spec.ts +19 -0
  18. package/src/index.ts +42 -0
  19. package/src/lib/components/elements/applepay-element.tsx +36 -0
  20. package/src/lib/components/elements/bank-element.spec.tsx +119 -0
  21. package/src/lib/components/elements/bank-element.tsx +77 -0
  22. package/src/lib/components/elements/base-element.tsx +100 -0
  23. package/src/lib/components/elements/card-element.spec.tsx +113 -0
  24. package/src/lib/components/elements/card-element.tsx +76 -0
  25. package/src/lib/components/elements/googlepay-element.tsx +36 -0
  26. package/src/lib/components/elements/iban-element.spec.tsx +104 -0
  27. package/src/lib/components/elements/iban-element.tsx +78 -0
  28. package/src/lib/components/elements/paypal-element.tsx +36 -0
  29. package/src/lib/components/injector.spec.tsx +162 -0
  30. package/src/lib/components/injector.tsx +495 -0
  31. package/src/lib/components/provider.spec.tsx +98 -0
  32. package/src/lib/components/provider.tsx +111 -0
  33. package/src/lib/constants.ts +43 -0
  34. package/src/lib/context.ts +24 -0
  35. package/src/lib/dom-util.ts +35 -0
  36. package/src/lib/framepay-error.ts +59 -0
  37. package/src/lib/get-rebilly-api.ts +11 -0
  38. package/test/e2e/assets/prop-types.js +849 -0
  39. package/test/e2e/assets/react-0.14.0.js +18759 -0
  40. package/test/e2e/assets/react-15.0.0.js +19309 -0
  41. package/test/e2e/assets/react-16.js +3318 -0
  42. package/test/e2e/assets/react-17.js +3357 -0
  43. package/test/e2e/assets/react-18.js +3342 -0
  44. package/test/e2e/assets/react-dom-0.14.0.js +42 -0
  45. package/test/e2e/assets/react-dom-15.0.0.js +42 -0
  46. package/test/e2e/assets/react-dom-16.js +25147 -0
  47. package/test/e2e/assets/react-dom-17.js +26292 -0
  48. package/test/e2e/assets/react-dom-18.js +29869 -0
  49. package/test/e2e/cypress-support.js +2 -0
  50. package/test/e2e/cypress.d.ts +1 -0
  51. package/test/e2e/fixtures/apple-pay.html +15 -0
  52. package/test/e2e/fixtures/apple-pay.js +63 -0
  53. package/test/e2e/fixtures/bank-separate.html +12 -0
  54. package/test/e2e/fixtures/bank-separate.js +323 -0
  55. package/test/e2e/fixtures/card-separate-brands.html +12 -0
  56. package/test/e2e/fixtures/card-separate-brands.js +260 -0
  57. package/test/e2e/fixtures/card-separate-rebilly-fields.html +12 -0
  58. package/test/e2e/fixtures/card-separate-rebilly-fields.js +281 -0
  59. package/test/e2e/fixtures/card-separate.html +12 -0
  60. package/test/e2e/fixtures/card-separate.js +227 -0
  61. package/test/e2e/fixtures/checkout-combined.html +12 -0
  62. package/test/e2e/fixtures/checkout-combined.js +199 -0
  63. package/test/e2e/fixtures/google-pay.html +15 -0
  64. package/test/e2e/fixtures/google-pay.js +63 -0
  65. package/test/e2e/fixtures/iban.html +12 -0
  66. package/test/e2e/fixtures/iban.js +239 -0
  67. package/test/e2e/fixtures/multiple-methods.html +12 -0
  68. package/test/e2e/fixtures/multiple-methods.js +470 -0
  69. package/test/e2e/fixtures/nav.js +20 -0
  70. package/test/e2e/fixtures/paypal.html +15 -0
  71. package/test/e2e/fixtures/paypal.js +62 -0
  72. package/test/e2e/fixtures/style.css +55 -0
  73. package/test/e2e/fixtures/util.js +71 -0
  74. package/test/e2e/local-server.mjs +12 -0
  75. package/test/e2e/server.mjs +43 -0
  76. package/test/e2e/specs/bank-separate.cy.ts +27 -0
  77. package/test/e2e/specs/card-separate-brands.cy.ts +68 -0
  78. package/test/e2e/specs/card-separate.cy.ts +27 -0
  79. package/test/e2e/specs/checkout-combined.cy.ts +24 -0
  80. package/test/e2e/specs/google-pay.cy.ts +13 -0
  81. package/test/e2e/specs/iban.cy.ts +17 -0
  82. package/test/e2e/specs/multiple-methods.cy.ts +128 -0
  83. package/test/e2e/specs/paypal.cy.ts +13 -0
  84. package/test/e2e/specs/react-version.cy.ts +12 -0
  85. package/test/e2e/switch-react-version.js +42 -0
  86. package/test/e2e/tsconfig.json +8 -0
  87. package/test/unit/jest.config.js +29 -0
  88. package/test/unit/specs/declaration-mock.spec.tsx +143 -0
  89. package/tsconfig.json +31 -0
  90. package/tsconfig.spec.json +13 -0
  91. package/tslint.json +36 -0
@@ -0,0 +1,227 @@
1
+ import React, { Component } from 'react';
2
+ import ReactDOM from 'react-dom';
3
+
4
+ import { FramePayProvider, withFramePayCardComponent } from '../../../build';
5
+ import { deepMerge, prettyDebugRender, ReactVersion } from './util';
6
+ import './style.css';
7
+
8
+ const params = {
9
+ publishableKey: 'pk_sandbox_c6cqKLddciVikuBOjhcng-rLccTz70NT4W_qZ_h',
10
+ style: {
11
+ base: {
12
+ color: 'green',
13
+ fontSize: '12px',
14
+ webkitFontSmoothing: 'auto',
15
+ fontFeatureSettings: 'test',
16
+ fontStyle: 'italic',
17
+ fontVariant: 'normal',
18
+ fontStretch: 'none',
19
+ fontSomething: 'not-included',
20
+ fontOtherThing: 'not-included',
21
+ lineHeight: '20px'
22
+ },
23
+ invalid: {
24
+ fontWeight: 'bold'
25
+ }
26
+ },
27
+ classes: {
28
+ base: 'rebilly-framepay',
29
+ focus: 'rebilly-framepay-focus',
30
+ valid: 'rebilly-framepay-valid',
31
+ invalid: 'rebilly-framepay-invalid',
32
+ buttons: 'rebilly-framepay-buttons',
33
+ webkitAutofill: 'rebilly-framepay-webkit-autofill'
34
+ },
35
+ icon: {
36
+ foobar: 123,
37
+ display: true,
38
+ color: 'blue'
39
+ }
40
+ };
41
+
42
+ class CardElementComponent extends Component {
43
+
44
+ constructor(props) {
45
+ super(props);
46
+ this.state = {
47
+ events: {
48
+ number: {
49
+ onReady: null,
50
+ onChange: null,
51
+ onFocus: null,
52
+ onBlur: null
53
+ },
54
+ cvv: {
55
+ onReady: null,
56
+ onChange: null,
57
+ onFocus: null,
58
+ onBlur: null
59
+ },
60
+ expiry: {
61
+ onReady: null,
62
+ onChange: null,
63
+ onFocus: null,
64
+ onBlur: null
65
+ }
66
+ },
67
+ billingAddress: {
68
+ firstName: 'first-name-value',
69
+ lastName: 'last-name-value',
70
+ address: 'address-value',
71
+ country: 'GB',
72
+ region: 'region-value'
73
+ },
74
+ token: {
75
+ error: null,
76
+ data: null
77
+ }
78
+ };
79
+ this.handleSubmit = this.handleSubmit.bind(this);
80
+ }
81
+
82
+ handleSubmit(e) {
83
+ e.preventDefault();
84
+ /**
85
+ *
86
+ * @see https://rebilly.github.io/framepay-docs/reference/rebilly.html#rebilly-createtoken
87
+ *
88
+ */
89
+ const billingAddress = {
90
+ ...this.state.billingAddress
91
+ };
92
+ if (billingAddress.emails) {
93
+ billingAddress.emails = [
94
+ {
95
+ label: 'Email',
96
+ value: billingAddress.emails
97
+ }
98
+ ];
99
+ }
100
+ if (billingAddress.phoneNumbers) {
101
+ billingAddress.phoneNumbers = [
102
+ {
103
+ label: 'Phone Number',
104
+ value: billingAddress.phoneNumbers
105
+ }
106
+ ];
107
+ }
108
+
109
+ this.props.Rebilly.createToken(this.formNode, { billingAddress })
110
+ .then(data => {
111
+ this.deepUpdateState({ token: { error: false, data } });
112
+ })
113
+ .catch(err => {
114
+ this.deepUpdateState({ token: { error: true, data: err } });
115
+ });
116
+ }
117
+
118
+ deepUpdateState(data) {
119
+ this.setState(deepMerge(this.state, data));
120
+ }
121
+
122
+ render() {
123
+ return (<div>
124
+ <h2>{this.props.title}</h2>
125
+ <h3>FramePay version: {this.props.Rebilly.version}</h3>
126
+ <div className="flex-wrapper">
127
+ {prettyDebugRender(this.state)}
128
+ <div className="example-2">
129
+ <form id="form" ref={node => this.formNode = node} method="post" onSubmit={this.handleSubmit}>
130
+ <fieldset>
131
+ <div className="field">
132
+ <input
133
+ type="text"
134
+ name="firstName"
135
+ placeholder="First Name"
136
+ defaultValue={this.state.billingAddress.firstName}
137
+ onChange={e => {
138
+ this.deepUpdateState({ billingAddress: { firstName: e.target.value } });
139
+ }}/>
140
+ </div>
141
+ <div className="field">
142
+ <input
143
+ type="text"
144
+ name="lastName"
145
+ placeholder="Last Name"
146
+ defaultValue={this.state.billingAddress.lastName}
147
+ onChange={e => {
148
+ this.deepUpdateState({ billingAddress: { lastName: e.target.value } });
149
+ }}/>
150
+ </div>
151
+ <div className="field">
152
+ <input
153
+ type="text"
154
+ name="email"
155
+ placeholder="Email"
156
+ defaultValue={this.state.billingAddress.emails}
157
+ onChange={e => {
158
+ this.deepUpdateState({ billingAddress: { emails: e.target.value } });
159
+ }}/>
160
+ </div>
161
+ <div className="field">
162
+ <input
163
+ type="text"
164
+ name="phone"
165
+ placeholder="Phone"
166
+ defaultValue={this.state.billingAddress.phoneNumbers}
167
+ onChange={e => {
168
+ this.deepUpdateState({ billingAddress: { phoneNumbers: e.target.value } });
169
+ }}/>
170
+ </div>
171
+ <div className="field">
172
+ <this.props.CardNumberElement
173
+ onReady={() => this.deepUpdateState({ events: { number: { onReady: true } } })}
174
+ onChange={(data) => this.deepUpdateState({ events: { number: { onChange: data } } })}
175
+ onFocus={() => this.deepUpdateState({ events: { number: { onFocus: true } } })}
176
+ onBlur={() => this.deepUpdateState({ events: { number: { onBlur: true } } })}
177
+ />
178
+ </div>
179
+
180
+ <div className="field">
181
+ <this.props.CardCvvElement
182
+ onReady={() => this.deepUpdateState({ events: { cvv: { onReady: true } } })}
183
+ onChange={(data) => this.deepUpdateState({ events: { cvv: { onChange: data } } })}
184
+ onFocus={() => this.deepUpdateState({ events: { cvv: { onFocus: true } } })}
185
+ onBlur={() => this.deepUpdateState({ events: { cvv: { onBlur: true } } })}
186
+ />
187
+ </div>
188
+
189
+ <div className="field">
190
+ <this.props.CardExpiryElement
191
+ onReady={() => this.deepUpdateState({ events: { expiry: { onReady: true } } })}
192
+ onChange={(data) => this.deepUpdateState({ events: { expiry: { onChange: data } } })}
193
+ onFocus={() => this.deepUpdateState({ events: { expiry: { onFocus: true } } })}
194
+ onBlur={() => this.deepUpdateState({ events: { expiry: { onBlur: true } } })}
195
+ />
196
+ </div>
197
+ </fieldset>
198
+ <button id="submit">Make Payment</button>
199
+ </form>
200
+ </div>
201
+ </div>
202
+ </div>);
203
+ }
204
+ }
205
+
206
+ const CardElement = withFramePayCardComponent(CardElementComponent);
207
+
208
+ class App extends Component {
209
+
210
+ render() {
211
+ return (<FramePayProvider injectStyle
212
+ {...params}
213
+ onReady={() => {
214
+ //console.log('FramePayProvider.onReady');
215
+ }}
216
+ onError={(err) => {
217
+ //console.log('FramePayProvider.onError', err);
218
+ }}>
219
+ <div>
220
+ {ReactVersion()}
221
+ <CardElement/>
222
+ </div>
223
+ </FramePayProvider>);
224
+ }
225
+ }
226
+
227
+ ReactDOM.render(<App/>, document.getElementById('app'));
@@ -0,0 +1,12 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8"/>
5
+ <title>Test Checkout Page Combined Field</title>
6
+ </head>
7
+ <body>
8
+ <div id="app"></div>
9
+ <script src="checkout-combined.js"></script>
10
+ <script src="nav.js"></script>
11
+ </body>
12
+ </html>
@@ -0,0 +1,199 @@
1
+ import React, { Component } from 'react';
2
+ import ReactDOM from 'react-dom';
3
+
4
+ import { FramePayProvider, withFramePayCardComponent } from '../../../build';
5
+ import { deepMerge, prettyDebugRender, ReactVersion } from './util';
6
+ import './style.css';
7
+
8
+ const params = {
9
+ publishableKey: 'pk_sandbox_c6cqKLddciVikuBOjhcng-rLccTz70NT4W_qZ_h',
10
+ style: {
11
+ base: {
12
+ color: 'green',
13
+ fontSize: '12px',
14
+ webkitFontSmoothing: 'auto',
15
+ fontFeatureSettings: 'test',
16
+ fontStyle: 'italic',
17
+ fontVariant: 'normal',
18
+ fontStretch: 'none',
19
+ fontSomething: 'not-included',
20
+ fontOtherThing: 'not-included',
21
+ lineHeight: '20px'
22
+ },
23
+ invalid: {
24
+ fontWeight: 'bold'
25
+ }
26
+ },
27
+ classes: {
28
+ base: 'rebilly-framepay',
29
+ focus: 'rebilly-framepay-focus',
30
+ valid: 'rebilly-framepay-valid',
31
+ invalid: 'rebilly-framepay-invalid',
32
+ buttons: 'rebilly-framepay-buttons',
33
+ webkitAutofill: 'rebilly-framepay-webkit-autofill'
34
+ },
35
+ icon: {
36
+ foobar: 123,
37
+ display: true,
38
+ color: 'blue'
39
+ }
40
+ };
41
+
42
+ class CardElementComponent extends Component {
43
+
44
+ constructor(props) {
45
+ super(props);
46
+ this.state = {
47
+ events: {
48
+ onReady: null,
49
+ onError: null,
50
+ onChange: null,
51
+ onFocus: null,
52
+ onBlur: null
53
+ },
54
+ billingAddress: {
55
+ firstName: 'first-name-value',
56
+ lastName: 'last-name-value',
57
+ address: 'address-value',
58
+ country: 'GB',
59
+ region: 'region-value'
60
+ },
61
+ token: {
62
+ error: null,
63
+ data: null
64
+ }
65
+ };
66
+ this.handleSubmit = this.handleSubmit.bind(this);
67
+ }
68
+
69
+ handleSubmit(e) {
70
+ e.preventDefault();
71
+ /**
72
+ *
73
+ * @see https://rebilly.github.io/framepay-docs/reference/rebilly.html#rebilly-createtoken
74
+ *
75
+ */
76
+ const billingAddress = {
77
+ ...this.state.billingAddress
78
+ };
79
+ if (billingAddress.emails) {
80
+ billingAddress.emails = [
81
+ {
82
+ label: 'Email',
83
+ value: billingAddress.emails
84
+ }
85
+ ];
86
+ }
87
+ if (billingAddress.phoneNumbers) {
88
+ billingAddress.phoneNumbers = [
89
+ {
90
+ label: 'Phone Number',
91
+ value: billingAddress.phoneNumbers
92
+ }
93
+ ];
94
+ }
95
+
96
+ this.props.Rebilly.createToken(this.formNode, { billingAddress })
97
+ .then(data => {
98
+ this.deepUpdateState({ token: { error: false, data } });
99
+ })
100
+ .catch(err => {
101
+ this.deepUpdateState({ token: { error: true, data: err } });
102
+ });
103
+ }
104
+
105
+ deepUpdateState(data) {
106
+ this.setState(prevState => {
107
+ return deepMerge(prevState, data);
108
+ });
109
+ }
110
+
111
+ render() {
112
+ return (<div>
113
+ <h2>{this.props.title}</h2>
114
+ <h3>FramePay version: {this.props.Rebilly.version}</h3>
115
+ <div className="flex-wrapper">
116
+ {prettyDebugRender(this.state)}
117
+ <div className="example-2">
118
+ <form id="form" ref={node => this.formNode = node} method="post" onSubmit={this.handleSubmit}>
119
+ <fieldset>
120
+ <div className="field">
121
+ <input
122
+ type="text"
123
+ name="firstName"
124
+ placeholder="First Name"
125
+ defaultValue={this.state.billingAddress.firstName}
126
+ onChange={e => {
127
+ this.deepUpdateState({ billingAddress: { firstName: e.target.value } });
128
+ }}/>
129
+ </div>
130
+ <div className="field">
131
+ <input
132
+ type="text"
133
+ name="lastName"
134
+ placeholder="Last Name"
135
+ defaultValue={this.state.billingAddress.lastName}
136
+ onChange={e => {
137
+ this.deepUpdateState({ billingAddress: { lastName: e.target.value } });
138
+ }}/>
139
+ </div>
140
+ <div className="field">
141
+ <input
142
+ type="text"
143
+ name="email"
144
+ placeholder="Email"
145
+ defaultValue={this.state.billingAddress.emails}
146
+ onChange={e => {
147
+ this.deepUpdateState({ billingAddress: { emails: e.target.value } });
148
+ }}/>
149
+ </div>
150
+ <div className="field">
151
+ <input
152
+ type="text"
153
+ name="phone"
154
+ placeholder="Phone"
155
+ defaultValue={this.state.billingAddress.phoneNumbers}
156
+ onChange={e => {
157
+ this.deepUpdateState({ billingAddress: { phoneNumbers: e.target.value } });
158
+ }}/>
159
+ </div>
160
+ <div className="field">
161
+ <this.props.CardElement
162
+ onError={(err) => this.deepUpdateState({ events: { onError: err } })}
163
+ onReady={() => this.deepUpdateState({ events: { onReady: true } })}
164
+ onChange={(data) => this.deepUpdateState({ events: { onChange: data } })}
165
+ onFocus={() => this.deepUpdateState({ events: { onFocus: true } })}
166
+ onBlur={() => this.deepUpdateState({ events: { onBlur: true } })}
167
+ />
168
+ </div>
169
+ </fieldset>
170
+ <button id="submit">Make Payment</button>
171
+ </form>
172
+ </div>
173
+ </div>
174
+ </div>);
175
+ }
176
+ }
177
+
178
+ const CardElement = withFramePayCardComponent(CardElementComponent);
179
+
180
+ class App extends Component {
181
+
182
+ render() {
183
+ return (<FramePayProvider injectStyle
184
+ {...params}
185
+ onReady={() => {
186
+ //console.log('FramePayProvider.onReady');
187
+ }}
188
+ onError={(err) => {
189
+ //console.log('FramePayProvider.onError', err);
190
+ }}>
191
+ <div>
192
+ {ReactVersion()}
193
+ <CardElement/>
194
+ </div>
195
+ </FramePayProvider>);
196
+ }
197
+ }
198
+
199
+ ReactDOM.render(<App/>, document.getElementById('app'));
@@ -0,0 +1,15 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+
4
+ <head>
5
+ <meta charset="utf-8" />
6
+ <title>Test Google Pay</title>
7
+ </head>
8
+
9
+ <body>
10
+ <div id="app"></div>
11
+ <script src="google-pay.js"></script>
12
+ <script src="nav.js"></script>
13
+ </body>
14
+
15
+ </html>
@@ -0,0 +1,63 @@
1
+ import React, { Component } from 'react';
2
+ import ReactDOM from 'react-dom';
3
+
4
+ import {
5
+ FramePayProvider,
6
+ withFramePayGooglePayComponent
7
+ } from '../../../build';
8
+ import { prettyDebugRender, ReactVersion } from './util';
9
+ import './style.css';
10
+
11
+ const params = {
12
+ publishableKey: 'pk_sandbox_S95ATjj4hXZs-T9QpZq1ENl2tDSrUkCGv98utc9',
13
+ organizationId: '5977150c-1c97-4dd4-9860-6bb2bab070b4',
14
+ websiteId: 'demo.com',
15
+ transactionData: {
16
+ amount: 10,
17
+ currency: 'USD',
18
+ label: 'Purchase label 1'
19
+ }
20
+ };
21
+
22
+ class App extends Component {
23
+
24
+ constructor(props) {
25
+ super(props);
26
+ this.state = {
27
+ token: null,
28
+ };
29
+ }
30
+
31
+ render() {
32
+ return (
33
+ <FramePayProvider
34
+ injectStyle
35
+ {...params}
36
+ onReady={() => {
37
+ console.log('FramePayProvider.onReady');
38
+ }}
39
+ onError={err => {
40
+ console.log('FramePayProvider.onError', err);
41
+ }}
42
+ onTokenReady={token => this.setState({ token })}
43
+ >
44
+ <div>
45
+ {ReactVersion()}
46
+ <div>
47
+ <h3>FramePay version: {this.props.Rebilly.version}</h3>
48
+ <div className="flex-wrapper">
49
+ {prettyDebugRender(this.state)}
50
+ <this.props.GooglePayElement />
51
+ </div>
52
+ </div>
53
+ </div>
54
+ </FramePayProvider>
55
+ );
56
+ }
57
+ }
58
+
59
+ const WrappedApp = withFramePayGooglePayComponent(App);
60
+ ReactDOM.render(
61
+ <WrappedApp />,
62
+ document.getElementById('app')
63
+ );
@@ -0,0 +1,12 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8"/>
5
+ <title>Test IBAN Field</title>
6
+ </head>
7
+ <body>
8
+ <div id="app"></div>
9
+ <script src="iban.js"></script>
10
+ <script src="nav.js"></script>
11
+ </body>
12
+ </html>