@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.
- package/.babelrc +13 -4
- package/.eslintrc.js +3 -0
- package/.prettierrc.js +11 -0
- package/README.md +15 -314
- package/dist/events/base-event.js +6 -9
- package/dist/events/events.spec.js +4 -4
- package/dist/events/index.js +2 -1
- package/dist/functions/destroy.js +12 -14
- package/dist/functions/destroy.spec.js +3 -3
- package/dist/functions/mount/fetch-data.js +187 -0
- package/dist/functions/mount/fetch-data.spec.js +189 -0
- package/dist/functions/mount/index.js +164 -251
- package/dist/functions/mount/mount.spec.js +25 -124
- package/dist/functions/mount/setup-element.js +40 -0
- package/dist/functions/mount/setup-framepay-theme.js +95 -0
- package/dist/functions/mount/setup-framepay.js +46 -0
- package/dist/functions/mount/setup-i18n.js +33 -0
- package/dist/functions/mount/setup-options.js +99 -0
- package/dist/functions/mount/setup-options.spec.js +66 -0
- package/dist/functions/mount/setup-storefront.js +34 -0
- package/dist/functions/mount/setup-styles.js +43 -0
- package/dist/functions/on.js +13 -4
- package/dist/functions/on.spec.js +19 -5
- package/dist/functions/purchase.js +139 -22
- package/dist/functions/purchase.spec.js +23 -19
- package/dist/functions/setup.js +85 -0
- package/dist/functions/setup.spec.js +87 -0
- package/dist/functions/show.js +31 -14
- package/dist/functions/show.spec.js +47 -18
- package/dist/functions/update.js +53 -27
- package/dist/functions/update.spec.js +40 -21
- package/dist/i18n/en.json +5 -2
- package/dist/i18n/es.json +4 -1
- package/dist/index.js +67 -56
- package/dist/index.spec.js +7 -27
- package/dist/loader/index.js +4 -3
- package/dist/storefront/index.js +33 -0
- package/dist/storefront/invoices.js +27 -0
- package/dist/storefront/models/base-model.js +18 -0
- package/dist/storefront/models/invoice-model.js +14 -0
- package/dist/storefront/models/plan-model.js +4 -35
- package/dist/storefront/models/product-model.js +4 -23
- package/dist/storefront/models/summary-model.js +12 -25
- package/dist/storefront/models/transaction-model.js +31 -0
- package/dist/storefront/payment-instruments.js +47 -0
- package/dist/storefront/payment-instruments.spec.js +55 -0
- package/dist/storefront/plans.js +15 -24
- package/dist/storefront/plans.spec.js +17 -44
- package/dist/storefront/products.js +16 -20
- package/dist/storefront/products.spec.js +25 -49
- package/dist/storefront/purchase.js +28 -16
- package/dist/storefront/purchase.spec.js +4 -22
- package/dist/storefront/ready-to-pay.js +26 -22
- package/dist/storefront/ready-to-pay.spec.js +25 -54
- package/dist/storefront/storefront.spec.js +1 -1
- package/dist/storefront/summary.js +27 -24
- package/dist/storefront/summary.spec.js +44 -86
- package/dist/storefront/transactions.js +27 -0
- package/dist/style/base/__snapshots__/theme.spec.js.snap +188 -45
- package/dist/style/base/default-theme.js +699 -0
- package/dist/style/base/index.js +48 -16
- package/dist/style/base/theme.js +15 -48
- package/dist/style/base/theme.spec.js +4 -15
- package/dist/style/components/address.js +3 -3
- package/dist/style/components/button.js +32 -22
- package/dist/style/components/divider.js +9 -9
- package/dist/style/components/forms/checkbox.js +12 -9
- package/dist/style/components/forms/field.js +18 -6
- package/dist/style/components/forms/form.js +2 -2
- package/dist/style/components/forms/input.js +54 -13
- package/dist/style/components/forms/label.js +44 -18
- package/dist/style/components/forms/select.js +54 -22
- package/dist/style/components/forms/validation.js +53 -6
- package/dist/style/components/icons.js +4 -4
- package/dist/style/components/loader.js +5 -3
- package/dist/style/components/methods.js +52 -48
- package/dist/style/components/overlay.js +5 -5
- package/dist/style/helpers/index.js +46 -46
- package/dist/style/index.js +3 -1
- package/dist/style/payment-instruments/payment-card.js +4 -4
- package/dist/style/utils/border.js +47 -0
- package/dist/style/utils/color-values.js +37 -3
- package/dist/style/utils/remove-empty-null.js +20 -0
- package/dist/style/vendor/framepay.js +11 -8
- package/dist/style/vendor/postmate.js +2 -2
- package/dist/style/views/confirmation.js +13 -13
- package/dist/style/views/method-selector.js +3 -3
- package/dist/style/views/modal.js +8 -6
- package/dist/style/views/result.js +4 -4
- package/dist/style/views/summary.js +26 -22
- package/dist/utils/format-currency.js +4 -2
- package/dist/utils/has-valid-css-selector.js +1 -1
- package/dist/utils/process-property-as-dom-element.js +0 -2
- package/dist/views/__snapshots__/summary.spec.js.snap +72 -118
- package/dist/views/common/iframe/base-iframe.js +10 -2
- package/dist/views/common/iframe/modal-iframe.js +50 -4
- package/dist/views/confirmation.js +44 -20
- package/dist/views/method-selector/express-methods/apple-pay.js +92 -0
- package/dist/views/method-selector/express-methods/google-pay.js +31 -0
- package/dist/views/method-selector/express-methods/paypal.js +19 -0
- package/dist/views/method-selector/generate-digital-wallet.js +68 -0
- package/dist/views/method-selector/generate-digital-wallet.spec.js +135 -0
- package/dist/views/method-selector/get-payment-methods.js +27 -7
- package/dist/views/method-selector/get-payment-methods.spec.js +25 -26
- package/dist/views/method-selector/index.js +55 -86
- package/dist/views/method-selector/method-selector.spec.js +80 -69
- package/dist/views/method-selector/mount-express-methods.js +38 -62
- package/dist/views/method-selector/mount-methods.js +18 -18
- package/dist/views/modal.js +18 -12
- package/dist/views/result.js +13 -16
- package/dist/views/summary.js +176 -114
- package/dist/views/summary.spec.js +72 -76
- package/package.json +7 -4
- package/src/events/base-event.js +15 -17
- package/src/events/events.spec.js +6 -4
- package/src/events/index.js +6 -3
- package/src/functions/destroy.js +12 -13
- package/src/functions/destroy.spec.js +30 -31
- package/src/functions/mount/fetch-data.js +152 -0
- package/src/functions/mount/fetch-data.spec.js +238 -0
- package/src/functions/mount/index.js +131 -244
- package/src/functions/mount/mount.spec.js +35 -141
- package/src/functions/mount/setup-element.js +26 -0
- package/src/functions/mount/setup-framepay-theme.js +82 -0
- package/src/functions/mount/setup-framepay.js +41 -0
- package/src/functions/mount/setup-i18n.js +19 -0
- package/src/functions/mount/setup-options.js +103 -0
- package/src/functions/mount/setup-options.spec.js +60 -0
- package/src/functions/mount/setup-storefront.js +24 -0
- package/src/functions/mount/setup-styles.js +30 -0
- package/src/functions/on.js +13 -8
- package/src/functions/on.spec.js +30 -17
- package/src/functions/purchase.js +101 -19
- package/src/functions/purchase.spec.js +18 -18
- package/src/functions/setup.js +48 -0
- package/src/functions/setup.spec.js +98 -0
- package/src/functions/show.js +20 -10
- package/src/functions/show.spec.js +43 -22
- package/src/functions/update.js +50 -27
- package/src/functions/update.spec.js +57 -22
- package/src/i18n/en.json +5 -2
- package/src/i18n/es.json +4 -1
- package/src/i18n/i18n.spec.js +6 -4
- package/src/i18n/index.js +14 -11
- package/src/index.js +41 -52
- package/src/index.spec.js +8 -37
- package/src/loader/index.js +51 -47
- package/src/loader/loader.spec.js +26 -19
- package/src/storefront/index.js +37 -7
- package/src/storefront/invoices.js +11 -0
- package/src/storefront/models/base-model.js +10 -0
- package/src/storefront/models/invoice-model.js +3 -0
- package/src/storefront/models/plan-model.js +3 -35
- package/src/storefront/models/product-model.js +3 -23
- package/src/storefront/models/ready-to-pay-model.js +3 -3
- package/src/storefront/models/summary-model.js +15 -29
- package/src/storefront/models/transaction-model.js +19 -0
- package/src/storefront/payment-instruments.js +30 -0
- package/src/storefront/payment-instruments.spec.js +69 -0
- package/src/storefront/plans.js +16 -23
- package/src/storefront/plans.spec.js +25 -54
- package/src/storefront/products.js +18 -22
- package/src/storefront/products.spec.js +23 -54
- package/src/storefront/purchase.js +14 -14
- package/src/storefront/purchase.spec.js +17 -29
- package/src/storefront/ready-to-pay.js +26 -23
- package/src/storefront/ready-to-pay.spec.js +41 -71
- package/src/storefront/storefront.spec.js +1 -1
- package/src/storefront/summary.js +26 -22
- package/src/storefront/summary.spec.js +60 -109
- package/src/storefront/transactions.js +11 -0
- package/src/style/base/__snapshots__/theme.spec.js.snap +188 -45
- package/src/style/base/default-theme.js +674 -0
- package/src/style/base/index.js +48 -16
- package/src/style/base/theme.js +20 -48
- package/src/style/base/theme.spec.js +5 -15
- package/src/style/browserslist.js +1 -3
- package/src/style/components/address.js +3 -3
- package/src/style/components/button.js +32 -22
- package/src/style/components/divider.js +9 -9
- package/src/style/components/forms/checkbox.js +11 -9
- package/src/style/components/forms/field.js +18 -6
- package/src/style/components/forms/form.js +2 -2
- package/src/style/components/forms/input.js +54 -13
- package/src/style/components/forms/label.js +44 -18
- package/src/style/components/forms/select.js +54 -22
- package/src/style/components/forms/validation.js +53 -6
- package/src/style/components/icons.js +4 -4
- package/src/style/components/index.js +1 -1
- package/src/style/components/loader.js +4 -3
- package/src/style/components/methods.js +52 -48
- package/src/style/components/overlay.js +5 -5
- package/src/style/helpers/index.js +46 -46
- package/src/style/index.js +4 -2
- package/src/style/payment-instruments/payment-card.js +4 -4
- package/src/style/utils/border.js +34 -0
- package/src/style/utils/color-values.js +30 -4
- package/src/style/utils/remove-empty-null.js +10 -0
- package/src/style/vendor/framepay.js +12 -9
- package/src/style/vendor/postmate.js +3 -3
- package/src/style/views/confirmation.js +13 -13
- package/src/style/views/index.js +1 -1
- package/src/style/views/method-selector.js +3 -3
- package/src/style/views/modal.js +9 -7
- package/src/style/views/result.js +4 -4
- package/src/style/views/summary.js +26 -22
- package/src/utils/add-dom-element.js +12 -13
- package/src/utils/format-currency.js +6 -2
- package/src/utils/has-valid-css-selector.js +2 -2
- package/src/utils/is-dom-element.js +1 -1
- package/src/utils/process-property-as-dom-element.js +27 -24
- package/src/utils/sleep.js +1 -1
- package/src/views/__snapshots__/summary.spec.js.snap +72 -118
- package/src/views/common/iframe/base-iframe.js +12 -4
- package/src/views/common/iframe/event-listeners.js +6 -6
- package/src/views/common/iframe/index.js +1 -1
- package/src/views/common/iframe/method-iframe.js +3 -6
- package/src/views/common/iframe/modal-iframe.js +48 -6
- package/src/views/common/iframe/view-iframe.js +3 -5
- package/src/views/common/render-utilities.js +3 -3
- package/src/views/confirmation.js +34 -25
- package/src/views/method-selector/express-methods/apple-pay.js +78 -0
- package/src/views/method-selector/express-methods/google-pay.js +24 -0
- package/src/views/method-selector/express-methods/paypal.js +7 -0
- package/src/views/method-selector/generate-digital-wallet.js +51 -0
- package/src/views/method-selector/generate-digital-wallet.spec.js +135 -0
- package/src/views/method-selector/get-method-data.js +7 -4
- package/src/views/method-selector/get-payment-methods.js +38 -31
- package/src/views/method-selector/get-payment-methods.spec.js +26 -33
- package/src/views/method-selector/index.js +70 -99
- package/src/views/method-selector/method-selector.spec.js +88 -78
- package/src/views/method-selector/mount-express-methods.js +36 -60
- package/src/views/method-selector/mount-methods.js +32 -21
- package/src/views/modal.js +36 -22
- package/src/views/result.js +12 -15
- package/src/views/summary.js +175 -101
- package/src/views/summary.spec.js +99 -74
- package/tests/async-utilities.js +22 -0
- package/tests/mocks/rebilly-instruments-mock.js +89 -77
- package/tests/mocks/storefront-api-mock.js +8 -0
- package/tests/mocks/storefront-mock.js +17 -0
- package/dist/events/purchase-completed.js +0 -24
- package/dist/functions/initialize.js +0 -82
- package/dist/functions/initialize.spec.js +0 -34
- package/dist/functions/mount/fetch-summary-data.js +0 -31
- package/dist/functions/mount/fetch-summary-data.spec.js +0 -45
- package/dist/views/method-selector/process-digital-wallet-options.js +0 -35
- package/dist/views/method-selector/process-digital-wallet-options.spec.js +0 -80
- package/src/events/purchase-completed.js +0 -11
- package/src/functions/initialize.js +0 -74
- package/src/functions/initialize.spec.js +0 -38
- package/src/functions/mount/fetch-summary-data.js +0 -26
- package/src/functions/mount/fetch-summary-data.spec.js +0 -46
- package/src/views/method-selector/process-digital-wallet-options.js +0 -16
- package/src/views/method-selector/process-digital-wallet-options.spec.js +0 -94
package/.babelrc
CHANGED
package/.eslintrc.js
CHANGED
package/.prettierrc.js
ADDED
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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.
|
|
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.
|
|
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
|
|
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(
|
|
15
|
-
expect(
|
|
16
|
-
expect((0, _lodash.default)(internalEventName) in
|
|
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
|
});
|
package/dist/events/index.js
CHANGED
|
@@ -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.
|
|
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
|
|
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
|
-
[...(
|
|
19
|
-
|
|
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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
;
|
|
33
|
+
state.loader.clearAll();
|
|
34
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _events = _interopRequireWildcard(require("
|
|
3
|
+
var _events = _interopRequireWildcard(require("../events"));
|
|
4
4
|
|
|
5
|
-
var _baseEvent = _interopRequireDefault(require("
|
|
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,187 @@
|
|
|
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
|
+
get isShippingRequired() {
|
|
102
|
+
return this.products.some(product => product.requiresShipping);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
exports.DataInstance = DataInstance;
|
|
108
|
+
|
|
109
|
+
async function fetchData({
|
|
110
|
+
state = null,
|
|
111
|
+
riskMetadata = null,
|
|
112
|
+
summaryPayload = null,
|
|
113
|
+
// Dependancy injectable functions
|
|
114
|
+
fetchInvoice = _invoices.fetchInvoice,
|
|
115
|
+
fetchTransaction = _transactions.fetchTransaction
|
|
116
|
+
}) {
|
|
117
|
+
try {
|
|
118
|
+
var _state$options2, _state$options3, _state$data, _state$data$transacti, _state$data3;
|
|
119
|
+
|
|
120
|
+
let transaction = null;
|
|
121
|
+
|
|
122
|
+
if ((_state$options2 = state.options) !== null && _state$options2 !== void 0 && _state$options2.transactionId) {
|
|
123
|
+
transaction = await fetchTransaction({
|
|
124
|
+
data: {
|
|
125
|
+
id: state.options.transactionId
|
|
126
|
+
},
|
|
127
|
+
state
|
|
128
|
+
});
|
|
129
|
+
state.data.transaction = transaction;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
let invoice = null;
|
|
133
|
+
|
|
134
|
+
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) {
|
|
135
|
+
var _state$options4, _state$data2, _state$data2$transact;
|
|
136
|
+
|
|
137
|
+
invoice = await fetchInvoice({
|
|
138
|
+
data: {
|
|
139
|
+
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)
|
|
140
|
+
},
|
|
141
|
+
state
|
|
142
|
+
});
|
|
143
|
+
state.data.invoice = invoice;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (!riskMetadata) {
|
|
147
|
+
const {
|
|
148
|
+
riskMetadata: data
|
|
149
|
+
} = await (0, _riskDataCollector.collectData)();
|
|
150
|
+
riskMetadata = data;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
state.data = new DataInstance({
|
|
154
|
+
state,
|
|
155
|
+
invoice,
|
|
156
|
+
transaction,
|
|
157
|
+
riskMetadata
|
|
158
|
+
});
|
|
159
|
+
const [readyToPay, previewPurchase] = await Promise.all([((_state$data3 = state.data) === null || _state$data3 === void 0 ? void 0 : _state$data3.readyToPay) || (0, _readyToPay.fetchReadyToPay)({
|
|
160
|
+
riskMetadata,
|
|
161
|
+
state
|
|
162
|
+
}), state.options.items ? (0, _summary.fetchSummary)({
|
|
163
|
+
data: summaryPayload,
|
|
164
|
+
state
|
|
165
|
+
}) : null]);
|
|
166
|
+
const plans = await (0, _plans.fetchPlans)({
|
|
167
|
+
state
|
|
168
|
+
});
|
|
169
|
+
state.data.plans = plans;
|
|
170
|
+
const products = await (0, _products.fetchProducts)({
|
|
171
|
+
state
|
|
172
|
+
});
|
|
173
|
+
return new DataInstance({
|
|
174
|
+
state,
|
|
175
|
+
readyToPay,
|
|
176
|
+
previewPurchase,
|
|
177
|
+
plans,
|
|
178
|
+
products,
|
|
179
|
+
invoice,
|
|
180
|
+
transaction,
|
|
181
|
+
riskMetadata
|
|
182
|
+
});
|
|
183
|
+
} catch (error) {// console.log(error);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return new DataInstance({});
|
|
187
|
+
}
|