@miden-npm/react 2.0.0 → 2.0.2

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/index.js CHANGED
@@ -79,6 +79,26 @@ var getQueryParams = (url) => {
79
79
  });
80
80
  return params;
81
81
  };
82
+ function buildDeviceInformation(partial) {
83
+ const language = navigator.language || (navigator.languages?.[0] ?? "");
84
+ const tzOffsetMinutes = String((/* @__PURE__ */ new Date()).getTimezoneOffset());
85
+ return {
86
+ httpBrowserLanguage: language,
87
+ httpBrowserJavaEnabled: typeof navigator.javaEnabled === "function" ? navigator.javaEnabled() : false,
88
+ httpBrowserJavaScriptEnabled: true,
89
+ // if this code runs, JS is enabled
90
+ httpBrowserColorDepth: String(screen.colorDepth ?? ""),
91
+ httpBrowserScreenHeight: String(screen.height ?? ""),
92
+ httpBrowserScreenWidth: String(screen.width ?? ""),
93
+ httpBrowserTimeDifference: tzOffsetMinutes,
94
+ userAgentBrowserValue: navigator.userAgent ?? "",
95
+ deviceChannel: "BROWSER",
96
+ deviceIpAddress: "",
97
+ httpAcceptContent: language,
98
+ // browsers don't expose Accept header; use language as a proxy (or set app value)
99
+ ...partial
100
+ };
101
+ }
82
102
 
83
103
  // src/utils/api.util.ts
84
104
  var getBaseUrl = (mode, caller) => {
@@ -402,10 +422,7 @@ async function createPaymentLink(paymentObject, environment, secretKey, caller)
402
422
  } catch (error) {
403
423
  }
404
424
  }
405
- async function authorizeCardPayment(environment, {
406
- merchantId,
407
- ...rest
408
- }, caller) {
425
+ async function authorizeCardPayment(environment, { merchantId, ...rest }, caller) {
409
426
  try {
410
427
  const baseUrl = getBaseUrl(environment, caller);
411
428
  const apiKey = {
@@ -2240,7 +2257,7 @@ function BzpCheckoutIframe({
2240
2257
  email: "",
2241
2258
  phoneNumber: "",
2242
2259
  narration: "",
2243
- redirectUrl: "https://sandbox-merchant.buzapay.com/account/three-ds-status"
2260
+ redirectUrl: ""
2244
2261
  },
2245
2262
  onError
2246
2263
  }) {
@@ -2327,7 +2344,7 @@ function BzpCheckoutButton({
2327
2344
  email: "",
2328
2345
  phoneNumber: "",
2329
2346
  narration: "",
2330
- redirectUrl: "https://sandbox-merchant.buzapay.com/account/three-ds-status"
2347
+ redirectUrl: ""
2331
2348
  },
2332
2349
  mode = "redirect",
2333
2350
  onError
@@ -2519,19 +2536,40 @@ function PayByCard({
2519
2536
  phoneNumber: billingForm.phoneNumber ?? ""
2520
2537
  };
2521
2538
  const encryptedCardDetails = encryptPayload(secretKey, cardDetails);
2522
- const payload = {
2523
- customerId: paymentObject?.email || payForm.customerName || "",
2524
- amount: String(paymentObject?.amount ?? ""),
2525
- currency: paymentObject?.currency || "USD",
2526
- narration: paymentObject?.narration || "Test transaction",
2527
- encryptedCardDetails: encryptedCardDetails.requestParam,
2528
- billingDetails,
2529
- redirectUrl: paymentObject?.redirectUrl || "",
2530
- paymentReference: transactionReference,
2531
- isCheckout: true
2532
- };
2533
- const request = { ...payload, merchantId: secretKey };
2539
+ let payload = null;
2540
+ let payloadMiden = null;
2541
+ if (caller === "buzapay") {
2542
+ payload = {
2543
+ customerId: paymentObject?.email || payForm.customerName || "",
2544
+ amount: String(paymentObject?.amount ?? ""),
2545
+ currency: paymentObject?.currency || "USD",
2546
+ narration: paymentObject?.narration || "Test transaction",
2547
+ encryptedCardDetails: encryptedCardDetails.requestParam,
2548
+ billingDetails,
2549
+ redirectUrl: paymentObject?.redirectUrl || "https://sandbox-merchant.buzapay.com/account/three-ds-status",
2550
+ paymentReference: transactionReference,
2551
+ isCheckout: true
2552
+ };
2553
+ } else {
2554
+ const deviceInformation = buildDeviceInformation();
2555
+ payloadMiden = {
2556
+ customerId: paymentObject?.email || payForm.customerName || "",
2557
+ amount: String(paymentObject?.amount ?? ""),
2558
+ currency: paymentObject?.currency || "USD",
2559
+ narration: paymentObject?.narration || "Test transaction",
2560
+ encryptedCardDetails: encryptedCardDetails.requestParam,
2561
+ billingDetails,
2562
+ redirectUrl: paymentObject?.redirectUrl || "",
2563
+ paymentReference: transactionReference,
2564
+ isCheckout: true,
2565
+ postBackUrl: "",
2566
+ saveCard: false,
2567
+ deviceInformation
2568
+ };
2569
+ }
2570
+ const request = caller === "buzapay" ? { ...payload, merchantId: secretKey } : { ...payloadMiden, merchantId: secretKey };
2534
2571
  let response = await authorizeCardPayment(environment, request, caller);
2572
+ debugger;
2535
2573
  if (response?.responseParam) {
2536
2574
  response = decryptPayload(environment, response.responseParam);
2537
2575
  }
@@ -2875,7 +2913,7 @@ function PayByCard({
2875
2913
  mask: "0000 0000 0000 0000",
2876
2914
  placeholder: "0000 0000 0000 0000",
2877
2915
  value: payForm.cardNo,
2878
- preventPaste: true,
2916
+ preventPaste: false,
2879
2917
  onChange: (e) => {
2880
2918
  setPayForm({ ...payForm, cardNo: e });
2881
2919
  if (payErrors.cardNo)
@@ -3743,7 +3781,7 @@ function BzpCheckoutCard({
3743
3781
  email: "",
3744
3782
  phoneNumber: "",
3745
3783
  narration: "",
3746
- redirectUrl: "https://sandbox-merchant.buzapay.com/account/three-ds-status"
3784
+ redirectUrl: ""
3747
3785
  },
3748
3786
  onPaymentAuthorized,
3749
3787
  onError
@@ -3911,7 +3949,7 @@ function MidenCheckoutIframe({
3911
3949
  email: "",
3912
3950
  phoneNumber: "",
3913
3951
  narration: "",
3914
- redirectUrl: "https://sandbox-merchant.buzapay.com/account/three-ds-status"
3952
+ redirectUrl: ""
3915
3953
  },
3916
3954
  onError
3917
3955
  }) {
@@ -3998,7 +4036,7 @@ function MidenCheckoutButton({
3998
4036
  email: "",
3999
4037
  phoneNumber: "",
4000
4038
  narration: "",
4001
- redirectUrl: "https://sandbox-merchant.buzapay.com/account/three-ds-status"
4039
+ redirectUrl: ""
4002
4040
  },
4003
4041
  mode = "redirect",
4004
4042
  onError
@@ -4081,7 +4119,7 @@ function MidenCheckoutCard({
4081
4119
  email: "",
4082
4120
  phoneNumber: "",
4083
4121
  narration: "",
4084
- redirectUrl: "https://sandbox-merchant.buzapay.com/account/three-ds-status"
4122
+ redirectUrl: ""
4085
4123
  },
4086
4124
  onPaymentAuthorized,
4087
4125
  onError