@school24/paymentjs-rn 1.1.0 → 1.3.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/dist/PaymentJS.d.ts +27 -1
- package/dist/PaymentJS.js +20 -4
- package/dist/types.d.ts +8 -2
- package/package.json +1 -1
package/dist/PaymentJS.d.ts
CHANGED
|
@@ -1,4 +1,30 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import type { PaymentJSProps } from "./types";
|
|
3
|
-
|
|
3
|
+
interface EnhancedPaymentJSProps extends PaymentJSProps {
|
|
4
|
+
/**
|
|
5
|
+
* Environment: 'test' or 'live'
|
|
6
|
+
*/
|
|
7
|
+
environment?: "test" | "live";
|
|
8
|
+
/**
|
|
9
|
+
* Shopper reference (required for stored cards)
|
|
10
|
+
*/
|
|
11
|
+
shopperReference?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Amount in minor units (e.g. 100 = 1.00 AUD)
|
|
14
|
+
*/
|
|
15
|
+
amount?: number;
|
|
16
|
+
/**
|
|
17
|
+
* Currency (default: AUD)
|
|
18
|
+
*/
|
|
19
|
+
currency?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Whether to store the card on first payment
|
|
22
|
+
*/
|
|
23
|
+
storePaymentMethod?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Optional base URL for the payment page (defaults to your hosted HTML)
|
|
26
|
+
*/
|
|
27
|
+
baseUrl?: string;
|
|
28
|
+
}
|
|
29
|
+
declare const PaymentJS: React.FC<EnhancedPaymentJSProps>;
|
|
4
30
|
export default PaymentJS;
|
package/dist/PaymentJS.js
CHANGED
|
@@ -37,11 +37,23 @@ const react_1 = __importStar(require("react"));
|
|
|
37
37
|
const react_native_1 = require("react-native");
|
|
38
38
|
const react_native_webview_1 = require("react-native-webview");
|
|
39
39
|
const PaymentJS = (props) => {
|
|
40
|
-
const { uri, onSuccess, onFailure, style } = props;
|
|
40
|
+
const { uri: customUri, onSuccess, onFailure, style, environment = "test", shopperReference = "USER123", amount = 100, currency = "AUD", storePaymentMethod = true, baseUrl = "https://your-domain.com/payment.html", } = props;
|
|
41
|
+
// Auto-build URI with query params if customUri not provided
|
|
42
|
+
const finalUri = (0, react_1.useMemo)(() => {
|
|
43
|
+
if (customUri)
|
|
44
|
+
return customUri;
|
|
45
|
+
const params = new URLSearchParams({
|
|
46
|
+
env: environment,
|
|
47
|
+
shopperReference,
|
|
48
|
+
amount: amount.toString(),
|
|
49
|
+
currency,
|
|
50
|
+
storePaymentMethod: storePaymentMethod.toString(),
|
|
51
|
+
});
|
|
52
|
+
return `${baseUrl}?${params.toString()}`;
|
|
53
|
+
}, [customUri, environment, shopperReference, amount, currency, storePaymentMethod, baseUrl]);
|
|
41
54
|
const handleMessage = (0, react_1.useCallback)((event) => {
|
|
42
55
|
var _a, _b;
|
|
43
56
|
try {
|
|
44
|
-
// Type guard for WebView events
|
|
45
57
|
const data = (_b = (_a = event === null || event === void 0 ? void 0 : event.nativeEvent) === null || _a === void 0 ? void 0 : _a.data) !== null && _b !== void 0 ? _b : event === null || event === void 0 ? void 0 : event.data;
|
|
46
58
|
if (!data)
|
|
47
59
|
return;
|
|
@@ -56,16 +68,20 @@ const PaymentJS = (props) => {
|
|
|
56
68
|
case "CONFIG_ERROR":
|
|
57
69
|
onFailure === null || onFailure === void 0 ? void 0 : onFailure(message.payload);
|
|
58
70
|
break;
|
|
71
|
+
default:
|
|
72
|
+
console.warn("Unknown PaymentJS event:", message.event);
|
|
59
73
|
}
|
|
60
74
|
}
|
|
61
75
|
catch (err) {
|
|
76
|
+
console.error("Failed to parse WebView message:", err);
|
|
62
77
|
onFailure === null || onFailure === void 0 ? void 0 : onFailure({
|
|
63
78
|
message: "Invalid message from payment WebView",
|
|
64
|
-
error: err
|
|
79
|
+
error: err,
|
|
65
80
|
});
|
|
66
81
|
}
|
|
67
82
|
}, [onSuccess, onFailure]);
|
|
68
83
|
return (react_1.default.createElement(react_native_1.View, { style: [{ flex: 1, backgroundColor: "#fff" }, style] },
|
|
69
|
-
react_1.default.createElement(react_native_webview_1.WebView, { source: { uri }, javaScriptEnabled: true, domStorageEnabled: true, originWhitelist: ["*"], startInLoadingState: true,
|
|
84
|
+
react_1.default.createElement(react_native_webview_1.WebView, { source: { uri: finalUri }, javaScriptEnabled: true, domStorageEnabled: true, originWhitelist: ["*"], startInLoadingState: true, renderLoading: () => (react_1.default.createElement(react_native_1.View, { style: { flex: 1, justifyContent: "center", alignItems: "center" } },
|
|
85
|
+
react_1.default.createElement(react_native_1.ActivityIndicator, { size: "large", color: "#2563eb" }))), onMessage: handleMessage, allowsBackForwardNavigationGestures: true, setSupportMultipleWindows: false })));
|
|
70
86
|
};
|
|
71
87
|
exports.default = PaymentJS;
|
package/dist/types.d.ts
CHANGED
|
@@ -7,9 +7,9 @@ export interface PaymentJSMessage {
|
|
|
7
7
|
}
|
|
8
8
|
export interface PaymentJSProps {
|
|
9
9
|
/**
|
|
10
|
-
* Full URL to
|
|
10
|
+
* Full URL to the payment HTML page (optional if using auto-built URI)
|
|
11
11
|
*/
|
|
12
|
-
uri
|
|
12
|
+
uri?: string;
|
|
13
13
|
/**
|
|
14
14
|
* Called when payment completes successfully
|
|
15
15
|
*/
|
|
@@ -22,4 +22,10 @@ export interface PaymentJSProps {
|
|
|
22
22
|
* Optional container styling
|
|
23
23
|
*/
|
|
24
24
|
style?: StyleProp<ViewStyle>;
|
|
25
|
+
environment?: "test" | "live";
|
|
26
|
+
shopperReference?: string;
|
|
27
|
+
amount?: number;
|
|
28
|
+
currency?: string;
|
|
29
|
+
storePaymentMethod?: boolean;
|
|
30
|
+
baseUrl?: string;
|
|
25
31
|
}
|