@rotateprotocol/sdk 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/README.md +453 -0
- package/dist/catalog.d.ts +112 -0
- package/dist/catalog.d.ts.map +1 -0
- package/dist/catalog.js +210 -0
- package/dist/catalog.js.map +1 -0
- package/dist/components/CheckoutForm.d.ts +86 -0
- package/dist/components/CheckoutForm.d.ts.map +1 -0
- package/dist/components/CheckoutForm.js +332 -0
- package/dist/components/CheckoutForm.js.map +1 -0
- package/dist/components/HostedCheckout.d.ts +57 -0
- package/dist/components/HostedCheckout.d.ts.map +1 -0
- package/dist/components/HostedCheckout.js +414 -0
- package/dist/components/HostedCheckout.js.map +1 -0
- package/dist/components/PaymentButton.d.ts +80 -0
- package/dist/components/PaymentButton.d.ts.map +1 -0
- package/dist/components/PaymentButton.js +210 -0
- package/dist/components/PaymentButton.js.map +1 -0
- package/dist/components/RotateProvider.d.ts +115 -0
- package/dist/components/RotateProvider.d.ts.map +1 -0
- package/dist/components/RotateProvider.js +264 -0
- package/dist/components/RotateProvider.js.map +1 -0
- package/dist/components/index.d.ts +17 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +27 -0
- package/dist/components/index.js.map +1 -0
- package/dist/embed.d.ts +85 -0
- package/dist/embed.d.ts.map +1 -0
- package/dist/embed.js +313 -0
- package/dist/embed.js.map +1 -0
- package/dist/hooks.d.ts +156 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +280 -0
- package/dist/hooks.js.map +1 -0
- package/dist/idl/rotate_connect.json +2572 -0
- package/dist/index.d.ts +505 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1197 -0
- package/dist/index.js.map +1 -0
- package/dist/marketplace.d.ts +257 -0
- package/dist/marketplace.d.ts.map +1 -0
- package/dist/marketplace.js +433 -0
- package/dist/marketplace.js.map +1 -0
- package/dist/platform.d.ts +234 -0
- package/dist/platform.d.ts.map +1 -0
- package/dist/platform.js +268 -0
- package/dist/platform.js.map +1 -0
- package/dist/react.d.ts +140 -0
- package/dist/react.d.ts.map +1 -0
- package/dist/react.js +429 -0
- package/dist/react.js.map +1 -0
- package/dist/store.d.ts +213 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +404 -0
- package/dist/store.js.map +1 -0
- package/dist/webhooks.d.ts +149 -0
- package/dist/webhooks.d.ts.map +1 -0
- package/dist/webhooks.js +371 -0
- package/dist/webhooks.js.map +1 -0
- package/package.json +114 -0
- package/src/catalog.ts +299 -0
- package/src/components/CheckoutForm.tsx +608 -0
- package/src/components/HostedCheckout.tsx +675 -0
- package/src/components/PaymentButton.tsx +348 -0
- package/src/components/RotateProvider.tsx +370 -0
- package/src/components/index.ts +26 -0
- package/src/embed.ts +408 -0
- package/src/hooks.ts +518 -0
- package/src/idl/rotate_connect.json +2572 -0
- package/src/index.ts +1538 -0
- package/src/marketplace.ts +642 -0
- package/src/platform.ts +403 -0
- package/src/react.ts +459 -0
- package/src/store.ts +577 -0
- package/src/webhooks.ts +506 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Rotate Protocol React Components
|
|
4
|
+
*
|
|
5
|
+
* Drop-in components for seamless payment integration on Solana.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.default = exports.HostedCheckout = exports.CheckoutForm = exports.PaymentButton = exports.useRotateContext = exports.RotateProvider = void 0;
|
|
11
|
+
// Provider
|
|
12
|
+
var RotateProvider_1 = require("./RotateProvider");
|
|
13
|
+
Object.defineProperty(exports, "RotateProvider", { enumerable: true, get: function () { return RotateProvider_1.RotateProvider; } });
|
|
14
|
+
Object.defineProperty(exports, "useRotateContext", { enumerable: true, get: function () { return RotateProvider_1.useRotateContext; } });
|
|
15
|
+
// Payment Button
|
|
16
|
+
var PaymentButton_1 = require("./PaymentButton");
|
|
17
|
+
Object.defineProperty(exports, "PaymentButton", { enumerable: true, get: function () { return PaymentButton_1.PaymentButton; } });
|
|
18
|
+
// Checkout Form
|
|
19
|
+
var CheckoutForm_1 = require("./CheckoutForm");
|
|
20
|
+
Object.defineProperty(exports, "CheckoutForm", { enumerable: true, get: function () { return CheckoutForm_1.CheckoutForm; } });
|
|
21
|
+
// Hosted Checkout
|
|
22
|
+
var HostedCheckout_1 = require("./HostedCheckout");
|
|
23
|
+
Object.defineProperty(exports, "HostedCheckout", { enumerable: true, get: function () { return HostedCheckout_1.HostedCheckout; } });
|
|
24
|
+
// Default export for convenience
|
|
25
|
+
var RotateProvider_2 = require("./RotateProvider");
|
|
26
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return RotateProvider_2.RotateProvider; } });
|
|
27
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH,WAAW;AACX,mDAAoE;AAA3D,gHAAA,cAAc,OAAA;AAAE,kHAAA,gBAAgB,OAAA;AAGzC,iBAAiB;AACjB,iDAAgD;AAAvC,8GAAA,aAAa,OAAA;AAGtB,gBAAgB;AAChB,+CAA8C;AAArC,4GAAA,YAAY,OAAA;AAGrB,kBAAkB;AAClB,mDAAkD;AAAzC,gHAAA,cAAc,OAAA;AAGvB,iCAAiC;AACjC,mDAA6D;AAApD,yGAAA,cAAc,OAAW"}
|
package/dist/embed.d.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rotate Embeddable Widget
|
|
3
|
+
*
|
|
4
|
+
* Add Rotate payments to any website with just a script tag.
|
|
5
|
+
* No React required - works with vanilla HTML/JS.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```html
|
|
9
|
+
* <!-- Add this to your HTML -->
|
|
10
|
+
* <script src="https://js.rotate.app/embed.js"></script>
|
|
11
|
+
*
|
|
12
|
+
* <!-- Simple payment button -->
|
|
13
|
+
* <button data-rotate-pay data-amount="29.99" data-merchant="1000000" data-platform="1000000">
|
|
14
|
+
* Pay $29.99
|
|
15
|
+
* </button>
|
|
16
|
+
*
|
|
17
|
+
* <!-- Or use JavaScript -->
|
|
18
|
+
* <script>
|
|
19
|
+
* Rotate.checkout({
|
|
20
|
+
* amount: 29.99,
|
|
21
|
+
* merchantId: 1000000,
|
|
22
|
+
* platformId: 1000000,
|
|
23
|
+
* onSuccess: (payment) => console.log('Paid!', payment)
|
|
24
|
+
* });
|
|
25
|
+
* </script>
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
interface RotateCheckoutOptions {
|
|
29
|
+
amount: number;
|
|
30
|
+
merchantId: number;
|
|
31
|
+
platformId: number;
|
|
32
|
+
currency?: 'SOL' | 'USDC' | 'USDT' | 'USD';
|
|
33
|
+
description?: string;
|
|
34
|
+
orderRef?: string;
|
|
35
|
+
allowTips?: boolean;
|
|
36
|
+
brandName?: string;
|
|
37
|
+
brandLogo?: string;
|
|
38
|
+
brandColor?: string;
|
|
39
|
+
successUrl?: string;
|
|
40
|
+
cancelUrl?: string;
|
|
41
|
+
popup?: boolean;
|
|
42
|
+
onSuccess?: (payment: PaymentResult) => void;
|
|
43
|
+
onCancel?: () => void;
|
|
44
|
+
onError?: (error: Error) => void;
|
|
45
|
+
}
|
|
46
|
+
interface PaymentResult {
|
|
47
|
+
linkId: number;
|
|
48
|
+
amount: number;
|
|
49
|
+
currency: string;
|
|
50
|
+
transactionId: string;
|
|
51
|
+
paidAt: number;
|
|
52
|
+
}
|
|
53
|
+
interface RotateButtonOptions extends RotateCheckoutOptions {
|
|
54
|
+
element: HTMLElement;
|
|
55
|
+
label?: string;
|
|
56
|
+
size?: 'sm' | 'md' | 'lg';
|
|
57
|
+
variant?: 'solid' | 'outline' | 'ghost';
|
|
58
|
+
}
|
|
59
|
+
declare const Rotate: {
|
|
60
|
+
_config: {
|
|
61
|
+
baseUrl: string;
|
|
62
|
+
network: "devnet" | "mainnet-beta";
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Configure Rotate settings
|
|
66
|
+
*/
|
|
67
|
+
configure(options: {
|
|
68
|
+
baseUrl?: string;
|
|
69
|
+
network?: "devnet" | "mainnet-beta";
|
|
70
|
+
}): void;
|
|
71
|
+
/**
|
|
72
|
+
* Open checkout popup/redirect
|
|
73
|
+
*/
|
|
74
|
+
checkout(options: RotateCheckoutOptions): void;
|
|
75
|
+
/**
|
|
76
|
+
* Create a payment button
|
|
77
|
+
*/
|
|
78
|
+
createButton(options: RotateButtonOptions): HTMLButtonElement;
|
|
79
|
+
/**
|
|
80
|
+
* Auto-initialize buttons from data attributes
|
|
81
|
+
*/
|
|
82
|
+
init(): void;
|
|
83
|
+
};
|
|
84
|
+
export default Rotate;
|
|
85
|
+
//# sourceMappingURL=embed.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embed.d.ts","sourceRoot":"","sources":["../src/embed.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAIH,UAAU,qBAAqB;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC;IAC3C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,aAAa,KAAK,IAAI,CAAC;IAC7C,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;IACtB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAClC;AAED,UAAU,aAAa;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,UAAU,mBAAoB,SAAQ,qBAAqB;IACzD,OAAO,EAAE,WAAW,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;IAC1B,OAAO,CAAC,EAAE,OAAO,GAAG,SAAS,GAAG,OAAO,CAAC;CACzC;AAgED,QAAA,MAAM,MAAM;;;iBAImB,QAAQ,GAAG,cAAc;;IAGtD;;OAEG;uBACgB;QAAE,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,QAAQ,GAAG,cAAc,CAAA;KAAE;IAK5E;;OAEG;sBACe,qBAAqB;IAoFvC;;OAEG;0BACmB,mBAAmB;IA2HzC;;OAEG;;CAqCJ,CAAC;AAcF,eAAe,MAAM,CAAC"}
|
package/dist/embed.js
ADDED
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Rotate Embeddable Widget
|
|
4
|
+
*
|
|
5
|
+
* Add Rotate payments to any website with just a script tag.
|
|
6
|
+
* No React required - works with vanilla HTML/JS.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```html
|
|
10
|
+
* <!-- Add this to your HTML -->
|
|
11
|
+
* <script src="https://js.rotate.app/embed.js"></script>
|
|
12
|
+
*
|
|
13
|
+
* <!-- Simple payment button -->
|
|
14
|
+
* <button data-rotate-pay data-amount="29.99" data-merchant="1000000" data-platform="1000000">
|
|
15
|
+
* Pay $29.99
|
|
16
|
+
* </button>
|
|
17
|
+
*
|
|
18
|
+
* <!-- Or use JavaScript -->
|
|
19
|
+
* <script>
|
|
20
|
+
* Rotate.checkout({
|
|
21
|
+
* amount: 29.99,
|
|
22
|
+
* merchantId: 1000000,
|
|
23
|
+
* platformId: 1000000,
|
|
24
|
+
* onSuccess: (payment) => console.log('Paid!', payment)
|
|
25
|
+
* });
|
|
26
|
+
* </script>
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
+
// ==================== STYLES ====================
|
|
31
|
+
const BUTTON_BASE_STYLES = `
|
|
32
|
+
display: inline-flex;
|
|
33
|
+
align-items: center;
|
|
34
|
+
justify-content: center;
|
|
35
|
+
gap: 8px;
|
|
36
|
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
|
37
|
+
font-weight: 600;
|
|
38
|
+
border: none;
|
|
39
|
+
cursor: pointer;
|
|
40
|
+
transition: all 0.2s ease;
|
|
41
|
+
position: relative;
|
|
42
|
+
overflow: hidden;
|
|
43
|
+
`;
|
|
44
|
+
const BUTTON_SIZES = {
|
|
45
|
+
sm: 'padding: 8px 16px; font-size: 14px; border-radius: 6px;',
|
|
46
|
+
md: 'padding: 12px 24px; font-size: 16px; border-radius: 8px;',
|
|
47
|
+
lg: 'padding: 16px 32px; font-size: 18px; border-radius: 10px;',
|
|
48
|
+
};
|
|
49
|
+
const SPINNER_CSS = `
|
|
50
|
+
@keyframes rotate-spin {
|
|
51
|
+
from { transform: rotate(0deg); }
|
|
52
|
+
to { transform: rotate(360deg); }
|
|
53
|
+
}
|
|
54
|
+
`;
|
|
55
|
+
// ==================== UTILITY FUNCTIONS ====================
|
|
56
|
+
function adjustColor(hex, percent) {
|
|
57
|
+
const num = parseInt(hex.replace('#', ''), 16);
|
|
58
|
+
const amt = Math.round(2.55 * percent);
|
|
59
|
+
const R = (num >> 16) + amt;
|
|
60
|
+
const G = (num >> 8 & 0x00FF) + amt;
|
|
61
|
+
const B = (num & 0x0000FF) + amt;
|
|
62
|
+
return '#' + (0x1000000 +
|
|
63
|
+
(R < 255 ? R < 1 ? 0 : R : 255) * 0x10000 +
|
|
64
|
+
(G < 255 ? G < 1 ? 0 : G : 255) * 0x100 +
|
|
65
|
+
(B < 255 ? B < 1 ? 0 : B : 255)).toString(16).slice(1);
|
|
66
|
+
}
|
|
67
|
+
function createSpinner() {
|
|
68
|
+
return `<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" style="animation: rotate-spin 1s linear infinite;">
|
|
69
|
+
<circle cx="12" cy="12" r="10" stroke-opacity="0.25"/>
|
|
70
|
+
<path d="M12 2a10 10 0 0 1 10 10" stroke-linecap="round"/>
|
|
71
|
+
</svg>`;
|
|
72
|
+
}
|
|
73
|
+
function createWalletIcon() {
|
|
74
|
+
return `<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
75
|
+
<path d="M21 12V7H5a2 2 0 0 1 0-4h14v4"/>
|
|
76
|
+
<path d="M3 5v14a2 2 0 0 0 2 2h16v-5"/>
|
|
77
|
+
<path d="M18 12a2 2 0 0 0 0 4h4v-4h-4z"/>
|
|
78
|
+
</svg>`;
|
|
79
|
+
}
|
|
80
|
+
// ==================== MAIN ROTATE OBJECT ====================
|
|
81
|
+
const Rotate = {
|
|
82
|
+
// Configuration
|
|
83
|
+
_config: {
|
|
84
|
+
baseUrl: 'https://rotate.app',
|
|
85
|
+
network: 'mainnet-beta',
|
|
86
|
+
},
|
|
87
|
+
/**
|
|
88
|
+
* Configure Rotate settings
|
|
89
|
+
*/
|
|
90
|
+
configure(options) {
|
|
91
|
+
if (options.baseUrl)
|
|
92
|
+
this._config.baseUrl = options.baseUrl;
|
|
93
|
+
if (options.network)
|
|
94
|
+
this._config.network = options.network;
|
|
95
|
+
},
|
|
96
|
+
/**
|
|
97
|
+
* Open checkout popup/redirect
|
|
98
|
+
*/
|
|
99
|
+
checkout(options) {
|
|
100
|
+
const { amount, merchantId, platformId, currency = 'USD', description, orderRef, allowTips, brandName, brandLogo, brandColor = '#8B5CF6', successUrl, cancelUrl, popup = true, onSuccess, onCancel, onError, } = options;
|
|
101
|
+
// Build checkout URL
|
|
102
|
+
const params = new URLSearchParams({
|
|
103
|
+
amount: amount.toString(),
|
|
104
|
+
merchant: merchantId.toString(),
|
|
105
|
+
platform: platformId.toString(),
|
|
106
|
+
currency,
|
|
107
|
+
network: this._config.network,
|
|
108
|
+
});
|
|
109
|
+
if (description)
|
|
110
|
+
params.set('description', description);
|
|
111
|
+
if (orderRef)
|
|
112
|
+
params.set('ref', orderRef);
|
|
113
|
+
if (allowTips)
|
|
114
|
+
params.set('tips', '1');
|
|
115
|
+
if (brandName)
|
|
116
|
+
params.set('brand', brandName);
|
|
117
|
+
if (brandLogo)
|
|
118
|
+
params.set('logo', brandLogo);
|
|
119
|
+
if (brandColor)
|
|
120
|
+
params.set('color', brandColor.replace('#', ''));
|
|
121
|
+
if (successUrl)
|
|
122
|
+
params.set('success', successUrl);
|
|
123
|
+
if (cancelUrl)
|
|
124
|
+
params.set('cancel', cancelUrl);
|
|
125
|
+
const checkoutUrl = `${this._config.baseUrl}/checkout?${params.toString()}`;
|
|
126
|
+
if (popup) {
|
|
127
|
+
// Open popup window
|
|
128
|
+
const width = 450;
|
|
129
|
+
const height = 700;
|
|
130
|
+
const left = window.screenX + (window.outerWidth - width) / 2;
|
|
131
|
+
const top = window.screenY + (window.outerHeight - height) / 2;
|
|
132
|
+
const popupWindow = window.open(checkoutUrl, 'rotate_checkout', `width=${width},height=${height},left=${left},top=${top},popup=1`);
|
|
133
|
+
if (popupWindow) {
|
|
134
|
+
// Listen for popup messages
|
|
135
|
+
const messageHandler = (event) => {
|
|
136
|
+
if (event.data?.type === 'rotate_payment_success') {
|
|
137
|
+
onSuccess?.(event.data.payment);
|
|
138
|
+
window.removeEventListener('message', messageHandler);
|
|
139
|
+
}
|
|
140
|
+
else if (event.data?.type === 'rotate_payment_cancel') {
|
|
141
|
+
onCancel?.();
|
|
142
|
+
window.removeEventListener('message', messageHandler);
|
|
143
|
+
}
|
|
144
|
+
else if (event.data?.type === 'rotate_payment_error') {
|
|
145
|
+
onError?.(new Error(event.data.message));
|
|
146
|
+
window.removeEventListener('message', messageHandler);
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
window.addEventListener('message', messageHandler);
|
|
150
|
+
// Check if popup closed without completing
|
|
151
|
+
const checkClosed = setInterval(() => {
|
|
152
|
+
if (popupWindow.closed) {
|
|
153
|
+
clearInterval(checkClosed);
|
|
154
|
+
window.removeEventListener('message', messageHandler);
|
|
155
|
+
}
|
|
156
|
+
}, 500);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
// Redirect
|
|
161
|
+
window.location.href = checkoutUrl;
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
/**
|
|
165
|
+
* Create a payment button
|
|
166
|
+
*/
|
|
167
|
+
createButton(options) {
|
|
168
|
+
const { element, amount, merchantId, platformId, currency = 'USD', label, size = 'md', variant = 'solid', brandColor = '#8B5CF6', onSuccess, onCancel, onError, ...checkoutOptions } = options;
|
|
169
|
+
// Inject styles
|
|
170
|
+
if (!document.getElementById('rotate-styles')) {
|
|
171
|
+
const style = document.createElement('style');
|
|
172
|
+
style.id = 'rotate-styles';
|
|
173
|
+
style.textContent = SPINNER_CSS;
|
|
174
|
+
document.head.appendChild(style);
|
|
175
|
+
}
|
|
176
|
+
// Format amount
|
|
177
|
+
const formattedAmount = currency === 'SOL'
|
|
178
|
+
? `${amount} SOL`
|
|
179
|
+
: `$${amount.toFixed(2)}`;
|
|
180
|
+
const buttonLabel = label || `Pay ${formattedAmount}`;
|
|
181
|
+
// Build styles
|
|
182
|
+
let buttonStyles = BUTTON_BASE_STYLES + BUTTON_SIZES[size];
|
|
183
|
+
if (variant === 'solid') {
|
|
184
|
+
buttonStyles += `
|
|
185
|
+
background: linear-gradient(135deg, ${brandColor} 0%, ${adjustColor(brandColor, -20)} 100%);
|
|
186
|
+
color: #ffffff;
|
|
187
|
+
box-shadow: 0 4px 14px ${brandColor}40;
|
|
188
|
+
`;
|
|
189
|
+
}
|
|
190
|
+
else if (variant === 'outline') {
|
|
191
|
+
buttonStyles += `
|
|
192
|
+
background: transparent;
|
|
193
|
+
color: ${brandColor};
|
|
194
|
+
border: 2px solid ${brandColor};
|
|
195
|
+
`;
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
buttonStyles += `
|
|
199
|
+
background: ${brandColor}15;
|
|
200
|
+
color: ${brandColor};
|
|
201
|
+
`;
|
|
202
|
+
}
|
|
203
|
+
// Create button
|
|
204
|
+
const button = document.createElement('button');
|
|
205
|
+
button.setAttribute('style', buttonStyles);
|
|
206
|
+
button.innerHTML = `${createWalletIcon()}<span>${buttonLabel}</span>`;
|
|
207
|
+
button.className = 'rotate-pay-button';
|
|
208
|
+
// Add hover effect
|
|
209
|
+
button.addEventListener('mouseenter', () => {
|
|
210
|
+
button.style.transform = 'translateY(-2px)';
|
|
211
|
+
button.style.filter = 'brightness(1.1)';
|
|
212
|
+
});
|
|
213
|
+
button.addEventListener('mouseleave', () => {
|
|
214
|
+
button.style.transform = 'translateY(0)';
|
|
215
|
+
button.style.filter = 'brightness(1)';
|
|
216
|
+
});
|
|
217
|
+
// Handle click
|
|
218
|
+
let loading = false;
|
|
219
|
+
button.addEventListener('click', () => {
|
|
220
|
+
if (loading)
|
|
221
|
+
return;
|
|
222
|
+
loading = true;
|
|
223
|
+
button.innerHTML = `${createSpinner()}<span>Processing...</span>`;
|
|
224
|
+
button.style.cursor = 'wait';
|
|
225
|
+
this.checkout({
|
|
226
|
+
amount,
|
|
227
|
+
merchantId,
|
|
228
|
+
platformId,
|
|
229
|
+
currency,
|
|
230
|
+
brandColor,
|
|
231
|
+
...checkoutOptions,
|
|
232
|
+
onSuccess: (payment) => {
|
|
233
|
+
loading = false;
|
|
234
|
+
button.innerHTML = `<span>✓ Paid!</span>`;
|
|
235
|
+
button.style.background = '#10B981';
|
|
236
|
+
button.style.cursor = 'pointer';
|
|
237
|
+
onSuccess?.(payment);
|
|
238
|
+
// Reset after delay
|
|
239
|
+
setTimeout(() => {
|
|
240
|
+
button.innerHTML = `${createWalletIcon()}<span>${buttonLabel}</span>`;
|
|
241
|
+
button.style.background = variant === 'solid'
|
|
242
|
+
? `linear-gradient(135deg, ${brandColor} 0%, ${adjustColor(brandColor, -20)} 100%)`
|
|
243
|
+
: variant === 'outline' ? 'transparent' : `${brandColor}15`;
|
|
244
|
+
}, 3000);
|
|
245
|
+
},
|
|
246
|
+
onCancel: () => {
|
|
247
|
+
loading = false;
|
|
248
|
+
button.innerHTML = `${createWalletIcon()}<span>${buttonLabel}</span>`;
|
|
249
|
+
button.style.cursor = 'pointer';
|
|
250
|
+
onCancel?.();
|
|
251
|
+
},
|
|
252
|
+
onError: (error) => {
|
|
253
|
+
loading = false;
|
|
254
|
+
button.innerHTML = `${createWalletIcon()}<span>${buttonLabel}</span>`;
|
|
255
|
+
button.style.cursor = 'pointer';
|
|
256
|
+
onError?.(error);
|
|
257
|
+
},
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
// Replace element content
|
|
261
|
+
element.innerHTML = '';
|
|
262
|
+
element.appendChild(button);
|
|
263
|
+
return button;
|
|
264
|
+
},
|
|
265
|
+
/**
|
|
266
|
+
* Auto-initialize buttons from data attributes
|
|
267
|
+
*/
|
|
268
|
+
init() {
|
|
269
|
+
// Find all elements with data-rotate-pay
|
|
270
|
+
const buttons = document.querySelectorAll('[data-rotate-pay]');
|
|
271
|
+
buttons.forEach((element) => {
|
|
272
|
+
const el = element;
|
|
273
|
+
const amount = parseFloat(el.dataset.amount || '0');
|
|
274
|
+
const merchantId = parseInt(el.dataset.merchant || '0');
|
|
275
|
+
const platformId = parseInt(el.dataset.platform || '0');
|
|
276
|
+
if (!amount || !merchantId || !platformId) {
|
|
277
|
+
console.warn('Rotate: Missing required data attributes (amount, merchant, platform)', el);
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
this.createButton({
|
|
281
|
+
element: el,
|
|
282
|
+
amount,
|
|
283
|
+
merchantId,
|
|
284
|
+
platformId,
|
|
285
|
+
currency: el.dataset.currency || 'USD',
|
|
286
|
+
label: el.dataset.label || el.textContent?.trim(),
|
|
287
|
+
size: el.dataset.size || 'md',
|
|
288
|
+
variant: el.dataset.variant || 'solid',
|
|
289
|
+
brandColor: el.dataset.color || '#8B5CF6',
|
|
290
|
+
brandName: el.dataset.brand,
|
|
291
|
+
description: el.dataset.description,
|
|
292
|
+
orderRef: el.dataset.ref,
|
|
293
|
+
allowTips: el.dataset.tips === 'true',
|
|
294
|
+
successUrl: el.dataset.successUrl,
|
|
295
|
+
cancelUrl: el.dataset.cancelUrl,
|
|
296
|
+
popup: el.dataset.popup !== 'false',
|
|
297
|
+
});
|
|
298
|
+
});
|
|
299
|
+
},
|
|
300
|
+
};
|
|
301
|
+
// Auto-initialize on DOMContentLoaded
|
|
302
|
+
if (typeof window !== 'undefined') {
|
|
303
|
+
if (document.readyState === 'loading') {
|
|
304
|
+
document.addEventListener('DOMContentLoaded', () => Rotate.init());
|
|
305
|
+
}
|
|
306
|
+
else {
|
|
307
|
+
Rotate.init();
|
|
308
|
+
}
|
|
309
|
+
// Expose globally
|
|
310
|
+
window.Rotate = Rotate;
|
|
311
|
+
}
|
|
312
|
+
exports.default = Rotate;
|
|
313
|
+
//# sourceMappingURL=embed.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embed.js","sourceRoot":"","sources":["../src/embed.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;;AAsCH,mDAAmD;AAEnD,MAAM,kBAAkB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AAC,KAAK,KAAK,OAAO;aACpC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF,CAAC;AAEF,sCAAsC;AACtC,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;IAClC,IAAI,QAAQ,CAAC,UAAU,KAAK,SAAS,EAAE,CAAC;QACtC,QAAQ,CAAC,gBAAgB,CAAC,kBAAkB,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;IACrE,CAAC;SAAM,CAAC;QACN,MAAM,CAAC,IAAI,EAAE,CAAC;IAChB,CAAC;IAED,kBAAkB;IACjB,MAAc,CAAC,MAAM,GAAG,MAAM,CAAC;AAClC,CAAC;AAED,kBAAe,MAAM,CAAC"}
|
package/dist/hooks.d.ts
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rotate React Hooks — Store, Cart & Marketplace
|
|
3
|
+
*
|
|
4
|
+
* Drop-in React hooks for building storefronts and marketplaces.
|
|
5
|
+
* Think of these as a ready-made React integration for Solana payments.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```tsx
|
|
9
|
+
* function ProductPage() {
|
|
10
|
+
* const { products, getByCategory } = useProducts(store);
|
|
11
|
+
* const { cart, addItem, totals, checkout } = useCart(store);
|
|
12
|
+
*
|
|
13
|
+
* return (
|
|
14
|
+
* <div>
|
|
15
|
+
* {getByCategory('shirts').map(p => (
|
|
16
|
+
* <button key={p.id} onClick={() => addItem(p.id)}>
|
|
17
|
+
* {p.name} — ${p.price}
|
|
18
|
+
* </button>
|
|
19
|
+
* ))}
|
|
20
|
+
* <p>Cart: {totals.totalQuantity} items, ${totals.total}</p>
|
|
21
|
+
* <button onClick={() => checkout()}>Pay Now</button>
|
|
22
|
+
* </div>
|
|
23
|
+
* );
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @packageDocumentation
|
|
28
|
+
*/
|
|
29
|
+
import { RotateStore, RotateCart, Product, LineItem, CartTotals, CheckoutResult, Currency } from './store';
|
|
30
|
+
import { RotateMarketplace, MarketplaceCart, MarketplaceProduct, MarketplaceLineItem, MarketplaceCartTotals, MarketplaceCheckoutResult, Vendor } from './marketplace';
|
|
31
|
+
export interface UseProductsReturn {
|
|
32
|
+
/** All active products */
|
|
33
|
+
products: Product[];
|
|
34
|
+
/** All categories */
|
|
35
|
+
categories: string[];
|
|
36
|
+
/** Get product by ID */
|
|
37
|
+
getProduct: (id: string) => Product | undefined;
|
|
38
|
+
/** Get products by category */
|
|
39
|
+
getByCategory: (category: string) => Product[];
|
|
40
|
+
/** Search products */
|
|
41
|
+
search: (query: string) => Product[];
|
|
42
|
+
/** Paginated product listing */
|
|
43
|
+
paginate: (page: number, perPage: number) => {
|
|
44
|
+
products: Product[];
|
|
45
|
+
totalPages: number;
|
|
46
|
+
total: number;
|
|
47
|
+
};
|
|
48
|
+
/** Check stock */
|
|
49
|
+
isInStock: (productId: string, qty?: number) => boolean;
|
|
50
|
+
/** Total product count */
|
|
51
|
+
count: number;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Hook for browsing products in a RotateStore.
|
|
55
|
+
*/
|
|
56
|
+
export declare function useProducts(store: RotateStore): UseProductsReturn;
|
|
57
|
+
export interface UseCartReturn {
|
|
58
|
+
/** The underlying cart instance */
|
|
59
|
+
cart: RotateCart;
|
|
60
|
+
/** Current line items */
|
|
61
|
+
items: LineItem[];
|
|
62
|
+
/** Calculated totals */
|
|
63
|
+
totals: CartTotals;
|
|
64
|
+
/** Is the cart empty */
|
|
65
|
+
isEmpty: boolean;
|
|
66
|
+
/** Add item to cart */
|
|
67
|
+
addItem: (productId: string, quantity?: number) => void;
|
|
68
|
+
/** Set exact quantity */
|
|
69
|
+
setQuantity: (productId: string, quantity: number) => void;
|
|
70
|
+
/** Remove item */
|
|
71
|
+
removeItem: (productId: string) => void;
|
|
72
|
+
/** Clear entire cart */
|
|
73
|
+
clear: () => void;
|
|
74
|
+
/** Apply discount code */
|
|
75
|
+
applyDiscount: (code: string) => boolean;
|
|
76
|
+
/** Remove discount */
|
|
77
|
+
removeDiscount: (code: string) => boolean;
|
|
78
|
+
/** Set metadata */
|
|
79
|
+
setMetadata: (key: string, value: string) => void;
|
|
80
|
+
/** Checkout and create on-chain payment link */
|
|
81
|
+
checkout: (options?: {
|
|
82
|
+
currency?: Currency;
|
|
83
|
+
expiresIn?: number;
|
|
84
|
+
allowTips?: boolean;
|
|
85
|
+
orderRef?: string;
|
|
86
|
+
}) => Promise<CheckoutResult>;
|
|
87
|
+
/** Whether checkout is in progress */
|
|
88
|
+
checkingOut: boolean;
|
|
89
|
+
/** Last checkout result */
|
|
90
|
+
lastCheckout: CheckoutResult | null;
|
|
91
|
+
/** Error from last operation */
|
|
92
|
+
error: string | null;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Hook for managing a shopping cart backed by a RotateStore.
|
|
96
|
+
*/
|
|
97
|
+
export declare function useCart(store: RotateStore): UseCartReturn;
|
|
98
|
+
export interface UseMarketplaceReturn {
|
|
99
|
+
/** All vendors */
|
|
100
|
+
vendors: Vendor[];
|
|
101
|
+
/** All marketplace products */
|
|
102
|
+
products: MarketplaceProduct[];
|
|
103
|
+
/** Categories */
|
|
104
|
+
categories: string[];
|
|
105
|
+
/** Get products by vendor */
|
|
106
|
+
getVendorProducts: (vendorId: string) => MarketplaceProduct[];
|
|
107
|
+
/** Search products across all vendors */
|
|
108
|
+
search: (query: string) => MarketplaceProduct[];
|
|
109
|
+
/** Check stock */
|
|
110
|
+
isInStock: (productId: string, qty?: number) => boolean;
|
|
111
|
+
/** Get a specific vendor */
|
|
112
|
+
getVendor: (id: string) => Vendor | undefined;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Hook for browsing a marketplace catalog.
|
|
116
|
+
*/
|
|
117
|
+
export declare function useMarketplace(marketplace: RotateMarketplace): UseMarketplaceReturn;
|
|
118
|
+
export interface UseMarketplaceCartReturn {
|
|
119
|
+
/** The underlying marketplace cart */
|
|
120
|
+
cart: MarketplaceCart;
|
|
121
|
+
/** Current line items with vendor info */
|
|
122
|
+
items: MarketplaceLineItem[];
|
|
123
|
+
/** Per-vendor + combined totals */
|
|
124
|
+
totals: MarketplaceCartTotals;
|
|
125
|
+
/** Is empty */
|
|
126
|
+
isEmpty: boolean;
|
|
127
|
+
/** Number of unique vendors in cart */
|
|
128
|
+
vendorCount: number;
|
|
129
|
+
/** Add item */
|
|
130
|
+
addItem: (productId: string, quantity?: number) => void;
|
|
131
|
+
/** Set quantity */
|
|
132
|
+
setQuantity: (productId: string, quantity: number) => void;
|
|
133
|
+
/** Remove item */
|
|
134
|
+
removeItem: (productId: string) => void;
|
|
135
|
+
/** Clear */
|
|
136
|
+
clear: () => void;
|
|
137
|
+
/** Checkout — creates one payment link per vendor */
|
|
138
|
+
checkout: (options?: {
|
|
139
|
+
currency?: Currency;
|
|
140
|
+
expiresIn?: number;
|
|
141
|
+
allowTips?: boolean;
|
|
142
|
+
orderRef?: string;
|
|
143
|
+
}) => Promise<MarketplaceCheckoutResult>;
|
|
144
|
+
/** Whether checkout is in progress */
|
|
145
|
+
checkingOut: boolean;
|
|
146
|
+
/** Last checkout result */
|
|
147
|
+
lastCheckout: MarketplaceCheckoutResult | null;
|
|
148
|
+
/** Error */
|
|
149
|
+
error: string | null;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Hook for managing a multi-vendor marketplace cart.
|
|
153
|
+
*/
|
|
154
|
+
export declare function useMarketplaceCart(marketplace: RotateMarketplace): UseMarketplaceCartReturn;
|
|
155
|
+
export { RotateStore, RotateCart, RotateMarketplace, MarketplaceCart, };
|
|
156
|
+
//# sourceMappingURL=hooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;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