@arthapay/widget 1.0.0
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/arthapay.js +47 -0
- package/dist/esm/index.js +12891 -0
- package/dist/esm/react.js +71 -0
- package/dist/iife/arthapay.js +47 -0
- package/dist/types/ArthaPay.d.ts +25 -0
- package/dist/types/api.d.ts +6 -0
- package/dist/types/components/App.d.ts +7 -0
- package/dist/types/components/CheckoutModal.d.ts +7 -0
- package/dist/types/components/CoinSelector.d.ts +10 -0
- package/dist/types/components/CountdownTimer.d.ts +6 -0
- package/dist/types/components/PaymentDetails.d.ts +9 -0
- package/dist/types/components/PaymentStatus.d.ts +9 -0
- package/dist/types/components/QRCode.d.ts +7 -0
- package/dist/types/index.d.ts +23 -0
- package/dist/types/react.d.ts +24 -0
- package/dist/types/socket.d.ts +17 -0
- package/dist/types/types.d.ts +64 -0
- package/package.json +53 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ArthaPayConfig, CheckoutOptions, RedirectCheckoutOptions } from './types';
|
|
2
|
+
import './styles/widget.css';
|
|
3
|
+
declare class ArthaPayInstance {
|
|
4
|
+
private config;
|
|
5
|
+
private mountPoint;
|
|
6
|
+
private root;
|
|
7
|
+
constructor(config: ArthaPayConfig);
|
|
8
|
+
/**
|
|
9
|
+
* Open the checkout modal
|
|
10
|
+
*/
|
|
11
|
+
createCheckout(options: CheckoutOptions): void;
|
|
12
|
+
/**
|
|
13
|
+
* Redirect to hosted checkout page
|
|
14
|
+
*/
|
|
15
|
+
redirectToCheckout(options: RedirectCheckoutOptions): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* Destroy the widget instance
|
|
18
|
+
*/
|
|
19
|
+
destroy(): void;
|
|
20
|
+
private mount;
|
|
21
|
+
private detectBaseUrl;
|
|
22
|
+
private getStyles;
|
|
23
|
+
}
|
|
24
|
+
export { ArthaPayInstance };
|
|
25
|
+
export type { ArthaPayConfig, CheckoutOptions };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { InvoiceData, CheckoutOptions } from './types';
|
|
2
|
+
export declare function configure(url: string, key: string): void;
|
|
3
|
+
export declare function createInvoice(options: CheckoutOptions): Promise<InvoiceData>;
|
|
4
|
+
export declare function getInvoice(invoiceId: string): Promise<InvoiceData>;
|
|
5
|
+
export declare function selectMethod(invoiceId: string, currency: string, network: string): Promise<InvoiceData>;
|
|
6
|
+
export declare function getBaseUrl(): string;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { CheckoutOptions } from '../types';
|
|
2
|
+
interface AppProps {
|
|
3
|
+
initialCheckout?: CheckoutOptions;
|
|
4
|
+
}
|
|
5
|
+
export declare function getOpenCheckout(): ((options: CheckoutOptions) => void) | null;
|
|
6
|
+
export declare function App({ initialCheckout }: AppProps): import("react/jsx-runtime").JSX.Element | null;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { CheckoutOptions } from '../types';
|
|
2
|
+
interface CheckoutModalProps {
|
|
3
|
+
options: CheckoutOptions;
|
|
4
|
+
onClose: () => void;
|
|
5
|
+
}
|
|
6
|
+
export declare function CheckoutModal({ options, onClose }: CheckoutModalProps): import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AvailableMethod } from '../types';
|
|
2
|
+
interface CoinSelectorProps {
|
|
3
|
+
methods: AvailableMethod[];
|
|
4
|
+
fiatAmount: number;
|
|
5
|
+
fiatCurrency: string;
|
|
6
|
+
onSelect: (method: AvailableMethod) => void;
|
|
7
|
+
loading?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare function CoinSelector({ methods, fiatAmount, fiatCurrency, onSelect, loading }: CoinSelectorProps): import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CryptoOption } from '../types';
|
|
2
|
+
interface PaymentDetailsProps {
|
|
3
|
+
option: CryptoOption;
|
|
4
|
+
fiatAmount: number;
|
|
5
|
+
fiatCurrency: string;
|
|
6
|
+
onBack: () => void;
|
|
7
|
+
}
|
|
8
|
+
export declare function PaymentDetails({ option, fiatAmount, fiatCurrency, onBack }: PaymentDetailsProps): import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { PaymentData } from '../types';
|
|
2
|
+
interface PaymentStatusProps {
|
|
3
|
+
status: 'detected' | 'confirmed' | 'complete';
|
|
4
|
+
payment: PaymentData | null;
|
|
5
|
+
invoiceId?: string;
|
|
6
|
+
onClose: () => void;
|
|
7
|
+
}
|
|
8
|
+
export declare function PaymentStatus({ status, payment, invoiceId, onClose }: PaymentStatusProps): import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ArthaPayConfig, CheckoutOptions, RedirectCheckoutOptions } from './types';
|
|
2
|
+
declare class ArthaPayWidget {
|
|
3
|
+
private mountPoint;
|
|
4
|
+
private root;
|
|
5
|
+
constructor(config: ArthaPayConfig);
|
|
6
|
+
/** Open the checkout modal on the merchant's page */
|
|
7
|
+
createCheckout(options: CheckoutOptions): void;
|
|
8
|
+
private showOverlay;
|
|
9
|
+
private hideOverlay;
|
|
10
|
+
/** Redirect to the hosted checkout page */
|
|
11
|
+
redirectToCheckout(options: RedirectCheckoutOptions): Promise<void>;
|
|
12
|
+
/** Destroy the widget and clean up */
|
|
13
|
+
destroy(): void;
|
|
14
|
+
private mount;
|
|
15
|
+
private detectBaseUrl;
|
|
16
|
+
}
|
|
17
|
+
declare const ArthaPay: {
|
|
18
|
+
/** Initialize the widget */
|
|
19
|
+
init(config: ArthaPayConfig): ArthaPayWidget;
|
|
20
|
+
/** Get the current instance */
|
|
21
|
+
getInstance(): ArthaPayWidget | null;
|
|
22
|
+
};
|
|
23
|
+
export default ArthaPay;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ArthaPayConfig, CheckoutOptions, RedirectCheckoutOptions, PaymentData } from './types';
|
|
3
|
+
export type { ArthaPayConfig, CheckoutOptions, RedirectCheckoutOptions, PaymentData };
|
|
4
|
+
export interface ArthaPayProps {
|
|
5
|
+
apiKey: string;
|
|
6
|
+
baseUrl?: string;
|
|
7
|
+
amount: number;
|
|
8
|
+
currency?: string;
|
|
9
|
+
orderId?: string;
|
|
10
|
+
redirectUrl?: string;
|
|
11
|
+
metadata?: Record<string, unknown>;
|
|
12
|
+
mode?: 'modal' | 'redirect';
|
|
13
|
+
onSuccess?: (payment: PaymentData) => void;
|
|
14
|
+
onClose?: () => void;
|
|
15
|
+
onError?: (error: Error) => void;
|
|
16
|
+
children?: React.ReactNode;
|
|
17
|
+
className?: string;
|
|
18
|
+
disabled?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export declare function ArthaPayButton({ apiKey, baseUrl, amount, currency, orderId, redirectUrl, metadata, mode, onSuccess, onClose, onError, children, className, disabled, }: ArthaPayProps): import("react/jsx-runtime").JSX.Element;
|
|
21
|
+
export declare function useArthaPay(config: ArthaPayConfig): {
|
|
22
|
+
createCheckout: (options: CheckoutOptions) => void;
|
|
23
|
+
redirectToCheckout: (options: RedirectCheckoutOptions) => void;
|
|
24
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Socket } from 'socket.io-client';
|
|
2
|
+
export declare function connectSocket(): Socket;
|
|
3
|
+
export declare function subscribeToInvoice(invoiceId: string, callbacks: {
|
|
4
|
+
onStatusUpdate?: (data: {
|
|
5
|
+
invoiceId: string;
|
|
6
|
+
status: string;
|
|
7
|
+
}) => void;
|
|
8
|
+
onPaymentDetected?: (data: {
|
|
9
|
+
invoiceId: string;
|
|
10
|
+
payment: unknown;
|
|
11
|
+
}) => void;
|
|
12
|
+
onPaymentConfirmed?: (data: {
|
|
13
|
+
invoiceId: string;
|
|
14
|
+
payment: unknown;
|
|
15
|
+
}) => void;
|
|
16
|
+
}): () => void;
|
|
17
|
+
export declare function disconnectSocket(): void;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export interface ArthaPayConfig {
|
|
2
|
+
apiKey: string;
|
|
3
|
+
baseUrl?: string;
|
|
4
|
+
}
|
|
5
|
+
export interface CheckoutOptions {
|
|
6
|
+
amount: number;
|
|
7
|
+
currency?: string;
|
|
8
|
+
orderId?: string;
|
|
9
|
+
redirectUrl?: string;
|
|
10
|
+
metadata?: Record<string, unknown>;
|
|
11
|
+
onSuccess?: (payment: PaymentData) => void;
|
|
12
|
+
onClose?: () => void;
|
|
13
|
+
onError?: (error: Error) => void;
|
|
14
|
+
}
|
|
15
|
+
export interface RedirectCheckoutOptions {
|
|
16
|
+
amount: number;
|
|
17
|
+
currency?: string;
|
|
18
|
+
orderId?: string;
|
|
19
|
+
redirectUrl: string;
|
|
20
|
+
metadata?: Record<string, unknown>;
|
|
21
|
+
}
|
|
22
|
+
export interface AvailableMethod {
|
|
23
|
+
currency: string;
|
|
24
|
+
network: string;
|
|
25
|
+
name: string;
|
|
26
|
+
addressFamily: string;
|
|
27
|
+
}
|
|
28
|
+
export interface InvoiceData {
|
|
29
|
+
id: string;
|
|
30
|
+
status: string;
|
|
31
|
+
merchantId: string;
|
|
32
|
+
orderId: string | null;
|
|
33
|
+
price: number;
|
|
34
|
+
currency: string;
|
|
35
|
+
expiresAt: string;
|
|
36
|
+
availableMethods: AvailableMethod[];
|
|
37
|
+
cryptoPaymentOptions: CryptoOption[];
|
|
38
|
+
payment: PaymentData | null;
|
|
39
|
+
redirectUrl: string | null;
|
|
40
|
+
createdAt: string;
|
|
41
|
+
merchantName?: string;
|
|
42
|
+
merchantBrandColor?: string;
|
|
43
|
+
merchantLogoUrl?: string;
|
|
44
|
+
}
|
|
45
|
+
export interface CryptoOption {
|
|
46
|
+
currency: string;
|
|
47
|
+
network: string;
|
|
48
|
+
amount: string;
|
|
49
|
+
address: string;
|
|
50
|
+
exchangeRate: number;
|
|
51
|
+
qrCodeData: string;
|
|
52
|
+
qrImage?: string | null;
|
|
53
|
+
}
|
|
54
|
+
export interface PaymentData {
|
|
55
|
+
status: string;
|
|
56
|
+
currency: string;
|
|
57
|
+
network: string;
|
|
58
|
+
amount: string;
|
|
59
|
+
txHash: string | null;
|
|
60
|
+
confirmations: number;
|
|
61
|
+
detectedAt: string | null;
|
|
62
|
+
confirmedAt: string | null;
|
|
63
|
+
}
|
|
64
|
+
export type WidgetState = 'loading' | 'select-coin' | 'awaiting-payment' | 'detected' | 'confirmed' | 'expired' | 'error';
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@arthapay/widget",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "ArthaPay — Crypto Payment Gateway Widget",
|
|
5
|
+
"main": "dist/esm/index.js",
|
|
6
|
+
"module": "dist/esm/index.js",
|
|
7
|
+
"types": "dist/types/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/esm/index.js",
|
|
11
|
+
"types": "./dist/types/index.d.ts"
|
|
12
|
+
},
|
|
13
|
+
"./react": {
|
|
14
|
+
"import": "./dist/esm/react.js",
|
|
15
|
+
"types": "./dist/types/react.d.ts"
|
|
16
|
+
},
|
|
17
|
+
"./iife": "./dist/iife/arthapay.js"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist/"
|
|
21
|
+
],
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public"
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"dev": "vite build --watch --config vite.config.iife.ts",
|
|
27
|
+
"build": "npm run build:types && npm run build:iife && npm run build:esm && npm run postbuild",
|
|
28
|
+
"build:iife": "vite build --config vite.config.iife.ts",
|
|
29
|
+
"build:esm": "vite build --config vite.config.esm.ts",
|
|
30
|
+
"build:types": "tsc --project tsconfig.types.json",
|
|
31
|
+
"postbuild": "node -e \"require('fs').copyFileSync('dist/iife/arthapay.js','dist/arthapay.js')\""
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"react": ">=18.0.0",
|
|
35
|
+
"react-dom": ">=18.0.0"
|
|
36
|
+
},
|
|
37
|
+
"peerDependenciesMeta": {
|
|
38
|
+
"react": { "optional": true },
|
|
39
|
+
"react-dom": { "optional": true }
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"socket.io-client": "^4.8.1"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@types/react": "^19.0.8",
|
|
46
|
+
"@types/react-dom": "^19.0.3",
|
|
47
|
+
"@vitejs/plugin-react": "^4.3.4",
|
|
48
|
+
"react": "^19.0.0",
|
|
49
|
+
"react-dom": "^19.0.0",
|
|
50
|
+
"typescript": "^5.7.3",
|
|
51
|
+
"vite": "^6.1.0"
|
|
52
|
+
}
|
|
53
|
+
}
|