@rebilly/instruments 1.0.2-beta.9 → 3.0.0-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 (255) 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 +187 -0
  11. package/dist/functions/mount/fetch-data.spec.js +189 -0
  12. package/dist/functions/mount/index.js +164 -251
  13. package/dist/functions/mount/mount.spec.js +25 -124
  14. package/dist/functions/mount/setup-element.js +40 -0
  15. package/dist/functions/mount/setup-framepay-theme.js +95 -0
  16. package/dist/functions/mount/setup-framepay.js +46 -0
  17. package/dist/functions/mount/setup-i18n.js +33 -0
  18. package/dist/functions/mount/setup-options.js +99 -0
  19. package/dist/functions/mount/setup-options.spec.js +66 -0
  20. package/dist/functions/mount/setup-storefront.js +34 -0
  21. package/dist/functions/mount/setup-styles.js +43 -0
  22. package/dist/functions/on.js +13 -4
  23. package/dist/functions/on.spec.js +19 -5
  24. package/dist/functions/purchase.js +139 -22
  25. package/dist/functions/purchase.spec.js +23 -19
  26. package/dist/functions/setup.js +85 -0
  27. package/dist/functions/setup.spec.js +87 -0
  28. package/dist/functions/show.js +31 -14
  29. package/dist/functions/show.spec.js +47 -18
  30. package/dist/functions/update.js +53 -27
  31. package/dist/functions/update.spec.js +40 -21
  32. package/dist/i18n/en.json +5 -2
  33. package/dist/i18n/es.json +4 -1
  34. package/dist/index.js +67 -56
  35. package/dist/index.spec.js +7 -27
  36. package/dist/loader/index.js +4 -3
  37. package/dist/storefront/index.js +33 -0
  38. package/dist/storefront/invoices.js +27 -0
  39. package/dist/storefront/models/base-model.js +18 -0
  40. package/dist/storefront/models/invoice-model.js +14 -0
  41. package/dist/storefront/models/plan-model.js +4 -35
  42. package/dist/storefront/models/product-model.js +4 -23
  43. package/dist/storefront/models/summary-model.js +12 -25
  44. package/dist/storefront/models/transaction-model.js +31 -0
  45. package/dist/storefront/payment-instruments.js +47 -0
  46. package/dist/storefront/payment-instruments.spec.js +55 -0
  47. package/dist/storefront/plans.js +15 -24
  48. package/dist/storefront/plans.spec.js +17 -44
  49. package/dist/storefront/products.js +16 -20
  50. package/dist/storefront/products.spec.js +25 -49
  51. package/dist/storefront/purchase.js +28 -16
  52. package/dist/storefront/purchase.spec.js +4 -22
  53. package/dist/storefront/ready-to-pay.js +26 -22
  54. package/dist/storefront/ready-to-pay.spec.js +25 -54
  55. package/dist/storefront/storefront.spec.js +1 -1
  56. package/dist/storefront/summary.js +27 -24
  57. package/dist/storefront/summary.spec.js +44 -86
  58. package/dist/storefront/transactions.js +27 -0
  59. package/dist/style/base/__snapshots__/theme.spec.js.snap +188 -45
  60. package/dist/style/base/default-theme.js +699 -0
  61. package/dist/style/base/index.js +48 -16
  62. package/dist/style/base/theme.js +15 -48
  63. package/dist/style/base/theme.spec.js +4 -15
  64. package/dist/style/components/address.js +3 -3
  65. package/dist/style/components/button.js +32 -22
  66. package/dist/style/components/divider.js +9 -9
  67. package/dist/style/components/forms/checkbox.js +12 -9
  68. package/dist/style/components/forms/field.js +18 -6
  69. package/dist/style/components/forms/form.js +2 -2
  70. package/dist/style/components/forms/input.js +54 -13
  71. package/dist/style/components/forms/label.js +44 -18
  72. package/dist/style/components/forms/select.js +54 -22
  73. package/dist/style/components/forms/validation.js +53 -6
  74. package/dist/style/components/icons.js +4 -4
  75. package/dist/style/components/loader.js +5 -3
  76. package/dist/style/components/methods.js +52 -48
  77. package/dist/style/components/overlay.js +5 -5
  78. package/dist/style/helpers/index.js +46 -46
  79. package/dist/style/index.js +3 -1
  80. package/dist/style/payment-instruments/payment-card.js +4 -4
  81. package/dist/style/utils/border.js +47 -0
  82. package/dist/style/utils/color-values.js +37 -3
  83. package/dist/style/utils/remove-empty-null.js +20 -0
  84. package/dist/style/vendor/framepay.js +11 -8
  85. package/dist/style/vendor/postmate.js +2 -2
  86. package/dist/style/views/confirmation.js +13 -13
  87. package/dist/style/views/method-selector.js +3 -3
  88. package/dist/style/views/modal.js +8 -6
  89. package/dist/style/views/result.js +4 -4
  90. package/dist/style/views/summary.js +26 -22
  91. package/dist/utils/format-currency.js +4 -2
  92. package/dist/utils/has-valid-css-selector.js +1 -1
  93. package/dist/utils/process-property-as-dom-element.js +0 -2
  94. package/dist/views/__snapshots__/summary.spec.js.snap +72 -118
  95. package/dist/views/common/iframe/base-iframe.js +10 -2
  96. package/dist/views/common/iframe/modal-iframe.js +50 -4
  97. package/dist/views/confirmation.js +44 -20
  98. package/dist/views/method-selector/express-methods/apple-pay.js +92 -0
  99. package/dist/views/method-selector/express-methods/google-pay.js +31 -0
  100. package/dist/views/method-selector/express-methods/paypal.js +19 -0
  101. package/dist/views/method-selector/generate-digital-wallet.js +68 -0
  102. package/dist/views/method-selector/generate-digital-wallet.spec.js +135 -0
  103. package/dist/views/method-selector/get-payment-methods.js +27 -7
  104. package/dist/views/method-selector/get-payment-methods.spec.js +25 -26
  105. package/dist/views/method-selector/index.js +55 -86
  106. package/dist/views/method-selector/method-selector.spec.js +80 -69
  107. package/dist/views/method-selector/mount-express-methods.js +38 -62
  108. package/dist/views/method-selector/mount-methods.js +18 -18
  109. package/dist/views/modal.js +18 -12
  110. package/dist/views/result.js +13 -16
  111. package/dist/views/summary.js +176 -114
  112. package/dist/views/summary.spec.js +72 -76
  113. package/package.json +7 -4
  114. package/src/events/base-event.js +15 -17
  115. package/src/events/events.spec.js +6 -4
  116. package/src/events/index.js +6 -3
  117. package/src/functions/destroy.js +12 -13
  118. package/src/functions/destroy.spec.js +30 -31
  119. package/src/functions/mount/fetch-data.js +152 -0
  120. package/src/functions/mount/fetch-data.spec.js +238 -0
  121. package/src/functions/mount/index.js +131 -244
  122. package/src/functions/mount/mount.spec.js +35 -141
  123. package/src/functions/mount/setup-element.js +26 -0
  124. package/src/functions/mount/setup-framepay-theme.js +82 -0
  125. package/src/functions/mount/setup-framepay.js +41 -0
  126. package/src/functions/mount/setup-i18n.js +19 -0
  127. package/src/functions/mount/setup-options.js +103 -0
  128. package/src/functions/mount/setup-options.spec.js +60 -0
  129. package/src/functions/mount/setup-storefront.js +24 -0
  130. package/src/functions/mount/setup-styles.js +30 -0
  131. package/src/functions/on.js +13 -8
  132. package/src/functions/on.spec.js +30 -17
  133. package/src/functions/purchase.js +101 -19
  134. package/src/functions/purchase.spec.js +18 -18
  135. package/src/functions/setup.js +48 -0
  136. package/src/functions/setup.spec.js +98 -0
  137. package/src/functions/show.js +20 -10
  138. package/src/functions/show.spec.js +43 -22
  139. package/src/functions/update.js +50 -27
  140. package/src/functions/update.spec.js +57 -22
  141. package/src/i18n/en.json +5 -2
  142. package/src/i18n/es.json +4 -1
  143. package/src/i18n/i18n.spec.js +6 -4
  144. package/src/i18n/index.js +14 -11
  145. package/src/index.js +41 -52
  146. package/src/index.spec.js +8 -37
  147. package/src/loader/index.js +51 -47
  148. package/src/loader/loader.spec.js +26 -19
  149. package/src/storefront/index.js +37 -7
  150. package/src/storefront/invoices.js +11 -0
  151. package/src/storefront/models/base-model.js +10 -0
  152. package/src/storefront/models/invoice-model.js +3 -0
  153. package/src/storefront/models/plan-model.js +3 -35
  154. package/src/storefront/models/product-model.js +3 -23
  155. package/src/storefront/models/ready-to-pay-model.js +3 -3
  156. package/src/storefront/models/summary-model.js +15 -29
  157. package/src/storefront/models/transaction-model.js +19 -0
  158. package/src/storefront/payment-instruments.js +30 -0
  159. package/src/storefront/payment-instruments.spec.js +69 -0
  160. package/src/storefront/plans.js +16 -23
  161. package/src/storefront/plans.spec.js +25 -54
  162. package/src/storefront/products.js +18 -22
  163. package/src/storefront/products.spec.js +23 -54
  164. package/src/storefront/purchase.js +14 -14
  165. package/src/storefront/purchase.spec.js +17 -29
  166. package/src/storefront/ready-to-pay.js +26 -23
  167. package/src/storefront/ready-to-pay.spec.js +41 -71
  168. package/src/storefront/storefront.spec.js +1 -1
  169. package/src/storefront/summary.js +26 -22
  170. package/src/storefront/summary.spec.js +60 -109
  171. package/src/storefront/transactions.js +11 -0
  172. package/src/style/base/__snapshots__/theme.spec.js.snap +188 -45
  173. package/src/style/base/default-theme.js +674 -0
  174. package/src/style/base/index.js +48 -16
  175. package/src/style/base/theme.js +20 -48
  176. package/src/style/base/theme.spec.js +5 -15
  177. package/src/style/browserslist.js +1 -3
  178. package/src/style/components/address.js +3 -3
  179. package/src/style/components/button.js +32 -22
  180. package/src/style/components/divider.js +9 -9
  181. package/src/style/components/forms/checkbox.js +11 -9
  182. package/src/style/components/forms/field.js +18 -6
  183. package/src/style/components/forms/form.js +2 -2
  184. package/src/style/components/forms/input.js +54 -13
  185. package/src/style/components/forms/label.js +44 -18
  186. package/src/style/components/forms/select.js +54 -22
  187. package/src/style/components/forms/validation.js +53 -6
  188. package/src/style/components/icons.js +4 -4
  189. package/src/style/components/index.js +1 -1
  190. package/src/style/components/loader.js +4 -3
  191. package/src/style/components/methods.js +52 -48
  192. package/src/style/components/overlay.js +5 -5
  193. package/src/style/helpers/index.js +46 -46
  194. package/src/style/index.js +4 -2
  195. package/src/style/payment-instruments/payment-card.js +4 -4
  196. package/src/style/utils/border.js +34 -0
  197. package/src/style/utils/color-values.js +30 -4
  198. package/src/style/utils/remove-empty-null.js +10 -0
  199. package/src/style/vendor/framepay.js +12 -9
  200. package/src/style/vendor/postmate.js +3 -3
  201. package/src/style/views/confirmation.js +13 -13
  202. package/src/style/views/index.js +1 -1
  203. package/src/style/views/method-selector.js +3 -3
  204. package/src/style/views/modal.js +9 -7
  205. package/src/style/views/result.js +4 -4
  206. package/src/style/views/summary.js +26 -22
  207. package/src/utils/add-dom-element.js +12 -13
  208. package/src/utils/format-currency.js +6 -2
  209. package/src/utils/has-valid-css-selector.js +2 -2
  210. package/src/utils/is-dom-element.js +1 -1
  211. package/src/utils/process-property-as-dom-element.js +27 -24
  212. package/src/utils/sleep.js +1 -1
  213. package/src/views/__snapshots__/summary.spec.js.snap +72 -118
  214. package/src/views/common/iframe/base-iframe.js +12 -4
  215. package/src/views/common/iframe/event-listeners.js +6 -6
  216. package/src/views/common/iframe/index.js +1 -1
  217. package/src/views/common/iframe/method-iframe.js +3 -6
  218. package/src/views/common/iframe/modal-iframe.js +48 -6
  219. package/src/views/common/iframe/view-iframe.js +3 -5
  220. package/src/views/common/render-utilities.js +3 -3
  221. package/src/views/confirmation.js +34 -25
  222. package/src/views/method-selector/express-methods/apple-pay.js +78 -0
  223. package/src/views/method-selector/express-methods/google-pay.js +24 -0
  224. package/src/views/method-selector/express-methods/paypal.js +7 -0
  225. package/src/views/method-selector/generate-digital-wallet.js +51 -0
  226. package/src/views/method-selector/generate-digital-wallet.spec.js +135 -0
  227. package/src/views/method-selector/get-method-data.js +7 -4
  228. package/src/views/method-selector/get-payment-methods.js +38 -31
  229. package/src/views/method-selector/get-payment-methods.spec.js +26 -33
  230. package/src/views/method-selector/index.js +70 -99
  231. package/src/views/method-selector/method-selector.spec.js +88 -78
  232. package/src/views/method-selector/mount-express-methods.js +36 -60
  233. package/src/views/method-selector/mount-methods.js +32 -21
  234. package/src/views/modal.js +36 -22
  235. package/src/views/result.js +12 -15
  236. package/src/views/summary.js +175 -101
  237. package/src/views/summary.spec.js +99 -74
  238. package/tests/async-utilities.js +22 -0
  239. package/tests/mocks/rebilly-instruments-mock.js +89 -77
  240. package/tests/mocks/storefront-api-mock.js +8 -0
  241. package/tests/mocks/storefront-mock.js +17 -0
  242. package/dist/events/purchase-completed.js +0 -24
  243. package/dist/functions/initialize.js +0 -82
  244. package/dist/functions/initialize.spec.js +0 -34
  245. package/dist/functions/mount/fetch-summary-data.js +0 -31
  246. package/dist/functions/mount/fetch-summary-data.spec.js +0 -45
  247. package/dist/views/method-selector/process-digital-wallet-options.js +0 -35
  248. package/dist/views/method-selector/process-digital-wallet-options.spec.js +0 -80
  249. package/src/events/purchase-completed.js +0 -11
  250. package/src/functions/initialize.js +0 -74
  251. package/src/functions/initialize.spec.js +0 -38
  252. package/src/functions/mount/fetch-summary-data.js +0 -26
  253. package/src/functions/mount/fetch-summary-data.spec.js +0 -46
  254. package/src/views/method-selector/process-digital-wallet-options.js +0 -16
  255. package/src/views/method-selector/process-digital-wallet-options.spec.js +0 -94
@@ -5,150 +5,151 @@ exports[`Summary component should render the summary correctly 1`] = `
5
5
  class="rebilly-instruments-summary-line-items"
6
6
  >
7
7
 
8
-
8
+
9
9
  <div
10
10
  class="rebilly-instruments-summary-line-item"
11
11
  >
12
12
 
13
-
14
-
13
+
14
+
15
15
  <div
16
16
  class="rebilly-instruments-summary-line-item-synopsis"
17
17
  >
18
18
 
19
-
19
+
20
20
  <p
21
21
  class="rebilly-instruments-summary-line-item-synopsis-title"
22
22
  >
23
23
  My Awesome Product
24
24
  </p>
25
25
 
26
+
26
27
 
27
-
28
28
  <p
29
29
  class="rebilly-instruments-summary-line-item-synopsis-description"
30
30
  >
31
31
  My Awesome Product
32
32
  </p>
33
33
 
34
-
35
-
34
+
35
+
36
36
  </div>
37
37
 
38
-
38
+
39
39
  <div
40
40
  class="rebilly-instruments-summary-line-item-price-breakdown"
41
41
  >
42
42
 
43
-
43
+
44
44
  <p
45
45
  class="rebilly-instruments-summary-line-item-price-breakdown-quantity"
46
46
  >
47
47
  1
48
48
  </p>
49
49
 
50
-
50
+
51
51
  <svg
52
52
  class="rebilly-instruments-icon"
53
53
  viewBox="0 0 24 24"
54
54
  xmlns="http://www.w3.org/2000/svg"
55
55
  >
56
56
 
57
-
57
+
58
58
  <path
59
59
  d="M12 10.5858l2.8284-2.8284c.3906-.3906 1.0237-.3906 1.4142 0 .3906.3905.3906 1.0236 0 1.4142L13.4142 12l2.8284 2.8284c.3906.3906.3906 1.0237 0 1.4142-.3905.3906-1.0236.3906-1.4142 0L12 13.4142l-2.8284 2.8284c-.3906.3906-1.0237.3906-1.4142 0-.3906-.3905-.3906-1.0236 0-1.4142L10.5858 12 7.7574 9.1716c-.3906-.3906-.3906-1.0237 0-1.4142.3905-.3906 1.0236-.3906 1.4142 0L12 10.5858z"
60
60
  fill-rule="nonzero"
61
61
  />
62
62
 
63
-
63
+
64
64
  </svg>
65
65
 
66
-
66
+
67
67
  <p
68
68
  class="rebilly-instruments-summary-line-item-price-breakdown-unit-price"
69
69
  >
70
70
  $30.00
71
71
  </p>
72
72
 
73
-
73
+
74
74
  </div>
75
75
 
76
-
76
+
77
77
  </div>
78
78
 
79
+
80
+
79
81
 
80
-
81
82
  <div
82
83
  class="rebilly-instruments-summary-line-item"
83
84
  >
84
85
 
85
-
86
-
86
+
87
+
87
88
  <div
88
89
  class="rebilly-instruments-summary-line-item-synopsis"
89
90
  >
90
91
 
91
-
92
+
92
93
  <p
93
94
  class="rebilly-instruments-summary-line-item-synopsis-title"
94
95
  >
95
96
  My Awesome T-Shirt
96
97
  </p>
97
98
 
99
+
98
100
 
99
-
100
101
  <p
101
102
  class="rebilly-instruments-summary-line-item-synopsis-description"
102
103
  >
103
- My Awesome T-Shirt
104
+ Awesome T-Shirt
104
105
  </p>
105
106
 
106
-
107
-
107
+
108
+
108
109
  </div>
109
110
 
110
-
111
+
111
112
  <div
112
113
  class="rebilly-instruments-summary-line-item-price-breakdown"
113
114
  >
114
115
 
115
-
116
+
116
117
  <p
117
118
  class="rebilly-instruments-summary-line-item-price-breakdown-quantity"
118
119
  >
119
120
  2
120
121
  </p>
121
122
 
122
-
123
+
123
124
  <svg
124
125
  class="rebilly-instruments-icon"
125
126
  viewBox="0 0 24 24"
126
127
  xmlns="http://www.w3.org/2000/svg"
127
128
  >
128
129
 
129
-
130
+
130
131
  <path
131
132
  d="M12 10.5858l2.8284-2.8284c.3906-.3906 1.0237-.3906 1.4142 0 .3906.3905.3906 1.0236 0 1.4142L13.4142 12l2.8284 2.8284c.3906.3906.3906 1.0237 0 1.4142-.3905.3906-1.0236.3906-1.4142 0L12 13.4142l-2.8284 2.8284c-.3906.3906-1.0237.3906-1.4142 0-.3906-.3905-.3906-1.0236 0-1.4142L10.5858 12 7.7574 9.1716c-.3906-.3906-.3906-1.0237 0-1.4142.3905-.3906 1.0236-.3906 1.4142 0L12 10.5858z"
132
133
  fill-rule="nonzero"
133
134
  />
134
135
 
135
-
136
+
136
137
  </svg>
137
138
 
138
-
139
+
139
140
  <p
140
141
  class="rebilly-instruments-summary-line-item-price-breakdown-unit-price"
141
142
  >
142
143
  $20.00
143
144
  </p>
144
145
 
145
-
146
+
146
147
  </div>
147
148
 
148
-
149
+
149
150
  </div>
150
151
 
151
-
152
+
152
153
  </div>
153
154
  `;
154
155
 
@@ -156,137 +157,90 @@ exports[`Summary component should render the summary correctly 2`] = `
156
157
  <div
157
158
  class="rebilly-instruments-summary-breakdown"
158
159
  >
159
-
160
-
161
160
  <table>
162
161
 
163
-
162
+
164
163
  <colgroup>
165
164
 
166
-
165
+
167
166
  <col />
168
167
 
169
-
168
+
170
169
  <col />
171
170
 
172
-
171
+
173
172
  </colgroup>
174
173
 
175
174
 
176
- <tbody>
177
- <tr
178
- class="rebilly-instruments-summary-breakdown-sub-total"
179
- >
180
-
181
-
182
- <td
183
- data-rebilly-i18n="summary.subTotal"
184
- >
185
- Sub Total
186
- </td>
187
-
188
-
189
- <td>
190
- $70.00
191
- </td>
192
-
193
-
194
- </tr>
195
-
175
+ <tr
176
+ class="rebilly-instruments-summary-breakdown-sub-total"
177
+ >
196
178
 
197
- <tr
198
- class="rebilly-instruments-summary-breakdown-discounts"
199
- >
200
-
201
179
 
202
- <td
203
- data-rebilly-i18n="summary.discounts"
204
- >
205
- Discounts
206
- </td>
207
-
208
-
209
- <td>
210
- $0.00
211
- </td>
212
-
213
-
214
- </tr>
215
-
216
-
217
- <tr
218
- class="rebilly-instruments-summary-breakdown-taxes"
180
+ <td
181
+ data-rebilly-i18n="summary.subTotal"
219
182
  >
183
+ Sub Total
184
+ </td>
185
+
220
186
 
221
-
222
- <td
223
- data-rebilly-i18n="summary.taxes"
224
- >
225
- Taxes
226
- </td>
227
-
228
-
229
- <td>
230
- $0.00
231
- </td>
232
-
187
+ <td>
188
+ $70.00
189
+ </td>
233
190
 
234
- </tr>
235
191
 
192
+ </tr>
193
+ <tr
194
+ class="rebilly-instruments-summary-breakdown-taxes"
195
+ >
236
196
 
237
- <tr
238
- class="rebilly-instruments-summary-breakdown-taxes"
239
- >
240
-
241
-
242
- <td
243
- data-rebilly-i18n="summary.shipping"
244
- >
245
- Shipping
246
- </td>
247
197
 
198
+ <td
199
+ data-rebilly-i18n="summary.taxes"
200
+ >
201
+ Taxes
202
+ </td>
203
+
248
204
 
249
- <td>
250
- $0.00
251
- </td>
252
-
205
+ <td>
206
+ $0.00
207
+ </td>
253
208
 
254
- </tr>
255
209
 
256
-
257
- </tbody>
210
+ </tr>
258
211
  </table>
259
-
260
-
261
212
  <div
262
213
  class="rebilly-instruments-summary-breakdown-total"
263
214
  >
264
215
 
265
-
216
+
266
217
  <p
267
218
  data-rebilly-i18n="summary.total"
268
219
  >
269
220
  Total
270
221
  </p>
271
222
 
272
-
223
+
273
224
  <p
274
225
  class="rebilly-instruments-summary-breakdown-total-amount"
275
226
  >
276
227
 
277
-
228
+
278
229
  <span
279
230
  class="rebilly-instruments-summary-breakdown-total-amount-currency"
280
231
  >
232
+
281
233
  USD
234
+
282
235
  </span>
236
+
283
237
  $70.00
238
+
239
+ </p>
240
+ <p>
284
241
 
242
+
285
243
  </p>
286
-
287
-
288
244
  </div>
289
-
290
-
291
245
  </div>
292
246
  `;
@@ -5,12 +5,13 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
- var _postmate = _interopRequireDefault(require("postmate"));
8
+ var _popostmate = _interopRequireDefault(require("popostmate"));
9
9
 
10
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
11
 
12
12
  class BaseIframe {
13
13
  constructor({
14
+ state = {},
14
15
  name = '',
15
16
  url = '',
16
17
  model = {},
@@ -23,6 +24,7 @@ class BaseIframe {
23
24
  classListArray.push('rebilly-instruments-iframe');
24
25
  }
25
26
 
27
+ this.state = state;
26
28
  this.container = container;
27
29
  this.classListArray = classListArray;
28
30
  this.name = name;
@@ -35,8 +37,14 @@ class BaseIframe {
35
37
  })();
36
38
  }
37
39
 
40
+ async destroy() {
41
+ if (this.component.frame.parentNode) {
42
+ await this.component.destroy();
43
+ }
44
+ }
45
+
38
46
  async createComponent() {
39
- const component = await new _postmate.default({
47
+ const component = await new _popostmate.default({
40
48
  name: this.name,
41
49
  url: this.url,
42
50
  container: this.container,
@@ -23,14 +23,60 @@ class ModalIframe extends _baseIframe.default {
23
23
  (0, _eventListeners.dispatchRebillyInsturmentEventHandler)(this);
24
24
  (0, _eventListeners.resizeComponentHandler)(this);
25
25
  (0, _eventListeners.changeIframeSrcHandler)(this);
26
- this.component.on(`${this.name}-close`, (...args) => {
27
- close(...args);
28
- });
29
26
  (0, _eventListeners.stopLoaderHandler)(this, {
30
27
  loader,
31
28
  section: 'modal',
32
29
  id: 'modal-content'
33
- });
30
+ }); // Close modal via postmate
31
+
32
+ this.component.on(`${this.name}-close`, (...args) => {
33
+ close(...args);
34
+ }); // Close modal via postMessage (specifically during approal url flow)
35
+
36
+ window.addEventListener('message', async event => {
37
+ if (event.data === 'rebilly-instruments-approval-url-close') {
38
+ if (this.state.options.transactionType === 'purchase') {
39
+ var _this$state$data$invo;
40
+
41
+ this.state.storefront.setSessionToken(this.state.data.token);
42
+ const [{
43
+ fields: transaction
44
+ }, {
45
+ fields: invoice
46
+ }] = await Promise.all([this.state.storefront.transactions.get({
47
+ id: this.state.data.transaction.id
48
+ }), (_this$state$data$invo = this.state.data.invoice) !== null && _this$state$data$invo !== void 0 && _this$state$data$invo.id ? this.state.storefront.invoices.get({
49
+ id: this.state.data.invoice.id
50
+ }) : {
51
+ fields: null
52
+ }]);
53
+ const updatedPurchase = {
54
+ orderId: this.state.data.orderId,
55
+ token: this.state.data.token,
56
+ transaction
57
+ };
58
+
59
+ if (invoice) {
60
+ updatedPurchase.invoice = invoice;
61
+ }
62
+
63
+ close(updatedPurchase);
64
+ } else if (this.state.options.transactionType === 'setup') {
65
+ this.state.storefront.setSessionToken(this.state.data.instrument.token);
66
+ const {
67
+ fields: transaction
68
+ } = await this.state.storefront.transactions.get({
69
+ id: this.state.data.transaction.id
70
+ });
71
+ close({
72
+ transaction,
73
+ instrument: this.state.data.instrument
74
+ });
75
+ } else {
76
+ close();
77
+ }
78
+ }
79
+ }, false);
34
80
  }
35
81
 
36
82
  }
@@ -3,36 +3,46 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.MountConfirmation = MountConfirmation;
6
+ exports.mountConfirmation = mountConfirmation;
7
7
  exports.baseConfirmationHTML = void 0;
8
8
 
9
+ var _purchase = require("../functions/purchase");
10
+
11
+ var _setup = require("../functions/setup");
12
+
9
13
  var _iframe = require("./common/iframe");
10
14
 
11
15
  var _renderUtilities = require("./common/render-utilities");
12
16
 
17
+ var _methodSelector = require("./method-selector");
18
+
19
+ var _summary = require("./summary");
20
+
13
21
  const baseConfirmationHTML = '<div class="rebilly-instruments-confirmation"></div>';
14
22
  exports.baseConfirmationHTML = baseConfirmationHTML;
15
23
 
16
- async function MountConfirmation({
17
- instrument,
18
- mainStyle
24
+ async function mountConfirmation({
25
+ payload: instrument,
26
+ state
19
27
  }) {
20
- if (instrument.billingAddress && this.summary) {
21
- this._updateSummary.call(this, instrument);
28
+ if (instrument.billingAddress && state.summary && state.data.isPurchase) {
29
+ (0, _summary.updateSummary)({
30
+ state,
31
+ instrument
32
+ });
22
33
  }
23
34
 
24
- (0, _renderUtilities.replaceContent)(this.form, baseConfirmationHTML);
25
- this.loader.startLoading({
35
+ (0, _renderUtilities.replaceContent)(state.form, baseConfirmationHTML);
36
+ state.loader.startLoading({
26
37
  id: 'confirmation'
27
38
  });
28
39
  const container = document.querySelector('.rebilly-instruments-confirmation');
29
40
  const {
30
41
  paymentMethodsUrl
31
- } = this.options._computed;
42
+ } = state.options._computed;
32
43
  const model = {
33
- configs: this.configs,
34
- options: this.options,
35
- mainStyle,
44
+ options: state.options,
45
+ mainStyle: state.mainStyle,
36
46
  instrument
37
47
  };
38
48
  const name = 'rebilly-instruments-confirmation';
@@ -43,26 +53,40 @@ async function MountConfirmation({
43
53
  model
44
54
  });
45
55
  iframe.bindEventListeners({
46
- loader: this.loader
56
+ loader: state.loader
47
57
  });
48
58
  iframe.component.on(`${name}-confirm-purchase`, confirmedInstrument => {
49
- this.purchase(confirmedInstrument);
59
+ (0, _purchase.purchase)({
60
+ state,
61
+ payload: confirmedInstrument
62
+ });
63
+ });
64
+ iframe.component.on(`${name}-confirm-setup`, confirmedInstrument => {
65
+ (0, _setup.setup)({
66
+ state,
67
+ payload: confirmedInstrument
68
+ });
50
69
  });
51
70
  iframe.component.on('choose-another-method', () => {
52
- this.iframeComponents = this.iframeComponents.filter(item => {
71
+ state.iframeComponents = state.iframeComponents.filter(item => {
53
72
  if (item.name === iframe.name) {
54
- item.component.destroy();
73
+ item.destroy();
55
74
  return false;
56
75
  }
57
76
 
58
77
  return true;
59
78
  });
60
79
 
61
- this._updateSummary.call(this);
80
+ if (state.data.isPurchase) {
81
+ (0, _summary.updateSummary)({
82
+ state
83
+ });
84
+ }
62
85
 
63
- this._updateSelector.call(this, {
64
- mainStyle
86
+ (0, _methodSelector.updateMethodSelector)({
87
+ state,
88
+ mainStyle: state.mainStyle
65
89
  });
66
90
  });
67
- this.iframeComponents.push(iframe);
91
+ state.iframeComponents.push(iframe);
68
92
  }
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = mountApplePay;
7
+
8
+ var _events = _interopRequireDefault(require("../../../events"));
9
+
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+
12
+ const browserIsSafari = () => window.ApplePaySession;
13
+
14
+ function mountApplePay({
15
+ state,
16
+ METHOD_ID,
17
+ METHOD_TYPE,
18
+ EXPRESS_METHODS,
19
+ EXPRESS_METHODS_CONTAINER
20
+ }) {
21
+ const container = document.querySelector(`.rebilly-instruments-${METHOD_ID}-method`);
22
+ const digitalWallet = state.options.digitalWallet.applePay;
23
+
24
+ function mountApplePayButton() {
25
+ if (!container.children.length) {
26
+ Rebilly.applePay.mount(`.rebilly-instruments-${METHOD_ID}-method`);
27
+ }
28
+
29
+ state.loader.stopLoading({
30
+ id: `${METHOD_TYPE}-express`
31
+ });
32
+ } // Hack: The correct way to do this is to accept the options via the framepay package
33
+ // Will remove once these options are added to framepay
34
+
35
+
36
+ function updateBtnStyling() {
37
+ const applePayButton = document.querySelector('#rebilly-apple-pay-button');
38
+ applePayButton.style.margin = '0px';
39
+ applePayButton.style.width = '100%';
40
+ applePayButton.style.height = digitalWallet.applePayDisplayOptions.buttonHeight;
41
+ }
42
+
43
+ if (!browserIsSafari()) {
44
+ if (EXPRESS_METHODS.length === 1) {
45
+ EXPRESS_METHODS_CONTAINER.parentNode.style.display = 'none';
46
+ }
47
+
48
+ state.loader.stopLoading({
49
+ id: `${METHOD_TYPE}-express`
50
+ });
51
+ container.style.display = 'none';
52
+ return;
53
+ }
54
+
55
+ container.style.height = digitalWallet.applePayDisplayOptions.buttonHeight;
56
+
57
+ if (!Rebilly.initialized) {
58
+ Rebilly.initialize({
59
+ publishableKey: state.options.publishableKey,
60
+ organizationId: state.options.organizationId,
61
+ digitalWallet
62
+ });
63
+ } else {
64
+ mountApplePayButton();
65
+ updateBtnStyling();
66
+ }
67
+
68
+ Rebilly.on('ready', () => {
69
+ mountApplePayButton();
70
+ updateBtnStyling();
71
+ });
72
+ Rebilly.on('token-ready', token => {
73
+ const instrumentReadyPayload = {
74
+ websiteId: state.options.websiteId,
75
+ items: state.options.items,
76
+ paymentInstruction: {
77
+ token: token.id
78
+ },
79
+ billingAddress: token.billingAddress,
80
+ _raw: token
81
+ };
82
+
83
+ if (!token.shippingAddress) {
84
+ instrumentReadyPayload.deliveryAddress = token.shippingAddress;
85
+ }
86
+
87
+ _events.default.instrumentReady.dispatch(instrumentReadyPayload);
88
+ });
89
+ Rebilly.on('error', error => {
90
+ console.error(error);
91
+ });
92
+ }
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = mountGooglePay;
7
+
8
+ var _iframe = require("../../common/iframe");
9
+
10
+ async function mountGooglePay({
11
+ state,
12
+ METHOD_ID
13
+ }) {
14
+ const container = document.querySelector(`.rebilly-instruments-${METHOD_ID}-method`);
15
+ const {
16
+ paymentMethodsUrl
17
+ } = state.options._computed;
18
+ const model = {
19
+ options: state.options
20
+ };
21
+ const iframe = await new _iframe.MethodIframe({
22
+ name: METHOD_ID,
23
+ url: `${paymentMethodsUrl}/${METHOD_ID}`,
24
+ container,
25
+ model
26
+ });
27
+ iframe.bindEventListeners({
28
+ loader: state.loader
29
+ });
30
+ state.iframeComponents.push(iframe);
31
+ }