@gatepayfe/pay-js-react 0.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/README.md +66 -0
- package/dist/cjs/gate-pay-element.cjs +187 -0
- package/dist/cjs/gate-pay-element.d.ts +4 -0
- package/dist/cjs/gate-pay-element.d.ts.map +1 -0
- package/dist/cjs/index.cjs +56 -0
- package/dist/cjs/index.d.ts +5 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/types.cjs +18 -0
- package/dist/cjs/types.d.ts +13 -0
- package/dist/cjs/types.d.ts.map +1 -0
- package/dist/esm/gate-pay-element.d.ts +4 -0
- package/dist/esm/gate-pay-element.d.ts.map +1 -0
- package/dist/esm/gate-pay-element.js +153 -0
- package/dist/esm/index.d.ts +5 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/types.d.ts +13 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +0 -0
- package/package.json +51 -0
package/README.md
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# @gatepayfe/pay-js-react
|
|
2
|
+
|
|
3
|
+
React bindings for [`@gatepayfe/pay-js`](../pay-js). Provides a declarative `<GatePayElement />` component.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @gatepayfe/pay-js @gatepayfe/pay-js-react react react-dom
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Peer dependencies: `react` ^18.2.0 or ^19.0.0, `react-dom` ^18.2.0 or ^19.0.0.
|
|
12
|
+
|
|
13
|
+
## Quick start
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import { GatePayElement } from '@gatepayfe/pay-js-react'
|
|
17
|
+
|
|
18
|
+
export function Checkout() {
|
|
19
|
+
return (
|
|
20
|
+
<GatePayElement
|
|
21
|
+
gatePay={{
|
|
22
|
+
clientId: 'your-client-id',
|
|
23
|
+
locale: 'en-US',
|
|
24
|
+
theme: 'auto',
|
|
25
|
+
}}
|
|
26
|
+
payment={{
|
|
27
|
+
clientSessionSecret: 'cs_xxx',
|
|
28
|
+
onReady: () => console.log('ready'),
|
|
29
|
+
onSuccess: result => console.log('paid', result),
|
|
30
|
+
onError: error => console.error(error),
|
|
31
|
+
}}
|
|
32
|
+
/>
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Next.js App Router
|
|
38
|
+
|
|
39
|
+
This package is marked with `"use client"`. Import it only in Client Components.
|
|
40
|
+
|
|
41
|
+
```tsx
|
|
42
|
+
'use client'
|
|
43
|
+
|
|
44
|
+
import { GatePayElement } from '@gatepayfe/pay-js-react'
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Ref API
|
|
48
|
+
|
|
49
|
+
```tsx
|
|
50
|
+
import { useRef } from 'react'
|
|
51
|
+
import { GatePayElement, type GatePayElementRef } from '@gatepayfe/pay-js-react'
|
|
52
|
+
|
|
53
|
+
const ref = useRef<GatePayElementRef>(null)
|
|
54
|
+
|
|
55
|
+
// ref.current?.updateLocale('zh-CN')
|
|
56
|
+
// ref.current?.updateTheme('dark')
|
|
57
|
+
// ref.current?.destroy()
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Re-exports
|
|
61
|
+
|
|
62
|
+
This package also re-exports core APIs from `@gatepayfe/pay-js` (`GatePay`, `CheckoutBridge`, types, etc.).
|
|
63
|
+
|
|
64
|
+
## License
|
|
65
|
+
|
|
66
|
+
UNLICENSED — contact Gate Pay for usage terms.
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
var __webpack_require__ = {};
|
|
4
|
+
(()=>{
|
|
5
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
6
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: definition[key]
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
})();
|
|
12
|
+
(()=>{
|
|
13
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
14
|
+
})();
|
|
15
|
+
(()=>{
|
|
16
|
+
__webpack_require__.r = (exports1)=>{
|
|
17
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
18
|
+
value: 'Module'
|
|
19
|
+
});
|
|
20
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
21
|
+
value: true
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
})();
|
|
25
|
+
var __webpack_exports__ = {};
|
|
26
|
+
__webpack_require__.r(__webpack_exports__);
|
|
27
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
28
|
+
GatePayElement: ()=>gate_pay_element_GatePayElement
|
|
29
|
+
});
|
|
30
|
+
const pay_js_namespaceObject = require("@gatepayfe/pay-js");
|
|
31
|
+
const external_react_namespaceObject = require("react");
|
|
32
|
+
function toMethodKey(methods) {
|
|
33
|
+
var _ref;
|
|
34
|
+
return null != (_ref = null == methods ? void 0 : methods.join('|')) ? _ref : '';
|
|
35
|
+
}
|
|
36
|
+
function toRecreateKey(gatePay, payment) {
|
|
37
|
+
var _gatePay_baseUrl, _gatePay_debug, _gatePay_fiatCurrency, _payment_showLanguageSwitcher;
|
|
38
|
+
return JSON.stringify({
|
|
39
|
+
baseUrl: null != (_gatePay_baseUrl = gatePay.baseUrl) ? _gatePay_baseUrl : pay_js_namespaceObject.DEFAULT_GATE_PAY_BASE_URL,
|
|
40
|
+
clientId: gatePay.clientId,
|
|
41
|
+
debug: null != (_gatePay_debug = gatePay.debug) ? _gatePay_debug : false,
|
|
42
|
+
fiatCurrency: null != (_gatePay_fiatCurrency = gatePay.fiatCurrency) ? _gatePay_fiatCurrency : '',
|
|
43
|
+
clientSessionSecret: payment.clientSessionSecret,
|
|
44
|
+
paymentMethods: toMethodKey(payment.paymentMethods),
|
|
45
|
+
showLanguageSwitcher: null != (_payment_showLanguageSwitcher = payment.showLanguageSwitcher) ? _payment_showLanguageSwitcher : false
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
function getRuntimeConfig(gatePay, payment) {
|
|
49
|
+
var _payment_locale, _payment_theme;
|
|
50
|
+
return {
|
|
51
|
+
locale: null != (_payment_locale = payment.locale) ? _payment_locale : gatePay.locale,
|
|
52
|
+
theme: null != (_payment_theme = payment.theme) ? _payment_theme : gatePay.theme
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
const gate_pay_element_GatePayElement = /*#__PURE__*/ (0, external_react_namespaceObject.forwardRef)(function(param, ref) {
|
|
56
|
+
let { gatePay, payment, ...divProps } = param;
|
|
57
|
+
const containerRef = (0, external_react_namespaceObject.useRef)(null);
|
|
58
|
+
const elementRef = (0, external_react_namespaceObject.useRef)(null);
|
|
59
|
+
const runtimeConfigRef = (0, external_react_namespaceObject.useRef)({});
|
|
60
|
+
const callbacksRef = (0, external_react_namespaceObject.useRef)({});
|
|
61
|
+
callbacksRef.current = {
|
|
62
|
+
onReady: payment.onReady,
|
|
63
|
+
onProcessing: payment.onProcessing,
|
|
64
|
+
onSuccess: payment.onSuccess,
|
|
65
|
+
onCancel: payment.onCancel,
|
|
66
|
+
onExpired: payment.onExpired,
|
|
67
|
+
onSessionExpired: payment.onSessionExpired,
|
|
68
|
+
onError: payment.onError,
|
|
69
|
+
onStatusChange: payment.onStatusChange
|
|
70
|
+
};
|
|
71
|
+
const recreateKey = toRecreateKey(gatePay, payment);
|
|
72
|
+
const destroyElement = ()=>{
|
|
73
|
+
var _elementRef_current;
|
|
74
|
+
null == (_elementRef_current = elementRef.current) || _elementRef_current.destroy();
|
|
75
|
+
elementRef.current = null;
|
|
76
|
+
};
|
|
77
|
+
const mountElement = ()=>{
|
|
78
|
+
const container = containerRef.current;
|
|
79
|
+
if (!container) return;
|
|
80
|
+
destroyElement();
|
|
81
|
+
const runtimeConfig = getRuntimeConfig(gatePay, payment);
|
|
82
|
+
const gatePayInstance = (0, pay_js_namespaceObject.GatePay)({
|
|
83
|
+
...gatePay,
|
|
84
|
+
locale: runtimeConfig.locale,
|
|
85
|
+
theme: runtimeConfig.theme
|
|
86
|
+
});
|
|
87
|
+
const paymentElement = gatePayInstance.createPaymentElement({
|
|
88
|
+
clientSessionSecret: payment.clientSessionSecret,
|
|
89
|
+
paymentMethods: payment.paymentMethods,
|
|
90
|
+
locale: runtimeConfig.locale,
|
|
91
|
+
theme: runtimeConfig.theme,
|
|
92
|
+
showLanguageSwitcher: payment.showLanguageSwitcher,
|
|
93
|
+
onReady: ()=>{
|
|
94
|
+
var _callbacksRef_current_onReady, _callbacksRef_current;
|
|
95
|
+
return null == (_callbacksRef_current_onReady = (_callbacksRef_current = callbacksRef.current).onReady) ? void 0 : _callbacksRef_current_onReady.call(_callbacksRef_current);
|
|
96
|
+
},
|
|
97
|
+
onProcessing: (detail)=>{
|
|
98
|
+
var _callbacksRef_current_onProcessing, _callbacksRef_current;
|
|
99
|
+
return null == (_callbacksRef_current_onProcessing = (_callbacksRef_current = callbacksRef.current).onProcessing) ? void 0 : _callbacksRef_current_onProcessing.call(_callbacksRef_current, detail);
|
|
100
|
+
},
|
|
101
|
+
onSuccess: (result)=>{
|
|
102
|
+
var _callbacksRef_current_onSuccess, _callbacksRef_current;
|
|
103
|
+
return null == (_callbacksRef_current_onSuccess = (_callbacksRef_current = callbacksRef.current).onSuccess) ? void 0 : _callbacksRef_current_onSuccess.call(_callbacksRef_current, result);
|
|
104
|
+
},
|
|
105
|
+
onCancel: ()=>{
|
|
106
|
+
var _callbacksRef_current_onCancel, _callbacksRef_current;
|
|
107
|
+
return null == (_callbacksRef_current_onCancel = (_callbacksRef_current = callbacksRef.current).onCancel) ? void 0 : _callbacksRef_current_onCancel.call(_callbacksRef_current);
|
|
108
|
+
},
|
|
109
|
+
onExpired: ()=>{
|
|
110
|
+
var _callbacksRef_current_onExpired, _callbacksRef_current;
|
|
111
|
+
return null == (_callbacksRef_current_onExpired = (_callbacksRef_current = callbacksRef.current).onExpired) ? void 0 : _callbacksRef_current_onExpired.call(_callbacksRef_current);
|
|
112
|
+
},
|
|
113
|
+
onSessionExpired: ()=>{
|
|
114
|
+
var _callbacksRef_current_onSessionExpired, _callbacksRef_current;
|
|
115
|
+
return null == (_callbacksRef_current_onSessionExpired = (_callbacksRef_current = callbacksRef.current).onSessionExpired) ? void 0 : _callbacksRef_current_onSessionExpired.call(_callbacksRef_current);
|
|
116
|
+
},
|
|
117
|
+
onError: (error)=>{
|
|
118
|
+
var _callbacksRef_current_onError, _callbacksRef_current;
|
|
119
|
+
return null == (_callbacksRef_current_onError = (_callbacksRef_current = callbacksRef.current).onError) ? void 0 : _callbacksRef_current_onError.call(_callbacksRef_current, error);
|
|
120
|
+
},
|
|
121
|
+
onStatusChange: (status, detail)=>{
|
|
122
|
+
var _callbacksRef_current_onStatusChange, _callbacksRef_current;
|
|
123
|
+
return null == (_callbacksRef_current_onStatusChange = (_callbacksRef_current = callbacksRef.current).onStatusChange) ? void 0 : _callbacksRef_current_onStatusChange.call(_callbacksRef_current, status, detail);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
paymentElement.mount(container);
|
|
127
|
+
elementRef.current = paymentElement;
|
|
128
|
+
runtimeConfigRef.current = runtimeConfig;
|
|
129
|
+
};
|
|
130
|
+
(0, external_react_namespaceObject.useEffect)(()=>{
|
|
131
|
+
mountElement();
|
|
132
|
+
return ()=>{
|
|
133
|
+
destroyElement();
|
|
134
|
+
};
|
|
135
|
+
}, [
|
|
136
|
+
recreateKey
|
|
137
|
+
]);
|
|
138
|
+
(0, external_react_namespaceObject.useEffect)(()=>{
|
|
139
|
+
var _elementRef_current;
|
|
140
|
+
const nextLocale = getRuntimeConfig(gatePay, payment).locale;
|
|
141
|
+
if (nextLocale === runtimeConfigRef.current.locale) return;
|
|
142
|
+
if (!nextLocale) return void mountElement();
|
|
143
|
+
null == (_elementRef_current = elementRef.current) || _elementRef_current.updateLocale(nextLocale);
|
|
144
|
+
runtimeConfigRef.current.locale = nextLocale;
|
|
145
|
+
}, [
|
|
146
|
+
gatePay.locale,
|
|
147
|
+
payment.locale
|
|
148
|
+
]);
|
|
149
|
+
(0, external_react_namespaceObject.useEffect)(()=>{
|
|
150
|
+
var _elementRef_current;
|
|
151
|
+
const nextTheme = getRuntimeConfig(gatePay, payment).theme;
|
|
152
|
+
if (nextTheme === runtimeConfigRef.current.theme) return;
|
|
153
|
+
if (!nextTheme) return void mountElement();
|
|
154
|
+
null == (_elementRef_current = elementRef.current) || _elementRef_current.updateTheme(nextTheme);
|
|
155
|
+
runtimeConfigRef.current.theme = nextTheme;
|
|
156
|
+
}, [
|
|
157
|
+
gatePay.theme,
|
|
158
|
+
payment.theme
|
|
159
|
+
]);
|
|
160
|
+
(0, external_react_namespaceObject.useImperativeHandle)(ref, ()=>({
|
|
161
|
+
destroy: ()=>{
|
|
162
|
+
destroyElement();
|
|
163
|
+
},
|
|
164
|
+
getInstance: ()=>elementRef.current,
|
|
165
|
+
updateLocale: (locale)=>{
|
|
166
|
+
var _elementRef_current;
|
|
167
|
+
null == (_elementRef_current = elementRef.current) || _elementRef_current.updateLocale(locale);
|
|
168
|
+
runtimeConfigRef.current.locale = locale;
|
|
169
|
+
},
|
|
170
|
+
updateTheme: (theme)=>{
|
|
171
|
+
var _elementRef_current;
|
|
172
|
+
null == (_elementRef_current = elementRef.current) || _elementRef_current.updateTheme(theme);
|
|
173
|
+
runtimeConfigRef.current.theme = theme;
|
|
174
|
+
}
|
|
175
|
+
}), []);
|
|
176
|
+
return /*#__PURE__*/ React.createElement("div", {
|
|
177
|
+
ref: containerRef,
|
|
178
|
+
...divProps
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
exports.GatePayElement = __webpack_exports__.GatePayElement;
|
|
182
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
183
|
+
"GatePayElement"
|
|
184
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
185
|
+
Object.defineProperty(exports, '__esModule', {
|
|
186
|
+
value: true
|
|
187
|
+
});
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { GatePayElementProps, GatePayElementRef } from './types';
|
|
3
|
+
export declare const GatePayElement: import("react").ForwardRefExoticComponent<GatePayElementProps & import("react").RefAttributes<GatePayElementRef>>;
|
|
4
|
+
//# sourceMappingURL=gate-pay-element.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gate-pay-element.d.ts","sourceRoot":"","sources":["../../src/gate-pay-element.tsx"],"names":[],"mappings":";AAaA,OAAO,KAAK,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AA6CrE,eAAO,MAAM,cAAc,mHAoHzB,CAAA"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
var __webpack_require__ = {};
|
|
4
|
+
(()=>{
|
|
5
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
6
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: definition[key]
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
})();
|
|
12
|
+
(()=>{
|
|
13
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
14
|
+
})();
|
|
15
|
+
(()=>{
|
|
16
|
+
__webpack_require__.r = (exports1)=>{
|
|
17
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
18
|
+
value: 'Module'
|
|
19
|
+
});
|
|
20
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
21
|
+
value: true
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
})();
|
|
25
|
+
var __webpack_exports__ = {};
|
|
26
|
+
__webpack_require__.r(__webpack_exports__);
|
|
27
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
28
|
+
PROTOCOL_VERSION: ()=>pay_js_namespaceObject.PROTOCOL_VERSION,
|
|
29
|
+
GatePayElement: ()=>external_gate_pay_element_cjs_namespaceObject.GatePayElement,
|
|
30
|
+
PROCESSING_PAYMENT_STATUSES: ()=>pay_js_namespaceObject.PROCESSING_PAYMENT_STATUSES,
|
|
31
|
+
isProcessingPaymentStatus: ()=>pay_js_namespaceObject.isProcessingPaymentStatus,
|
|
32
|
+
CheckoutBridge: ()=>pay_js_namespaceObject.CheckoutBridge,
|
|
33
|
+
CheckoutPageBridge: ()=>pay_js_namespaceObject.CheckoutPageBridge,
|
|
34
|
+
GatePay: ()=>pay_js_namespaceObject.GatePay
|
|
35
|
+
});
|
|
36
|
+
const pay_js_namespaceObject = require("@gatepayfe/pay-js");
|
|
37
|
+
const external_gate_pay_element_cjs_namespaceObject = require("./gate-pay-element.cjs");
|
|
38
|
+
exports.CheckoutBridge = __webpack_exports__.CheckoutBridge;
|
|
39
|
+
exports.CheckoutPageBridge = __webpack_exports__.CheckoutPageBridge;
|
|
40
|
+
exports.GatePay = __webpack_exports__.GatePay;
|
|
41
|
+
exports.GatePayElement = __webpack_exports__.GatePayElement;
|
|
42
|
+
exports.PROCESSING_PAYMENT_STATUSES = __webpack_exports__.PROCESSING_PAYMENT_STATUSES;
|
|
43
|
+
exports.PROTOCOL_VERSION = __webpack_exports__.PROTOCOL_VERSION;
|
|
44
|
+
exports.isProcessingPaymentStatus = __webpack_exports__.isProcessingPaymentStatus;
|
|
45
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
46
|
+
"CheckoutBridge",
|
|
47
|
+
"CheckoutPageBridge",
|
|
48
|
+
"GatePay",
|
|
49
|
+
"GatePayElement",
|
|
50
|
+
"PROCESSING_PAYMENT_STATUSES",
|
|
51
|
+
"PROTOCOL_VERSION",
|
|
52
|
+
"isProcessingPaymentStatus"
|
|
53
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
54
|
+
Object.defineProperty(exports, '__esModule', {
|
|
55
|
+
value: true
|
|
56
|
+
});
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type { BridgeInitPayload, BridgeLocaleUpdatePayload, BridgeMessage, BridgeMessageType, BridgeResizePayload, BridgeThemeUpdatePayload, CashierType, CheckoutBridgeCallbacks, FiatCurrency, GatePayError, GatePayInstance, GatePayOptions, PaymentElementInstance, PaymentElementOptions, PaymentMethod, PaymentResult, PaymentStatus, PaymentStatusDetail, Theme, } from '@gatepayfe/pay-js';
|
|
2
|
+
export type { GatePayElementProps, GatePayElementRef } from './types';
|
|
3
|
+
export { CheckoutBridge, CheckoutPageBridge, GatePay, isProcessingPaymentStatus, PROCESSING_PAYMENT_STATUSES, PROTOCOL_VERSION, } from '@gatepayfe/pay-js';
|
|
4
|
+
export { GatePayElement } from './gate-pay-element';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,YAAY,EACV,iBAAiB,EACjB,yBAAyB,EACzB,aAAa,EACb,iBAAiB,EACjB,mBAAmB,EACnB,wBAAwB,EACxB,WAAW,EACX,uBAAuB,EACvB,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,cAAc,EACd,sBAAsB,EACtB,qBAAqB,EACrB,aAAa,EACb,aAAa,EACb,aAAa,EACb,mBAAmB,EACnB,KAAK,GACN,MAAM,mBAAmB,CAAA;AAC1B,YAAY,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAErE,OAAO,EACL,cAAc,EACd,kBAAkB,EAClB,OAAO,EACP,yBAAyB,EACzB,2BAA2B,EAC3B,gBAAgB,GACjB,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.r = (exports1)=>{
|
|
5
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
6
|
+
value: 'Module'
|
|
7
|
+
});
|
|
8
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
9
|
+
value: true
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
})();
|
|
13
|
+
var __webpack_exports__ = {};
|
|
14
|
+
__webpack_require__.r(__webpack_exports__);
|
|
15
|
+
for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
16
|
+
Object.defineProperty(exports, '__esModule', {
|
|
17
|
+
value: true
|
|
18
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { GatePayOptions, PaymentElementInstance, PaymentElementOptions, Theme } from '@gatepayfe/pay-js';
|
|
2
|
+
import type { ComponentPropsWithoutRef } from 'react';
|
|
3
|
+
export interface GatePayElementProps extends Omit<ComponentPropsWithoutRef<'div'>, 'children'> {
|
|
4
|
+
gatePay: GatePayOptions;
|
|
5
|
+
payment: PaymentElementOptions;
|
|
6
|
+
}
|
|
7
|
+
export interface GatePayElementRef {
|
|
8
|
+
destroy: () => void;
|
|
9
|
+
getInstance: () => PaymentElementInstance | null;
|
|
10
|
+
updateLocale: (locale: string) => void;
|
|
11
|
+
updateTheme: (theme: Theme) => void;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAC7G,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,OAAO,CAAA;AAErD,MAAM,WAAW,mBAAoB,SAAQ,IAAI,CAAC,wBAAwB,CAAC,KAAK,CAAC,EAAE,UAAU,CAAC;IAC5F,OAAO,EAAE,cAAc,CAAA;IACvB,OAAO,EAAE,qBAAqB,CAAA;CAC/B;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,MAAM,IAAI,CAAA;IACnB,WAAW,EAAE,MAAM,sBAAsB,GAAG,IAAI,CAAA;IAChD,YAAY,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAA;IACtC,WAAW,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAA;CACpC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { GatePayElementProps, GatePayElementRef } from './types';
|
|
3
|
+
export declare const GatePayElement: import("react").ForwardRefExoticComponent<GatePayElementProps & import("react").RefAttributes<GatePayElementRef>>;
|
|
4
|
+
//# sourceMappingURL=gate-pay-element.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gate-pay-element.d.ts","sourceRoot":"","sources":["../../src/gate-pay-element.tsx"],"names":[],"mappings":";AAaA,OAAO,KAAK,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AA6CrE,eAAO,MAAM,cAAc,mHAoHzB,CAAA"}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { DEFAULT_GATE_PAY_BASE_URL, GatePay } from "@gatepayfe/pay-js";
|
|
3
|
+
import { forwardRef, useEffect, useImperativeHandle, useRef } from "react";
|
|
4
|
+
function toMethodKey(methods) {
|
|
5
|
+
var _ref;
|
|
6
|
+
return null != (_ref = null == methods ? void 0 : methods.join('|')) ? _ref : '';
|
|
7
|
+
}
|
|
8
|
+
function toRecreateKey(gatePay, payment) {
|
|
9
|
+
var _gatePay_baseUrl, _gatePay_debug, _gatePay_fiatCurrency, _payment_showLanguageSwitcher;
|
|
10
|
+
return JSON.stringify({
|
|
11
|
+
baseUrl: null != (_gatePay_baseUrl = gatePay.baseUrl) ? _gatePay_baseUrl : DEFAULT_GATE_PAY_BASE_URL,
|
|
12
|
+
clientId: gatePay.clientId,
|
|
13
|
+
debug: null != (_gatePay_debug = gatePay.debug) ? _gatePay_debug : false,
|
|
14
|
+
fiatCurrency: null != (_gatePay_fiatCurrency = gatePay.fiatCurrency) ? _gatePay_fiatCurrency : '',
|
|
15
|
+
clientSessionSecret: payment.clientSessionSecret,
|
|
16
|
+
paymentMethods: toMethodKey(payment.paymentMethods),
|
|
17
|
+
showLanguageSwitcher: null != (_payment_showLanguageSwitcher = payment.showLanguageSwitcher) ? _payment_showLanguageSwitcher : false
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
function getRuntimeConfig(gatePay, payment) {
|
|
21
|
+
var _payment_locale, _payment_theme;
|
|
22
|
+
return {
|
|
23
|
+
locale: null != (_payment_locale = payment.locale) ? _payment_locale : gatePay.locale,
|
|
24
|
+
theme: null != (_payment_theme = payment.theme) ? _payment_theme : gatePay.theme
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
const gate_pay_element_GatePayElement = /*#__PURE__*/ forwardRef(function(param, ref) {
|
|
28
|
+
let { gatePay, payment, ...divProps } = param;
|
|
29
|
+
const containerRef = useRef(null);
|
|
30
|
+
const elementRef = useRef(null);
|
|
31
|
+
const runtimeConfigRef = useRef({});
|
|
32
|
+
const callbacksRef = useRef({});
|
|
33
|
+
callbacksRef.current = {
|
|
34
|
+
onReady: payment.onReady,
|
|
35
|
+
onProcessing: payment.onProcessing,
|
|
36
|
+
onSuccess: payment.onSuccess,
|
|
37
|
+
onCancel: payment.onCancel,
|
|
38
|
+
onExpired: payment.onExpired,
|
|
39
|
+
onSessionExpired: payment.onSessionExpired,
|
|
40
|
+
onError: payment.onError,
|
|
41
|
+
onStatusChange: payment.onStatusChange
|
|
42
|
+
};
|
|
43
|
+
const recreateKey = toRecreateKey(gatePay, payment);
|
|
44
|
+
const destroyElement = ()=>{
|
|
45
|
+
var _elementRef_current;
|
|
46
|
+
null == (_elementRef_current = elementRef.current) || _elementRef_current.destroy();
|
|
47
|
+
elementRef.current = null;
|
|
48
|
+
};
|
|
49
|
+
const mountElement = ()=>{
|
|
50
|
+
const container = containerRef.current;
|
|
51
|
+
if (!container) return;
|
|
52
|
+
destroyElement();
|
|
53
|
+
const runtimeConfig = getRuntimeConfig(gatePay, payment);
|
|
54
|
+
const gatePayInstance = GatePay({
|
|
55
|
+
...gatePay,
|
|
56
|
+
locale: runtimeConfig.locale,
|
|
57
|
+
theme: runtimeConfig.theme
|
|
58
|
+
});
|
|
59
|
+
const paymentElement = gatePayInstance.createPaymentElement({
|
|
60
|
+
clientSessionSecret: payment.clientSessionSecret,
|
|
61
|
+
paymentMethods: payment.paymentMethods,
|
|
62
|
+
locale: runtimeConfig.locale,
|
|
63
|
+
theme: runtimeConfig.theme,
|
|
64
|
+
showLanguageSwitcher: payment.showLanguageSwitcher,
|
|
65
|
+
onReady: ()=>{
|
|
66
|
+
var _callbacksRef_current_onReady, _callbacksRef_current;
|
|
67
|
+
return null == (_callbacksRef_current_onReady = (_callbacksRef_current = callbacksRef.current).onReady) ? void 0 : _callbacksRef_current_onReady.call(_callbacksRef_current);
|
|
68
|
+
},
|
|
69
|
+
onProcessing: (detail)=>{
|
|
70
|
+
var _callbacksRef_current_onProcessing, _callbacksRef_current;
|
|
71
|
+
return null == (_callbacksRef_current_onProcessing = (_callbacksRef_current = callbacksRef.current).onProcessing) ? void 0 : _callbacksRef_current_onProcessing.call(_callbacksRef_current, detail);
|
|
72
|
+
},
|
|
73
|
+
onSuccess: (result)=>{
|
|
74
|
+
var _callbacksRef_current_onSuccess, _callbacksRef_current;
|
|
75
|
+
return null == (_callbacksRef_current_onSuccess = (_callbacksRef_current = callbacksRef.current).onSuccess) ? void 0 : _callbacksRef_current_onSuccess.call(_callbacksRef_current, result);
|
|
76
|
+
},
|
|
77
|
+
onCancel: ()=>{
|
|
78
|
+
var _callbacksRef_current_onCancel, _callbacksRef_current;
|
|
79
|
+
return null == (_callbacksRef_current_onCancel = (_callbacksRef_current = callbacksRef.current).onCancel) ? void 0 : _callbacksRef_current_onCancel.call(_callbacksRef_current);
|
|
80
|
+
},
|
|
81
|
+
onExpired: ()=>{
|
|
82
|
+
var _callbacksRef_current_onExpired, _callbacksRef_current;
|
|
83
|
+
return null == (_callbacksRef_current_onExpired = (_callbacksRef_current = callbacksRef.current).onExpired) ? void 0 : _callbacksRef_current_onExpired.call(_callbacksRef_current);
|
|
84
|
+
},
|
|
85
|
+
onSessionExpired: ()=>{
|
|
86
|
+
var _callbacksRef_current_onSessionExpired, _callbacksRef_current;
|
|
87
|
+
return null == (_callbacksRef_current_onSessionExpired = (_callbacksRef_current = callbacksRef.current).onSessionExpired) ? void 0 : _callbacksRef_current_onSessionExpired.call(_callbacksRef_current);
|
|
88
|
+
},
|
|
89
|
+
onError: (error)=>{
|
|
90
|
+
var _callbacksRef_current_onError, _callbacksRef_current;
|
|
91
|
+
return null == (_callbacksRef_current_onError = (_callbacksRef_current = callbacksRef.current).onError) ? void 0 : _callbacksRef_current_onError.call(_callbacksRef_current, error);
|
|
92
|
+
},
|
|
93
|
+
onStatusChange: (status, detail)=>{
|
|
94
|
+
var _callbacksRef_current_onStatusChange, _callbacksRef_current;
|
|
95
|
+
return null == (_callbacksRef_current_onStatusChange = (_callbacksRef_current = callbacksRef.current).onStatusChange) ? void 0 : _callbacksRef_current_onStatusChange.call(_callbacksRef_current, status, detail);
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
paymentElement.mount(container);
|
|
99
|
+
elementRef.current = paymentElement;
|
|
100
|
+
runtimeConfigRef.current = runtimeConfig;
|
|
101
|
+
};
|
|
102
|
+
useEffect(()=>{
|
|
103
|
+
mountElement();
|
|
104
|
+
return ()=>{
|
|
105
|
+
destroyElement();
|
|
106
|
+
};
|
|
107
|
+
}, [
|
|
108
|
+
recreateKey
|
|
109
|
+
]);
|
|
110
|
+
useEffect(()=>{
|
|
111
|
+
var _elementRef_current;
|
|
112
|
+
const nextLocale = getRuntimeConfig(gatePay, payment).locale;
|
|
113
|
+
if (nextLocale === runtimeConfigRef.current.locale) return;
|
|
114
|
+
if (!nextLocale) return void mountElement();
|
|
115
|
+
null == (_elementRef_current = elementRef.current) || _elementRef_current.updateLocale(nextLocale);
|
|
116
|
+
runtimeConfigRef.current.locale = nextLocale;
|
|
117
|
+
}, [
|
|
118
|
+
gatePay.locale,
|
|
119
|
+
payment.locale
|
|
120
|
+
]);
|
|
121
|
+
useEffect(()=>{
|
|
122
|
+
var _elementRef_current;
|
|
123
|
+
const nextTheme = getRuntimeConfig(gatePay, payment).theme;
|
|
124
|
+
if (nextTheme === runtimeConfigRef.current.theme) return;
|
|
125
|
+
if (!nextTheme) return void mountElement();
|
|
126
|
+
null == (_elementRef_current = elementRef.current) || _elementRef_current.updateTheme(nextTheme);
|
|
127
|
+
runtimeConfigRef.current.theme = nextTheme;
|
|
128
|
+
}, [
|
|
129
|
+
gatePay.theme,
|
|
130
|
+
payment.theme
|
|
131
|
+
]);
|
|
132
|
+
useImperativeHandle(ref, ()=>({
|
|
133
|
+
destroy: ()=>{
|
|
134
|
+
destroyElement();
|
|
135
|
+
},
|
|
136
|
+
getInstance: ()=>elementRef.current,
|
|
137
|
+
updateLocale: (locale)=>{
|
|
138
|
+
var _elementRef_current;
|
|
139
|
+
null == (_elementRef_current = elementRef.current) || _elementRef_current.updateLocale(locale);
|
|
140
|
+
runtimeConfigRef.current.locale = locale;
|
|
141
|
+
},
|
|
142
|
+
updateTheme: (theme)=>{
|
|
143
|
+
var _elementRef_current;
|
|
144
|
+
null == (_elementRef_current = elementRef.current) || _elementRef_current.updateTheme(theme);
|
|
145
|
+
runtimeConfigRef.current.theme = theme;
|
|
146
|
+
}
|
|
147
|
+
}), []);
|
|
148
|
+
return /*#__PURE__*/ React.createElement("div", {
|
|
149
|
+
ref: containerRef,
|
|
150
|
+
...divProps
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
export { gate_pay_element_GatePayElement as GatePayElement };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type { BridgeInitPayload, BridgeLocaleUpdatePayload, BridgeMessage, BridgeMessageType, BridgeResizePayload, BridgeThemeUpdatePayload, CashierType, CheckoutBridgeCallbacks, FiatCurrency, GatePayError, GatePayInstance, GatePayOptions, PaymentElementInstance, PaymentElementOptions, PaymentMethod, PaymentResult, PaymentStatus, PaymentStatusDetail, Theme, } from '@gatepayfe/pay-js';
|
|
2
|
+
export type { GatePayElementProps, GatePayElementRef } from './types';
|
|
3
|
+
export { CheckoutBridge, CheckoutPageBridge, GatePay, isProcessingPaymentStatus, PROCESSING_PAYMENT_STATUSES, PROTOCOL_VERSION, } from '@gatepayfe/pay-js';
|
|
4
|
+
export { GatePayElement } from './gate-pay-element';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,YAAY,EACV,iBAAiB,EACjB,yBAAyB,EACzB,aAAa,EACb,iBAAiB,EACjB,mBAAmB,EACnB,wBAAwB,EACxB,WAAW,EACX,uBAAuB,EACvB,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,cAAc,EACd,sBAAsB,EACtB,qBAAqB,EACrB,aAAa,EACb,aAAa,EACb,aAAa,EACb,mBAAmB,EACnB,KAAK,GACN,MAAM,mBAAmB,CAAA;AAC1B,YAAY,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAErE,OAAO,EACL,cAAc,EACd,kBAAkB,EAClB,OAAO,EACP,yBAAyB,EACzB,2BAA2B,EAC3B,gBAAgB,GACjB,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { CheckoutBridge, CheckoutPageBridge, GatePay, PROCESSING_PAYMENT_STATUSES, PROTOCOL_VERSION, isProcessingPaymentStatus } from "@gatepayfe/pay-js";
|
|
3
|
+
import { GatePayElement } from "./gate-pay-element.js";
|
|
4
|
+
export { CheckoutBridge, CheckoutPageBridge, GatePay, GatePayElement, PROCESSING_PAYMENT_STATUSES, PROTOCOL_VERSION, isProcessingPaymentStatus };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { GatePayOptions, PaymentElementInstance, PaymentElementOptions, Theme } from '@gatepayfe/pay-js';
|
|
2
|
+
import type { ComponentPropsWithoutRef } from 'react';
|
|
3
|
+
export interface GatePayElementProps extends Omit<ComponentPropsWithoutRef<'div'>, 'children'> {
|
|
4
|
+
gatePay: GatePayOptions;
|
|
5
|
+
payment: PaymentElementOptions;
|
|
6
|
+
}
|
|
7
|
+
export interface GatePayElementRef {
|
|
8
|
+
destroy: () => void;
|
|
9
|
+
getInstance: () => PaymentElementInstance | null;
|
|
10
|
+
updateLocale: (locale: string) => void;
|
|
11
|
+
updateTheme: (theme: Theme) => void;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAC7G,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,OAAO,CAAA;AAErD,MAAM,WAAW,mBAAoB,SAAQ,IAAI,CAAC,wBAAwB,CAAC,KAAK,CAAC,EAAE,UAAU,CAAC;IAC5F,OAAO,EAAE,cAAc,CAAA;IACvB,OAAO,EAAE,qBAAqB,CAAA;CAC/B;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,MAAM,IAAI,CAAA;IACnB,WAAW,EAAE,MAAM,sBAAsB,GAAG,IAAI,CAAA;IAChD,YAAY,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAA;IACtC,WAAW,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAA;CACpC"}
|
|
File without changes
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@gatepayfe/pay-js-react",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "React bindings for @gatepayfe/pay-js embedded cashier SDK",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/cjs/index.cjs",
|
|
7
|
+
"module": "dist/esm/index.js",
|
|
8
|
+
"types": "dist/esm/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./dist/esm/index.d.ts",
|
|
13
|
+
"default": "./dist/esm/index.js"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./dist/cjs/index.d.ts",
|
|
17
|
+
"default": "./dist/cjs/index.cjs"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist",
|
|
23
|
+
"README.md"
|
|
24
|
+
],
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public",
|
|
27
|
+
"registry": "https://registry.npmjs.org/"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@gatepayfe/pay-js": "0.0.1"
|
|
31
|
+
},
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"react": "^18.2.0 || ^19.0.0",
|
|
34
|
+
"react-dom": "^18.2.0 || ^19.0.0"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@rslib/core": "^0.18.2",
|
|
38
|
+
"@types/react": "^18.2.0",
|
|
39
|
+
"@types/react-dom": "^18.2.0",
|
|
40
|
+
"typescript": "5.0.4"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"build": "rslib build",
|
|
44
|
+
"build:test": "rslib build",
|
|
45
|
+
"build:pre": "rslib build",
|
|
46
|
+
"build:prod": "rslib build",
|
|
47
|
+
"dev": "rslib build --watch",
|
|
48
|
+
"check": "biome check --write --no-errors-on-unmatched",
|
|
49
|
+
"check:staged": "pnpm run check --staged"
|
|
50
|
+
}
|
|
51
|
+
}
|