@school24/paymentjs-rn 1.5.0 → 1.6.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.
Files changed (2) hide show
  1. package/dist/PaymentJS.js +25 -45
  2. package/package.json +1 -1
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 (So Cherian doesn't have to pass them)
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,32 +51,29 @@ 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 now default to internal constants if not provided
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], mode = "pay", shopperReference = "", amount = 0, currency = "AUD", storePaymentMethod = false, ts, style, debug = false, onPaymentSuccess, onPaymentFailure, onEncryptSuccess, onEncryptFailure, onDebug, } = props;
49
59
  const finalUri = (0, react_1.useMemo)(() => {
50
- if (uri)
51
- return uri;
52
60
  const params = new URLSearchParams();
53
- // Required by HTML:
54
61
  params.set("mode", mode);
55
62
  params.set("env", environment);
56
63
  params.set("baseUrl", normalizeBase(lambdaUrl));
57
64
  params.set("currency", currency);
58
- // Optional but required for MIT/Saved Card compliance:
65
+ // Use the auto-selected or provided store ID
59
66
  if (store)
60
67
  params.set("store", store);
61
68
  if (shopperReference)
62
69
  params.set("shopperReference", shopperReference);
63
70
  params.set("storePaymentMethod", safeBoolString(storePaymentMethod));
64
- // Pay mode requires amount
65
71
  if (mode === "pay") {
66
72
  params.set("amount", String(amount !== null && amount !== void 0 ? amount : 0));
67
73
  }
68
- // cache buster for Expo/WebView refresh
69
74
  params.set("ts", String(ts !== null && ts !== void 0 ? ts : Date.now()));
70
75
  return `${pageUrl}?${params.toString()}`;
71
76
  }, [
72
- uri,
73
77
  pageUrl,
74
78
  lambdaUrl,
75
79
  store,
@@ -90,68 +94,44 @@ function PaymentJS(props) {
90
94
  const message = JSON.parse(raw);
91
95
  if (message.source !== "PaymentJS" || !message.event)
92
96
  return;
93
- if (message.event === "DEBUG") {
94
- if (debug)
95
- console.log("💳 PaymentJS DEBUG:", message.payload);
96
- onDebug === null || onDebug === void 0 ? void 0 : onDebug(message.payload);
97
- return;
98
- }
99
97
  switch (message.event) {
100
98
  case "PAYMENT_SUCCESS":
101
99
  onPaymentSuccess === null || onPaymentSuccess === void 0 ? void 0 : onPaymentSuccess(message.payload);
102
- return;
100
+ break;
103
101
  case "PAYMENT_ERROR":
104
102
  case "CONFIG_ERROR":
105
- // Enhanced error payloads now contain specific codes like CvcRequired or ContractNotFound
106
103
  onPaymentFailure === null || onPaymentFailure === void 0 ? void 0 : onPaymentFailure(message.payload);
107
- return;
104
+ break;
108
105
  case "ENCRYPT_SUCCESS":
109
106
  onEncryptSuccess === null || onEncryptSuccess === void 0 ? void 0 : onEncryptSuccess(message.payload);
110
- return;
107
+ break;
111
108
  case "ENCRYPT_ERROR":
112
109
  onEncryptFailure === null || onEncryptFailure === void 0 ? void 0 : onEncryptFailure(message.payload);
113
- return;
114
- default:
110
+ break;
111
+ case "DEBUG":
115
112
  if (debug)
116
- console.warn("Unknown PaymentJS event:", message.event);
117
- onDebug === null || onDebug === void 0 ? void 0 : onDebug({ step: "UNKNOWN_EVENT", message });
118
- return;
113
+ console.log("DEBUG:", message.payload);
114
+ onDebug === null || onDebug === void 0 ? void 0 : onDebug(message.payload);
115
+ break;
119
116
  }
120
117
  }
121
118
  catch (err) {
122
- if (debug)
123
- console.error("Failed to parse WebView message:", err);
124
- onPaymentFailure === null || onPaymentFailure === void 0 ? void 0 : onPaymentFailure({
125
- message: "Invalid message from payment WebView",
126
- error: String(err),
127
- });
119
+ onPaymentFailure === null || onPaymentFailure === void 0 ? void 0 : onPaymentFailure({ message: "WebView Bridge Error", error: String(err) });
128
120
  }
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
121
+ }, [debug, onDebug, onPaymentSuccess, onPaymentFailure, onEncryptSuccess, onEncryptFailure]);
138
122
  const configError = (0, react_1.useMemo)(() => {
139
- if (!finalUri)
140
- return "Missing payment page URL";
141
123
  if (mode === "pay") {
142
124
  if (!shopperReference)
143
125
  return "shopperReference is required in pay mode";
144
126
  if (!amount || amount <= 0)
145
127
  return "amount > 0 is required in pay mode";
146
128
  }
147
- if (!lambdaUrl)
148
- return "lambdaUrl is required";
149
129
  return "";
150
- }, [finalUri, mode, shopperReference, amount, lambdaUrl]);
130
+ }, [mode, shopperReference, amount]);
151
131
  if (configError) {
152
132
  return (react_1.default.createElement(react_native_1.View, { style: [{ flex: 1, justifyContent: "center", padding: 16 }, style] },
153
133
  react_1.default.createElement(react_native_1.Text, { style: { color: "red", textAlign: "center" } }, configError)));
154
134
  }
155
135
  return (react_1.default.createElement(react_native_1.View, { style: [{ flex: 1, backgroundColor: "#fff" }, style] },
156
- react_1.default.createElement(react_native_webview_1.WebView, { source: { uri: finalUri }, javaScriptEnabled: true, domStorageEnabled: true, originWhitelist: ["*"], onMessage: handleMessage, allowsBackForwardNavigationGestures: true, setSupportMultipleWindows: false })));
136
+ react_1.default.createElement(react_native_webview_1.WebView, { source: { uri: finalUri }, javaScriptEnabled: true, domStorageEnabled: true, originWhitelist: ["*"], onMessage: handleMessage })));
157
137
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@school24/paymentjs-rn",
3
- "version": "1.5.0",
3
+ "version": "1.6.0",
4
4
  "description": "React Native WebView wrapper for PaymentJS (Adyen)",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",