@guestyorg/tokenization-js 1.0.4 → 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 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 });
@@ -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 existingScript = findScriptElement(SCRIPT_URL);
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: SCRIPT_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(SCRIPT_URL, " failed to load")));
52
+ reject(new Error("The script ".concat(scriptUrl, " failed to load")));
51
53
  },
52
54
  });
53
55
  });
@@ -1 +1 @@
1
- "use strict";var e="guestyTokenization",o="https://pay.guesty.com/tokenization/v1/init.js";exports.loadScript=function(n){if(void 0===n&&(n={}),"undefined"==typeof window)return Promise.resolve(null);var r,t=(r=o,document.querySelector('script[src="'.concat(r,'"]'))),i=window[e];if(t){if(i)return Promise.resolve(i);t.remove()}return new Promise((function(r,t){var i;!function(e){var o=e.url,n=e.sandbox,r=e.onSuccess,t=e.onError,i=document.createElement("script");i.src=o,i.async=!0,i.onerror=t,i.onload=r,n&&i.setAttribute("data-env","sandbox"),document.head.insertBefore(i,document.head.firstElementChild)}({url:o,sandbox:null!==(i=n.sandbox)&&void 0!==i&&i,onSuccess:function(){var o=window[e];o?r(o):t(new Error("Guesty Tokenization is not available"))},onError:function(){t(new Error("The script ".concat(o," failed to load")))}})}))};
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,3 +1,2 @@
1
1
  export declare const NAMESPACE = "guestyTokenization";
2
- export declare const SCRIPT_URL = "https://pay.guesty.com/tokenization/v1/init.js";
3
2
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS,uBAAuB,CAAC;AAC9C,eAAO,MAAM,UAAU,mDAAmD,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,qBAgCpD,CAAC"}
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 existingScript = findScriptElement(SCRIPT_URL);
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: SCRIPT_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(SCRIPT_URL, " failed to load")));
50
+ reject(new Error("The script ".concat(scriptUrl, " failed to load")));
49
51
  },
50
52
  });
51
53
  });
@@ -1 +1 @@
1
- var e="guestyTokenization",n="https://pay.guesty.com/tokenization/v1/init.js",o=function(o){if(void 0===o&&(o={}),"undefined"==typeof window)return Promise.resolve(null);var r,t=(r=n,document.querySelector('script[src="'.concat(r,'"]'))),i=window[e];if(t){if(i)return Promise.resolve(i);t.remove()}return new Promise((function(r,t){var i;!function(e){var n=e.url,o=e.sandbox,r=e.onSuccess,t=e.onError,i=document.createElement("script");i.src=n,i.async=!0,i.onerror=t,i.onload=r,o&&i.setAttribute("data-env","sandbox"),document.head.insertBefore(i,document.head.firstElementChild)}({url:n,sandbox:null!==(i=o.sandbox)&&void 0!==i&&i,onSuccess:function(){var n=window[e];n?r(n):t(new Error("Guesty Tokenization is not available"))},onError:function(){t(new Error("The script ".concat(n," failed to load")))}})}))};export{o as loadScript};
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,3 +1,2 @@
1
1
  export declare const NAMESPACE = "guestyTokenization";
2
- export declare const SCRIPT_URL = "https://pay.guesty.com/tokenization/v1/init.js";
3
2
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS,uBAAuB,CAAC;AAC9C,eAAO,MAAM,UAAU,mDAAmD,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,qBAgCpD,CAAC"}
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guestyorg/tokenization-js",
3
- "version": "1.0.4",
3
+ "version": "1.1.0",
4
4
  "description": "Guesty Tokenization SDK loading utility and types",
5
5
  "main": "index.js",
6
6
  "module": "lib/esm/guesty-tokenization-js.js",
package/types/index.d.ts CHANGED
@@ -30,7 +30,7 @@ type TInput =
30
30
  | TBillingAddressInput
31
31
  | TPaymentDetailsInput;
32
32
 
33
- export interface GuestyTokenizationRenderOptions {
33
+ export interface GuestyTokenizationV1RenderOptions {
34
34
  containerId: string;
35
35
  providerId: string;
36
36
  amount: number;
@@ -54,27 +54,93 @@ export interface GuestyTokenizationRenderOptions {
54
54
  };
55
55
  }
56
56
 
57
+ export interface GuestyTokenizationV2RenderOptions {
58
+ containerId: string;
59
+ providerId: string;
60
+ onStatusChange?: (status: boolean) => void;
61
+ styles?: GuestyTokenizationStyles;
62
+ lang?: string;
63
+ initialValues?: {
64
+ firstName?: string;
65
+ lastName?: string;
66
+ street?: string;
67
+ city?: string;
68
+ state?: string;
69
+ zipCode?: string;
70
+ country?: string;
71
+ };
72
+ showInitialValuesToggle?: boolean;
73
+ initialValuesToggleLabel?: string;
74
+ sections?: Section[];
75
+ showSupportedCards?: boolean;
76
+ showPciCompliantLink?: boolean;
77
+ }
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
+
57
103
  export interface PaymentMethod {
58
104
  _id: string;
59
105
  }
60
106
 
61
- export interface GuestyTokenizationNamespace {
62
- render: (options: GuestyTokenizationRenderOptions) => Promise<void>;
107
+ export interface GuestyTokenizationV1Namespace {
108
+ render: (options: GuestyTokenizationV1RenderOptions) => Promise<void>;
63
109
  destroy: () => Promise<void>;
64
110
  submit: () => Promise<PaymentMethod>;
65
111
  validate: () => void;
66
112
  }
67
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
+
68
130
  export interface LoadScriptOptions {
69
131
  sandbox?: boolean;
132
+ version?: 'v1' | 'v2';
70
133
  }
71
134
 
72
135
  export function loadScript(
73
136
  options?: LoadScriptOptions
74
- ): Promise<GuestyTokenizationNamespace | null>;
137
+ ): Promise<NamespaceBasedOnVersion<LoadScriptOptions['version']> | null>;
75
138
 
76
139
  declare global {
77
140
  interface Window {
78
- guestyTokenization?: GuestyTokenizationNamespace | null;
141
+ guestyTokenization?:
142
+ | GuestyTokenizationV1Namespace
143
+ | GuestyTokenizationV2Namespace
144
+ | null;
79
145
  }
80
146
  }