@school24/paymentjs-rn 1.6.0 → 1.7.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.js CHANGED
@@ -37,7 +37,7 @@ exports.default = PaymentJS;
37
37
  const react_1 = __importStar(require("react"));
38
38
  const react_native_1 = require("react-native");
39
39
  const react_native_webview_1 = require("react-native-webview");
40
- // INTERNAL DEFAULTS (So Cherian doesn't have to pass them)
40
+ // INTERNAL DEFAULTS
41
41
  const DEFAULT_PAGE_URL = "https://client.brandsyncstudio.com/paymentjs/payment-rn.html";
42
42
  const DEFAULT_LAMBDA_URL = "https://qb3epa62mry53z3woeiecuhpve0scpjb.lambda-url.ap-southeast-2.on.aws";
43
43
  const STORE_IDS = {
@@ -52,31 +52,42 @@ function normalizeBase(url) {
52
52
  }
53
53
  function PaymentJS(props) {
54
54
  const {
55
- // These now default to internal constants if not provided
55
+ // These default to internal constants if not provided by Cherian
56
56
  pageUrl = DEFAULT_PAGE_URL, lambdaUrl = DEFAULT_LAMBDA_URL, environment = "test",
57
57
  // Auto-select store based on environment if store prop is missing
58
- store = STORE_IDS[environment], mode = "pay", shopperReference = "", amount = 0, currency = "AUD", storePaymentMethod = false, ts, style, debug = false, onPaymentSuccess, onPaymentFailure, onEncryptSuccess, onEncryptFailure, onDebug, } = props;
58
+ store = STORE_IDS[environment],
59
+ // Metadata for Logging & Dashboard
60
+ schoolId = "", orderId = "", mode = "pay", shopperReference = "", amount = 0, currency = "AUD", storePaymentMethod = false, ts, style, debug = false, onPaymentSuccess, onPaymentFailure, onEncryptSuccess, onEncryptFailure, onDebug, } = props;
59
61
  const finalUri = (0, react_1.useMemo)(() => {
60
62
  const params = new URLSearchParams();
63
+ // Core Config
61
64
  params.set("mode", mode);
62
65
  params.set("env", environment);
63
66
  params.set("baseUrl", normalizeBase(lambdaUrl));
64
67
  params.set("currency", currency);
65
- // Use the auto-selected or provided store ID
68
+ // Merchant & Logging Context
66
69
  if (store)
67
70
  params.set("store", store);
71
+ if (schoolId)
72
+ params.set("schoolId", schoolId);
73
+ if (orderId)
74
+ params.set("orderId", orderId);
75
+ // Shopper & Payment Options
68
76
  if (shopperReference)
69
77
  params.set("shopperReference", shopperReference);
70
78
  params.set("storePaymentMethod", safeBoolString(storePaymentMethod));
71
79
  if (mode === "pay") {
72
80
  params.set("amount", String(amount !== null && amount !== void 0 ? amount : 0));
73
81
  }
82
+ // Cache buster for WebView refresh
74
83
  params.set("ts", String(ts !== null && ts !== void 0 ? ts : Date.now()));
75
84
  return `${pageUrl}?${params.toString()}`;
76
85
  }, [
77
86
  pageUrl,
78
87
  lambdaUrl,
79
88
  store,
89
+ schoolId,
90
+ orderId,
80
91
  mode,
81
92
  environment,
82
93
  shopperReference,
@@ -94,12 +105,19 @@ function PaymentJS(props) {
94
105
  const message = JSON.parse(raw);
95
106
  if (message.source !== "PaymentJS" || !message.event)
96
107
  return;
108
+ if (message.event === "DEBUG") {
109
+ if (debug)
110
+ console.log("💳 PaymentJS DEBUG:", message.payload);
111
+ onDebug === null || onDebug === void 0 ? void 0 : onDebug(message.payload);
112
+ return;
113
+ }
97
114
  switch (message.event) {
98
115
  case "PAYMENT_SUCCESS":
99
116
  onPaymentSuccess === null || onPaymentSuccess === void 0 ? void 0 : onPaymentSuccess(message.payload);
100
117
  break;
101
118
  case "PAYMENT_ERROR":
102
119
  case "CONFIG_ERROR":
120
+ // Receives the granular messages (Insufficient Funds, etc.) from Lambda
103
121
  onPaymentFailure === null || onPaymentFailure === void 0 ? void 0 : onPaymentFailure(message.payload);
104
122
  break;
105
123
  case "ENCRYPT_SUCCESS":
@@ -108,17 +126,22 @@ function PaymentJS(props) {
108
126
  case "ENCRYPT_ERROR":
109
127
  onEncryptFailure === null || onEncryptFailure === void 0 ? void 0 : onEncryptFailure(message.payload);
110
128
  break;
111
- case "DEBUG":
129
+ default:
112
130
  if (debug)
113
- console.log("DEBUG:", message.payload);
114
- onDebug === null || onDebug === void 0 ? void 0 : onDebug(message.payload);
131
+ console.warn("Unknown PaymentJS event:", message.event);
115
132
  break;
116
133
  }
117
134
  }
118
135
  catch (err) {
119
- onPaymentFailure === null || onPaymentFailure === void 0 ? void 0 : onPaymentFailure({ message: "WebView Bridge Error", error: String(err) });
136
+ if (debug)
137
+ console.error("Failed to parse WebView message:", err);
138
+ onPaymentFailure === null || onPaymentFailure === void 0 ? void 0 : onPaymentFailure({
139
+ message: "WebView Bridge Error",
140
+ error: String(err),
141
+ });
120
142
  }
121
143
  }, [debug, onDebug, onPaymentSuccess, onPaymentFailure, onEncryptSuccess, onEncryptFailure]);
144
+ // Pre-flight validation
122
145
  const configError = (0, react_1.useMemo)(() => {
123
146
  if (mode === "pay") {
124
147
  if (!shopperReference)
@@ -130,8 +153,8 @@ function PaymentJS(props) {
130
153
  }, [mode, shopperReference, amount]);
131
154
  if (configError) {
132
155
  return (react_1.default.createElement(react_native_1.View, { style: [{ flex: 1, justifyContent: "center", padding: 16 }, style] },
133
- react_1.default.createElement(react_native_1.Text, { style: { color: "red", textAlign: "center" } }, configError)));
156
+ react_1.default.createElement(react_native_1.Text, { style: { color: "red", textAlign: "center", fontWeight: "600" } }, configError)));
134
157
  }
135
158
  return (react_1.default.createElement(react_native_1.View, { style: [{ flex: 1, backgroundColor: "#fff" }, style] },
136
- react_1.default.createElement(react_native_webview_1.WebView, { source: { uri: finalUri }, javaScriptEnabled: true, domStorageEnabled: true, originWhitelist: ["*"], onMessage: handleMessage })));
159
+ react_1.default.createElement(react_native_webview_1.WebView, { source: { uri: finalUri }, javaScriptEnabled: true, domStorageEnabled: true, originWhitelist: ["*"], onMessage: handleMessage, allowsBackForwardNavigationGestures: true, setSupportMultipleWindows: false })));
137
160
  }
package/dist/types.d.ts CHANGED
@@ -23,16 +23,28 @@ export type PaymentJSProps = {
23
23
  */
24
24
  lambdaUrl?: string;
25
25
  /**
26
- * Optional: The specific store ID for the merchant account.
26
+ * The specific store ID for the merchant account.
27
+ * If omitted, the library auto-selects based on environment.
27
28
  */
28
29
  store?: string;
30
+ /**
31
+ * NEW: The unique identifier for the specific school/location.
32
+ * Used for transaction logging and dashboard filtering.
33
+ */
34
+ schoolId?: string;
35
+ /**
36
+ * NEW: The unique identifier for the specific order.
37
+ * Used to track the payment against a specific basket/purchase.
38
+ */
39
+ orderId?: string;
29
40
  mode?: PaymentJSMode;
30
41
  environment?: PaymentJSEnvironment;
42
+ /** The unique identifier for the parent/customer */
31
43
  shopperReference?: string;
32
- /** Required for pay mode (minor units) */
44
+ /** Required for pay mode (minor units, e.g., 1000 for $10.00) */
33
45
  amount?: number;
34
46
  currency?: string;
35
- /** If true, ask Adyen to store the card */
47
+ /** If true, ask Adyen to store the card for future MIT payments */
36
48
  storePaymentMethod?: boolean;
37
49
  /** Extra cache buster */
38
50
  ts?: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@school24/paymentjs-rn",
3
- "version": "1.6.0",
3
+ "version": "1.7.0",
4
4
  "description": "React Native WebView wrapper for PaymentJS (Adyen)",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",