@rebilly/instruments 1.0.2-beta.1 → 1.0.2-beta.10
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 +27 -0
- package/.prettierrc.js +11 -0
- package/CONTRIBUTING.md +4 -0
- package/README.md +350 -0
- package/dist/events/base-event.js +40 -11
- package/dist/events/events.spec.js +18 -0
- package/dist/events/index.js +10 -7
- package/dist/functions/destroy.js +27 -5
- package/dist/functions/destroy.spec.js +69 -0
- package/dist/functions/initialize.js +24 -20
- package/dist/functions/initialize.spec.js +4 -4
- package/dist/functions/mount/fetch-summary-data.js +26 -11
- package/dist/functions/mount/fetch-summary-data.spec.js +15 -16
- package/dist/functions/mount/index.js +168 -106
- package/dist/functions/mount/mount.spec.js +14 -36
- package/dist/functions/on.js +25 -17
- package/dist/functions/on.spec.js +36 -18
- package/dist/functions/purchase.js +33 -74
- package/dist/functions/purchase.spec.js +17 -14
- package/dist/functions/show.js +31 -8
- package/dist/functions/show.spec.js +42 -17
- package/dist/functions/update.js +60 -4
- package/dist/functions/update.spec.js +100 -0
- package/dist/i18n/en.json +19 -0
- package/dist/i18n/es.json +19 -0
- package/dist/i18n/index.js +5 -0
- package/dist/index.js +67 -55
- package/dist/index.spec.js +6 -10
- package/dist/loader/index.js +24 -4
- package/dist/loader/loader.spec.js +4 -4
- package/dist/storefront/models/ready-to-pay-model.js +7 -1
- package/dist/storefront/plans.js +9 -10
- package/dist/storefront/plans.spec.js +20 -20
- package/dist/storefront/products.js +9 -10
- package/dist/storefront/products.spec.js +20 -20
- package/dist/storefront/purchase.js +9 -8
- package/dist/storefront/purchase.spec.js +7 -4
- package/dist/storefront/ready-to-pay.js +12 -11
- package/dist/storefront/ready-to-pay.spec.js +24 -19
- package/dist/storefront/storefront.spec.js +1 -1
- package/dist/storefront/summary.js +11 -12
- package/dist/storefront/summary.spec.js +25 -24
- package/dist/style/base/__snapshots__/theme.spec.js.snap +52 -0
- package/dist/style/base/index.js +72 -0
- package/dist/style/base/theme.js +73 -0
- package/dist/style/base/theme.spec.js +30 -0
- package/dist/style/browserslist.js +8 -0
- package/dist/style/components/address.js +64 -0
- package/dist/style/components/button.js +61 -0
- package/dist/style/components/divider.js +48 -0
- package/dist/style/components/forms/checkbox.js +83 -0
- package/dist/style/components/forms/field.js +53 -0
- package/dist/style/components/forms/form.js +28 -0
- package/dist/style/components/forms/input.js +45 -0
- package/dist/style/components/forms/label.js +43 -0
- package/dist/style/components/forms/select.js +63 -0
- package/dist/style/components/forms/validation.js +34 -0
- package/dist/style/components/icons.js +22 -0
- package/dist/style/components/index.js +57 -0
- package/dist/style/components/loader.js +48 -0
- package/dist/style/components/methods.js +104 -0
- package/dist/style/components/overlay.js +33 -0
- package/dist/style/helpers/index.js +59 -0
- package/dist/style/index.js +48 -0
- package/dist/style/payment-instruments/content.js +17 -0
- package/dist/style/payment-instruments/index.js +20 -0
- package/dist/{styles → style/payment-instruments}/payment-card.js +14 -6
- package/dist/{styles/shade-tint-values-helper.js → style/utils/color-values.js} +5 -9
- package/dist/style/vendor/framepay.js +34 -0
- package/dist/style/vendor/postmate.js +17 -0
- package/dist/style/views/confirmation.js +85 -0
- package/dist/style/views/index.js +29 -0
- package/dist/style/views/method-selector.js +20 -0
- package/dist/style/views/modal.js +93 -0
- package/dist/style/views/result.js +61 -0
- package/dist/style/views/summary.js +123 -0
- package/dist/utils/format-currency.js +1 -0
- package/dist/utils/has-valid-css-selector.js +1 -1
- package/dist/utils/index.js +3 -19
- package/dist/utils/process-property-as-dom-element.js +0 -2
- package/dist/utils/sleep.js +10 -0
- package/{src/components → dist/views}/__snapshots__/summary.spec.js.snap +7 -3
- package/dist/views/common/iframe/base-iframe.js +57 -0
- package/dist/views/common/iframe/event-listeners.js +50 -0
- package/dist/views/common/iframe/index.js +19 -0
- package/dist/views/common/iframe/method-iframe.js +33 -0
- package/dist/views/common/iframe/modal-iframe.js +38 -0
- package/dist/views/common/iframe/view-iframe.js +31 -0
- package/dist/views/common/render-utilities.js +11 -0
- package/dist/views/confirmation.js +82 -0
- package/dist/views/method-selector/__snapshots__/method-selector.spec.js.snap +3 -0
- package/dist/views/method-selector/express-methods/apple-pay.js +92 -0
- package/dist/views/method-selector/express-methods/google-pay.js +32 -0
- package/dist/views/method-selector/express-methods/paypal.js +19 -0
- package/dist/views/method-selector/generate-digital-wallet.js +59 -0
- package/dist/views/method-selector/generate-digital-wallet.spec.js +132 -0
- package/dist/views/method-selector/get-method-data.js +25 -0
- package/dist/{components/form → views/method-selector}/get-payment-methods.js +22 -6
- package/dist/views/method-selector/get-payment-methods.spec.js +44 -0
- package/dist/views/method-selector/index.js +133 -0
- package/dist/views/method-selector/method-selector.spec.js +139 -0
- package/dist/views/method-selector/mount-express-methods.js +69 -0
- package/dist/views/method-selector/mount-methods.js +78 -0
- package/dist/views/modal.js +83 -0
- package/dist/views/result.js +42 -0
- package/dist/{components → views}/summary.js +36 -25
- package/dist/{components → views}/summary.spec.js +49 -22
- package/package.json +11 -5
- package/src/events/base-event.js +35 -12
- package/src/events/events.spec.js +11 -0
- package/src/events/index.js +12 -6
- package/src/functions/destroy.js +22 -3
- package/src/functions/destroy.spec.js +63 -0
- package/src/functions/initialize.js +23 -18
- package/src/functions/initialize.spec.js +9 -7
- package/src/functions/mount/fetch-summary-data.js +16 -13
- package/src/functions/mount/fetch-summary-data.spec.js +22 -27
- package/src/functions/mount/index.js +194 -133
- package/src/functions/mount/mount.spec.js +83 -84
- package/src/functions/on.js +17 -14
- package/src/functions/on.spec.js +39 -29
- package/src/functions/purchase.js +24 -64
- package/src/functions/purchase.spec.js +19 -17
- package/src/functions/show.js +26 -6
- package/src/functions/show.spec.js +41 -19
- package/src/functions/update.js +49 -3
- package/src/functions/update.spec.js +107 -0
- package/src/i18n/i18n.spec.js +6 -4
- package/src/i18n/index.js +19 -11
- package/src/index.js +42 -51
- package/src/index.spec.js +11 -20
- package/src/loader/index.js +55 -39
- package/src/loader/loader.spec.js +30 -23
- package/src/storefront/index.js +9 -7
- package/src/storefront/models/plan-model.js +1 -1
- package/src/storefront/models/product-model.js +1 -1
- package/src/storefront/models/ready-to-pay-model.js +10 -4
- package/src/storefront/models/summary-model.js +8 -15
- package/src/storefront/plans.js +16 -12
- package/src/storefront/plans.spec.js +29 -37
- package/src/storefront/products.js +16 -12
- package/src/storefront/products.spec.js +28 -39
- package/src/storefront/purchase.js +8 -6
- package/src/storefront/purchase.spec.js +18 -17
- package/src/storefront/ready-to-pay.js +19 -13
- package/src/storefront/ready-to-pay.spec.js +41 -41
- package/src/storefront/storefront.spec.js +1 -1
- package/src/storefront/summary.js +14 -12
- package/src/storefront/summary.spec.js +37 -50
- package/src/style/base/__snapshots__/theme.spec.js.snap +52 -0
- package/src/style/base/index.js +63 -0
- package/src/style/base/theme.js +61 -0
- package/src/style/base/theme.spec.js +32 -0
- package/src/style/browserslist.js +1 -0
- package/src/style/components/address.js +55 -0
- package/src/style/components/button.js +54 -0
- package/src/style/components/divider.js +39 -0
- package/src/style/components/forms/checkbox.js +76 -0
- package/src/style/components/forms/field.js +44 -0
- package/src/style/components/forms/form.js +19 -0
- package/src/style/components/forms/input.js +36 -0
- package/src/style/components/forms/label.js +34 -0
- package/src/style/components/forms/select.js +54 -0
- package/src/style/components/forms/validation.js +25 -0
- package/src/style/components/icons.js +13 -0
- package/src/style/components/index.js +35 -0
- package/src/style/components/loader.js +41 -0
- package/src/style/components/methods.js +93 -0
- package/src/style/components/overlay.js +24 -0
- package/src/style/helpers/index.js +51 -0
- package/src/style/index.js +30 -0
- package/src/style/payment-instruments/content.js +8 -0
- package/src/style/payment-instruments/index.js +10 -0
- package/src/style/payment-instruments/payment-card.js +26 -0
- package/src/style/utils/color-values.js +9 -0
- package/src/style/vendor/framepay.js +25 -0
- package/src/style/vendor/postmate.js +8 -0
- package/src/style/views/confirmation.js +76 -0
- package/src/style/views/index.js +16 -0
- package/src/style/views/method-selector.js +11 -0
- package/src/style/views/modal.js +84 -0
- package/src/style/views/result.js +52 -0
- package/src/style/views/summary.js +114 -0
- package/src/utils/add-dom-element.js +12 -13
- package/src/utils/format-currency.js +4 -1
- package/src/utils/has-valid-css-selector.js +2 -2
- package/src/utils/index.js +2 -6
- 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 +3 -0
- package/src/views/__snapshots__/summary.spec.js.snap +292 -0
- package/src/views/common/iframe/base-iframe.js +46 -0
- package/src/views/common/iframe/event-listeners.js +27 -0
- package/src/views/common/iframe/index.js +7 -0
- package/src/views/common/iframe/method-iframe.js +21 -0
- package/src/views/common/iframe/modal-iframe.js +27 -0
- package/src/views/common/iframe/view-iframe.js +18 -0
- package/src/views/common/render-utilities.js +4 -0
- package/src/views/confirmation.js +57 -0
- package/src/views/method-selector/__snapshots__/method-selector.spec.js.snap +3 -0
- package/src/views/method-selector/express-methods/apple-pay.js +78 -0
- package/src/views/method-selector/express-methods/google-pay.js +25 -0
- package/src/views/method-selector/express-methods/paypal.js +7 -0
- package/src/views/method-selector/generate-digital-wallet.js +44 -0
- package/src/views/method-selector/generate-digital-wallet.spec.js +131 -0
- package/src/{components/form → views/method-selector}/get-method-data.js +9 -5
- package/src/views/method-selector/get-payment-methods.js +40 -0
- package/src/views/method-selector/get-payment-methods.spec.js +40 -0
- package/src/views/method-selector/index.js +110 -0
- package/src/views/method-selector/method-selector.spec.js +146 -0
- package/src/views/method-selector/mount-express-methods.js +53 -0
- package/src/views/method-selector/mount-methods.js +71 -0
- package/src/views/modal.js +84 -0
- package/src/views/result.js +30 -0
- package/src/{components → views}/summary.js +65 -33
- package/src/views/summary.spec.js +170 -0
- package/tests/async-utilities.js +22 -0
- package/tests/mocks/rebilly-instruments-mock.js +105 -7
- package/dist/components/confirmation.js +0 -113
- package/dist/components/form/form.js +0 -143
- package/dist/components/form/form.spec.js +0 -111
- package/dist/components/form/get-method-data.js +0 -21
- package/dist/components/form/method-selector.js +0 -60
- package/dist/components/form/mount-express-payment-methods.js +0 -102
- package/dist/components/form/process-digital-wallet-options.js +0 -24
- package/dist/components/form/zoid-helpers.js +0 -131
- package/dist/components/result.js +0 -68
- package/dist/events/instrument-ready.js +0 -24
- package/dist/events/purchase-complete.js +0 -24
- package/dist/styles/base-styles.js +0 -793
- package/dist/styles/flat-theme-object.js +0 -23
- package/dist/styles/framepay.js +0 -38
- package/dist/styles/main.js +0 -29
- package/dist/styles/style-variables.js +0 -44
- package/dist/utils/camel-case.js +0 -10
- package/dist/utils/kebab-case.js +0 -10
- package/dist/utils/un-kebab-case.js +0 -10
- package/src/components/confirmation.js +0 -81
- package/src/components/form/__snapshots__/form.spec.js.snap +0 -43
- package/src/components/form/form.js +0 -117
- package/src/components/form/form.spec.js +0 -109
- package/src/components/form/get-payment-methods.js +0 -32
- package/src/components/form/method-selector.js +0 -47
- package/src/components/form/mount-express-payment-methods.js +0 -84
- package/src/components/form/process-digital-wallet-options.js +0 -11
- package/src/components/form/zoid-helpers.js +0 -117
- package/src/components/result.js +0 -50
- package/src/components/summary.spec.js +0 -106
- package/src/events/instrument-ready.js +0 -11
- package/src/events/purchase-complete.js +0 -11
- package/src/styles/base-styles.js +0 -784
- package/src/styles/flat-theme-object.js +0 -12
- package/src/styles/framepay.js +0 -30
- package/src/styles/main.js +0 -17
- package/src/styles/payment-card.js +0 -18
- package/src/styles/shade-tint-values-helper.js +0 -13
- package/src/styles/style-variables.js +0 -34
- package/src/utils/camel-case.js +0 -3
- package/src/utils/kebab-case.js +0 -3
- package/src/utils/un-kebab-case.js +0 -3
package/.babelrc
CHANGED
package/.eslintrc.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
root: true,
|
|
3
|
+
env: {
|
|
4
|
+
browser: true,
|
|
5
|
+
es6: true,
|
|
6
|
+
},
|
|
7
|
+
globals: {
|
|
8
|
+
Rebilly: "readonly",
|
|
9
|
+
},
|
|
10
|
+
rules: {
|
|
11
|
+
'class-methods-use-this': 'off',
|
|
12
|
+
'import/no-extraneous-dependencies': 'off',
|
|
13
|
+
'import/prefer-default-export': 'off',
|
|
14
|
+
'max-classes-per-file': 'off',
|
|
15
|
+
'max-len': ['error', {code: 120, ignoreStrings: true, ignoreTemplateLiterals: true, ignoreUrls: true}],
|
|
16
|
+
'no-useless-catch': 'off',
|
|
17
|
+
'no-underscore-dangle': 'off',
|
|
18
|
+
'no-console': 'off',
|
|
19
|
+
'no-param-reassign': 0,
|
|
20
|
+
quotes: ["error", "single"],
|
|
21
|
+
},
|
|
22
|
+
parser: 'babel-eslint',
|
|
23
|
+
extends: [
|
|
24
|
+
'airbnb-base',
|
|
25
|
+
'prettier',
|
|
26
|
+
],
|
|
27
|
+
};
|
package/.prettierrc.js
ADDED
package/CONTRIBUTING.md
ADDED
package/README.md
CHANGED
|
@@ -10,3 +10,353 @@
|
|
|
10
10
|
<p>The last payment integration that you will ever need.</p>
|
|
11
11
|
<br>
|
|
12
12
|
</div>
|
|
13
|
+
|
|
14
|
+
> **Rebilly Instruments** is in active development and should be treated as **beta** software. This means it may contain bugs and instability.
|
|
15
|
+
|
|
16
|
+
<div align="center">
|
|
17
|
+
<br>
|
|
18
|
+
<img src="https://user-images.githubusercontent.com/13054039/134418583-e051a891-5559-4170-9364-b5f89a96082e.png" alt="rebilly instruments" width="600"/>
|
|
19
|
+
<br>
|
|
20
|
+
<br>
|
|
21
|
+
</div>
|
|
22
|
+
|
|
23
|
+
# Getting Started
|
|
24
|
+
|
|
25
|
+
## ⏳ Installation
|
|
26
|
+
|
|
27
|
+
Install Rebilly Instruments with this **Quickstart** command to add Rebilly instruments to your existing project:
|
|
28
|
+
|
|
29
|
+
- Use **yarn** to install (recommended). [Install yarn with these docs](https://yarnpkg.com/lang/en/docs/install/).
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
yarn add @rebilly/instruments
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
**or**
|
|
36
|
+
|
|
37
|
+
- Use npm/npx to install Rebilly Instruments.
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
npx install @rebilly/instruments
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Enjoy 🎉
|
|
44
|
+
|
|
45
|
+
# 🛠️ Usage
|
|
46
|
+
|
|
47
|
+
```html
|
|
48
|
+
<div class="rebilly-instruments-summary"></div>
|
|
49
|
+
<div class="rebilly-instruments"></div>
|
|
50
|
+
|
|
51
|
+
<script type="text/javascript">
|
|
52
|
+
import RebillyInstruments from '@rebilly/instruments';
|
|
53
|
+
|
|
54
|
+
RebillyInstruments.initialize({
|
|
55
|
+
// ...see documentation below for initialize options
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
RebillyInstruments.mount({
|
|
59
|
+
// ...see documentation below for mounting options
|
|
60
|
+
});
|
|
61
|
+
</script>
|
|
62
|
+
```
|
|
63
|
+
|
|
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
|
+
```
|
|
@@ -3,29 +3,58 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default = void 0;
|
|
6
|
+
exports.default = exports.registeredListeners = exports.RegisteredListeners = void 0;
|
|
7
|
+
|
|
8
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
9
|
+
|
|
10
|
+
class RegisteredListeners {
|
|
11
|
+
constructor() {
|
|
12
|
+
_defineProperty(this, "_listeners", {});
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
add(eventName, callback) {
|
|
16
|
+
document.addEventListener(eventName, callback, false);
|
|
17
|
+
|
|
18
|
+
if (!(eventName in this._listeners)) {
|
|
19
|
+
this._listeners[eventName] = [];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
this._listeners[eventName].push(callback);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
removeAll() {
|
|
26
|
+
Object.keys(this._listeners).forEach(eventName => {
|
|
27
|
+
this._listeners[eventName].forEach(callback => document.removeEventListener(eventName, callback, false));
|
|
28
|
+
});
|
|
29
|
+
this._listeners = {};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
exports.RegisteredListeners = RegisteredListeners;
|
|
35
|
+
const registeredListeners = new RegisteredListeners();
|
|
36
|
+
exports.registeredListeners = registeredListeners;
|
|
7
37
|
|
|
8
38
|
class BaseEvent {
|
|
39
|
+
/**
|
|
40
|
+
* @param {string} name
|
|
41
|
+
*/
|
|
9
42
|
constructor(name) {
|
|
10
|
-
|
|
11
|
-
|
|
43
|
+
// Using namespaced internal name as a protection mechanism
|
|
44
|
+
const PREFIX = 'rebilly-instruments-';
|
|
45
|
+
this.internalName = PREFIX + name;
|
|
12
46
|
}
|
|
13
47
|
|
|
14
48
|
addEventListener(callback) {
|
|
15
|
-
|
|
49
|
+
const innerCallback = ({
|
|
16
50
|
detail
|
|
17
51
|
}) => callback(detail);
|
|
18
52
|
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
removeEventListener() {
|
|
23
|
-
document.removeEventListener(this.name, this.callback, false);
|
|
24
|
-
this.callback = null;
|
|
53
|
+
registeredListeners.add(this.internalName, innerCallback);
|
|
25
54
|
}
|
|
26
55
|
|
|
27
56
|
dispatch(detail) {
|
|
28
|
-
const event = new CustomEvent(this.
|
|
57
|
+
const event = new CustomEvent(this.internalName, {
|
|
29
58
|
bubbles: true,
|
|
30
59
|
detail
|
|
31
60
|
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _lodash = _interopRequireDefault(require("lodash.kebabcase"));
|
|
4
|
+
|
|
5
|
+
var _ = _interopRequireWildcard(require("./"));
|
|
6
|
+
|
|
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
|
+
|
|
9
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
10
|
+
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
+
|
|
13
|
+
it('Should export all public event names', async () => {
|
|
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
|
+
});
|
|
18
|
+
});
|
package/dist/events/index.js
CHANGED
|
@@ -3,16 +3,19 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default = void 0;
|
|
6
|
+
exports.publicEventNames = exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _lodash = _interopRequireDefault(require("lodash.kebabcase"));
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _baseEvent = _interopRequireDefault(require("./base-event"));
|
|
11
11
|
|
|
12
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
instrumentReady: new
|
|
16
|
-
|
|
14
|
+
const events = {
|
|
15
|
+
instrumentReady: new _baseEvent.default('instrument-ready'),
|
|
16
|
+
purchaseCompleted: new _baseEvent.default('purchase-completed')
|
|
17
17
|
};
|
|
18
|
-
|
|
18
|
+
var _default = events;
|
|
19
|
+
exports.default = _default;
|
|
20
|
+
const publicEventNames = Object.keys(events).map(internalName => (0, _lodash.default)(internalName));
|
|
21
|
+
exports.publicEventNames = publicEventNames;
|
|
@@ -3,10 +3,32 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.destroy = destroy;
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
console.error('Destroy no yet implemented');
|
|
10
|
-
}
|
|
8
|
+
var _rebillyJsSdk = require("rebilly-js-sdk");
|
|
11
9
|
|
|
12
|
-
;
|
|
10
|
+
var _baseEvent = require("../events/base-event");
|
|
11
|
+
|
|
12
|
+
var _utils = require("../utils");
|
|
13
|
+
|
|
14
|
+
async function destroy({
|
|
15
|
+
state
|
|
16
|
+
}) {
|
|
17
|
+
// wait to allow for cancellation to catch any pending api requests
|
|
18
|
+
const sleepMilliseconds = 1000;
|
|
19
|
+
await (0, _utils.sleep)(sleepMilliseconds);
|
|
20
|
+
[...(state.iframeComponents || {})].forEach(iframe => {
|
|
21
|
+
iframe.destroy();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
_baseEvent.registeredListeners.removeAll(document);
|
|
25
|
+
|
|
26
|
+
state.iframeComponents = [];
|
|
27
|
+
state.hasMounted = false;
|
|
28
|
+
state.summary.textContent = '';
|
|
29
|
+
state.form.textContent = '';
|
|
30
|
+
|
|
31
|
+
_rebillyJsSdk.cancellation.cancelAll();
|
|
32
|
+
|
|
33
|
+
state.loader.clearAll();
|
|
34
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _events = _interopRequireWildcard(require("../events"));
|
|
4
|
+
|
|
5
|
+
var _baseEvent = _interopRequireDefault(require("../events/base-event"));
|
|
6
|
+
|
|
7
|
+
var _rebillyInstrumentsMock = require("../../tests/mocks/rebilly-instruments-mock");
|
|
8
|
+
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
+
|
|
11
|
+
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); }
|
|
12
|
+
|
|
13
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
14
|
+
|
|
15
|
+
describe('RebillyInstruments Destroy', () => {
|
|
16
|
+
it('should be able to destroy instance', async () => {
|
|
17
|
+
const rebillyInstruments = await (0, _rebillyInstrumentsMock.RenderMockRebillyInstruments)();
|
|
18
|
+
const formElement = document.querySelector('.form-selector');
|
|
19
|
+
const summaryElement = document.querySelector('.summary-selector');
|
|
20
|
+
expect(formElement.innerHTML).not.toEqual('');
|
|
21
|
+
expect(summaryElement.innerHTML).not.toEqual('');
|
|
22
|
+
await rebillyInstruments.destroy();
|
|
23
|
+
expect(formElement.innerHTML).toEqual('');
|
|
24
|
+
expect(summaryElement.innerHTML).toEqual('');
|
|
25
|
+
});
|
|
26
|
+
it('should remove registered listeners', async () => {
|
|
27
|
+
const rebillyInstruments = await (0, _rebillyInstrumentsMock.RenderMockRebillyInstruments)();
|
|
28
|
+
const fakeEventListener = jest.fn();
|
|
29
|
+
_events.default.fakeEvent = new _baseEvent.default('fake-event');
|
|
30
|
+
|
|
31
|
+
_events.publicEventNames.push('fake-event');
|
|
32
|
+
|
|
33
|
+
rebillyInstruments.on('fake-event', fakeEventListener);
|
|
34
|
+
|
|
35
|
+
_events.default.fakeEvent.dispatch();
|
|
36
|
+
|
|
37
|
+
expect(fakeEventListener).toHaveBeenCalledTimes(1);
|
|
38
|
+
fakeEventListener.mockClear();
|
|
39
|
+
await rebillyInstruments.destroy();
|
|
40
|
+
|
|
41
|
+
_events.default.fakeEvent.dispatch();
|
|
42
|
+
|
|
43
|
+
expect(fakeEventListener).not.toHaveBeenCalled();
|
|
44
|
+
});
|
|
45
|
+
it('should remove multiple listeners on the same event', async () => {
|
|
46
|
+
const rebillyInstruments = await (0, _rebillyInstrumentsMock.RenderMockRebillyInstruments)();
|
|
47
|
+
const fakeEventListener = jest.fn();
|
|
48
|
+
const anotherFakeEventListener = jest.fn();
|
|
49
|
+
_events.default.fakeEvent = new _baseEvent.default('fake-event');
|
|
50
|
+
|
|
51
|
+
_events.publicEventNames.push('fake-event');
|
|
52
|
+
|
|
53
|
+
rebillyInstruments.on('fake-event', fakeEventListener);
|
|
54
|
+
rebillyInstruments.on('fake-event', anotherFakeEventListener);
|
|
55
|
+
|
|
56
|
+
_events.default.fakeEvent.dispatch();
|
|
57
|
+
|
|
58
|
+
expect(fakeEventListener).toHaveBeenCalledTimes(1);
|
|
59
|
+
expect(anotherFakeEventListener).toHaveBeenCalledTimes(1);
|
|
60
|
+
fakeEventListener.mockClear();
|
|
61
|
+
anotherFakeEventListener.mockClear();
|
|
62
|
+
await rebillyInstruments.destroy();
|
|
63
|
+
|
|
64
|
+
_events.default.fakeEvent.dispatch();
|
|
65
|
+
|
|
66
|
+
expect(fakeEventListener).not.toHaveBeenCalled();
|
|
67
|
+
expect(anotherFakeEventListener).not.toHaveBeenCalled();
|
|
68
|
+
});
|
|
69
|
+
});
|