@rebilly/instruments 1.0.2-beta.8 → 2.1.1-beta.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 (211) hide show
  1. package/.babelrc +13 -4
  2. package/.eslintrc.js +3 -0
  3. package/.prettierrc.js +11 -0
  4. package/README.md +15 -314
  5. package/dist/events/base-event.js +6 -9
  6. package/dist/events/events.spec.js +4 -4
  7. package/dist/events/index.js +2 -1
  8. package/dist/functions/destroy.js +12 -14
  9. package/dist/functions/destroy.spec.js +3 -3
  10. package/dist/functions/mount/fetch-data.js +183 -0
  11. package/dist/functions/mount/fetch-data.spec.js +189 -0
  12. package/dist/functions/mount/index.js +158 -251
  13. package/dist/functions/mount/mount.spec.js +24 -121
  14. package/dist/functions/mount/setup-element.js +40 -0
  15. package/dist/functions/mount/setup-framepay.js +46 -0
  16. package/dist/functions/mount/setup-i18n.js +33 -0
  17. package/dist/functions/mount/setup-options.js +96 -0
  18. package/dist/functions/mount/setup-options.spec.js +66 -0
  19. package/dist/functions/mount/setup-storefront.js +34 -0
  20. package/dist/functions/mount/setup-styles.js +43 -0
  21. package/dist/functions/on.js +13 -4
  22. package/dist/functions/on.spec.js +19 -5
  23. package/dist/functions/purchase.js +139 -22
  24. package/dist/functions/purchase.spec.js +23 -19
  25. package/dist/functions/setup.js +85 -0
  26. package/dist/functions/setup.spec.js +87 -0
  27. package/dist/functions/show.js +31 -14
  28. package/dist/functions/show.spec.js +47 -18
  29. package/dist/functions/update.js +53 -27
  30. package/dist/functions/update.spec.js +40 -21
  31. package/dist/i18n/en.json +4 -1
  32. package/dist/i18n/es.json +4 -1
  33. package/dist/index.js +67 -56
  34. package/dist/index.spec.js +7 -27
  35. package/dist/loader/index.js +4 -3
  36. package/dist/storefront/index.js +33 -0
  37. package/dist/storefront/invoices.js +27 -0
  38. package/dist/storefront/models/base-model.js +18 -0
  39. package/dist/storefront/models/invoice-model.js +14 -0
  40. package/dist/storefront/models/plan-model.js +4 -35
  41. package/dist/storefront/models/product-model.js +4 -23
  42. package/dist/storefront/models/summary-model.js +12 -25
  43. package/dist/storefront/models/transaction-model.js +31 -0
  44. package/dist/storefront/payment-instruments.js +47 -0
  45. package/dist/storefront/payment-instruments.spec.js +55 -0
  46. package/dist/storefront/plans.js +15 -24
  47. package/dist/storefront/plans.spec.js +17 -44
  48. package/dist/storefront/products.js +16 -20
  49. package/dist/storefront/products.spec.js +25 -49
  50. package/dist/storefront/purchase.js +28 -16
  51. package/dist/storefront/purchase.spec.js +4 -22
  52. package/dist/storefront/ready-to-pay.js +26 -22
  53. package/dist/storefront/ready-to-pay.spec.js +25 -54
  54. package/dist/storefront/storefront.spec.js +1 -1
  55. package/dist/storefront/summary.js +27 -24
  56. package/dist/storefront/summary.spec.js +44 -86
  57. package/dist/storefront/transactions.js +27 -0
  58. package/dist/style/base/theme.js +3 -3
  59. package/dist/style/components/methods.js +43 -42
  60. package/dist/style/utils/color-values.js +1 -3
  61. package/dist/style/views/confirmation.js +0 -4
  62. package/dist/style/views/method-selector.js +1 -1
  63. package/dist/style/views/modal.js +3 -1
  64. package/dist/style/views/summary.js +5 -1
  65. package/dist/utils/format-currency.js +4 -2
  66. package/dist/utils/has-valid-css-selector.js +1 -1
  67. package/dist/utils/process-property-as-dom-element.js +0 -2
  68. package/dist/views/__snapshots__/summary.spec.js.snap +103 -113
  69. package/dist/views/common/iframe/base-iframe.js +10 -2
  70. package/dist/views/common/iframe/modal-iframe.js +44 -3
  71. package/dist/views/confirmation.js +44 -20
  72. package/dist/views/method-selector/express-methods/apple-pay.js +92 -0
  73. package/dist/views/method-selector/express-methods/google-pay.js +31 -0
  74. package/dist/views/method-selector/express-methods/paypal.js +19 -0
  75. package/dist/views/method-selector/generate-digital-wallet.js +68 -0
  76. package/dist/views/method-selector/generate-digital-wallet.spec.js +135 -0
  77. package/dist/views/method-selector/get-payment-methods.js +28 -8
  78. package/dist/views/method-selector/get-payment-methods.spec.js +25 -26
  79. package/dist/views/method-selector/index.js +55 -86
  80. package/dist/views/method-selector/method-selector.spec.js +80 -69
  81. package/dist/views/method-selector/mount-express-methods.js +38 -62
  82. package/dist/views/method-selector/mount-methods.js +18 -18
  83. package/dist/views/modal.js +21 -15
  84. package/dist/views/result.js +13 -16
  85. package/dist/views/summary.js +170 -114
  86. package/dist/views/summary.spec.js +72 -76
  87. package/package.json +5 -4
  88. package/src/events/base-event.js +15 -17
  89. package/src/events/events.spec.js +6 -4
  90. package/src/events/index.js +6 -3
  91. package/src/functions/destroy.js +12 -13
  92. package/src/functions/destroy.spec.js +30 -31
  93. package/src/functions/mount/fetch-data.js +148 -0
  94. package/src/functions/mount/fetch-data.spec.js +238 -0
  95. package/src/functions/mount/index.js +129 -244
  96. package/src/functions/mount/mount.spec.js +35 -139
  97. package/src/functions/mount/setup-element.js +26 -0
  98. package/src/functions/mount/setup-framepay.js +41 -0
  99. package/src/functions/mount/setup-i18n.js +19 -0
  100. package/src/functions/mount/setup-options.js +100 -0
  101. package/src/functions/mount/setup-options.spec.js +60 -0
  102. package/src/functions/mount/setup-storefront.js +24 -0
  103. package/src/functions/mount/setup-styles.js +30 -0
  104. package/src/functions/on.js +13 -8
  105. package/src/functions/on.spec.js +30 -17
  106. package/src/functions/purchase.js +101 -19
  107. package/src/functions/purchase.spec.js +18 -18
  108. package/src/functions/setup.js +48 -0
  109. package/src/functions/setup.spec.js +98 -0
  110. package/src/functions/show.js +20 -10
  111. package/src/functions/show.spec.js +43 -22
  112. package/src/functions/update.js +50 -27
  113. package/src/functions/update.spec.js +57 -22
  114. package/src/i18n/en.json +4 -1
  115. package/src/i18n/es.json +4 -1
  116. package/src/i18n/i18n.spec.js +6 -4
  117. package/src/i18n/index.js +14 -11
  118. package/src/index.js +41 -52
  119. package/src/index.spec.js +8 -37
  120. package/src/loader/index.js +51 -47
  121. package/src/loader/loader.spec.js +26 -19
  122. package/src/storefront/index.js +37 -7
  123. package/src/storefront/invoices.js +11 -0
  124. package/src/storefront/models/base-model.js +10 -0
  125. package/src/storefront/models/invoice-model.js +3 -0
  126. package/src/storefront/models/plan-model.js +3 -35
  127. package/src/storefront/models/product-model.js +3 -23
  128. package/src/storefront/models/ready-to-pay-model.js +3 -3
  129. package/src/storefront/models/summary-model.js +15 -29
  130. package/src/storefront/models/transaction-model.js +19 -0
  131. package/src/storefront/payment-instruments.js +30 -0
  132. package/src/storefront/payment-instruments.spec.js +69 -0
  133. package/src/storefront/plans.js +16 -23
  134. package/src/storefront/plans.spec.js +25 -54
  135. package/src/storefront/products.js +18 -22
  136. package/src/storefront/products.spec.js +23 -54
  137. package/src/storefront/purchase.js +14 -14
  138. package/src/storefront/purchase.spec.js +17 -29
  139. package/src/storefront/ready-to-pay.js +26 -23
  140. package/src/storefront/ready-to-pay.spec.js +41 -71
  141. package/src/storefront/storefront.spec.js +1 -1
  142. package/src/storefront/summary.js +26 -22
  143. package/src/storefront/summary.spec.js +60 -109
  144. package/src/storefront/transactions.js +11 -0
  145. package/src/style/base/theme.js +10 -8
  146. package/src/style/base/theme.spec.js +4 -2
  147. package/src/style/browserslist.js +1 -3
  148. package/src/style/components/button.js +3 -1
  149. package/src/style/components/forms/checkbox.js +3 -1
  150. package/src/style/components/index.js +1 -1
  151. package/src/style/components/loader.js +3 -1
  152. package/src/style/components/methods.js +43 -42
  153. package/src/style/helpers/index.js +1 -1
  154. package/src/style/index.js +2 -1
  155. package/src/style/utils/color-values.js +4 -4
  156. package/src/style/vendor/framepay.js +1 -1
  157. package/src/style/vendor/postmate.js +1 -1
  158. package/src/style/views/confirmation.js +0 -4
  159. package/src/style/views/index.js +1 -1
  160. package/src/style/views/method-selector.js +1 -1
  161. package/src/style/views/modal.js +4 -2
  162. package/src/style/views/summary.js +5 -1
  163. package/src/utils/add-dom-element.js +12 -13
  164. package/src/utils/format-currency.js +6 -2
  165. package/src/utils/has-valid-css-selector.js +2 -2
  166. package/src/utils/is-dom-element.js +1 -1
  167. package/src/utils/process-property-as-dom-element.js +27 -24
  168. package/src/utils/sleep.js +1 -1
  169. package/src/views/__snapshots__/summary.spec.js.snap +103 -113
  170. package/src/views/common/iframe/base-iframe.js +12 -4
  171. package/src/views/common/iframe/event-listeners.js +6 -6
  172. package/src/views/common/iframe/index.js +1 -1
  173. package/src/views/common/iframe/method-iframe.js +3 -6
  174. package/src/views/common/iframe/modal-iframe.js +42 -6
  175. package/src/views/common/iframe/view-iframe.js +3 -5
  176. package/src/views/common/render-utilities.js +3 -3
  177. package/src/views/confirmation.js +34 -25
  178. package/src/views/method-selector/express-methods/apple-pay.js +78 -0
  179. package/src/views/method-selector/express-methods/google-pay.js +24 -0
  180. package/src/views/method-selector/express-methods/paypal.js +7 -0
  181. package/src/views/method-selector/generate-digital-wallet.js +51 -0
  182. package/src/views/method-selector/generate-digital-wallet.spec.js +135 -0
  183. package/src/views/method-selector/get-method-data.js +7 -4
  184. package/src/views/method-selector/get-payment-methods.js +38 -29
  185. package/src/views/method-selector/get-payment-methods.spec.js +26 -33
  186. package/src/views/method-selector/index.js +70 -99
  187. package/src/views/method-selector/method-selector.spec.js +88 -78
  188. package/src/views/method-selector/mount-express-methods.js +36 -60
  189. package/src/views/method-selector/mount-methods.js +32 -21
  190. package/src/views/modal.js +37 -23
  191. package/src/views/result.js +12 -15
  192. package/src/views/summary.js +169 -101
  193. package/src/views/summary.spec.js +99 -74
  194. package/tests/async-utilities.js +22 -0
  195. package/tests/mocks/rebilly-instruments-mock.js +89 -77
  196. package/tests/mocks/storefront-api-mock.js +8 -0
  197. package/tests/mocks/storefront-mock.js +17 -0
  198. package/dist/events/purchase-completed.js +0 -24
  199. package/dist/functions/initialize.js +0 -82
  200. package/dist/functions/initialize.spec.js +0 -34
  201. package/dist/functions/mount/fetch-summary-data.js +0 -31
  202. package/dist/functions/mount/fetch-summary-data.spec.js +0 -45
  203. package/dist/views/method-selector/process-digital-wallet-options.js +0 -35
  204. package/dist/views/method-selector/process-digital-wallet-options.spec.js +0 -80
  205. package/src/events/purchase-completed.js +0 -11
  206. package/src/functions/initialize.js +0 -74
  207. package/src/functions/initialize.spec.js +0 -38
  208. package/src/functions/mount/fetch-summary-data.js +0 -26
  209. package/src/functions/mount/fetch-summary-data.spec.js +0 -46
  210. package/src/views/method-selector/process-digital-wallet-options.js +0 -16
  211. package/src/views/method-selector/process-digital-wallet-options.spec.js +0 -94
package/.babelrc CHANGED
@@ -10,8 +10,17 @@
10
10
  ]
11
11
  ],
12
12
  "plugins": [
13
- ["module-resolver", {
14
- "root": ["./src"]
15
- }]
13
+ [
14
+ "module-resolver",
15
+ {
16
+ "root": [
17
+ "./"
18
+ ],
19
+ "alias": {
20
+ "@": "./src/",
21
+ "test": "./test"
22
+ }
23
+ }
24
+ ]
16
25
  ]
17
- }
26
+ }
package/.eslintrc.js CHANGED
@@ -4,6 +4,9 @@ module.exports = {
4
4
  browser: true,
5
5
  es6: true,
6
6
  },
7
+ globals: {
8
+ Rebilly: "readonly",
9
+ },
7
10
  rules: {
8
11
  'class-methods-use-this': 'off',
9
12
  'import/no-extraneous-dependencies': 'off',
package/.prettierrc.js ADDED
@@ -0,0 +1,11 @@
1
+ module.exports = {
2
+ semi: true,
3
+ tabWidth: 2,
4
+ useTabs: false,
5
+ printWidth: 80,
6
+ endOfLine: 'auto',
7
+ trailingComma: 'none',
8
+ bracketSpacing: true,
9
+ arrowParens: 'always',
10
+ singleQuote: true,
11
+ }
package/README.md CHANGED
@@ -1,14 +1,8 @@
1
- <p align="center">
2
- <img src="https://user-images.githubusercontent.com/1580169/129248437-0d0d5082-1fa5-48a5-b9ae-0b4c9ba1c526.png" alt="drawing" width="176"/>
3
- </p>
4
- <p align="center">
5
- <img src="https://github.com/Rebilly/instruments/actions/workflows/publish.yaml/badge.svg" />
6
- </p>
7
- <p align="center"><br></p>
8
1
  <div align="center">
9
- <h1>Rebilly Instruments</h1>
10
- <p>The last payment integration that you will ever need.</p>
11
- <br>
2
+ <img src="https://user-images.githubusercontent.com/1580169/129248437-0d0d5082-1fa5-48a5-b9ae-0b4c9ba1c526.png" alt="drawing" width="176"/>
3
+ <h1>Rebilly Instruments</h1>
4
+ <p>The last payment integration that you will ever need.</p>
5
+ <br>
12
6
  </div>
13
7
 
14
8
  > **Rebilly Instruments** is in active development and should be treated as **beta** software. This means it may contain bugs and instability.
@@ -51,312 +45,19 @@ Enjoy 🎉
51
45
  <script type="text/javascript">
52
46
  import RebillyInstruments from '@rebilly/instruments';
53
47
 
54
- RebillyInstruments.initialize({
55
- // ...see documentation below for initialize options
56
- });
57
-
58
48
  RebillyInstruments.mount({
59
- // ...see documentation below for mounting options
49
+ publishableKey: 'pk_sandbox_123',
50
+ organizationId: 'org-123',
51
+ websiteId: 'my-website-id',
52
+ items: [
53
+ {
54
+ planId: 'my-plan-id',
55
+ quantity: 1
56
+ },
57
+ ]
58
+ // ...see documentation below for more options
60
59
  });
61
60
  </script>
62
61
  ```
63
62
 
64
- ## Initialization Options
65
-
66
- ### `organizationId`
67
-
68
- **Required** *string*
69
-
70
- The Rebilly organization id that all api requests will be associated with.
71
-
72
- ### `publishableKey`
73
-
74
- **Required** *string*
75
-
76
- The Rebilly publishable api key used to access the storefront api's.
77
-
78
- ### `websiteID`
79
-
80
- **Required** *string*
81
-
82
- The Rebilly website api.
83
-
84
- ### `apiMode`
85
- *string* - default: "live". "live", "sandbox"
86
-
87
- The rebilly storefront api mode
88
-
89
- ### `css`
90
- *string* - default: null.
91
-
92
- A stringified CSS to be injected into the forms to override default styling.
93
-
94
- ```js
95
- {
96
- css: `
97
- .rebilly-instruments-form-field-label {
98
- text-transform: uppercase;
99
- }
100
- `,
101
- }
102
- ```
103
- [List of used classes](https://github.com/Rebilly/instruments/tree/main/docs/CSS_CLASSES.md)
104
-
105
- It is possible to use your web browser developer tools and check the CSS rule you want to target.
106
-
107
- ### `theme`
108
- *object* - default: null
109
-
110
- Configurable object to override some styling. Use alone or with `css` to control the styles.
111
-
112
- ```js
113
- {
114
- typography: {/* options */},
115
- color: {/* options */}
116
- }
117
- ```
118
-
119
- #### `typography`
120
-
121
- * `fontFamily`: Same as CSS property "font-family". Will be used thoughout the library ui
122
-
123
- #### `color`
124
- * `primary`: CSS hexcode or color name, used to draw user attention
125
- * `errorText`: CSS hexcode or color name, used to display error messages
126
- * `text`: CSS hexcode or color name, used to display font color
127
- * `buttonText`: CSS hexcode or color name, used for buttons text, primary will be it's background
128
- * `background`: CSS hexcode or color name, the color used for the background of the forms
129
-
130
-
131
- ### `i18n`
132
- *object* - default: null
133
-
134
- ```js
135
- {
136
- en: {
137
- /* translations */
138
- },
139
- "en-US": {
140
- /* translations */
141
- },
142
- // any other languages...
143
- }
144
- ```
145
-
146
- ## Example Initialization Options
147
- ```js
148
- {
149
- organizationId: "abc-123-xyz",
150
- publishableKey: "def-456-uvw",
151
- websiteId: "ghi-789-qst",
152
- apiMode: "sandbox",
153
- css: ".rebilly-instruments-summary-line-item-figure { border: 2px solid #0044d4; }",
154
- theme: {
155
- color: {
156
- primary: "#0044d4",
157
- errorText: "#cd5c5c",
158
- text: "#0D2B3E",
159
- buttonText: "#ffffff",
160
- background: "#ffffff"
161
- },
162
- typography: {
163
- fontFamily: "Comic Sans MS"
164
- }
165
- },
166
- i18n: {
167
- en: {
168
- confirmation: {
169
- confirm: "Please continue to purchase"
170
- }
171
- }
172
- }
173
- }
174
- ```
175
-
176
- ## Mount Options
177
-
178
- ### `form`
179
-
180
- *string* or *HTMLElement* - default: ".rebilly-instruments"
181
-
182
- The CSS class or HTML element were the form will be mounted
183
-
184
- ### `summary`
185
-
186
- *string* or *HTMLElement* - default: ".rebilly-instruments-summary"
187
-
188
- The CSS class or HTML element were the summary will be mounted.
189
-
190
- ### `options`
191
-
192
- *object*
193
-
194
- The configurations that are to be passed to the library for use.
195
-
196
- ```js
197
- {
198
- local: ''
199
- features: {},
200
- intent: {},
201
- paymentInstruments: {},
202
- }
203
- ```
204
-
205
- ### `local`
206
-
207
- *string* - default: "auto"
208
-
209
- The locale of the forms to be posted, uses browser locale by default.
210
-
211
- ### features
212
-
213
- *object*
214
-
215
- ```js
216
- {
217
- autoConfirmation: true,
218
- autoResult: true
219
- }
220
- ```
221
-
222
- - `autoConfirmation`: default: true. Will mount the confirmation screen after `instrument-ready` event is triggered. Will need to trigger purchase manually if set to false. Can use RebillyInstruments.show('confirmation', options) to mount defautl component
223
-
224
- - autoResult - default: true. Show results of transaction after `purchase-completed` event is triggered will need to handle purchase result manually if set to false. Can use RebillyInstruments.show('result', options) to display default component
225
-
226
- ### `intent`
227
-
228
- *object*
229
-
230
- The information required for purchaseing or vaulting an instrument
231
-
232
- ```js
233
- {
234
- items: [],
235
- countryCode: 'US'
236
- }
237
- ```
238
-
239
- #### `items`
240
-
241
- *Array.objects*
242
-
243
- ```js
244
- [{
245
- planId: 'abc-123-def',
246
- quantity: 1,
247
- thumbnail: 'https://www.example.com/picture.png'
248
- }]
249
- ```
250
-
251
- - `planId`: *string* - Rebilly planId for the item
252
- - `quantity`: *number* - number of this item being purchased
253
- - `thumbnail`: *string* - The image sorce for the item. Recommend ~100px by 100px
254
-
255
- #### `countryCode`
256
-
257
- *string*
258
-
259
- The country code for the transaction
260
-
261
- ### `paymentInstruments`
262
-
263
- *object*
264
-
265
- ```js
266
- {
267
- compactExpressInstruments: true,
268
- address: {},
269
- googlePay: {}
270
- paymentCard: {},
271
- }
272
- ```
273
-
274
- #### `compactExpressInstruments`
275
-
276
- *boolean* - default: true
277
-
278
- Show express methods as inline pill buttons, or list of full width button.
279
-
280
- #### `address`
281
-
282
- *object*
283
-
284
- Address options control how the address form looks across the library.
285
-
286
- ```js
287
- {
288
- name: 'combined',
289
- region: 'split',
290
- show: ['organization', 'phoneNumber'],
291
- hide: ['email', 'address2'],
292
- require: ['address', 'postalCode']
293
- }
294
- ```
295
-
296
- - `name` - *string* - Controls how the first name and last name inputs are displayed. `default`, `combined`, or `stacked`
297
- - `region` - *string* - Controls how the country, region, and postal code inputs are displayed. `default`, `split`, or `stacked`
298
- - `show`- *array < string >* - Controls if `organization` or `phoneNumber` inputs are displayed.
299
- - `hide` - *array < string >* - Controls if `email`, `address2`, `city`, `country`, `region`, or `postalCode` are displayed.
300
- - `require` -*array < string >* - Controls if `organization`, `email`, `phoneNumber`, `address`, `address2`, `city`, `country`, `region`, or `postalCode` inputs are required by the customer.
301
-
302
- > Note: `firstName` and `lastName` are always required. `country` is required if there are shippable plans in the intent.
303
-
304
- #### `paymentCard`
305
-
306
- *object*
307
-
308
- - `popup`: *boolean* - default: false. Show method as a button with a form popup. Otherwise the form will be mounted inline.
309
-
310
- #### `googlePay`
311
-
312
- *object*
313
-
314
- - `displayOptions` - display options for google pay instrument
315
-
316
- **displayOptions**
317
-
318
- - `buttonColor` - default "black". Color of google pay button. "back", "white"
319
- - `buttonType` - default "short". The length of the button. "short", "long"
320
- - `buttonHeight` - The value and units of the button to match other payment buttons. example: "44px", "1rem" etc.
321
-
322
- ## Example Mount Options
323
- ```js
324
- {
325
- form: '.form-mounting-point',
326
- summary: '.summary-mounting-point',
327
- options: {
328
- local: 'en-CA'
329
- features: {
330
- autoConfirmation: true,
331
- autoResult: true
332
- },
333
- intent: {
334
- items: [
335
- {
336
- planId: 'abc-123-def',
337
- quantity: 1,
338
- thumbnail: 'https://www.example.com/picture-1.png'
339
- }, {
340
- planId: 'xyz-987-uvw',
341
- quantity: 2,
342
- thumbnail: 'https://www.example.com/picture-2.png'
343
- }
344
- ],
345
- countryCode: 'US'
346
- },
347
- paymentInstruments: {
348
- compactExpressInstruments: true,
349
- googlePay: {
350
- displayOptions: {
351
- buttonColor: 'black',
352
- buttonType: 'short',
353
- buttonHeight: '44px'
354
- }
355
- },
356
- paymentCard: {
357
- popup: false
358
- },
359
- },
360
- }
361
- }
362
- ```
63
+ See documentation at [Rebilly developer docs](https://www.rebilly.com/docs/content/dev-docs/concept/rebilly-instruments/)
@@ -37,10 +37,12 @@ exports.registeredListeners = registeredListeners;
37
37
 
38
38
  class BaseEvent {
39
39
  /**
40
- * @param {string} name
40
+ * @param {string} name
41
41
  */
42
42
  constructor(name) {
43
- this.name = name;
43
+ // Using namespaced internal name as a protection mechanism
44
+ const PREFIX = 'rebilly-instruments-';
45
+ this.internalName = PREFIX + name;
44
46
  }
45
47
 
46
48
  addEventListener(callback) {
@@ -48,16 +50,11 @@ class BaseEvent {
48
50
  detail
49
51
  }) => callback(detail);
50
52
 
51
- registeredListeners.add(this.name, innerCallback);
52
- }
53
-
54
- removeEventListener() {
55
- document.removeEventListener(this.name, this.callback, false);
56
- this.callback = null;
53
+ registeredListeners.add(this.internalName, innerCallback);
57
54
  }
58
55
 
59
56
  dispatch(detail) {
60
- const event = new CustomEvent(this.name, {
57
+ const event = new CustomEvent(this.internalName, {
61
58
  bubbles: true,
62
59
  detail
63
60
  });
@@ -2,7 +2,7 @@
2
2
 
3
3
  var _lodash = _interopRequireDefault(require("lodash.kebabcase"));
4
4
 
5
- var _events = _interopRequireWildcard(require("@/events"));
5
+ var _ = _interopRequireWildcard(require("./"));
6
6
 
7
7
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
8
8
 
@@ -11,8 +11,8 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
11
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
12
 
13
13
  it('Should export all public event names', async () => {
14
- Object.keys(_events.default).forEach(internalEventName => {
15
- expect(_events.default[internalEventName].name).toEqual((0, _lodash.default)(internalEventName));
16
- expect((0, _lodash.default)(internalEventName) in _events.publicEventNames);
14
+ Object.keys(_.default).forEach(internalEventName => {
15
+ expect(_.default[internalEventName].internalName).toEqual(`rebilly-instruments-${(0, _lodash.default)(internalEventName)}`);
16
+ expect((0, _lodash.default)(internalEventName) in _.publicEventNames);
17
17
  });
18
18
  });
@@ -13,7 +13,8 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
13
13
 
14
14
  const events = {
15
15
  instrumentReady: new _baseEvent.default('instrument-ready'),
16
- purchaseCompleted: new _baseEvent.default('purchase-completed')
16
+ purchaseCompleted: new _baseEvent.default('purchase-completed'),
17
+ setupCompleted: new _baseEvent.default('setup-completed')
17
18
  };
18
19
  var _default = events;
19
20
  exports.default = _default;
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.Destroy = Destroy;
6
+ exports.destroy = destroy;
7
7
 
8
8
  var _rebillyJsSdk = require("rebilly-js-sdk");
9
9
 
@@ -11,26 +11,24 @@ var _baseEvent = require("../events/base-event");
11
11
 
12
12
  var _utils = require("../utils");
13
13
 
14
- async function Destroy() {
14
+ async function destroy({
15
+ state
16
+ }) {
15
17
  // wait to allow for cancellation to catch any pending api requests
16
18
  const sleepMilliseconds = 1000;
17
19
  await (0, _utils.sleep)(sleepMilliseconds);
18
- [...(this.iframeComponents || {})].forEach(iframe => {
19
- var _iframe$component;
20
-
21
- (_iframe$component = iframe.component) === null || _iframe$component === void 0 ? void 0 : _iframe$component.destroy();
20
+ [...(state.iframeComponents || {})].forEach(iframe => {
21
+ iframe.destroy();
22
22
  });
23
23
 
24
24
  _baseEvent.registeredListeners.removeAll(document);
25
25
 
26
- this.iframeComponents = [];
27
- this.hasMounted = false;
28
- this.summary.textContent = '';
29
- this.form.textContent = '';
26
+ state.iframeComponents = [];
27
+ state.hasMounted = false;
28
+ state.summary.textContent = '';
29
+ state.form.textContent = '';
30
30
 
31
31
  _rebillyJsSdk.cancellation.cancelAll();
32
32
 
33
- this.loader.clearAll();
34
- }
35
-
36
- ;
33
+ state.loader.clearAll();
34
+ }
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
 
3
- var _events = _interopRequireWildcard(require("@/events"));
3
+ var _events = _interopRequireWildcard(require("../events"));
4
4
 
5
- var _baseEvent = _interopRequireDefault(require("@/events/base-event"));
5
+ var _baseEvent = _interopRequireDefault(require("../events/base-event"));
6
6
 
7
- var _rebillyInstrumentsMock = require("tests/mocks/rebilly-instruments-mock");
7
+ var _rebillyInstrumentsMock = require("../../tests/mocks/rebilly-instruments-mock");
8
8
 
9
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
10
 
@@ -0,0 +1,183 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.fetchData = fetchData;
7
+ exports.DataInstance = void 0;
8
+
9
+ var _riskDataCollector = require("@rebilly/risk-data-collector");
10
+
11
+ var _plans = require("../../storefront/plans");
12
+
13
+ var _products = require("../../storefront/products");
14
+
15
+ var _readyToPay = require("../../storefront/ready-to-pay");
16
+
17
+ var _summary = require("../../storefront/summary");
18
+
19
+ var _invoices = require("../../storefront/invoices");
20
+
21
+ var _transactions = require("../../storefront/transactions");
22
+
23
+ class DataInstance {
24
+ constructor({
25
+ state = {},
26
+ ...fields
27
+ } = {}) {
28
+ var _state$options;
29
+
30
+ Object.entries({ ...(state.data || {}),
31
+ ...fields
32
+ }).forEach(([key, value]) => {
33
+ this[key] = value;
34
+ });
35
+ this.money = ((_state$options = state.options) === null || _state$options === void 0 ? void 0 : _state$options.money) || null;
36
+ }
37
+
38
+ get amountAndCurrency() {
39
+ let currency;
40
+ let amount;
41
+
42
+ if (this.previewPurchase) {
43
+ currency = this.previewPurchase.currency;
44
+ amount = this.previewPurchase.total;
45
+ } else if (this.invoice) {
46
+ currency = this.invoice.currency;
47
+ amount = this.invoice.amount;
48
+ } else if (this.transaction) {
49
+ currency = this.transaction.currency;
50
+ amount = this.transaction.amount;
51
+ } else if (this.money) {
52
+ currency = this.money.currency;
53
+ amount = this.money.amount;
54
+ }
55
+
56
+ return {
57
+ amount,
58
+ currency
59
+ };
60
+ }
61
+
62
+ get isPayment() {
63
+ return this.invoice || this.transaction || this.money;
64
+ }
65
+
66
+ get isPurchase() {
67
+ return this.previewPurchase;
68
+ }
69
+
70
+ get summaryItems() {
71
+ const {
72
+ discountsAmount = null,
73
+ shippingAmount = null,
74
+ subtotalAmount = null,
75
+ taxAmount = null
76
+ } = this.previewPurchase || this.invoice || {};
77
+ return {
78
+ discountsAmount,
79
+ shippingAmount,
80
+ subtotalAmount,
81
+ taxAmount
82
+ };
83
+ }
84
+
85
+ get summaryLineItems() {
86
+ let lineItems = [];
87
+
88
+ if (this.invoice) {
89
+ ({
90
+ items: lineItems = []
91
+ } = this.invoice);
92
+ } else {
93
+ ({
94
+ lineItems = []
95
+ } = this.previewPurchase || {});
96
+ }
97
+
98
+ return lineItems;
99
+ }
100
+
101
+ }
102
+
103
+ exports.DataInstance = DataInstance;
104
+
105
+ async function fetchData({
106
+ state = null,
107
+ riskMetadata = null,
108
+ summaryPayload = null,
109
+ // Dependancy injectable functions
110
+ fetchInvoice = _invoices.fetchInvoice,
111
+ fetchTransaction = _transactions.fetchTransaction
112
+ }) {
113
+ try {
114
+ var _state$options2, _state$options3, _state$data, _state$data$transacti, _state$data3;
115
+
116
+ let transaction = null;
117
+
118
+ if ((_state$options2 = state.options) !== null && _state$options2 !== void 0 && _state$options2.transactionId) {
119
+ transaction = await fetchTransaction({
120
+ data: {
121
+ id: state.options.transactionId
122
+ },
123
+ state
124
+ });
125
+ state.data.transaction = transaction;
126
+ }
127
+
128
+ let invoice = null;
129
+
130
+ if ((_state$options3 = state.options) !== null && _state$options3 !== void 0 && _state$options3.invoiceId || (_state$data = state.data) !== null && _state$data !== void 0 && (_state$data$transacti = _state$data.transaction) !== null && _state$data$transacti !== void 0 && _state$data$transacti.hasInvoice) {
131
+ var _state$options4, _state$data2, _state$data2$transact;
132
+
133
+ invoice = await fetchInvoice({
134
+ data: {
135
+ id: ((_state$options4 = state.options) === null || _state$options4 === void 0 ? void 0 : _state$options4.invoiceId) || ((_state$data2 = state.data) === null || _state$data2 === void 0 ? void 0 : (_state$data2$transact = _state$data2.transaction) === null || _state$data2$transact === void 0 ? void 0 : _state$data2$transact.invoiceId)
136
+ },
137
+ state
138
+ });
139
+ state.data.invoice = invoice;
140
+ }
141
+
142
+ if (!riskMetadata) {
143
+ const {
144
+ riskMetadata: data
145
+ } = await (0, _riskDataCollector.collectData)();
146
+ riskMetadata = data;
147
+ }
148
+
149
+ state.data = new DataInstance({
150
+ state,
151
+ invoice,
152
+ transaction,
153
+ riskMetadata
154
+ });
155
+ const [readyToPay, previewPurchase] = await Promise.all([((_state$data3 = state.data) === null || _state$data3 === void 0 ? void 0 : _state$data3.readyToPay) || (0, _readyToPay.fetchReadyToPay)({
156
+ riskMetadata,
157
+ state
158
+ }), state.options.items ? (0, _summary.fetchSummary)({
159
+ data: summaryPayload,
160
+ state
161
+ }) : null]);
162
+ const plans = await (0, _plans.fetchPlans)({
163
+ state
164
+ });
165
+ state.data.plans = plans;
166
+ const products = await (0, _products.fetchProducts)({
167
+ state
168
+ });
169
+ return new DataInstance({
170
+ state,
171
+ readyToPay,
172
+ previewPurchase,
173
+ plans,
174
+ products,
175
+ invoice,
176
+ transaction,
177
+ riskMetadata
178
+ });
179
+ } catch (error) {// console.log(error);
180
+ }
181
+
182
+ return new DataInstance({});
183
+ }