@superlogic/spree-pay 0.1.21 → 0.1.22
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/build/index.cjs +98 -52
- package/build/index.d.cts +4 -4
- package/build/index.d.ts +4 -4
- package/build/index.js +98 -52
- package/package.json +1 -1
package/build/index.cjs
CHANGED
|
@@ -62,7 +62,7 @@ var PaymentError = class extends Error {
|
|
|
62
62
|
var PaymentType = /* @__PURE__ */ ((PaymentType2) => {
|
|
63
63
|
PaymentType2["CREDIT_CARD"] = "CREDIT_CARD";
|
|
64
64
|
PaymentType2["CRYPTO"] = "CRYPTO";
|
|
65
|
-
PaymentType2["
|
|
65
|
+
PaymentType2["CREDIT_CARD_SPLIT"] = "SPLIT";
|
|
66
66
|
PaymentType2["POINTS"] = "POINTS";
|
|
67
67
|
return PaymentType2;
|
|
68
68
|
})(PaymentType || {});
|
|
@@ -325,7 +325,8 @@ var CheckoutButton = ({ isLoggedIn }) => {
|
|
|
325
325
|
const { pointsTitle, pointsConversionRatio } = staticConfig;
|
|
326
326
|
const { selectedPaymentMethod, isInternalProcessing } = useSpreePaymentMethod();
|
|
327
327
|
const { splitAmount, type, method } = selectedPaymentMethod;
|
|
328
|
-
const
|
|
328
|
+
const usdAmount = getSplitAmount(amount ?? 0, splitAmount ?? 0, pointsConversionRatio);
|
|
329
|
+
const isDisabled = !amount || !method && usdAmount !== 0 || !!isProcessing || isInternalProcessing || !isLoggedIn;
|
|
329
330
|
const isCC = type === "CREDIT_CARD" /* CREDIT_CARD */;
|
|
330
331
|
const isCrypto = type === "CRYPTO" /* CRYPTO */;
|
|
331
332
|
const getCheckoutContent = () => {
|
|
@@ -333,7 +334,6 @@ var CheckoutButton = ({ isLoggedIn }) => {
|
|
|
333
334
|
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Spinner, { className: "inline", size: "sm" });
|
|
334
335
|
}
|
|
335
336
|
if (isCC && amount) {
|
|
336
|
-
const usdAmount = getSplitAmount(amount, splitAmount ?? 0, pointsConversionRatio);
|
|
337
337
|
if (splitAmount && usdAmount) {
|
|
338
338
|
return `Pay ${formatUSD(usdAmount + getTransactionFee(usdAmount, transactionFeePercentage))} + ${formatPoints(splitAmount, pointsTitle)}`;
|
|
339
339
|
}
|
|
@@ -394,7 +394,7 @@ var SpreeLegal = () => {
|
|
|
394
394
|
// src/components/CreditCardTab/CreditCardTab.tsx
|
|
395
395
|
var import_react13 = require("react");
|
|
396
396
|
|
|
397
|
-
// src/hooks/useCardPayment.ts
|
|
397
|
+
// src/hooks/payments/useCardPayment.ts
|
|
398
398
|
var import_nice_modal_react2 = __toESM(require("@ebay/nice-modal-react"), 1);
|
|
399
399
|
|
|
400
400
|
// src/modals/Iframe3ds.tsx
|
|
@@ -629,17 +629,8 @@ var registerApi = (config) => {
|
|
|
629
629
|
|
|
630
630
|
// src/services/slapi.ts
|
|
631
631
|
var SlapiPaymentService = {
|
|
632
|
-
createPayment: (
|
|
633
|
-
|
|
634
|
-
let reqParams;
|
|
635
|
-
if (type === "CRYPTO" /* CRYPTO */) {
|
|
636
|
-
reqParams = { type, hash, crypto: params.crypto };
|
|
637
|
-
} else if (type === "CREDIT_CARD" /* CREDIT_CARD */ && params.points && params.points.amount > 0) {
|
|
638
|
-
reqParams = { type: "SPLIT" /* SPLIT */, hash, card: params.card, points: params.points };
|
|
639
|
-
} else {
|
|
640
|
-
reqParams = { type, hash, card: params.card };
|
|
641
|
-
}
|
|
642
|
-
return slapiApi.post("/v1/payments", { ...reqParams, capture, metadata }).then((data) => ({ data }));
|
|
632
|
+
createPayment: ({ capture = false, ...rest }) => {
|
|
633
|
+
return slapiApi.post("/v1/payments", { ...rest, capture }).then((data) => ({ data }));
|
|
643
634
|
},
|
|
644
635
|
baseVerify: ({ id, txHash }) => {
|
|
645
636
|
return slapiApi.post(`/v1/base-transactions/transactions/${id}/verify`, { txHash });
|
|
@@ -658,7 +649,7 @@ var SlapiPaymentService = {
|
|
|
658
649
|
}
|
|
659
650
|
};
|
|
660
651
|
|
|
661
|
-
// src/hooks/useCardPayment.ts
|
|
652
|
+
// src/hooks/payments/useCardPayment.ts
|
|
662
653
|
var useCardPayment = () => {
|
|
663
654
|
const { selectedPaymentMethod } = useSpreePaymentMethod();
|
|
664
655
|
const { env } = useSpreePayEnv();
|
|
@@ -707,20 +698,6 @@ var useCardPayment = () => {
|
|
|
707
698
|
return { cardPayment };
|
|
708
699
|
};
|
|
709
700
|
|
|
710
|
-
// src/hooks/useCards.ts
|
|
711
|
-
var import_swr2 = __toESM(require("swr"), 1);
|
|
712
|
-
var useCards = () => {
|
|
713
|
-
const { data, isLoading, mutate } = (0, import_swr2.default)(`/v1/payments/cards`);
|
|
714
|
-
return {
|
|
715
|
-
cards: data?.data.filter((c) => c.active) || [],
|
|
716
|
-
cardsIsLoading: isLoading,
|
|
717
|
-
mutateCards: mutate
|
|
718
|
-
};
|
|
719
|
-
};
|
|
720
|
-
|
|
721
|
-
// src/hooks/useSplitCardPayments.ts
|
|
722
|
-
var import_nice_modal_react3 = __toESM(require("@ebay/nice-modal-react"), 1);
|
|
723
|
-
|
|
724
701
|
// src/services/AirWalletService.ts
|
|
725
702
|
var import_airkit = require("@mocanetwork/airkit");
|
|
726
703
|
var import_viem = require("viem");
|
|
@@ -812,7 +789,8 @@ async function handleSendErc20(params) {
|
|
|
812
789
|
}
|
|
813
790
|
}
|
|
814
791
|
|
|
815
|
-
// src/hooks/
|
|
792
|
+
// src/hooks/payments/utils.ts
|
|
793
|
+
var import_nice_modal_react3 = __toESM(require("@ebay/nice-modal-react"), 1);
|
|
816
794
|
var REFRESH_INTERVAL = 3 * 1e3;
|
|
817
795
|
var MAX_RETRIES = 10;
|
|
818
796
|
async function longPollPoints(paymentId) {
|
|
@@ -853,6 +831,51 @@ async function longPollCardStatus(paymentId) {
|
|
|
853
831
|
}
|
|
854
832
|
throw new Error("Payment polling timed out");
|
|
855
833
|
}
|
|
834
|
+
|
|
835
|
+
// src/hooks/payments/usePointsPayment.ts
|
|
836
|
+
var usePointsPayment = () => {
|
|
837
|
+
const { selectedPaymentMethod } = useSpreePaymentMethod();
|
|
838
|
+
const { spreePayConfig } = useSpreePayConfig();
|
|
839
|
+
const pointsPayment = async (params) => {
|
|
840
|
+
if (selectedPaymentMethod.type !== "CREDIT_CARD" /* CREDIT_CARD */) {
|
|
841
|
+
throw new Error("Unsupported payment method");
|
|
842
|
+
}
|
|
843
|
+
const { hash, capture, metadata } = params;
|
|
844
|
+
const { data: paymentResData } = await SlapiPaymentService.createPayment({
|
|
845
|
+
hash,
|
|
846
|
+
capture,
|
|
847
|
+
metadata,
|
|
848
|
+
type: "POINTS" /* POINTS */
|
|
849
|
+
});
|
|
850
|
+
const wallet = peekAirWallet();
|
|
851
|
+
if (!wallet || !spreePayConfig?.pointsChain) {
|
|
852
|
+
throw new Error("AirWallet not found");
|
|
853
|
+
}
|
|
854
|
+
const transaction = await handleSendErc20({
|
|
855
|
+
amount: params.points,
|
|
856
|
+
token: spreePayConfig.pointsChain.pointsCoin,
|
|
857
|
+
recipient: spreePayConfig.pointsChain.recipientAddress
|
|
858
|
+
});
|
|
859
|
+
if (!transaction) {
|
|
860
|
+
throw new Error("Points transaction failed");
|
|
861
|
+
}
|
|
862
|
+
await SlapiPaymentService.validatePoints({
|
|
863
|
+
paymentId: paymentResData.id,
|
|
864
|
+
txHash: transaction.txHash
|
|
865
|
+
});
|
|
866
|
+
const pointsStatus = await longPollPoints(paymentResData.id);
|
|
867
|
+
return {
|
|
868
|
+
status: pointsStatus,
|
|
869
|
+
txId: paymentResData.txId,
|
|
870
|
+
txHash: transaction.txHash,
|
|
871
|
+
paymentId: paymentResData.id,
|
|
872
|
+
paymentType: "POINTS" /* POINTS */
|
|
873
|
+
};
|
|
874
|
+
};
|
|
875
|
+
return { pointsPayment };
|
|
876
|
+
};
|
|
877
|
+
|
|
878
|
+
// src/hooks/payments/useSplitCardPayments.ts
|
|
856
879
|
var useSplitCardPayments = () => {
|
|
857
880
|
const { selectedPaymentMethod } = useSpreePaymentMethod();
|
|
858
881
|
const { env } = useSpreePayEnv();
|
|
@@ -877,7 +900,7 @@ var useSplitCardPayments = () => {
|
|
|
877
900
|
hash,
|
|
878
901
|
capture,
|
|
879
902
|
metadata,
|
|
880
|
-
type: "
|
|
903
|
+
type: "SPLIT" /* CREDIT_CARD_SPLIT */,
|
|
881
904
|
card: {
|
|
882
905
|
cardId,
|
|
883
906
|
transactionFee,
|
|
@@ -906,7 +929,7 @@ var useSplitCardPayments = () => {
|
|
|
906
929
|
});
|
|
907
930
|
const pointsStatus = await longPollPoints(paymentResData.id);
|
|
908
931
|
return {
|
|
909
|
-
paymentType: "SPLIT" /*
|
|
932
|
+
paymentType: "SPLIT" /* CREDIT_CARD_SPLIT */,
|
|
910
933
|
status: pointsStatus,
|
|
911
934
|
paymentId: paymentResData.id,
|
|
912
935
|
txId: paymentResData.txId,
|
|
@@ -916,6 +939,17 @@ var useSplitCardPayments = () => {
|
|
|
916
939
|
return { splitPayment };
|
|
917
940
|
};
|
|
918
941
|
|
|
942
|
+
// src/hooks/useCards.ts
|
|
943
|
+
var import_swr2 = __toESM(require("swr"), 1);
|
|
944
|
+
var useCards = () => {
|
|
945
|
+
const { data, isLoading, mutate } = (0, import_swr2.default)(`/v1/payments/cards`);
|
|
946
|
+
return {
|
|
947
|
+
cards: data?.data.filter((c) => c.active) || [],
|
|
948
|
+
cardsIsLoading: isLoading,
|
|
949
|
+
mutateCards: mutate
|
|
950
|
+
};
|
|
951
|
+
};
|
|
952
|
+
|
|
919
953
|
// src/components/CreditCardTab/CreditCard/CreditCard.tsx
|
|
920
954
|
var import_react6 = require("react");
|
|
921
955
|
var import_react_stripe_js2 = require("@stripe/react-stripe-js");
|
|
@@ -2295,7 +2329,7 @@ var PointsSelector = (props) => {
|
|
|
2295
2329
|
const max = Math.min((appProps.amount ?? 0) * staticConfig.pointsConversionRatio, balance?.availablePoints ?? 0);
|
|
2296
2330
|
const step = 10;
|
|
2297
2331
|
const [splitTokens, setSplitTokens] = (0, import_react10.useState)(0);
|
|
2298
|
-
const
|
|
2332
|
+
const usdAmount = getSplitAmount(appProps.amount ?? 0, splitTokens, staticConfig.pointsConversionRatio);
|
|
2299
2333
|
const handleCommit = (value) => {
|
|
2300
2334
|
setSelectedPaymentMethod({ ...selectedPaymentMethod, splitAmount: value });
|
|
2301
2335
|
};
|
|
@@ -2323,7 +2357,7 @@ var PointsSelector = (props) => {
|
|
|
2323
2357
|
] }),
|
|
2324
2358
|
isSelected && /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { className: "px-3 pt-6 pb-2 md:px-4", children: /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)("div", { className: "flex justify-between gap-3", children: [
|
|
2325
2359
|
/* @__PURE__ */ (0, import_jsx_runtime24.jsxs)("div", { className: "flex max-w-[100px] flex-col gap-1", children: [
|
|
2326
|
-
/* @__PURE__ */ (0, import_jsx_runtime24.jsx)(Input, { readOnly: true, value: splitTokens, className: "bg-white text-center font-medium" }),
|
|
2360
|
+
/* @__PURE__ */ (0, import_jsx_runtime24.jsx)(Input, { readOnly: true, value: Math.round(splitTokens), className: "bg-white text-center font-medium" }),
|
|
2327
2361
|
/* @__PURE__ */ (0, import_jsx_runtime24.jsx)("p", { className: "text-left text-xs leading-[20px] text-black/45", children: "Points" })
|
|
2328
2362
|
] }),
|
|
2329
2363
|
/* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { className: "flex w-full items-center pb-6", children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
|
|
@@ -2342,7 +2376,7 @@ var PointsSelector = (props) => {
|
|
|
2342
2376
|
Input,
|
|
2343
2377
|
{
|
|
2344
2378
|
readOnly: true,
|
|
2345
|
-
value: formatUSD(
|
|
2379
|
+
value: formatUSD(usdAmount + getTransactionFee(usdAmount, appProps.transactionFeePercentage)),
|
|
2346
2380
|
className: "bg-white text-center font-medium"
|
|
2347
2381
|
}
|
|
2348
2382
|
),
|
|
@@ -2432,26 +2466,29 @@ var Points = () => {
|
|
|
2432
2466
|
var import_jsx_runtime27 = require("react/jsx-runtime");
|
|
2433
2467
|
var CreditCardTab = () => {
|
|
2434
2468
|
const { selectedPaymentMethod, setSelectedPaymentMethod } = useSpreePaymentMethod();
|
|
2469
|
+
const { staticConfig, appProps } = useStaticConfig();
|
|
2435
2470
|
const { register } = useSpreePayRegister();
|
|
2436
2471
|
const { mutateCards } = useCards();
|
|
2437
2472
|
const { cardPayment } = useCardPayment();
|
|
2438
2473
|
const { splitPayment } = useSplitCardPayments();
|
|
2474
|
+
const { pointsPayment } = usePointsPayment();
|
|
2439
2475
|
const handlePay = (0, import_react13.useCallback)(
|
|
2440
2476
|
async (data) => {
|
|
2441
2477
|
try {
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
}
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2478
|
+
let res = null;
|
|
2479
|
+
const pointsAmount = selectedPaymentMethod.splitAmount ?? 0;
|
|
2480
|
+
const usdAmount = getSplitAmount(appProps.amount ?? 0, pointsAmount, staticConfig.pointsConversionRatio);
|
|
2481
|
+
if (usdAmount && pointsAmount) {
|
|
2482
|
+
res = await splitPayment({ ...data, points: pointsAmount });
|
|
2483
|
+
} else if (!usdAmount && pointsAmount) {
|
|
2484
|
+
res = await pointsPayment({ ...data, points: pointsAmount });
|
|
2485
|
+
} else {
|
|
2486
|
+
res = await cardPayment(data);
|
|
2487
|
+
}
|
|
2488
|
+
if (["AUTHORIZED" /* AUTHORIZED */, "CAPTURED" /* CAPTURED */].includes(res.status)) {
|
|
2489
|
+
return Promise.resolve(res);
|
|
2453
2490
|
}
|
|
2454
|
-
return Promise.reject(new PaymentError("
|
|
2491
|
+
return Promise.reject(new PaymentError("Card payment failed", res.status));
|
|
2455
2492
|
} catch (_) {
|
|
2456
2493
|
return Promise.reject(new PaymentError("Payment failed", "FAILED" /* FAILED */));
|
|
2457
2494
|
} finally {
|
|
@@ -2459,7 +2496,16 @@ var CreditCardTab = () => {
|
|
|
2459
2496
|
mutateCards();
|
|
2460
2497
|
}
|
|
2461
2498
|
},
|
|
2462
|
-
[
|
|
2499
|
+
[
|
|
2500
|
+
mutateCards,
|
|
2501
|
+
selectedPaymentMethod,
|
|
2502
|
+
pointsPayment,
|
|
2503
|
+
appProps.amount,
|
|
2504
|
+
setSelectedPaymentMethod,
|
|
2505
|
+
cardPayment,
|
|
2506
|
+
splitPayment,
|
|
2507
|
+
staticConfig.pointsConversionRatio
|
|
2508
|
+
]
|
|
2463
2509
|
);
|
|
2464
2510
|
(0, import_react13.useEffect)(() => {
|
|
2465
2511
|
register(handlePay);
|
|
@@ -2534,7 +2580,7 @@ async function waitForTransactionReceipt(config, parameters) {
|
|
|
2534
2580
|
// ../../node_modules/@wagmi/core/dist/esm/exports/index.js
|
|
2535
2581
|
var import_viem3 = require("viem");
|
|
2536
2582
|
|
|
2537
|
-
// src/hooks/useCryptoPayment.ts
|
|
2583
|
+
// src/hooks/payments/useCryptoPayment.ts
|
|
2538
2584
|
var import_viem4 = require("viem");
|
|
2539
2585
|
var import_wagmi = require("wagmi");
|
|
2540
2586
|
|
|
@@ -2575,7 +2621,7 @@ var BASE_TOKENS = [
|
|
|
2575
2621
|
}
|
|
2576
2622
|
];
|
|
2577
2623
|
|
|
2578
|
-
// src/hooks/useCryptoPayment.ts
|
|
2624
|
+
// src/hooks/payments/useCryptoPayment.ts
|
|
2579
2625
|
var MAX_UINT256 = BigInt(2) ** BigInt(256) - BigInt(1);
|
|
2580
2626
|
var ONE_INCH_AGGREGATION_ROUTER_V6 = "0x111111125421ca6dc452d289314280a0f8842a65";
|
|
2581
2627
|
var useCryptoPayment = () => {
|
|
@@ -2625,7 +2671,7 @@ var useCryptoPayment = () => {
|
|
|
2625
2671
|
token: TOKEN,
|
|
2626
2672
|
publicKey: walletClient.account.address,
|
|
2627
2673
|
slippageType: "fixed",
|
|
2628
|
-
slippageBps: 0.5 * 100
|
|
2674
|
+
slippageBps: Math.round(0.5 * 100)
|
|
2629
2675
|
}
|
|
2630
2676
|
});
|
|
2631
2677
|
const parsedTX = JSON.parse(paymentRes.data.encodedTx);
|
package/build/index.d.cts
CHANGED
|
@@ -50,7 +50,7 @@ type Card = {
|
|
|
50
50
|
active: boolean;
|
|
51
51
|
addressZipCheck: string;
|
|
52
52
|
cardId: string;
|
|
53
|
-
createdAt: Date;
|
|
53
|
+
createdAt: string | Date;
|
|
54
54
|
default: boolean;
|
|
55
55
|
expireMonth: string;
|
|
56
56
|
expireYear: string;
|
|
@@ -62,7 +62,7 @@ type Card = {
|
|
|
62
62
|
name: string;
|
|
63
63
|
paymentProvider: string;
|
|
64
64
|
schema: string | undefined;
|
|
65
|
-
updatedAt: Date;
|
|
65
|
+
updatedAt: string | Date;
|
|
66
66
|
userId: string;
|
|
67
67
|
zipCode: string;
|
|
68
68
|
};
|
|
@@ -84,10 +84,10 @@ type SelectedPaymentMethod = CardPaymentMethod | CryptoPaymentMethod;
|
|
|
84
84
|
declare enum PaymentType {
|
|
85
85
|
CREDIT_CARD = "CREDIT_CARD",
|
|
86
86
|
CRYPTO = "CRYPTO",
|
|
87
|
-
|
|
87
|
+
CREDIT_CARD_SPLIT = "SPLIT",
|
|
88
88
|
POINTS = "POINTS"
|
|
89
89
|
}
|
|
90
|
-
declare
|
|
90
|
+
declare enum SlapiPaymentStatus {
|
|
91
91
|
NOT_INITIALIZED = "NOT_INITIALIZED",// back-end only
|
|
92
92
|
PENDING = "PENDING",// back-end only
|
|
93
93
|
AUTHORIZED = "AUTHORIZED",// success
|
package/build/index.d.ts
CHANGED
|
@@ -50,7 +50,7 @@ type Card = {
|
|
|
50
50
|
active: boolean;
|
|
51
51
|
addressZipCheck: string;
|
|
52
52
|
cardId: string;
|
|
53
|
-
createdAt: Date;
|
|
53
|
+
createdAt: string | Date;
|
|
54
54
|
default: boolean;
|
|
55
55
|
expireMonth: string;
|
|
56
56
|
expireYear: string;
|
|
@@ -62,7 +62,7 @@ type Card = {
|
|
|
62
62
|
name: string;
|
|
63
63
|
paymentProvider: string;
|
|
64
64
|
schema: string | undefined;
|
|
65
|
-
updatedAt: Date;
|
|
65
|
+
updatedAt: string | Date;
|
|
66
66
|
userId: string;
|
|
67
67
|
zipCode: string;
|
|
68
68
|
};
|
|
@@ -84,10 +84,10 @@ type SelectedPaymentMethod = CardPaymentMethod | CryptoPaymentMethod;
|
|
|
84
84
|
declare enum PaymentType {
|
|
85
85
|
CREDIT_CARD = "CREDIT_CARD",
|
|
86
86
|
CRYPTO = "CRYPTO",
|
|
87
|
-
|
|
87
|
+
CREDIT_CARD_SPLIT = "SPLIT",
|
|
88
88
|
POINTS = "POINTS"
|
|
89
89
|
}
|
|
90
|
-
declare
|
|
90
|
+
declare enum SlapiPaymentStatus {
|
|
91
91
|
NOT_INITIALIZED = "NOT_INITIALIZED",// back-end only
|
|
92
92
|
PENDING = "PENDING",// back-end only
|
|
93
93
|
AUTHORIZED = "AUTHORIZED",// success
|
package/build/index.js
CHANGED
|
@@ -22,7 +22,7 @@ var PaymentError = class extends Error {
|
|
|
22
22
|
var PaymentType = /* @__PURE__ */ ((PaymentType2) => {
|
|
23
23
|
PaymentType2["CREDIT_CARD"] = "CREDIT_CARD";
|
|
24
24
|
PaymentType2["CRYPTO"] = "CRYPTO";
|
|
25
|
-
PaymentType2["
|
|
25
|
+
PaymentType2["CREDIT_CARD_SPLIT"] = "SPLIT";
|
|
26
26
|
PaymentType2["POINTS"] = "POINTS";
|
|
27
27
|
return PaymentType2;
|
|
28
28
|
})(PaymentType || {});
|
|
@@ -285,7 +285,8 @@ var CheckoutButton = ({ isLoggedIn }) => {
|
|
|
285
285
|
const { pointsTitle, pointsConversionRatio } = staticConfig;
|
|
286
286
|
const { selectedPaymentMethod, isInternalProcessing } = useSpreePaymentMethod();
|
|
287
287
|
const { splitAmount, type, method } = selectedPaymentMethod;
|
|
288
|
-
const
|
|
288
|
+
const usdAmount = getSplitAmount(amount ?? 0, splitAmount ?? 0, pointsConversionRatio);
|
|
289
|
+
const isDisabled = !amount || !method && usdAmount !== 0 || !!isProcessing || isInternalProcessing || !isLoggedIn;
|
|
289
290
|
const isCC = type === "CREDIT_CARD" /* CREDIT_CARD */;
|
|
290
291
|
const isCrypto = type === "CRYPTO" /* CRYPTO */;
|
|
291
292
|
const getCheckoutContent = () => {
|
|
@@ -293,7 +294,6 @@ var CheckoutButton = ({ isLoggedIn }) => {
|
|
|
293
294
|
return /* @__PURE__ */ jsx4(Spinner, { className: "inline", size: "sm" });
|
|
294
295
|
}
|
|
295
296
|
if (isCC && amount) {
|
|
296
|
-
const usdAmount = getSplitAmount(amount, splitAmount ?? 0, pointsConversionRatio);
|
|
297
297
|
if (splitAmount && usdAmount) {
|
|
298
298
|
return `Pay ${formatUSD(usdAmount + getTransactionFee(usdAmount, transactionFeePercentage))} + ${formatPoints(splitAmount, pointsTitle)}`;
|
|
299
299
|
}
|
|
@@ -354,7 +354,7 @@ var SpreeLegal = () => {
|
|
|
354
354
|
// src/components/CreditCardTab/CreditCardTab.tsx
|
|
355
355
|
import { useCallback as useCallback5, useEffect as useEffect7 } from "react";
|
|
356
356
|
|
|
357
|
-
// src/hooks/useCardPayment.ts
|
|
357
|
+
// src/hooks/payments/useCardPayment.ts
|
|
358
358
|
import NiceModal2 from "@ebay/nice-modal-react";
|
|
359
359
|
|
|
360
360
|
// src/modals/Iframe3ds.tsx
|
|
@@ -589,17 +589,8 @@ var registerApi = (config) => {
|
|
|
589
589
|
|
|
590
590
|
// src/services/slapi.ts
|
|
591
591
|
var SlapiPaymentService = {
|
|
592
|
-
createPayment: (
|
|
593
|
-
|
|
594
|
-
let reqParams;
|
|
595
|
-
if (type === "CRYPTO" /* CRYPTO */) {
|
|
596
|
-
reqParams = { type, hash, crypto: params.crypto };
|
|
597
|
-
} else if (type === "CREDIT_CARD" /* CREDIT_CARD */ && params.points && params.points.amount > 0) {
|
|
598
|
-
reqParams = { type: "SPLIT" /* SPLIT */, hash, card: params.card, points: params.points };
|
|
599
|
-
} else {
|
|
600
|
-
reqParams = { type, hash, card: params.card };
|
|
601
|
-
}
|
|
602
|
-
return slapiApi.post("/v1/payments", { ...reqParams, capture, metadata }).then((data) => ({ data }));
|
|
592
|
+
createPayment: ({ capture = false, ...rest }) => {
|
|
593
|
+
return slapiApi.post("/v1/payments", { ...rest, capture }).then((data) => ({ data }));
|
|
603
594
|
},
|
|
604
595
|
baseVerify: ({ id, txHash }) => {
|
|
605
596
|
return slapiApi.post(`/v1/base-transactions/transactions/${id}/verify`, { txHash });
|
|
@@ -618,7 +609,7 @@ var SlapiPaymentService = {
|
|
|
618
609
|
}
|
|
619
610
|
};
|
|
620
611
|
|
|
621
|
-
// src/hooks/useCardPayment.ts
|
|
612
|
+
// src/hooks/payments/useCardPayment.ts
|
|
622
613
|
var useCardPayment = () => {
|
|
623
614
|
const { selectedPaymentMethod } = useSpreePaymentMethod();
|
|
624
615
|
const { env } = useSpreePayEnv();
|
|
@@ -667,20 +658,6 @@ var useCardPayment = () => {
|
|
|
667
658
|
return { cardPayment };
|
|
668
659
|
};
|
|
669
660
|
|
|
670
|
-
// src/hooks/useCards.ts
|
|
671
|
-
import useSWR2 from "swr";
|
|
672
|
-
var useCards = () => {
|
|
673
|
-
const { data, isLoading, mutate } = useSWR2(`/v1/payments/cards`);
|
|
674
|
-
return {
|
|
675
|
-
cards: data?.data.filter((c) => c.active) || [],
|
|
676
|
-
cardsIsLoading: isLoading,
|
|
677
|
-
mutateCards: mutate
|
|
678
|
-
};
|
|
679
|
-
};
|
|
680
|
-
|
|
681
|
-
// src/hooks/useSplitCardPayments.ts
|
|
682
|
-
import NiceModal3 from "@ebay/nice-modal-react";
|
|
683
|
-
|
|
684
661
|
// src/services/AirWalletService.ts
|
|
685
662
|
import { AirService, BUILD_ENV } from "@mocanetwork/airkit";
|
|
686
663
|
import { createWalletClient, custom, encodeFunctionData, erc20Abi, parseUnits } from "viem";
|
|
@@ -772,7 +749,8 @@ async function handleSendErc20(params) {
|
|
|
772
749
|
}
|
|
773
750
|
}
|
|
774
751
|
|
|
775
|
-
// src/hooks/
|
|
752
|
+
// src/hooks/payments/utils.ts
|
|
753
|
+
import NiceModal3 from "@ebay/nice-modal-react";
|
|
776
754
|
var REFRESH_INTERVAL = 3 * 1e3;
|
|
777
755
|
var MAX_RETRIES = 10;
|
|
778
756
|
async function longPollPoints(paymentId) {
|
|
@@ -813,6 +791,51 @@ async function longPollCardStatus(paymentId) {
|
|
|
813
791
|
}
|
|
814
792
|
throw new Error("Payment polling timed out");
|
|
815
793
|
}
|
|
794
|
+
|
|
795
|
+
// src/hooks/payments/usePointsPayment.ts
|
|
796
|
+
var usePointsPayment = () => {
|
|
797
|
+
const { selectedPaymentMethod } = useSpreePaymentMethod();
|
|
798
|
+
const { spreePayConfig } = useSpreePayConfig();
|
|
799
|
+
const pointsPayment = async (params) => {
|
|
800
|
+
if (selectedPaymentMethod.type !== "CREDIT_CARD" /* CREDIT_CARD */) {
|
|
801
|
+
throw new Error("Unsupported payment method");
|
|
802
|
+
}
|
|
803
|
+
const { hash, capture, metadata } = params;
|
|
804
|
+
const { data: paymentResData } = await SlapiPaymentService.createPayment({
|
|
805
|
+
hash,
|
|
806
|
+
capture,
|
|
807
|
+
metadata,
|
|
808
|
+
type: "POINTS" /* POINTS */
|
|
809
|
+
});
|
|
810
|
+
const wallet = peekAirWallet();
|
|
811
|
+
if (!wallet || !spreePayConfig?.pointsChain) {
|
|
812
|
+
throw new Error("AirWallet not found");
|
|
813
|
+
}
|
|
814
|
+
const transaction = await handleSendErc20({
|
|
815
|
+
amount: params.points,
|
|
816
|
+
token: spreePayConfig.pointsChain.pointsCoin,
|
|
817
|
+
recipient: spreePayConfig.pointsChain.recipientAddress
|
|
818
|
+
});
|
|
819
|
+
if (!transaction) {
|
|
820
|
+
throw new Error("Points transaction failed");
|
|
821
|
+
}
|
|
822
|
+
await SlapiPaymentService.validatePoints({
|
|
823
|
+
paymentId: paymentResData.id,
|
|
824
|
+
txHash: transaction.txHash
|
|
825
|
+
});
|
|
826
|
+
const pointsStatus = await longPollPoints(paymentResData.id);
|
|
827
|
+
return {
|
|
828
|
+
status: pointsStatus,
|
|
829
|
+
txId: paymentResData.txId,
|
|
830
|
+
txHash: transaction.txHash,
|
|
831
|
+
paymentId: paymentResData.id,
|
|
832
|
+
paymentType: "POINTS" /* POINTS */
|
|
833
|
+
};
|
|
834
|
+
};
|
|
835
|
+
return { pointsPayment };
|
|
836
|
+
};
|
|
837
|
+
|
|
838
|
+
// src/hooks/payments/useSplitCardPayments.ts
|
|
816
839
|
var useSplitCardPayments = () => {
|
|
817
840
|
const { selectedPaymentMethod } = useSpreePaymentMethod();
|
|
818
841
|
const { env } = useSpreePayEnv();
|
|
@@ -837,7 +860,7 @@ var useSplitCardPayments = () => {
|
|
|
837
860
|
hash,
|
|
838
861
|
capture,
|
|
839
862
|
metadata,
|
|
840
|
-
type: "
|
|
863
|
+
type: "SPLIT" /* CREDIT_CARD_SPLIT */,
|
|
841
864
|
card: {
|
|
842
865
|
cardId,
|
|
843
866
|
transactionFee,
|
|
@@ -866,7 +889,7 @@ var useSplitCardPayments = () => {
|
|
|
866
889
|
});
|
|
867
890
|
const pointsStatus = await longPollPoints(paymentResData.id);
|
|
868
891
|
return {
|
|
869
|
-
paymentType: "SPLIT" /*
|
|
892
|
+
paymentType: "SPLIT" /* CREDIT_CARD_SPLIT */,
|
|
870
893
|
status: pointsStatus,
|
|
871
894
|
paymentId: paymentResData.id,
|
|
872
895
|
txId: paymentResData.txId,
|
|
@@ -876,6 +899,17 @@ var useSplitCardPayments = () => {
|
|
|
876
899
|
return { splitPayment };
|
|
877
900
|
};
|
|
878
901
|
|
|
902
|
+
// src/hooks/useCards.ts
|
|
903
|
+
import useSWR2 from "swr";
|
|
904
|
+
var useCards = () => {
|
|
905
|
+
const { data, isLoading, mutate } = useSWR2(`/v1/payments/cards`);
|
|
906
|
+
return {
|
|
907
|
+
cards: data?.data.filter((c) => c.active) || [],
|
|
908
|
+
cardsIsLoading: isLoading,
|
|
909
|
+
mutateCards: mutate
|
|
910
|
+
};
|
|
911
|
+
};
|
|
912
|
+
|
|
879
913
|
// src/components/CreditCardTab/CreditCard/CreditCard.tsx
|
|
880
914
|
import { useMemo as useMemo2, useState as useState4 } from "react";
|
|
881
915
|
import { Elements } from "@stripe/react-stripe-js";
|
|
@@ -2255,7 +2289,7 @@ var PointsSelector = (props) => {
|
|
|
2255
2289
|
const max = Math.min((appProps.amount ?? 0) * staticConfig.pointsConversionRatio, balance?.availablePoints ?? 0);
|
|
2256
2290
|
const step = 10;
|
|
2257
2291
|
const [splitTokens, setSplitTokens] = useState8(0);
|
|
2258
|
-
const
|
|
2292
|
+
const usdAmount = getSplitAmount(appProps.amount ?? 0, splitTokens, staticConfig.pointsConversionRatio);
|
|
2259
2293
|
const handleCommit = (value) => {
|
|
2260
2294
|
setSelectedPaymentMethod({ ...selectedPaymentMethod, splitAmount: value });
|
|
2261
2295
|
};
|
|
@@ -2283,7 +2317,7 @@ var PointsSelector = (props) => {
|
|
|
2283
2317
|
] }),
|
|
2284
2318
|
isSelected && /* @__PURE__ */ jsx24("div", { className: "px-3 pt-6 pb-2 md:px-4", children: /* @__PURE__ */ jsxs12("div", { className: "flex justify-between gap-3", children: [
|
|
2285
2319
|
/* @__PURE__ */ jsxs12("div", { className: "flex max-w-[100px] flex-col gap-1", children: [
|
|
2286
|
-
/* @__PURE__ */ jsx24(Input, { readOnly: true, value: splitTokens, className: "bg-white text-center font-medium" }),
|
|
2320
|
+
/* @__PURE__ */ jsx24(Input, { readOnly: true, value: Math.round(splitTokens), className: "bg-white text-center font-medium" }),
|
|
2287
2321
|
/* @__PURE__ */ jsx24("p", { className: "text-left text-xs leading-[20px] text-black/45", children: "Points" })
|
|
2288
2322
|
] }),
|
|
2289
2323
|
/* @__PURE__ */ jsx24("div", { className: "flex w-full items-center pb-6", children: /* @__PURE__ */ jsx24(
|
|
@@ -2302,7 +2336,7 @@ var PointsSelector = (props) => {
|
|
|
2302
2336
|
Input,
|
|
2303
2337
|
{
|
|
2304
2338
|
readOnly: true,
|
|
2305
|
-
value: formatUSD(
|
|
2339
|
+
value: formatUSD(usdAmount + getTransactionFee(usdAmount, appProps.transactionFeePercentage)),
|
|
2306
2340
|
className: "bg-white text-center font-medium"
|
|
2307
2341
|
}
|
|
2308
2342
|
),
|
|
@@ -2392,26 +2426,29 @@ var Points = () => {
|
|
|
2392
2426
|
import { jsx as jsx27, jsxs as jsxs15 } from "react/jsx-runtime";
|
|
2393
2427
|
var CreditCardTab = () => {
|
|
2394
2428
|
const { selectedPaymentMethod, setSelectedPaymentMethod } = useSpreePaymentMethod();
|
|
2429
|
+
const { staticConfig, appProps } = useStaticConfig();
|
|
2395
2430
|
const { register } = useSpreePayRegister();
|
|
2396
2431
|
const { mutateCards } = useCards();
|
|
2397
2432
|
const { cardPayment } = useCardPayment();
|
|
2398
2433
|
const { splitPayment } = useSplitCardPayments();
|
|
2434
|
+
const { pointsPayment } = usePointsPayment();
|
|
2399
2435
|
const handlePay = useCallback5(
|
|
2400
2436
|
async (data) => {
|
|
2401
2437
|
try {
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
}
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2438
|
+
let res = null;
|
|
2439
|
+
const pointsAmount = selectedPaymentMethod.splitAmount ?? 0;
|
|
2440
|
+
const usdAmount = getSplitAmount(appProps.amount ?? 0, pointsAmount, staticConfig.pointsConversionRatio);
|
|
2441
|
+
if (usdAmount && pointsAmount) {
|
|
2442
|
+
res = await splitPayment({ ...data, points: pointsAmount });
|
|
2443
|
+
} else if (!usdAmount && pointsAmount) {
|
|
2444
|
+
res = await pointsPayment({ ...data, points: pointsAmount });
|
|
2445
|
+
} else {
|
|
2446
|
+
res = await cardPayment(data);
|
|
2447
|
+
}
|
|
2448
|
+
if (["AUTHORIZED" /* AUTHORIZED */, "CAPTURED" /* CAPTURED */].includes(res.status)) {
|
|
2449
|
+
return Promise.resolve(res);
|
|
2413
2450
|
}
|
|
2414
|
-
return Promise.reject(new PaymentError("
|
|
2451
|
+
return Promise.reject(new PaymentError("Card payment failed", res.status));
|
|
2415
2452
|
} catch (_) {
|
|
2416
2453
|
return Promise.reject(new PaymentError("Payment failed", "FAILED" /* FAILED */));
|
|
2417
2454
|
} finally {
|
|
@@ -2419,7 +2456,16 @@ var CreditCardTab = () => {
|
|
|
2419
2456
|
mutateCards();
|
|
2420
2457
|
}
|
|
2421
2458
|
},
|
|
2422
|
-
[
|
|
2459
|
+
[
|
|
2460
|
+
mutateCards,
|
|
2461
|
+
selectedPaymentMethod,
|
|
2462
|
+
pointsPayment,
|
|
2463
|
+
appProps.amount,
|
|
2464
|
+
setSelectedPaymentMethod,
|
|
2465
|
+
cardPayment,
|
|
2466
|
+
splitPayment,
|
|
2467
|
+
staticConfig.pointsConversionRatio
|
|
2468
|
+
]
|
|
2423
2469
|
);
|
|
2424
2470
|
useEffect7(() => {
|
|
2425
2471
|
register(handlePay);
|
|
@@ -2494,7 +2540,7 @@ async function waitForTransactionReceipt(config, parameters) {
|
|
|
2494
2540
|
// ../../node_modules/@wagmi/core/dist/esm/exports/index.js
|
|
2495
2541
|
import { custom as custom2, http, webSocket } from "viem";
|
|
2496
2542
|
|
|
2497
|
-
// src/hooks/useCryptoPayment.ts
|
|
2543
|
+
// src/hooks/payments/useCryptoPayment.ts
|
|
2498
2544
|
import { erc20Abi as erc20Abi2 } from "viem";
|
|
2499
2545
|
import { useConfig, useWalletClient } from "wagmi";
|
|
2500
2546
|
|
|
@@ -2535,7 +2581,7 @@ var BASE_TOKENS = [
|
|
|
2535
2581
|
}
|
|
2536
2582
|
];
|
|
2537
2583
|
|
|
2538
|
-
// src/hooks/useCryptoPayment.ts
|
|
2584
|
+
// src/hooks/payments/useCryptoPayment.ts
|
|
2539
2585
|
var MAX_UINT256 = BigInt(2) ** BigInt(256) - BigInt(1);
|
|
2540
2586
|
var ONE_INCH_AGGREGATION_ROUTER_V6 = "0x111111125421ca6dc452d289314280a0f8842a65";
|
|
2541
2587
|
var useCryptoPayment = () => {
|
|
@@ -2585,7 +2631,7 @@ var useCryptoPayment = () => {
|
|
|
2585
2631
|
token: TOKEN,
|
|
2586
2632
|
publicKey: walletClient.account.address,
|
|
2587
2633
|
slippageType: "fixed",
|
|
2588
|
-
slippageBps: 0.5 * 100
|
|
2634
|
+
slippageBps: Math.round(0.5 * 100)
|
|
2589
2635
|
}
|
|
2590
2636
|
});
|
|
2591
2637
|
const parsedTX = JSON.parse(paymentRes.data.encodedTx);
|