@school24/paymentjs-rn 1.5.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,6 +37,13 @@ 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
41
+ const DEFAULT_PAGE_URL = "https://client.brandsyncstudio.com/paymentjs/payment-rn.html";
42
+ const DEFAULT_LAMBDA_URL = "https://qb3epa62mry53z3woeiecuhpve0scpjb.lambda-url.ap-southeast-2.on.aws";
43
+ const STORE_IDS = {
44
+ test: "5b5f3c5c-d152-40d7-b602-669cbfb5b7b4",
45
+ live: "95ead788-0b9a-477d-9275-924b5f9fd00c",
46
+ };
40
47
  function safeBoolString(v) {
41
48
  return (v ? "true" : "false");
42
49
  }
@@ -44,35 +51,43 @@ function normalizeBase(url) {
44
51
  return url ? url.replace(/\/+$/, "") : "";
45
52
  }
46
53
  function PaymentJS(props) {
47
- const { uri, pageUrl = "https://client.brandsyncstudio.com/paymentjs/payment-rn.html", lambdaUrl = "https://qb3epa62mry53z3woeiecuhpve0scpjb.lambda-url.ap-southeast-2.on.aws", store = "", mode = "pay", environment = "test", shopperReference = "", amount = 0, currency = "AUD", storePaymentMethod = false, ts, style, debug = false, onPaymentSuccess, onPaymentFailure, onEncryptSuccess, onEncryptFailure, onDebug, } = props;
48
- // Build final URL if uri isn't provided
54
+ const {
55
+ // These default to internal constants if not provided by Cherian
56
+ pageUrl = DEFAULT_PAGE_URL, lambdaUrl = DEFAULT_LAMBDA_URL, environment = "test",
57
+ // Auto-select store based on environment if store prop is missing
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;
49
61
  const finalUri = (0, react_1.useMemo)(() => {
50
- if (uri)
51
- return uri;
52
62
  const params = new URLSearchParams();
53
- // Required by HTML:
63
+ // Core Config
54
64
  params.set("mode", mode);
55
65
  params.set("env", environment);
56
66
  params.set("baseUrl", normalizeBase(lambdaUrl));
57
67
  params.set("currency", currency);
58
- // Optional but required for MIT/Saved Card compliance:
68
+ // Merchant & Logging Context
59
69
  if (store)
60
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
61
76
  if (shopperReference)
62
77
  params.set("shopperReference", shopperReference);
63
78
  params.set("storePaymentMethod", safeBoolString(storePaymentMethod));
64
- // Pay mode requires amount
65
79
  if (mode === "pay") {
66
80
  params.set("amount", String(amount !== null && amount !== void 0 ? amount : 0));
67
81
  }
68
- // cache buster for Expo/WebView refresh
82
+ // Cache buster for WebView refresh
69
83
  params.set("ts", String(ts !== null && ts !== void 0 ? ts : Date.now()));
70
84
  return `${pageUrl}?${params.toString()}`;
71
85
  }, [
72
- uri,
73
86
  pageUrl,
74
87
  lambdaUrl,
75
88
  store,
89
+ schoolId,
90
+ orderId,
76
91
  mode,
77
92
  environment,
78
93
  shopperReference,
@@ -99,58 +114,46 @@ function PaymentJS(props) {
99
114
  switch (message.event) {
100
115
  case "PAYMENT_SUCCESS":
101
116
  onPaymentSuccess === null || onPaymentSuccess === void 0 ? void 0 : onPaymentSuccess(message.payload);
102
- return;
117
+ break;
103
118
  case "PAYMENT_ERROR":
104
119
  case "CONFIG_ERROR":
105
- // Enhanced error payloads now contain specific codes like CvcRequired or ContractNotFound
120
+ // Receives the granular messages (Insufficient Funds, etc.) from Lambda
106
121
  onPaymentFailure === null || onPaymentFailure === void 0 ? void 0 : onPaymentFailure(message.payload);
107
- return;
122
+ break;
108
123
  case "ENCRYPT_SUCCESS":
109
124
  onEncryptSuccess === null || onEncryptSuccess === void 0 ? void 0 : onEncryptSuccess(message.payload);
110
- return;
125
+ break;
111
126
  case "ENCRYPT_ERROR":
112
127
  onEncryptFailure === null || onEncryptFailure === void 0 ? void 0 : onEncryptFailure(message.payload);
113
- return;
128
+ break;
114
129
  default:
115
130
  if (debug)
116
131
  console.warn("Unknown PaymentJS event:", message.event);
117
- onDebug === null || onDebug === void 0 ? void 0 : onDebug({ step: "UNKNOWN_EVENT", message });
118
- return;
132
+ break;
119
133
  }
120
134
  }
121
135
  catch (err) {
122
136
  if (debug)
123
137
  console.error("Failed to parse WebView message:", err);
124
138
  onPaymentFailure === null || onPaymentFailure === void 0 ? void 0 : onPaymentFailure({
125
- message: "Invalid message from payment WebView",
139
+ message: "WebView Bridge Error",
126
140
  error: String(err),
127
141
  });
128
142
  }
129
- }, [
130
- debug,
131
- onDebug,
132
- onPaymentSuccess,
133
- onPaymentFailure,
134
- onEncryptSuccess,
135
- onEncryptFailure,
136
- ]);
137
- // Validation to prevent 800 (Contract Not Found) or 422 (Validation) errors upfront
143
+ }, [debug, onDebug, onPaymentSuccess, onPaymentFailure, onEncryptSuccess, onEncryptFailure]);
144
+ // Pre-flight validation
138
145
  const configError = (0, react_1.useMemo)(() => {
139
- if (!finalUri)
140
- return "Missing payment page URL";
141
146
  if (mode === "pay") {
142
147
  if (!shopperReference)
143
148
  return "shopperReference is required in pay mode";
144
149
  if (!amount || amount <= 0)
145
150
  return "amount > 0 is required in pay mode";
146
151
  }
147
- if (!lambdaUrl)
148
- return "lambdaUrl is required";
149
152
  return "";
150
- }, [finalUri, mode, shopperReference, amount, lambdaUrl]);
153
+ }, [mode, shopperReference, amount]);
151
154
  if (configError) {
152
155
  return (react_1.default.createElement(react_native_1.View, { style: [{ flex: 1, justifyContent: "center", padding: 16 }, style] },
153
- 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)));
154
157
  }
155
158
  return (react_1.default.createElement(react_native_1.View, { style: [{ flex: 1, backgroundColor: "#fff" }, style] },
156
159
  react_1.default.createElement(react_native_webview_1.WebView, { source: { uri: finalUri }, javaScriptEnabled: true, domStorageEnabled: true, originWhitelist: ["*"], onMessage: handleMessage, allowsBackForwardNavigationGestures: true, setSupportMultipleWindows: false })));
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.5.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",