@rebilly/framepay 1.0.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019, Rebilly, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,102 @@
1
+ # @rebilly/framepay
2
+
3
+ A lightweight wrapper to load Rebilly's [FramePay](https://www.rebilly.com/docs/dev-docs/framepay)
4
+ library and provide types.
5
+
6
+ ## Why use @rebilly/framepay?
7
+
8
+ FramePay must be loaded from our CDN, by adding a script tag to your webpage, for example:
9
+
10
+ ```html
11
+ <html>
12
+ <head>
13
+ <link href="https://framepay.rebilly.com/framepay.css" rel="stylesheet" />
14
+ <script src="https://framepay.rebilly.com/framepay.js"></script>
15
+ </head>
16
+ <body></body>
17
+ </html>
18
+ ```
19
+
20
+ But this can be difficult to implement in a modern web application in a non-blocking way,
21
+ and cannot provide types for typescript applications.
22
+
23
+ This library provides:
24
+
25
+ - 🔄 Async script loading to ensure page rendering isn't blocked
26
+ - ⚡️ A Promise API to know when script loading is complete
27
+ - 🛠 TypeScript support out of the box
28
+
29
+ ## Installation
30
+
31
+ ```bash
32
+ npm install @rebilly/framepay
33
+ # or
34
+ yarn add @rebilly/framepay
35
+ ```
36
+
37
+ ## Usage
38
+
39
+ The package exports a `loadFramepay` function that loads the FramePay CDN script and CSS.
40
+ It returns a promise that resolves with the FramePay instance.
41
+
42
+ ### Basic Usage
43
+
44
+ ```typescript
45
+ import { loadFramepay } from '@rebilly/framepay';
46
+
47
+ try {
48
+ // Load FramePay
49
+ const framepay = await loadFramepay();
50
+ } catch (err) {
51
+ console.error('Failed to load Framepay: ', err);
52
+ }
53
+
54
+ // Use FramePay as normal.
55
+ // For complete examples, see: https://www.rebilly.com/docs/dev-docs/basic-setup
56
+ framepay.initialize({
57
+ publishableKey: 'pk_sandbox_123',
58
+ // ...
59
+ });
60
+ framepay.on('ready', function () {
61
+ const card = framepay.card.mount('#mounting-point');
62
+ });
63
+ ```
64
+
65
+ ### TypeScript Support
66
+
67
+ This package includes TypeScript declarations for FramePay.
68
+
69
+ For example:
70
+
71
+ ```typescript
72
+ import type { FramePay, CardElement } from '@rebilly/framepay';
73
+
74
+ const mountCard = (framepay: FramePay, elementId: string): CardElement => {
75
+ return framepay.card.mount(elementId);
76
+ };
77
+ ```
78
+
79
+ ### Custom Script/Style URLs
80
+
81
+ You can optionally specify custom URLs for the FramePay script and stylesheet:
82
+
83
+ ```typescript
84
+ const framepay = await loadFramepay({
85
+ scriptLink: 'https://custom-domain.com/framepay.js',
86
+ styleLink: 'https://custom-domain.com/framepay.css',
87
+ });
88
+ ```
89
+
90
+ ### Global Window Object
91
+
92
+ When FramePay is loaded, it automatically adds itself to the global window object.
93
+ This means you can also access FramePay directly through these global variables:
94
+
95
+ ```typescript
96
+ const framepay = await loadFramepay();
97
+
98
+ // After loading, you can access FramePay as a global variable:
99
+ window.Framepay.initialize({
100
+ // ...
101
+ });
102
+ ```