@fractalpay/fractalpay-next-dev 0.0.303 → 0.0.305

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-dev",
42
- version: "0.0.303",
42
+ version: "0.0.305",
43
43
  private: false,
44
44
  type: "module",
45
45
  scripts: {
@@ -4257,6 +4257,7 @@ function GetPaymentPage(props) {
4257
4257
  const [loading, setLoading] = useState4(false);
4258
4258
  const [loadingIframe, setLoadingIframe] = useState4(false);
4259
4259
  const [loading2, setLoading2] = useState4(false);
4260
+ const [surchargeLookupLoading, setSurchargeLookupLoading] = useState4(false);
4260
4261
  const [error, setError] = useState4("");
4261
4262
  const [errorIframe, setErrorIframe] = useState4("");
4262
4263
  const [success, setSuccess] = useState4(false);
@@ -4354,6 +4355,47 @@ function GetPaymentPage(props) {
4354
4355
  cardholder_billing_zip: (cardData == null ? void 0 : cardData.zipCode) || void 0
4355
4356
  };
4356
4357
  };
4358
+ const runCofSurchargeLookup = async (cardId) => {
4359
+ var _a2, _b2;
4360
+ try {
4361
+ const res = await axios3.post(`${baseUrl}surcharge-lookup-cof`, {
4362
+ fractalpayPublicKey: fractalpayClientKey,
4363
+ customer_id: props == null ? void 0 : props.customerId,
4364
+ card_id: cardId,
4365
+ amount: Number((_a2 = cashDiscount != null ? cashDiscount : props == null ? void 0 : props.amount) != null ? _a2 : 0),
4366
+ cardholder_billing_zip: (cardData == null ? void 0 : cardData.zipCode) || void 0
4367
+ });
4368
+ const data = (_b2 = res == null ? void 0 : res.data) == null ? void 0 : _b2.data;
4369
+ if (!data) return null;
4370
+ return {
4371
+ card_brand: data.card_brand,
4372
+ card_issue_type: data.card_issue_type,
4373
+ surcharge_allowed: data.surcharge_allowed,
4374
+ max_surcharge_percent: data.max_surcharge_percent,
4375
+ max_surcharge_amount: data.max_surcharge_amount
4376
+ };
4377
+ } catch (err) {
4378
+ console.error("COF surcharge lookup failed", err);
4379
+ return null;
4380
+ }
4381
+ };
4382
+ useEffect8(() => {
4383
+ const surchargingOn = Number(paymentData == null ? void 0 : paymentData.surchargeProgram) === 1 && !!(props == null ? void 0 : props.pass_fee);
4384
+ if (!surchargingOn || !(selectedCard == null ? void 0 : selectedCard.id) || selectedCard.card_type === "Bank") {
4385
+ setSurchargeResult(null);
4386
+ return;
4387
+ }
4388
+ let cancelled = false;
4389
+ setSurchargeLookupLoading(true);
4390
+ runCofSurchargeLookup(selectedCard.id).then((result) => {
4391
+ if (cancelled) return;
4392
+ setSurchargeResult(result);
4393
+ setSurchargeLookupLoading(false);
4394
+ });
4395
+ return () => {
4396
+ cancelled = true;
4397
+ };
4398
+ }, [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]);
4357
4399
  useEffect8(() => {
4358
4400
  if (show) {
4359
4401
  let cash_discount = CalculateCashDiscount(props == null ? void 0 : props.amount, (props == null ? void 0 : props.surcharge) || 0);
@@ -4685,7 +4727,7 @@ function GetPaymentPage(props) {
4685
4727
  const customer_id = props == null ? void 0 : props.customerId;
4686
4728
  const fractalpayPublicKey = props == null ? void 0 : props.merchantPublicKey;
4687
4729
  const order_id = props == null ? void 0 : props.orderID;
4688
- const amount = props == null ? void 0 : props.amount;
4730
+ const amount = leftTotal;
4689
4731
  const card_id = selectedCard == null ? void 0 : selectedCard.id;
4690
4732
  const card_type = selectedCard == null ? void 0 : selectedCard.card_type;
4691
4733
  const preAuth_id = (props == null ? void 0 : props.preauthId) || "";
@@ -4755,7 +4797,7 @@ function GetPaymentPage(props) {
4755
4797
  try {
4756
4798
  const formData = {
4757
4799
  // amount: `${props.amount || 0}`,
4758
- amount: `${leftTotal}`,
4800
+ amount: `${orderAmount}`,
4759
4801
  fractalpayPublicKey: fractalpayClientKey,
4760
4802
  orderId: props == null ? void 0 : props.orderID,
4761
4803
  customer_id: props == null ? void 0 : props.customerId,
@@ -4828,8 +4870,8 @@ function GetPaymentPage(props) {
4828
4870
  return;
4829
4871
  }
4830
4872
  const card_issue_type = ((_i2 = tokenizeData == null ? void 0 : tokenizeData.bin_lookup_result) == null ? void 0 : _i2.card_issue_type) || null;
4831
- const feeExempt = ["debit", "prepaid"].includes(String(card_issue_type || "").toLowerCase());
4832
- if (feeExempt && (props == null ? void 0 : props.pass_fee) && (paymentData == null ? void 0 : paymentData.surchargeProgram) == 1) {
4873
+ const feeExempt2 = ["debit", "prepaid"].includes(String(card_issue_type || "").toLowerCase());
4874
+ if (feeExempt2 && (props == null ? void 0 : props.pass_fee) && (paymentData == null ? void 0 : paymentData.surchargeProgram) == 1) {
4833
4875
  setLoderText(`Processing ${card_issue_type} card without fee`);
4834
4876
  }
4835
4877
  console.log(tokenizeData, "tokenizeData");
@@ -5009,15 +5051,15 @@ function GetPaymentPage(props) {
5009
5051
  if (customer_id) {
5010
5052
  if (card_id) {
5011
5053
  setLoading2(true);
5012
- const feeExempt = ["debit", "prepaid"].includes(String(card_issue_type || "").toLowerCase());
5013
- if (feeExempt && (props == null ? void 0 : props.pass_fee) && (paymentData == null ? void 0 : paymentData.surchargeProgram) == 1) {
5054
+ const feeExempt2 = ["debit", "prepaid"].includes(String(card_issue_type || "").toLowerCase());
5055
+ if (feeExempt2 && (props == null ? void 0 : props.pass_fee) && (paymentData == null ? void 0 : paymentData.surchargeProgram) == 1) {
5014
5056
  setLoderText(`Processing ${card_issue_type} card without fee`);
5015
5057
  }
5016
5058
  let resultofOrderCreate;
5017
5059
  if (!(card_type === "Bank")) {
5018
5060
  const formData = {
5019
5061
  // amount: `${props.amount || 0}`,
5020
- amount: `${leftTotal}`,
5062
+ amount: `${orderAmount}`,
5021
5063
  fractalpayPublicKey: fractalpayClientKey,
5022
5064
  orderId: props == null ? void 0 : props.orderID,
5023
5065
  customer_id: props == null ? void 0 : props.customerId,
@@ -5032,7 +5074,7 @@ function GetPaymentPage(props) {
5032
5074
  console.log(resultofOrderCreate, "vfndsjkfvhg", resultofOrderCreate == null ? void 0 : resultofOrderCreate.data.data.posSalesIdEncode);
5033
5075
  }
5034
5076
  let chargeobj = __spreadValues(__spreadValues({
5035
- amount: card_type === "Bank" ? `${bankAmount}` : amount,
5077
+ amount: `${leftTotal}`,
5036
5078
  order_id,
5037
5079
  customer_id,
5038
5080
  card_id,
@@ -5219,19 +5261,24 @@ function GetPaymentPage(props) {
5219
5261
  const merchantName = (paymentData == null ? void 0 : paymentData.bname) || (paymentData == null ? void 0 : paymentData.customer_name) || "the merchant";
5220
5262
  const invoiceNo = String((props == null ? void 0 : props.orderID) || "").replace(/^\s*invoice\s*#?\s*/i, "").trim();
5221
5263
  const invoiceLabel = invoiceNo ? `Invoice #${invoiceNo}` : "Invoice";
5222
- const baseAmount = Number(cashDiscount && cashDiscount > 0 ? cashDiscount : (_a = props == null ? void 0 : props.amount) != null ? _a : 0);
5264
+ const isSurchargeProgram = Number(paymentData == null ? void 0 : paymentData.surchargeProgram) === 1;
5265
+ const baseAmount = Number((_a = cashDiscount != null ? cashDiscount : props == null ? void 0 : props.amount) != null ? _a : 0);
5223
5266
  const fundingType = (_b = surchargeResult == null ? void 0 : surchargeResult.card_issue_type) == null ? void 0 : _b.toLowerCase();
5224
- const lookupApproximated = !!surchargeResult && (surchargeResult.surcharge_lookup_status === "approximated" || !!surchargeResult.engine_error);
5225
- const surchargeBlocked = !!surchargeResult && (fundingType === "debit" || fundingType === "prepaid" || !lookupApproximated && fundingType !== "unknown" && (surchargeResult.surcharge_allowed === false || !(Number(surchargeResult.max_surcharge_percent) > 0)));
5226
- const cardTotal = surchargeBlocked ? baseAmount : Number((props == null ? void 0 : props.amount) || 0);
5267
+ const feeExempt = fundingType === "debit" || fundingType === "prepaid";
5268
+ let cardTotal;
5269
+ if (isSurchargeProgram) {
5270
+ cardTotal = feeExempt ? baseAmount : parseFloat((baseAmount * (1 + Number((props == null ? void 0 : props.surcharge) || 0) / 100)).toFixed(2));
5271
+ } else {
5272
+ cardTotal = Number((props == null ? void 0 : props.amount) || 0);
5273
+ }
5227
5274
  const surchargeFee = Math.max(cardTotal - baseAmount, 0);
5228
5275
  const isBankView = activetab === "ach";
5229
5276
  const discountNum = Number((props == null ? void 0 : props.discount) || 0);
5230
5277
  const taxNum = Number((props == null ? void 0 : props.tax) || 0);
5231
5278
  const leftTotal = isBankView ? Number(bankAmount || 0) : cardTotal;
5279
+ const orderAmount = isSurchargeProgram ? baseAmount : Number((props == null ? void 0 : props.amount) || 0);
5232
5280
  const fmtNum = (n) => Number(n).toLocaleString("en-US", { minimumFractionDigits: 2, maximumFractionDigits: 2 });
5233
5281
  const hasFee = surchargeFee > 0 && !!(props == null ? void 0 : props.pass_fee);
5234
- const isSurchargeProgram = Number(paymentData == null ? void 0 : paymentData.surchargeProgram) === 1;
5235
5282
  const showSurchargeLine = isSurchargeProgram && !isBankView && hasFee;
5236
5283
  const summarySubtotal = isSurchargeProgram || isBankView ? baseAmount : cardTotal;
5237
5284
  const savedMethods = [...cardList || [], ...bankList || []];
@@ -5354,7 +5401,7 @@ function GetPaymentPage(props) {
5354
5401
  } }) }),
5355
5402
  success && /* @__PURE__ */ jsx18(SuccessMsz, { onClose: handleClose, tranId, isDebitAdjusted }),
5356
5403
  !error && !errorIframe && !success && /* @__PURE__ */ jsxs9(Fragment9, { children: [
5357
- (loading || loading2 || loadingIframe) && /* @__PURE__ */ jsx18(Loader_default, { loading: loading || loading2 || loadingIframe, loaderText }),
5404
+ (loading || loading2 || loadingIframe || surchargeLookupLoading) && /* @__PURE__ */ jsx18(Loader_default, { loading: loading || loading2 || loadingIframe || surchargeLookupLoading, loaderText }),
5358
5405
  /* @__PURE__ */ jsxs9("div", { className: "fps-modal", children: [
5359
5406
  LeftSummary,
5360
5407
  /* @__PURE__ */ jsxs9("section", { className: "fps-content", children: [
@@ -5392,7 +5439,7 @@ function GetPaymentPage(props) {
5392
5439
  FractalFooter,
5393
5440
  {
5394
5441
  authText: AuthText,
5395
- disabled: loading2 || !(selectedCard == null ? void 0 : selectedCard.id),
5442
+ disabled: loading2 || !(selectedCard == null ? void 0 : selectedCard.id) || surchargeLookupLoading,
5396
5443
  onPay: handlechargeCustomer,
5397
5444
  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}`
5398
5445
  }