@guestyorg/tokenization-js 1.0.3 → 1.1.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/README.md +3 -2
- package/lib/cjs/guesty-tokenization-js.js +6 -4
- package/lib/cjs/guesty-tokenization-js.min.js +1 -1
- package/lib/cjs/src/constants.d.ts +0 -1
- package/lib/cjs/src/constants.d.ts.map +1 -1
- package/lib/cjs/src/loadScript.d.ts.map +1 -1
- package/lib/esm/guesty-tokenization-js.js +6 -4
- package/lib/esm/guesty-tokenization-js.min.js +1 -1
- package/lib/esm/src/constants.d.ts +0 -1
- package/lib/esm/src/constants.d.ts.map +1 -1
- package/lib/esm/src/loadScript.d.ts.map +1 -1
- package/package.json +1 -1
- package/types/index.d.ts +79 -5
package/README.md
CHANGED
|
@@ -41,6 +41,7 @@ Import the `loadScript` function for asynchronously loading the Guesty Tokenizat
|
|
|
41
41
|
#### options
|
|
42
42
|
|
|
43
43
|
- `sandbox` - load the SDK in a sandbox mode
|
|
44
|
+
- `version` - SDK version to load (default: `v1`)
|
|
44
45
|
|
|
45
46
|
```js
|
|
46
47
|
loadScript({ sandbox: true });
|
|
@@ -58,7 +59,7 @@ This is equivalent to the following script:
|
|
|
58
59
|
#### Async/Await
|
|
59
60
|
|
|
60
61
|
```js
|
|
61
|
-
import { loadScript } from '@
|
|
62
|
+
import { loadScript } from '@guestyorg/tokenization-js';
|
|
62
63
|
|
|
63
64
|
try {
|
|
64
65
|
const guestyTokenization = await loadScript();
|
|
@@ -71,7 +72,7 @@ try {
|
|
|
71
72
|
#### Promises
|
|
72
73
|
|
|
73
74
|
```js
|
|
74
|
-
import { loadScript } from '@
|
|
75
|
+
import { loadScript } from '@guestyorg/tokenization-js';
|
|
75
76
|
|
|
76
77
|
loadScript()
|
|
77
78
|
.then((guestyTokenization) => {
|
|
@@ -17,14 +17,16 @@ var injectScriptElement = function (_a) {
|
|
|
17
17
|
};
|
|
18
18
|
|
|
19
19
|
var NAMESPACE = 'guestyTokenization';
|
|
20
|
-
var SCRIPT_URL = 'https://pay.guesty.com/tokenization/v1/init.js';
|
|
21
20
|
|
|
22
21
|
var loadScript = function (options) {
|
|
22
|
+
var _a;
|
|
23
23
|
if (options === void 0) { options = {}; }
|
|
24
24
|
if (typeof window === 'undefined') {
|
|
25
25
|
return Promise.resolve(null);
|
|
26
26
|
}
|
|
27
|
-
var
|
|
27
|
+
var version = (_a = options.version) !== null && _a !== void 0 ? _a : 'v1';
|
|
28
|
+
var scriptUrl = "https://pay.guesty.com/tokenization/".concat(version, "/init.js");
|
|
29
|
+
var existingScript = findScriptElement(scriptUrl);
|
|
28
30
|
var existingNamespace = window[NAMESPACE];
|
|
29
31
|
if (existingScript) {
|
|
30
32
|
if (existingNamespace) {
|
|
@@ -35,7 +37,7 @@ var loadScript = function (options) {
|
|
|
35
37
|
return new Promise(function (resolve, reject) {
|
|
36
38
|
var _a;
|
|
37
39
|
injectScriptElement({
|
|
38
|
-
url:
|
|
40
|
+
url: scriptUrl,
|
|
39
41
|
sandbox: (_a = options.sandbox) !== null && _a !== void 0 ? _a : false,
|
|
40
42
|
onSuccess: function () {
|
|
41
43
|
var newNamespace = window[NAMESPACE];
|
|
@@ -47,7 +49,7 @@ var loadScript = function (options) {
|
|
|
47
49
|
}
|
|
48
50
|
},
|
|
49
51
|
onError: function () {
|
|
50
|
-
reject(new Error("The script ".concat(
|
|
52
|
+
reject(new Error("The script ".concat(scriptUrl, " failed to load")));
|
|
51
53
|
},
|
|
52
54
|
});
|
|
53
55
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var o="guestyTokenization";exports.loadScript=function(n){var e;if(void 0===n&&(n={}),"undefined"==typeof window)return Promise.resolve(null);var r,t=null!==(e=n.version)&&void 0!==e?e:"v1",i="https://pay.guesty.com/tokenization/".concat(t,"/init.js"),s=(r=i,document.querySelector('script[src="'.concat(r,'"]'))),a=window[o];if(s){if(a)return Promise.resolve(a);s.remove()}return new Promise((function(e,r){var t;!function(o){var n=o.url,e=o.sandbox,r=o.onSuccess,t=o.onError,i=document.createElement("script");i.src=n,i.async=!0,i.onerror=t,i.onload=r,e&&i.setAttribute("data-env","sandbox"),document.head.insertBefore(i,document.head.firstElementChild)}({url:i,sandbox:null!==(t=n.sandbox)&&void 0!==t&&t,onSuccess:function(){var n=window[o];n?e(n):r(new Error("Guesty Tokenization is not available"))},onError:function(){r(new Error("The script ".concat(i," failed to load")))}})}))};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS,uBAAuB,CAAC
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS,uBAAuB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loadScript.d.ts","sourceRoot":"","sources":["../../src/loadScript.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE7C,eAAO,MAAM,UAAU,aAAa,iBAAiB,
|
|
1
|
+
{"version":3,"file":"loadScript.d.ts","sourceRoot":"","sources":["../../src/loadScript.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE7C,eAAO,MAAM,UAAU,aAAa,iBAAiB,qBAmCpD,CAAC"}
|
|
@@ -15,14 +15,16 @@ var injectScriptElement = function (_a) {
|
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
var NAMESPACE = 'guestyTokenization';
|
|
18
|
-
var SCRIPT_URL = 'https://pay.guesty.com/tokenization/v1/init.js';
|
|
19
18
|
|
|
20
19
|
var loadScript = function (options) {
|
|
20
|
+
var _a;
|
|
21
21
|
if (options === void 0) { options = {}; }
|
|
22
22
|
if (typeof window === 'undefined') {
|
|
23
23
|
return Promise.resolve(null);
|
|
24
24
|
}
|
|
25
|
-
var
|
|
25
|
+
var version = (_a = options.version) !== null && _a !== void 0 ? _a : 'v1';
|
|
26
|
+
var scriptUrl = "https://pay.guesty.com/tokenization/".concat(version, "/init.js");
|
|
27
|
+
var existingScript = findScriptElement(scriptUrl);
|
|
26
28
|
var existingNamespace = window[NAMESPACE];
|
|
27
29
|
if (existingScript) {
|
|
28
30
|
if (existingNamespace) {
|
|
@@ -33,7 +35,7 @@ var loadScript = function (options) {
|
|
|
33
35
|
return new Promise(function (resolve, reject) {
|
|
34
36
|
var _a;
|
|
35
37
|
injectScriptElement({
|
|
36
|
-
url:
|
|
38
|
+
url: scriptUrl,
|
|
37
39
|
sandbox: (_a = options.sandbox) !== null && _a !== void 0 ? _a : false,
|
|
38
40
|
onSuccess: function () {
|
|
39
41
|
var newNamespace = window[NAMESPACE];
|
|
@@ -45,7 +47,7 @@ var loadScript = function (options) {
|
|
|
45
47
|
}
|
|
46
48
|
},
|
|
47
49
|
onError: function () {
|
|
48
|
-
reject(new Error("The script ".concat(
|
|
50
|
+
reject(new Error("The script ".concat(scriptUrl, " failed to load")));
|
|
49
51
|
},
|
|
50
52
|
});
|
|
51
53
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var n="guestyTokenization",o=function(o){var e;if(void 0===o&&(o={}),"undefined"==typeof window)return Promise.resolve(null);var r,t=null!==(e=o.version)&&void 0!==e?e:"v1",i="https://pay.guesty.com/tokenization/".concat(t,"/init.js"),a=(r=i,document.querySelector('script[src="'.concat(r,'"]'))),s=window[n];if(a){if(s)return Promise.resolve(s);a.remove()}return new Promise((function(e,r){var t;!function(n){var o=n.url,e=n.sandbox,r=n.onSuccess,t=n.onError,i=document.createElement("script");i.src=o,i.async=!0,i.onerror=t,i.onload=r,e&&i.setAttribute("data-env","sandbox"),document.head.insertBefore(i,document.head.firstElementChild)}({url:i,sandbox:null!==(t=o.sandbox)&&void 0!==t&&t,onSuccess:function(){var o=window[n];o?e(o):r(new Error("Guesty Tokenization is not available"))},onError:function(){r(new Error("The script ".concat(i," failed to load")))}})}))};export{o as loadScript};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS,uBAAuB,CAAC
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS,uBAAuB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loadScript.d.ts","sourceRoot":"","sources":["../../src/loadScript.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE7C,eAAO,MAAM,UAAU,aAAa,iBAAiB,
|
|
1
|
+
{"version":3,"file":"loadScript.d.ts","sourceRoot":"","sources":["../../src/loadScript.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE7C,eAAO,MAAM,UAAU,aAAa,iBAAiB,qBAmCpD,CAAC"}
|
package/package.json
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -21,8 +21,16 @@ export interface GuestyTokenizationStyles {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
type Section = 'cardholderName' | 'paymentDetails' | 'billingAddress';
|
|
24
|
+
type TCardholderNameInput = 'firstName' | 'lastName' | 'cardHolderId';
|
|
25
|
+
type TBillingAddressInput = 'street' | 'city' | 'state' | 'zipCode' | 'country';
|
|
26
|
+
type TPaymentDetailsInput = 'cardNumber' | 'expirationDate' | 'csc';
|
|
24
27
|
|
|
25
|
-
|
|
28
|
+
type TInput =
|
|
29
|
+
| TCardholderNameInput
|
|
30
|
+
| TBillingAddressInput
|
|
31
|
+
| TPaymentDetailsInput;
|
|
32
|
+
|
|
33
|
+
export interface GuestyTokenizationV1RenderOptions {
|
|
26
34
|
containerId: string;
|
|
27
35
|
providerId: string;
|
|
28
36
|
amount: number;
|
|
@@ -30,6 +38,28 @@ export interface GuestyTokenizationRenderOptions {
|
|
|
30
38
|
onStatusChange?: (status: boolean) => void;
|
|
31
39
|
styles?: GuestyTokenizationStyles;
|
|
32
40
|
lang?: string;
|
|
41
|
+
initialValues?: {
|
|
42
|
+
[key in Exclude<TInput, 'cardHolderId' | TPaymentDetailsInput>]?: string;
|
|
43
|
+
};
|
|
44
|
+
showInitialValuesToggle?: boolean;
|
|
45
|
+
initialValuesToggleLabel?: string;
|
|
46
|
+
sections?: Section[];
|
|
47
|
+
showSupportedCards?: boolean;
|
|
48
|
+
showPciCompliantLink?: boolean;
|
|
49
|
+
inputsConfig?: {
|
|
50
|
+
[key in TInput]?: {
|
|
51
|
+
label?: string;
|
|
52
|
+
placeholder?: string;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface GuestyTokenizationV2RenderOptions {
|
|
58
|
+
containerId: string;
|
|
59
|
+
providerId: string;
|
|
60
|
+
onStatusChange?: (status: boolean) => void;
|
|
61
|
+
styles?: GuestyTokenizationStyles;
|
|
62
|
+
lang?: string;
|
|
33
63
|
initialValues?: {
|
|
34
64
|
firstName?: string;
|
|
35
65
|
lastName?: string;
|
|
@@ -46,27 +76,71 @@ export interface GuestyTokenizationRenderOptions {
|
|
|
46
76
|
showPciCompliantLink?: boolean;
|
|
47
77
|
}
|
|
48
78
|
|
|
79
|
+
export interface GuestyTokenizationV2ApiV2SubmitPayload {
|
|
80
|
+
amount: number;
|
|
81
|
+
currency: string;
|
|
82
|
+
apiVersion: 'v2';
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export interface GuestyTokenizationV2ApiV3SubmitPayload {
|
|
86
|
+
listingId: string;
|
|
87
|
+
quoteId: string;
|
|
88
|
+
amount: number;
|
|
89
|
+
currency: string;
|
|
90
|
+
guest: {
|
|
91
|
+
firstName: string;
|
|
92
|
+
lastName: string;
|
|
93
|
+
email?: string;
|
|
94
|
+
phone?: string;
|
|
95
|
+
};
|
|
96
|
+
apiVersion?: 'v3';
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export type GuestyTokenizationV2SubmitPayload =
|
|
100
|
+
| GuestyTokenizationV2ApiV2SubmitPayload
|
|
101
|
+
| GuestyTokenizationV2ApiV3SubmitPayload;
|
|
102
|
+
|
|
49
103
|
export interface PaymentMethod {
|
|
50
104
|
_id: string;
|
|
51
105
|
}
|
|
52
106
|
|
|
53
|
-
export interface
|
|
54
|
-
render: (options:
|
|
107
|
+
export interface GuestyTokenizationV1Namespace {
|
|
108
|
+
render: (options: GuestyTokenizationV1RenderOptions) => Promise<void>;
|
|
55
109
|
destroy: () => Promise<void>;
|
|
56
110
|
submit: () => Promise<PaymentMethod>;
|
|
57
111
|
validate: () => void;
|
|
58
112
|
}
|
|
59
113
|
|
|
114
|
+
export interface GuestyTokenizationV2Namespace {
|
|
115
|
+
render: (options: GuestyTokenizationV2RenderOptions) => Promise<void>;
|
|
116
|
+
destroy: () => Promise<void>;
|
|
117
|
+
submit: (
|
|
118
|
+
payload: GuestyTokenizationV2SubmitPayload
|
|
119
|
+
) => Promise<PaymentMethod>;
|
|
120
|
+
validate: () => void;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
type NamespaceBasedOnVersion<T extends LoadScriptOptions['version']> =
|
|
124
|
+
T extends 'v1'
|
|
125
|
+
? GuestyTokenizationV1Namespace
|
|
126
|
+
: T extends 'v2'
|
|
127
|
+
? GuestyTokenizationV2Namespace
|
|
128
|
+
: GuestyTokenizationV1Namespace;
|
|
129
|
+
|
|
60
130
|
export interface LoadScriptOptions {
|
|
61
131
|
sandbox?: boolean;
|
|
132
|
+
version?: 'v1' | 'v2';
|
|
62
133
|
}
|
|
63
134
|
|
|
64
135
|
export function loadScript(
|
|
65
136
|
options?: LoadScriptOptions
|
|
66
|
-
): Promise<
|
|
137
|
+
): Promise<NamespaceBasedOnVersion<LoadScriptOptions['version']> | null>;
|
|
67
138
|
|
|
68
139
|
declare global {
|
|
69
140
|
interface Window {
|
|
70
|
-
guestyTokenization?:
|
|
141
|
+
guestyTokenization?:
|
|
142
|
+
| GuestyTokenizationV1Namespace
|
|
143
|
+
| GuestyTokenizationV2Namespace
|
|
144
|
+
| null;
|
|
71
145
|
}
|
|
72
146
|
}
|