@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,260 @@
1
+ import React, { Component } from 'react';
2
+ import ReactDOM from 'react-dom';
3
+
4
+ import { FramePayProvider, SUPPORTED_CARD_BRANDS, withFramePayCardComponent } from '../../../build';
5
+ import { deepMerge, prettyDebugRender, ReactVersion } from './util';
6
+ import './style.css';
7
+
8
+ console.log('SUPPORTED_CARD_BRANDS', SUPPORTED_CARD_BRANDS);
9
+
10
+ const params = {
11
+ publishableKey: 'pk_sandbox_c6cqKLddciVikuBOjhcng-rLccTz70NT4W_qZ_h',
12
+ icon: {
13
+ display: true,
14
+ color: 'blue'
15
+ },
16
+ card: {
17
+ brands: {
18
+ allowed: [
19
+ SUPPORTED_CARD_BRANDS.MasterCard,
20
+ SUPPORTED_CARD_BRANDS.Amex
21
+ ]
22
+ }
23
+ }
24
+ };
25
+
26
+ console.log('params', params);
27
+
28
+ class CardElementComponent extends Component {
29
+
30
+ constructor(props) {
31
+ super(props);
32
+ this.state = {
33
+ button: null,
34
+ events: {
35
+ number: {
36
+ onReady: null,
37
+ onChange: null,
38
+ onFocus: null,
39
+ onBlur: null
40
+ },
41
+ cvv: {
42
+ onReady: null,
43
+ onChange: null,
44
+ onFocus: null,
45
+ onBlur: null
46
+ },
47
+ expiry: {
48
+ onReady: null,
49
+ onChange: null,
50
+ onFocus: null,
51
+ onBlur: null
52
+ }
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
+ this.handleUpdateSettings = this.handleUpdateSettings.bind(this);
68
+ this.handleRestoreSettings = this.handleRestoreSettings.bind(this);
69
+ }
70
+
71
+ handleSubmit(e) {
72
+ e.preventDefault();
73
+ /**
74
+ *
75
+ * @see https://rebilly.github.io/framepay-docs/reference/rebilly.html#rebilly-createtoken
76
+ *
77
+ */
78
+ const billingAddress = {
79
+ ...this.state.billingAddress
80
+ };
81
+ if (billingAddress.emails) {
82
+ billingAddress.emails = [
83
+ {
84
+ label: 'Email',
85
+ value: billingAddress.emails
86
+ }
87
+ ];
88
+ }
89
+ if (billingAddress.phoneNumbers) {
90
+ billingAddress.phoneNumbers = [
91
+ {
92
+ label: 'Phone Number',
93
+ value: billingAddress.phoneNumbers
94
+ }
95
+ ];
96
+ }
97
+
98
+ this.props.Rebilly.createToken(this.formNode, { billingAddress })
99
+ .then(data => {
100
+ this.deepUpdateState({ token: { error: false, data } });
101
+ })
102
+ .catch(err => {
103
+ this.deepUpdateState({ token: { error: true, data: err } });
104
+ });
105
+ }
106
+
107
+ deepUpdateState(data) {
108
+ this.setState(deepMerge(this.state, data));
109
+ }
110
+
111
+ handleUpdateSettings() {
112
+ this.setState({ button: 'update' });
113
+ this.props.Rebilly.update({
114
+ ...params,
115
+ card: { brands: { allowed: null } }
116
+ });
117
+ }
118
+
119
+ handleRestoreSettings() {
120
+ this.setState({ button: 'restore' });
121
+ this.props.Rebilly.update({
122
+ ...params
123
+ });
124
+ }
125
+
126
+ render() {
127
+ return (<div>
128
+ <h2>{this.props.title}</h2>
129
+ <h3>FramePay version: {this.props.Rebilly.version}</h3>
130
+ <div className="flex-wrapper">
131
+ {prettyDebugRender(this.state)}
132
+ <div className="example-2">
133
+ <form id="form" ref={node => this.formNode = node} method="post" onSubmit={this.handleSubmit}>
134
+ <fieldset>
135
+ <div className="field">
136
+ <input
137
+ type="text"
138
+ name="firstName"
139
+ placeholder="First Name"
140
+ defaultValue={this.state.billingAddress.firstName}
141
+ onChange={e => {
142
+ this.deepUpdateState({ billingAddress: { firstName: e.target.value } });
143
+ }}/>
144
+ </div>
145
+ <div className="field">
146
+ <input
147
+ type="text"
148
+ name="lastName"
149
+ placeholder="Last Name"
150
+ defaultValue={this.state.billingAddress.lastName}
151
+ onChange={e => {
152
+ this.deepUpdateState({ billingAddress: { lastName: e.target.value } });
153
+ }}/>
154
+ </div>
155
+ <div className="field">
156
+ <input
157
+ type="text"
158
+ name="email"
159
+ placeholder="Email"
160
+ defaultValue={this.state.billingAddress.emails}
161
+ onChange={e => {
162
+ this.deepUpdateState({ billingAddress: { emails: e.target.value } });
163
+ }}/>
164
+ </div>
165
+ <div className="field">
166
+ <input
167
+ type="text"
168
+ name="phone"
169
+ placeholder="Phone"
170
+ defaultValue={this.state.billingAddress.phoneNumbers}
171
+ onChange={e => {
172
+ this.deepUpdateState({ billingAddress: { phoneNumbers: e.target.value } });
173
+ }}/>
174
+ </div>
175
+ <div className="field">
176
+ <label htmlFor="card">Card Number</label>
177
+ <this.props.CardNumberElement
178
+ id="card"
179
+ onReady={() => this.deepUpdateState({ events: { number: { onReady: true } } })}
180
+ onChange={(data) => this.deepUpdateState({
181
+ events: {
182
+ number: {
183
+ onChange: {
184
+ ...data,
185
+ error: data.error || ''
186
+ }
187
+ }
188
+ }
189
+ })}
190
+ onFocus={() => this.deepUpdateState({ events: { number: { onFocus: true } } })}
191
+ onBlur={() => this.deepUpdateState({ events: { number: { onBlur: true } } })}
192
+ />
193
+ </div>
194
+
195
+ <div className="field">
196
+ <label htmlFor="cvv">Card CVV</label>
197
+ <this.props.CardCvvElement
198
+ id="cvv"
199
+ onReady={() => this.deepUpdateState({ events: { cvv: { onReady: true } } })}
200
+ onChange={(data) => this.deepUpdateState({
201
+ events: {
202
+ cvv: {
203
+ onChange: {
204
+ ...data,
205
+ error: data.error || ''
206
+ }
207
+ }
208
+ }
209
+ })}
210
+ onFocus={() => this.deepUpdateState({ events: { cvv: { onFocus: true } } })}
211
+ onBlur={() => this.deepUpdateState({ events: { cvv: { onBlur: true } } })}
212
+ />
213
+ </div>
214
+
215
+ <div className="field">
216
+ <label htmlFor="expiry">Card expiry</label>
217
+ <this.props.CardExpiryElement
218
+ id="expiry"
219
+ onReady={() => this.deepUpdateState({ events: { expiry: { onReady: true } } })}
220
+ onChange={(data) => this.deepUpdateState({
221
+ events: {
222
+ expiry: {
223
+ onChange: {
224
+ ...data,
225
+ error: data.error || ''
226
+ }
227
+ }
228
+ }
229
+ })}
230
+ onFocus={() => this.deepUpdateState({ events: { expiry: { onFocus: true } } })}
231
+ onBlur={() => this.deepUpdateState({ events: { expiry: { onBlur: true } } })}
232
+ />
233
+ </div>
234
+ </fieldset>
235
+ <button id="submit">Make Payment</button>
236
+ </form>
237
+
238
+ <button id="btn-update" onClick={this.handleUpdateSettings}>Update</button>
239
+ <button id="btn-restore" onClick={this.handleRestoreSettings}>Restore</button>
240
+ </div>
241
+ </div>
242
+ </div>);
243
+ }
244
+ }
245
+
246
+ const CardElement = withFramePayCardComponent(CardElementComponent);
247
+
248
+ class App extends Component {
249
+
250
+ render() {
251
+ return (<FramePayProvider injectStyle {...params}>
252
+ <div>
253
+ {ReactVersion()}
254
+ <CardElement/>
255
+ </div>
256
+ </FramePayProvider>);
257
+ }
258
+ }
259
+
260
+ 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 Card Page Separate Fields</title>
6
+ </head>
7
+ <body>
8
+ <div id="app"></div>
9
+ <script src="card-separate-rebilly-fields.js"></script>
10
+ <script src="nav.js"></script>
11
+ </body>
12
+ </html>
@@ -0,0 +1,281 @@
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
+ constructor(props) {
44
+ super(props);
45
+ this.state = {
46
+ events: {
47
+ number: {
48
+ onReady: null,
49
+ onChange: null,
50
+ onFocus: null,
51
+ onBlur: null
52
+ },
53
+ cvv: {
54
+ onReady: null,
55
+ onChange: null,
56
+ onFocus: null,
57
+ onBlur: null
58
+ },
59
+ expiry: {
60
+ onReady: null,
61
+ onChange: null,
62
+ onFocus: null,
63
+ onBlur: null
64
+ }
65
+ },
66
+ token: {
67
+ error: null,
68
+ data: null
69
+ }
70
+ };
71
+ this.handleSubmit = this.handleSubmit.bind(this);
72
+ }
73
+
74
+ handleSubmit(e) {
75
+ e.preventDefault();
76
+ /**
77
+ *
78
+ * @see https://rebilly.github.io/framepay-docs/reference/rebilly.html#rebilly-createtoken
79
+ *
80
+ */
81
+ this.props.Rebilly.createToken(this.formNode, {
82
+ billingAddress:{
83
+ emails: [
84
+ {
85
+ label: 'email-extradata',
86
+ value: 'email-extradata@email.local'
87
+ }
88
+ ]
89
+ }
90
+ })
91
+ .then(data => {
92
+ this.deepUpdateState({ token: { error: false, data } });
93
+ })
94
+ .catch(err => {
95
+ this.deepUpdateState({ token: { error: true, data: err } });
96
+ });
97
+ }
98
+
99
+ deepUpdateState(data) {
100
+ this.setState(deepMerge(this.state, data));
101
+ }
102
+
103
+ render() {
104
+ return (
105
+ <div>
106
+ <h2>{this.props.title}</h2>
107
+ <h3>FramePay version: {this.props.Rebilly.version}</h3>
108
+ <div className="flex-wrapper">
109
+ {prettyDebugRender(this.state)}
110
+ <div className="example-2">
111
+ <form
112
+ id="form"
113
+ ref={node => (this.formNode = node)}
114
+ method="post"
115
+ onSubmit={this.handleSubmit}
116
+ >
117
+ <fieldset>
118
+ <div className="field">
119
+ <input
120
+ type="text"
121
+ placeholder="First Name"
122
+ data-rebilly="firstName"
123
+ />
124
+ </div>
125
+ <div className="field">
126
+ <input
127
+ type="text"
128
+ name="lastName"
129
+ placeholder="lastName"
130
+ data-rebilly="lastName"
131
+ />
132
+ </div>
133
+ <div className="field">
134
+ <input
135
+ type="text"
136
+ name="email"
137
+ placeholder="Email"
138
+ data-rebilly="emails"
139
+ />
140
+ </div>
141
+ <div className="field">
142
+ <input
143
+ type="text"
144
+ name="phone"
145
+ placeholder="Phone"
146
+ data-rebilly="phones"
147
+ />
148
+ </div>
149
+ <div className="field">
150
+ <this.props.CardNumberElement
151
+ onReady={() =>
152
+ this.deepUpdateState({
153
+ events: {
154
+ number: { onReady: true }
155
+ }
156
+ })
157
+ }
158
+ onChange={data =>
159
+ this.deepUpdateState({
160
+ events: {
161
+ number: { onChange: data }
162
+ }
163
+ })
164
+ }
165
+ onFocus={() =>
166
+ this.deepUpdateState({
167
+ events: {
168
+ number: { onFocus: true }
169
+ }
170
+ })
171
+ }
172
+ onBlur={() =>
173
+ this.deepUpdateState({
174
+ events: {
175
+ number: { onBlur: true }
176
+ }
177
+ })
178
+ }
179
+ />
180
+ </div>
181
+
182
+ <div className="field">
183
+ <this.props.CardCvvElement
184
+ onReady={() =>
185
+ this.deepUpdateState({
186
+ events: {
187
+ cvv: { onReady: true }
188
+ }
189
+ })
190
+ }
191
+ onChange={data =>
192
+ this.deepUpdateState({
193
+ events: {
194
+ cvv: { onChange: data }
195
+ }
196
+ })
197
+ }
198
+ onFocus={() =>
199
+ this.deepUpdateState({
200
+ events: {
201
+ cvv: { onFocus: true }
202
+ }
203
+ })
204
+ }
205
+ onBlur={() =>
206
+ this.deepUpdateState({
207
+ events: {
208
+ cvv: { onBlur: true }
209
+ }
210
+ })
211
+ }
212
+ />
213
+ </div>
214
+
215
+ <div className="field">
216
+ <this.props.CardExpiryElement
217
+ onReady={() =>
218
+ this.deepUpdateState({
219
+ events: {
220
+ expiry: { onReady: true }
221
+ }
222
+ })
223
+ }
224
+ onChange={data =>
225
+ this.deepUpdateState({
226
+ events: {
227
+ expiry: { onChange: data }
228
+ }
229
+ })
230
+ }
231
+ onFocus={() =>
232
+ this.deepUpdateState({
233
+ events: {
234
+ expiry: { onFocus: true }
235
+ }
236
+ })
237
+ }
238
+ onBlur={() =>
239
+ this.deepUpdateState({
240
+ events: {
241
+ expiry: { onBlur: true }
242
+ }
243
+ })
244
+ }
245
+ />
246
+ </div>
247
+ </fieldset>
248
+ <button id="submit">Make Payment</button>
249
+ </form>
250
+ </div>
251
+ </div>
252
+ </div>
253
+ );
254
+ }
255
+ }
256
+
257
+ const CardElement = withFramePayCardComponent(CardElementComponent);
258
+
259
+ class App extends Component {
260
+ render() {
261
+ return (
262
+ <FramePayProvider
263
+ injectStyle
264
+ {...params}
265
+ onReady={() => {
266
+ //console.log('FramePayProvider.onReady');
267
+ }}
268
+ onError={err => {
269
+ //console.log('FramePayProvider.onError', err);
270
+ }}
271
+ >
272
+ <div>
273
+ {ReactVersion()}
274
+ <CardElement />
275
+ </div>
276
+ </FramePayProvider>
277
+ );
278
+ }
279
+ }
280
+
281
+ 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 Card Page Separate Fields</title>
6
+ </head>
7
+ <body>
8
+ <div id="app"></div>
9
+ <script src="card-separate.js"></script>
10
+ <script src="nav.js"></script>
11
+ </body>
12
+ </html>