@rebilly/framepay-react 4.0.6 → 5.0.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 (59) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/build/index.d.ts +1 -1
  3. package/build/index.spec.js +1 -1
  4. package/build/lib/components/elements/applepay-element.js +2 -2
  5. package/build/lib/components/elements/bank-element.js +3 -3
  6. package/build/lib/components/elements/base-element.js +14 -13
  7. package/build/lib/components/elements/card-element.js +3 -3
  8. package/build/lib/components/elements/googlepay-element.js +2 -2
  9. package/build/lib/components/elements/iban-element.js +4 -4
  10. package/build/lib/components/elements/paypal-element.js +2 -2
  11. package/build/lib/components/injector.js +20 -20
  12. package/build/lib/components/provider.js +11 -11
  13. package/build/lib/constants.js +1 -1
  14. package/build/lib/context.js +2 -4
  15. package/build/lib/dom-util.js +1 -5
  16. package/build/lib/framepay-error.d.ts +1 -1
  17. package/build/lib/framepay-error.js +4 -4
  18. package/build/lib/get-rebilly-api.js +2 -2
  19. package/package.json +6 -16
  20. package/src/index.spec.ts +1 -1
  21. package/src/index.ts +3 -3
  22. package/src/lib/components/elements/applepay-element.tsx +2 -2
  23. package/src/lib/components/elements/bank-element.spec.tsx +12 -12
  24. package/src/lib/components/elements/bank-element.tsx +4 -4
  25. package/src/lib/components/elements/base-element.tsx +16 -16
  26. package/src/lib/components/elements/card-element.spec.tsx +13 -13
  27. package/src/lib/components/elements/card-element.tsx +4 -4
  28. package/src/lib/components/elements/googlepay-element.tsx +2 -2
  29. package/src/lib/components/elements/iban-element.spec.tsx +9 -9
  30. package/src/lib/components/elements/iban-element.tsx +4 -4
  31. package/src/lib/components/elements/paypal-element.tsx +2 -2
  32. package/src/lib/components/injector.spec.tsx +3 -4
  33. package/src/lib/components/injector.tsx +50 -48
  34. package/src/lib/components/provider.spec.tsx +5 -7
  35. package/src/lib/components/provider.tsx +15 -15
  36. package/src/lib/constants.ts +1 -1
  37. package/src/lib/context.ts +1 -3
  38. package/src/lib/dom-util.ts +0 -4
  39. package/src/lib/framepay-error.ts +9 -6
  40. package/src/lib/get-rebilly-api.ts +1 -1
  41. package/test/e2e/cypress-support.js +1 -1
  42. package/test/e2e/fixtures/apple-pay.js +4 -8
  43. package/test/e2e/fixtures/bank-separate.js +68 -67
  44. package/test/e2e/fixtures/card-separate-brands.js +256 -139
  45. package/test/e2e/fixtures/card-separate-rebilly-fields.js +48 -57
  46. package/test/e2e/fixtures/card-separate.js +214 -112
  47. package/test/e2e/fixtures/checkout-combined.js +145 -95
  48. package/test/e2e/fixtures/google-pay.js +6 -10
  49. package/test/e2e/fixtures/iban.js +47 -45
  50. package/test/e2e/fixtures/multiple-methods.js +104 -98
  51. package/test/e2e/fixtures/nav.js +3 -4
  52. package/test/e2e/fixtures/paypal.js +5 -12
  53. package/test/e2e/fixtures/util.js +50 -37
  54. package/test/e2e/specs/card-separate-brands.cy.ts +2 -2
  55. package/test/e2e/specs/react-version.cy.ts +1 -1
  56. package/test/e2e/switch-react-version.js +5 -6
  57. package/test/unit/jest.config.js +18 -28
  58. package/test/unit/specs/declaration-mock.spec.tsx +1 -0
  59. package/tslint.json +0 -36
@@ -1,7 +1,11 @@
1
1
  import React, { Component } from 'react';
2
2
  import ReactDOM from 'react-dom';
3
3
 
4
- import { FramePayProvider, SUPPORTED_CARD_BRANDS, withFramePayCardComponent } from '../../../build';
4
+ import {
5
+ FramePayProvider,
6
+ SUPPORTED_CARD_BRANDS,
7
+ withFramePayCardComponent,
8
+ } from '../../../build';
5
9
  import { deepMerge, prettyDebugRender, ReactVersion } from './util';
6
10
  import './style.css';
7
11
 
@@ -11,22 +15,21 @@ const params = {
11
15
  publishableKey: 'pk_sandbox_c6cqKLddciVikuBOjhcng-rLccTz70NT4W_qZ_h',
12
16
  icon: {
13
17
  display: true,
14
- color: 'blue'
18
+ color: 'blue',
15
19
  },
16
20
  card: {
17
21
  brands: {
18
22
  allowed: [
19
23
  SUPPORTED_CARD_BRANDS.MasterCard,
20
- SUPPORTED_CARD_BRANDS.Amex
21
- ]
22
- }
23
- }
24
+ SUPPORTED_CARD_BRANDS.Amex,
25
+ ],
26
+ },
27
+ },
24
28
  };
25
29
 
26
30
  console.log('params', params);
27
31
 
28
32
  class CardElementComponent extends Component {
29
-
30
33
  constructor(props) {
31
34
  super(props);
32
35
  this.state = {
@@ -36,32 +39,32 @@ class CardElementComponent extends Component {
36
39
  onReady: null,
37
40
  onChange: null,
38
41
  onFocus: null,
39
- onBlur: null
42
+ onBlur: null,
40
43
  },
41
44
  cvv: {
42
45
  onReady: null,
43
46
  onChange: null,
44
47
  onFocus: null,
45
- onBlur: null
48
+ onBlur: null,
46
49
  },
47
50
  expiry: {
48
51
  onReady: null,
49
52
  onChange: null,
50
53
  onFocus: null,
51
- onBlur: null
52
- }
54
+ onBlur: null,
55
+ },
53
56
  },
54
57
  billingAddress: {
55
58
  firstName: 'first-name-value',
56
59
  lastName: 'last-name-value',
57
60
  address: 'address-value',
58
61
  country: 'GB',
59
- region: 'region-value'
62
+ region: 'region-value',
60
63
  },
61
64
  token: {
62
65
  error: null,
63
- data: null
64
- }
66
+ data: null,
67
+ },
65
68
  };
66
69
  this.handleSubmit = this.handleSubmit.bind(this);
67
70
  this.handleUpdateSettings = this.handleUpdateSettings.bind(this);
@@ -76,30 +79,30 @@ class CardElementComponent extends Component {
76
79
  *
77
80
  */
78
81
  const billingAddress = {
79
- ...this.state.billingAddress
82
+ ...this.state.billingAddress,
80
83
  };
81
84
  if (billingAddress.emails) {
82
85
  billingAddress.emails = [
83
86
  {
84
87
  label: 'Email',
85
- value: billingAddress.emails
86
- }
88
+ value: billingAddress.emails,
89
+ },
87
90
  ];
88
91
  }
89
92
  if (billingAddress.phoneNumbers) {
90
93
  billingAddress.phoneNumbers = [
91
94
  {
92
95
  label: 'Phone Number',
93
- value: billingAddress.phoneNumbers
94
- }
96
+ value: billingAddress.phoneNumbers,
97
+ },
95
98
  ];
96
99
  }
97
100
 
98
101
  this.props.Rebilly.createToken(this.formNode, { billingAddress })
99
- .then(data => {
102
+ .then((data) => {
100
103
  this.deepUpdateState({ token: { error: false, data } });
101
104
  })
102
- .catch(err => {
105
+ .catch((err) => {
103
106
  this.deepUpdateState({ token: { error: true, data: err } });
104
107
  });
105
108
  }
@@ -112,149 +115,263 @@ class CardElementComponent extends Component {
112
115
  this.setState({ button: 'update' });
113
116
  this.props.Rebilly.update({
114
117
  ...params,
115
- card: { brands: { allowed: null } }
118
+ card: { brands: { allowed: null } },
116
119
  });
117
120
  }
118
121
 
119
122
  handleRestoreSettings() {
120
123
  this.setState({ button: 'restore' });
121
124
  this.props.Rebilly.update({
122
- ...params
125
+ ...params,
123
126
  });
124
127
  }
125
128
 
126
129
  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
- }
130
+ return (
131
+ <div>
132
+ <h2>{this.props.title}</h2>
133
+ <h3>FramePay version: {this.props.Rebilly.version}</h3>
134
+ <div className="flex-wrapper">
135
+ {prettyDebugRender(this.state)}
136
+ <div className="example-2">
137
+ <form
138
+ id="form"
139
+ ref={(node) => (this.formNode = node)}
140
+ method="post"
141
+ onSubmit={this.handleSubmit}
142
+ >
143
+ <fieldset>
144
+ <div className="field">
145
+ <input
146
+ type="text"
147
+ name="firstName"
148
+ placeholder="First Name"
149
+ defaultValue={
150
+ this.state.billingAddress.firstName
151
+ }
152
+ onChange={(e) => {
153
+ this.deepUpdateState({
154
+ billingAddress: {
155
+ firstName: e.target.value,
156
+ },
157
+ });
158
+ }}
159
+ />
160
+ </div>
161
+ <div className="field">
162
+ <input
163
+ type="text"
164
+ name="lastName"
165
+ placeholder="Last Name"
166
+ defaultValue={
167
+ this.state.billingAddress.lastName
168
+ }
169
+ onChange={(e) => {
170
+ this.deepUpdateState({
171
+ billingAddress: {
172
+ lastName: e.target.value,
173
+ },
174
+ });
175
+ }}
176
+ />
177
+ </div>
178
+ <div className="field">
179
+ <input
180
+ type="text"
181
+ name="email"
182
+ placeholder="Email"
183
+ defaultValue={
184
+ this.state.billingAddress.emails
185
+ }
186
+ onChange={(e) => {
187
+ this.deepUpdateState({
188
+ billingAddress: {
189
+ emails: e.target.value,
190
+ },
191
+ });
192
+ }}
193
+ />
194
+ </div>
195
+ <div className="field">
196
+ <input
197
+ type="text"
198
+ name="phone"
199
+ placeholder="Phone"
200
+ defaultValue={
201
+ this.state.billingAddress
202
+ .phoneNumbers
203
+ }
204
+ onChange={(e) => {
205
+ this.deepUpdateState({
206
+ billingAddress: {
207
+ phoneNumbers:
208
+ e.target.value,
209
+ },
210
+ });
211
+ }}
212
+ />
213
+ </div>
214
+ <div className="field">
215
+ <label htmlFor="card">Card Number</label>
216
+ <this.props.CardNumberElement
217
+ id="card"
218
+ onReady={() =>
219
+ this.deepUpdateState({
220
+ events: {
221
+ number: { onReady: true },
222
+ },
223
+ })
188
224
  }
189
- })}
190
- onFocus={() => this.deepUpdateState({ events: { number: { onFocus: true } } })}
191
- onBlur={() => this.deepUpdateState({ events: { number: { onBlur: true } } })}
192
- />
193
- </div>
225
+ onChange={(data) =>
226
+ this.deepUpdateState({
227
+ events: {
228
+ number: {
229
+ onChange: {
230
+ ...data,
231
+ error:
232
+ data.error ||
233
+ '',
234
+ },
235
+ },
236
+ },
237
+ })
238
+ }
239
+ onFocus={() =>
240
+ this.deepUpdateState({
241
+ events: {
242
+ number: { onFocus: true },
243
+ },
244
+ })
245
+ }
246
+ onBlur={() =>
247
+ this.deepUpdateState({
248
+ events: {
249
+ number: { onBlur: true },
250
+ },
251
+ })
252
+ }
253
+ />
254
+ </div>
194
255
 
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
- }
256
+ <div className="field">
257
+ <label htmlFor="cvv">Card CVV</label>
258
+ <this.props.CardCvvElement
259
+ id="cvv"
260
+ onReady={() =>
261
+ this.deepUpdateState({
262
+ events: {
263
+ cvv: { onReady: true },
264
+ },
265
+ })
266
+ }
267
+ onChange={(data) =>
268
+ this.deepUpdateState({
269
+ events: {
270
+ cvv: {
271
+ onChange: {
272
+ ...data,
273
+ error:
274
+ data.error ||
275
+ '',
276
+ },
277
+ },
278
+ },
279
+ })
208
280
  }
209
- })}
210
- onFocus={() => this.deepUpdateState({ events: { cvv: { onFocus: true } } })}
211
- onBlur={() => this.deepUpdateState({ events: { cvv: { onBlur: true } } })}
212
- />
213
- </div>
281
+ onFocus={() =>
282
+ this.deepUpdateState({
283
+ events: {
284
+ cvv: { onFocus: true },
285
+ },
286
+ })
287
+ }
288
+ onBlur={() =>
289
+ this.deepUpdateState({
290
+ events: {
291
+ cvv: { onBlur: true },
292
+ },
293
+ })
294
+ }
295
+ />
296
+ </div>
214
297
 
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
- }
298
+ <div className="field">
299
+ <label htmlFor="expiry">Card expiry</label>
300
+ <this.props.CardExpiryElement
301
+ id="expiry"
302
+ onReady={() =>
303
+ this.deepUpdateState({
304
+ events: {
305
+ expiry: { onReady: true },
306
+ },
307
+ })
308
+ }
309
+ onChange={(data) =>
310
+ this.deepUpdateState({
311
+ events: {
312
+ expiry: {
313
+ onChange: {
314
+ ...data,
315
+ error:
316
+ data.error ||
317
+ '',
318
+ },
319
+ },
320
+ },
321
+ })
228
322
  }
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>
323
+ onFocus={() =>
324
+ this.deepUpdateState({
325
+ events: {
326
+ expiry: { onFocus: true },
327
+ },
328
+ })
329
+ }
330
+ onBlur={() =>
331
+ this.deepUpdateState({
332
+ events: {
333
+ expiry: { onBlur: true },
334
+ },
335
+ })
336
+ }
337
+ />
338
+ </div>
339
+ </fieldset>
340
+ <button id="submit">Make Payment</button>
341
+ </form>
237
342
 
238
- <button id="btn-update" onClick={this.handleUpdateSettings}>Update</button>
239
- <button id="btn-restore" onClick={this.handleRestoreSettings}>Restore</button>
343
+ <button
344
+ id="btn-update"
345
+ onClick={this.handleUpdateSettings}
346
+ >
347
+ Update
348
+ </button>
349
+ <button
350
+ id="btn-restore"
351
+ onClick={this.handleRestoreSettings}
352
+ >
353
+ Restore
354
+ </button>
355
+ </div>
240
356
  </div>
241
357
  </div>
242
- </div>);
358
+ );
243
359
  }
244
360
  }
245
361
 
246
362
  const CardElement = withFramePayCardComponent(CardElementComponent);
247
363
 
248
364
  class App extends Component {
249
-
250
365
  render() {
251
- return (<FramePayProvider injectStyle {...params}>
252
- <div>
253
- {ReactVersion()}
254
- <CardElement/>
255
- </div>
256
- </FramePayProvider>);
366
+ return (
367
+ <FramePayProvider injectStyle {...params}>
368
+ <div>
369
+ {ReactVersion()}
370
+ <CardElement />
371
+ </div>
372
+ </FramePayProvider>
373
+ );
257
374
  }
258
375
  }
259
376
 
260
- ReactDOM.render(<App/>, document.getElementById('app'));
377
+ ReactDOM.render(<App />, document.getElementById('app'));