@fractalpay/fractalpay-next 0.1.4 → 0.1.6

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
@@ -39,7 +39,7 @@ var require_package = __commonJS({
39
39
  "package.json"(exports, module) {
40
40
  module.exports = {
41
41
  name: "@fractalpay/fractalpay-next",
42
- version: "0.1.4",
42
+ version: "0.1.6",
43
43
  private: false,
44
44
  type: "module",
45
45
  scripts: {
@@ -4284,6 +4284,7 @@ function GetPaymentPage(props) {
4284
4284
  const [loading, setLoading] = useState4(false);
4285
4285
  const [loadingIframe, setLoadingIframe] = useState4(false);
4286
4286
  const [loading2, setLoading2] = useState4(false);
4287
+ const [surchargeLookupLoading, setSurchargeLookupLoading] = useState4(false);
4287
4288
  const [error, setError] = useState4("");
4288
4289
  const [errorIframe, setErrorIframe] = useState4("");
4289
4290
  const [success, setSuccess] = useState4(false);
@@ -4381,6 +4382,47 @@ function GetPaymentPage(props) {
4381
4382
  cardholder_billing_zip: (cardData == null ? void 0 : cardData.zipCode) || void 0
4382
4383
  };
4383
4384
  };
4385
+ const runCofSurchargeLookup = async (cardId) => {
4386
+ var _a2, _b2;
4387
+ try {
4388
+ const res = await axios3.post(`${baseUrl}surcharge-lookup-cof`, {
4389
+ fractalpayPublicKey: fractalpayClientKey,
4390
+ customer_id: props == null ? void 0 : props.customerId,
4391
+ card_id: cardId,
4392
+ amount: Number((_a2 = cashDiscount != null ? cashDiscount : props == null ? void 0 : props.amount) != null ? _a2 : 0),
4393
+ cardholder_billing_zip: (cardData == null ? void 0 : cardData.zipCode) || void 0
4394
+ });
4395
+ const data = (_b2 = res == null ? void 0 : res.data) == null ? void 0 : _b2.data;
4396
+ if (!data) return null;
4397
+ return {
4398
+ card_brand: data.card_brand,
4399
+ card_issue_type: data.card_issue_type,
4400
+ surcharge_allowed: data.surcharge_allowed,
4401
+ max_surcharge_percent: data.max_surcharge_percent,
4402
+ max_surcharge_amount: data.max_surcharge_amount
4403
+ };
4404
+ } catch (err) {
4405
+ console.error("COF surcharge lookup failed", err);
4406
+ return null;
4407
+ }
4408
+ };
4409
+ useEffect8(() => {
4410
+ const surchargingOn = Number(paymentData == null ? void 0 : paymentData.surchargeProgram) === 1 && !!(props == null ? void 0 : props.pass_fee);
4411
+ if (!surchargingOn || !(selectedCard == null ? void 0 : selectedCard.id) || selectedCard.card_type === "Bank") {
4412
+ setSurchargeResult(null);
4413
+ return;
4414
+ }
4415
+ let cancelled = false;
4416
+ setSurchargeLookupLoading(true);
4417
+ runCofSurchargeLookup(selectedCard.id).then((result) => {
4418
+ if (cancelled) return;
4419
+ setSurchargeResult(result);
4420
+ setSurchargeLookupLoading(false);
4421
+ });
4422
+ return () => {
4423
+ cancelled = true;
4424
+ };
4425
+ }, [selectedCard == null ? void 0 : selectedCard.id, selectedCard == null ? void 0 : selectedCard.card_type, paymentData == null ? void 0 : paymentData.surchargeProgram, props == null ? void 0 : props.pass_fee]);
4384
4426
  useEffect8(() => {
4385
4427
  if (show) {
4386
4428
  let cash_discount = CalculateCashDiscount(props == null ? void 0 : props.amount, (props == null ? void 0 : props.surcharge) || 0);
@@ -4712,7 +4754,7 @@ function GetPaymentPage(props) {
4712
4754
  const customer_id = props == null ? void 0 : props.customerId;
4713
4755
  const fractalpayPublicKey = props == null ? void 0 : props.merchantPublicKey;
4714
4756
  const order_id = props == null ? void 0 : props.orderID;
4715
- const amount = props == null ? void 0 : props.amount;
4757
+ const amount = leftTotal;
4716
4758
  const card_id = selectedCard == null ? void 0 : selectedCard.id;
4717
4759
  const card_type = selectedCard == null ? void 0 : selectedCard.card_type;
4718
4760
  const preAuth_id = (props == null ? void 0 : props.preauthId) || "";
@@ -4782,7 +4824,7 @@ function GetPaymentPage(props) {
4782
4824
  try {
4783
4825
  const formData = {
4784
4826
  // amount: `${props.amount || 0}`,
4785
- amount: `${leftTotal}`,
4827
+ amount: `${orderAmount}`,
4786
4828
  fractalpayPublicKey: fractalpayClientKey,
4787
4829
  orderId: props == null ? void 0 : props.orderID,
4788
4830
  customer_id: props == null ? void 0 : props.customerId,
@@ -4855,8 +4897,8 @@ function GetPaymentPage(props) {
4855
4897
  return;
4856
4898
  }
4857
4899
  const card_issue_type = ((_i2 = tokenizeData == null ? void 0 : tokenizeData.bin_lookup_result) == null ? void 0 : _i2.card_issue_type) || null;
4858
- const feeExempt = ["debit", "prepaid"].includes(String(card_issue_type || "").toLowerCase());
4859
- if (feeExempt && (props == null ? void 0 : props.pass_fee) && (paymentData == null ? void 0 : paymentData.surchargeProgram) == 1) {
4900
+ const feeExempt2 = ["debit", "prepaid"].includes(String(card_issue_type || "").toLowerCase());
4901
+ if (feeExempt2 && (props == null ? void 0 : props.pass_fee) && (paymentData == null ? void 0 : paymentData.surchargeProgram) == 1) {
4860
4902
  setLoderText(`Processing ${card_issue_type} card without fee`);
4861
4903
  }
4862
4904
  console.log(tokenizeData, "tokenizeData");
@@ -5041,15 +5083,15 @@ function GetPaymentPage(props) {
5041
5083
  if (customer_id) {
5042
5084
  if (card_id) {
5043
5085
  setLoading2(true);
5044
- const feeExempt = ["debit", "prepaid"].includes(String(card_issue_type || "").toLowerCase());
5045
- if (feeExempt && (props == null ? void 0 : props.pass_fee) && (paymentData == null ? void 0 : paymentData.surchargeProgram) == 1) {
5086
+ const feeExempt2 = ["debit", "prepaid"].includes(String(card_issue_type || "").toLowerCase());
5087
+ if (feeExempt2 && (props == null ? void 0 : props.pass_fee) && (paymentData == null ? void 0 : paymentData.surchargeProgram) == 1) {
5046
5088
  setLoderText(`Processing ${card_issue_type} card without fee`);
5047
5089
  }
5048
5090
  let resultofOrderCreate;
5049
5091
  if (!(card_type === "Bank")) {
5050
5092
  const formData = {
5051
5093
  // amount: `${props.amount || 0}`,
5052
- amount: `${leftTotal}`,
5094
+ amount: `${orderAmount}`,
5053
5095
  fractalpayPublicKey: fractalpayClientKey,
5054
5096
  orderId: props == null ? void 0 : props.orderID,
5055
5097
  customer_id: props == null ? void 0 : props.customerId,
@@ -5064,7 +5106,7 @@ function GetPaymentPage(props) {
5064
5106
  console.log(resultofOrderCreate, "vfndsjkfvhg", resultofOrderCreate == null ? void 0 : resultofOrderCreate.data.data.posSalesIdEncode);
5065
5107
  }
5066
5108
  let chargeobj = __spreadValues(__spreadValues({
5067
- amount: card_type === "Bank" ? `${bankAmount}` : amount,
5109
+ amount: `${leftTotal}`,
5068
5110
  order_id,
5069
5111
  customer_id,
5070
5112
  card_id,
@@ -5251,18 +5293,24 @@ function GetPaymentPage(props) {
5251
5293
  const merchantName = (paymentData == null ? void 0 : paymentData.bname) || (paymentData == null ? void 0 : paymentData.customer_name) || "the merchant";
5252
5294
  const invoiceNo = String((props == null ? void 0 : props.orderID) || "").replace(/^\s*invoice\s*#?\s*/i, "").trim();
5253
5295
  const invoiceLabel = invoiceNo ? `Invoice #${invoiceNo}` : "Invoice";
5296
+ const isSurchargeProgram = Number(paymentData == null ? void 0 : paymentData.surchargeProgram) === 1;
5254
5297
  const baseAmount = Number((_a = cashDiscount != null ? cashDiscount : props == null ? void 0 : props.amount) != null ? _a : 0);
5255
5298
  const fundingType = (_b = surchargeResult == null ? void 0 : surchargeResult.card_issue_type) == null ? void 0 : _b.toLowerCase();
5256
- const surchargeBlocked = surchargeResult && (fundingType !== "debit" && fundingType !== "prepaid");
5257
- const cardTotal = !surchargeBlocked ? baseAmount : Number((props == null ? void 0 : props.amount) || 0);
5299
+ const feeExempt = fundingType === "debit" || fundingType === "prepaid";
5300
+ let cardTotal;
5301
+ if (isSurchargeProgram) {
5302
+ cardTotal = feeExempt ? baseAmount : parseFloat((baseAmount * (1 + Number((props == null ? void 0 : props.surcharge) || 0) / 100)).toFixed(2));
5303
+ } else {
5304
+ cardTotal = Number((props == null ? void 0 : props.amount) || 0);
5305
+ }
5258
5306
  const surchargeFee = Math.max(cardTotal - baseAmount, 0);
5259
5307
  const isBankView = activetab === "ach";
5260
5308
  const discountNum = Number((props == null ? void 0 : props.discount) || 0);
5261
5309
  const taxNum = Number((props == null ? void 0 : props.tax) || 0);
5262
5310
  const leftTotal = isBankView ? Number(bankAmount || 0) : cardTotal;
5311
+ const orderAmount = isSurchargeProgram ? baseAmount : Number((props == null ? void 0 : props.amount) || 0);
5263
5312
  const fmtNum = (n) => Number(n).toLocaleString("en-US", { minimumFractionDigits: 2, maximumFractionDigits: 2 });
5264
5313
  const hasFee = surchargeFee > 0 && !!(props == null ? void 0 : props.pass_fee);
5265
- const isSurchargeProgram = Number(paymentData == null ? void 0 : paymentData.surchargeProgram) === 1;
5266
5314
  const showSurchargeLine = isSurchargeProgram && !isBankView && hasFee;
5267
5315
  const summarySubtotal = isSurchargeProgram || isBankView ? baseAmount : cardTotal;
5268
5316
  const savedMethods = [...cardList || [], ...bankList || []];
@@ -5385,7 +5433,7 @@ function GetPaymentPage(props) {
5385
5433
  } }) }),
5386
5434
  success && /* @__PURE__ */ jsx18(SuccessMsz, { onClose: handleClose, tranId, isDebitAdjusted }),
5387
5435
  !error && !errorIframe && !success && /* @__PURE__ */ jsxs9(Fragment9, { children: [
5388
- (loading || loading2 || loadingIframe) && /* @__PURE__ */ jsx18(Loader_default, { loading: loading || loading2 || loadingIframe, loaderText }),
5436
+ (loading || loading2 || loadingIframe || surchargeLookupLoading) && /* @__PURE__ */ jsx18(Loader_default, { loading: loading || loading2 || loadingIframe || surchargeLookupLoading, loaderText }),
5389
5437
  /* @__PURE__ */ jsxs9("div", { className: "fps-modal", children: [
5390
5438
  LeftSummary,
5391
5439
  /* @__PURE__ */ jsxs9("section", { className: "fps-content", children: [
@@ -5423,7 +5471,7 @@ function GetPaymentPage(props) {
5423
5471
  FractalFooter,
5424
5472
  {
5425
5473
  authText: AuthText,
5426
- disabled: loading2 || !(selectedCard == null ? void 0 : selectedCard.id),
5474
+ disabled: loading2 || !(selectedCard == null ? void 0 : selectedCard.id) || surchargeLookupLoading,
5427
5475
  onPay: handlechargeCustomer,
5428
5476
  buttonLabel: isPreAuth ? `Authorize ${formatUSD(cardTotal.toFixed(2))}` : `Pay ${formatUSD(((selectedCard == null ? void 0 : selectedCard.card_type) === "Bank" ? Number(bankAmount || 0) : cardTotal).toFixed(2))} to ${merchantName}`
5429
5477
  }
@@ -11016,7 +11064,6 @@ var ModelContentSky = ({ amount, bankAmount, submitBtnText = "Pay", session_toke
11016
11064
  setProcessingFee(Number((_d2 = (_c2 = res == null ? void 0 : res.data) == null ? void 0 : _c2.data) == null ? void 0 : _d2.fee) || 0);
11017
11065
  setPaymentGateway((_f2 = (_e2 = res == null ? void 0 : res.data) == null ? void 0 : _e2.data) == null ? void 0 : _f2.paymentGateway);
11018
11066
  setDCToken((_h2 = (_g2 = res == null ? void 0 : res.data) == null ? void 0 : _g2.data) == null ? void 0 : _h2.dctoken);
11019
- debugger;
11020
11067
  if (((_j2 = (_i2 = res == null ? void 0 : res.data) == null ? void 0 : _i2.data) == null ? void 0 : _j2.paymentGateway) === 31 && ((_l2 = (_k2 = res == null ? void 0 : res.data) == null ? void 0 : _k2.data) == null ? void 0 : _l2.dctoken)) {
11021
11068
  setLoadingIframe(true);
11022
11069
  }