mainstack-payments 2.0.6 → 2.0.8

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.
@@ -1,5 +1,5 @@
1
1
  import { ReactNode } from 'react';
2
- import { TItemList } from 'types';
2
+ import { IAppliedFee, TItemList } from 'types';
3
3
 
4
4
  type IProps = {
5
5
  summaryTitle: string | ReactNode;
@@ -19,12 +19,7 @@ type IProps = {
19
19
  };
20
20
  transactionFees: {
21
21
  totalAmountPlusFees: number;
22
- applied_fees: Array<{
23
- _id: number;
24
- display_name: string;
25
- amount: number;
26
- extra: number;
27
- }>;
22
+ applied_fees?: IAppliedFee[];
28
23
  transactionFeeValue: number;
29
24
  };
30
25
  isSingleColumn: boolean;
@@ -1,5 +1,5 @@
1
- /** @format */
2
- /// <reference types="react" />
1
+ import { ITransactionFeesResponse } from 'types';
2
+
3
3
  interface WalletPayProps {
4
4
  currency: string;
5
5
  amount: number;
@@ -7,12 +7,17 @@ interface WalletPayProps {
7
7
  formik: any;
8
8
  checkForErrors: () => Promise<boolean>;
9
9
  onPaymentComplete: (payload: object) => void;
10
+ ProductRequest: any;
10
11
  PaymentRequest: any;
11
12
  stripeCountry: string;
12
13
  onInitializePayment?: (e: object) => Promise<{
13
14
  terminate?: boolean;
14
15
  }>;
15
16
  onToggleWallet: () => void;
17
+ subAmount: number;
18
+ totalAmount: number;
19
+ feesResponse?: ITransactionFeesResponse;
20
+ ip: string;
16
21
  }
17
- declare const WalletPay: import('react').MemoExoticComponent<({ currency, metadata, amount, formik, checkForErrors, onPaymentComplete, PaymentRequest, stripeCountry, onInitializePayment, onToggleWallet, }: WalletPayProps) => import("react/jsx-runtime").JSX.Element>;
22
+ declare const WalletPay: import('react').MemoExoticComponent<({ currency, metadata, amount, formik, checkForErrors, onPaymentComplete, ProductRequest, PaymentRequest, stripeCountry, onInitializePayment, onToggleWallet, subAmount, totalAmount, feesResponse, ip, }: WalletPayProps) => import("react/jsx-runtime").JSX.Element>;
18
23
  export default WalletPay;
@@ -1,25 +1,31 @@
1
- export interface IFetchResponse {
2
- data: any;
1
+ /** Shape returned by `refetch()` — mirrors the old callback contract. */
2
+ export interface IFetchResult<TData> {
3
+ data: TData | undefined;
3
4
  isSuccess: boolean;
4
- error: any;
5
+ error: unknown;
5
6
  }
6
- export declare const useQuery: ({ queryFn, enabled, dependingOn, }: {
7
- queryFn: () => Promise<any>;
8
- enabled?: boolean | undefined;
9
- dependingOn?: any[] | undefined;
10
- }) => {
11
- data: any;
7
+ export interface IQueryResult<TData> {
8
+ data: TData | undefined;
12
9
  isLoading: boolean;
13
- refetch: () => Promise<IFetchResponse>;
14
- error: any;
15
- };
16
- export declare const useMutation: <T>({ mutationFn, }: {
17
- mutationFn: (data: T) => Promise<any>;
18
- }) => {
19
- data: any;
10
+ error: unknown;
11
+ /** Re-runs the query and returns a result object with `{ isSuccess, data, error }`. */
12
+ refetch: () => Promise<IFetchResult<TData>>;
13
+ }
14
+ export declare const useQuery: <TData = unknown>({ queryFn, enabled, dependingOn, }: {
15
+ /** Should return the already-unwrapped data value (not the full axios response). */
16
+ queryFn: () => Promise<TData>;
17
+ enabled?: boolean | undefined;
18
+ dependingOn?: unknown[] | undefined;
19
+ }) => IQueryResult<TData>;
20
+ export interface IMutationResult<TInput, TData> {
21
+ data: TData | undefined;
20
22
  isLoading: boolean;
21
- mutate: (dataParams: T, { onSuccess, onError, }: {
22
- onSuccess: (data: any) => void;
23
- onError: (error: any) => void;
24
- }) => Promise<any>;
25
- };
23
+ mutate: (params: TInput, callbacks: {
24
+ onSuccess: (data: TData) => void;
25
+ onError: (error: unknown) => void;
26
+ }) => Promise<TData>;
27
+ }
28
+ export declare const useMutation: <TInput, TData = unknown>({ mutationFn, }: {
29
+ /** Should return the already-unwrapped data value (not the full axios response). */
30
+ mutationFn: (data: TInput) => Promise<TData>;
31
+ }) => IMutationResult<TInput, TData>;
@@ -0,0 +1,3 @@
1
+ /** @format */
2
+ declare const Receipt: () => import("react/jsx-runtime").JSX.Element;
3
+ export default Receipt;
@@ -4,4 +4,5 @@ export declare const ROUTES: {
4
4
  LOGIN: string;
5
5
  NOT_FOUND: string;
6
6
  PAYMENT_REDIRECT: string;
7
+ RECEIPT: string;
7
8
  };
@@ -1,8 +1,25 @@
1
1
  /** @format */
2
+ export declare enum EStatusCode {
3
+ StatusCode200 = 200,
4
+ StatusCode201 = 201,
5
+ StatusCode304 = 304,
6
+ StatusCode400 = 400,
7
+ StatusCode401 = 401,
8
+ StatusCode403 = 403,
9
+ StatusCode404 = 404,
10
+ StatusCode409 = 409,
11
+ StatusCode500 = 500
12
+ }
13
+ /** Shape every backend endpoint returns. Callers receive `T` directly after unwrapping. */
14
+ export interface IApiResponse<T = unknown> {
15
+ statusCode: EStatusCode;
16
+ message: string;
17
+ data?: T;
18
+ }
2
19
  type TPaymentOption = "wallet" | "startbutton" | "stripe" | "paystack" | "crypto" | "cashapp";
3
20
  type TPaymentMode = "card" | "transfer" | "mobile_money";
4
21
  type TPaymentModel = "ips" | "default";
5
- declare enum EPaymentMethods {
22
+ export declare enum EPaymentMethods {
6
23
  CARD = "card",
7
24
  GOOGLE_PAY = "google_pay",
8
25
  APPLE_PAY = "apple_pay",
@@ -169,6 +186,7 @@ export interface ITransactionFeesResponse {
169
186
  appliedFees: IAppliedFee[];
170
187
  appliedFeeIds: string[];
171
188
  tax: any;
189
+ isZeroDecimalCurrency?: boolean;
172
190
  }
173
191
  export interface IOrderAmount {
174
192
  currency: string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mainstack-payments",
3
3
  "type": "module",
4
- "version": "2.0.6",
4
+ "version": "2.0.8",
5
5
  "main": "build/mainstack-payments.js",
6
6
  "types": "build/src/index.d.ts",
7
7
  "style": "build/index.css",
@@ -1,114 +0,0 @@
1
- import { jsxs as o, jsx as a } from "react/jsx-runtime";
2
- import { u as I, a as v, C as S, v as b, b as E } from "./index-D6I8egaA.js";
3
- import { BodyText as z, ChevronRightIcon as N, toast as $ } from "mainstack-design-system";
4
- import { u as j } from "./payments-B3Hm80pK.js";
5
- import { useState as B } from "react";
6
- const M = (i) => /* @__PURE__ */ o(
7
- "svg",
8
- {
9
- viewBox: "0 0 32 32",
10
- fill: "none",
11
- xmlns: "http://www.w3.org/2000/svg",
12
- ...i,
13
- children: [
14
- /* @__PURE__ */ a("g", { clipPath: "url(#clip0_2605_970)", children: /* @__PURE__ */ a(
15
- "path",
16
- {
17
- d: "M16 32C7.163 32 0 24.837 0 16C0 7.163 7.163 0 16 0C24.837 0 32 7.163 32 16C32 24.837 24.837 32 16 32ZM21.002 9.855L21.812 6.614L19.216 5.968L18.573 8.543C18.1498 8.40049 17.7157 8.29247 17.275 8.22L17.919 5.645L15.323 5L14.513 8.241C11.53 8.783 9.004 10.978 8.233 14.064C7.462 17.15 8.659 20.27 11.037 22.144L10.227 25.386L12.823 26.032L13.466 23.457C13.8892 23.5995 14.3233 23.7075 14.764 23.78L14.12 26.355L16.716 27L17.526 23.759C18.575 23.5709 19.5756 23.1744 20.4687 22.593C21.3619 22.0116 22.1294 21.2571 22.726 20.374L19.879 19.666C19.2215 20.3303 18.4022 20.8116 17.5018 21.0624C16.6014 21.3132 15.6512 21.3248 14.745 21.096C11.879 20.384 10.125 17.524 10.828 14.709C11.531 11.894 14.427 10.19 17.294 10.903C18.2012 11.1247 19.0347 11.5798 19.7118 12.223C20.3889 12.8663 20.8861 13.6753 21.154 14.57L24 15.278C23.8889 14.2194 23.5663 13.1938 23.0513 12.2623C22.5363 11.3307 21.8394 10.5121 21.002 9.855Z",
18
- fill: "#131316"
19
- }
20
- ) }),
21
- /* @__PURE__ */ a("defs", { children: /* @__PURE__ */ a("clipPath", { id: "clip0_2605_970", children: /* @__PURE__ */ a("rect", { width: "32", height: "32", fill: "white" }) }) })
22
- ]
23
- }
24
- ), q = ({
25
- ProductRequest: i,
26
- PaymentRequest: C,
27
- metadata: f,
28
- amount: m,
29
- currency: c,
30
- redirectUrl: l,
31
- checkForErrors: u
32
- }) => {
33
- const d = j(), { mutate: g, isLoading: w } = I(i), { mutate: L, isLoading: P } = v(C), [_, r] = B(!1), p = w || P || _, x = async () => {
34
- var y;
35
- const s = b(), h = {
36
- ...f,
37
- reference: s
38
- };
39
- try {
40
- await g(
41
- E({
42
- metadata: h,
43
- amount: m,
44
- currency: c
45
- }),
46
- {
47
- onSuccess: (t) => {
48
- },
49
- onError: (t) => {
50
- var n;
51
- throw ((n = t == null ? void 0 : t.raw) == null ? void 0 : n.message) ?? t;
52
- }
53
- }
54
- );
55
- const { client_secret: e } = await L(
56
- {
57
- amount: m,
58
- currency: c,
59
- metadata: h,
60
- is_crypto_payment: !0
61
- },
62
- {
63
- onSuccess: (t) => {
64
- },
65
- onError: (t) => {
66
- var n;
67
- throw ((n = t == null ? void 0 : t.raw) == null ? void 0 : n.message) ?? t;
68
- }
69
- }
70
- );
71
- if (d) {
72
- r(!0);
73
- const { error: t } = await d.confirmPayment({
74
- clientSecret: e,
75
- confirmParams: {
76
- payment_method_data: {
77
- // @ts-ignore
78
- type: "crypto"
79
- },
80
- return_url: l.includes("?") ? `${l}&reference=${s}` : `${l}?reference=${s}`
81
- }
82
- });
83
- if (t)
84
- throw new Error(t.message ?? "Couldn't load wallet integration");
85
- }
86
- } catch (e) {
87
- r(!1), console.error(e), $.error({
88
- title: "",
89
- description: ((y = e == null ? void 0 : e.raw) == null ? void 0 : y.message) ?? (e == null ? void 0 : e.message) ?? e ?? "We couldn't complete your payment"
90
- });
91
- }
92
- };
93
- return /* @__PURE__ */ a(
94
- S,
95
- {
96
- onClick: async () => {
97
- await u() || x();
98
- },
99
- disabled: p,
100
- isLoading: p,
101
- children: /* @__PURE__ */ o("div", { className: "mpl:flex mpl:justify-between mpl:w-full mpl:items-center", children: [
102
- /* @__PURE__ */ o("div", { className: "mpl:flex mpl:items-center mpl:gap-12", children: [
103
- /* @__PURE__ */ a(M, { className: "mpl:size-32" }),
104
- /* @__PURE__ */ a(z, { size: "extrasmall", weight: "medium", children: "Stablecoins & Crypto" })
105
- ] }),
106
- /* @__PURE__ */ a(N, { className: "mpl:size-20" }),
107
- " "
108
- ] })
109
- }
110
- );
111
- };
112
- export {
113
- q as default
114
- };