@superlogic/spree-pay 0.1.39 → 0.2.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 CHANGED
@@ -33,17 +33,33 @@ function Checkout() {
33
33
  }
34
34
 
35
35
  function CheckoutContent() {
36
- const { process, selectedPaymentMethod, isProcessing } = useSpreePay(); // Access payment process function and processing state (must be inside provider)
36
+ const { process, selectedPaymentMethod, isProcessing, enabled } = useSpreePay();
37
37
  const [status, setStatus] = useState<'idle' | 'processing' | 'success' | 'error'>('idle');
38
38
 
39
39
  async function handleProcess() {
40
+ if (!enabled) {
41
+ console.log('Please select a payment method');
42
+ return;
43
+ }
44
+
40
45
  setStatus('processing');
41
46
  try {
42
47
  // Example: create order and process payment
43
48
  const order = await getOrderHash();
44
- await process({ hash: order.hash });
49
+ const result = await process({
50
+ hash: order.hash,
51
+ capture: true, // Optional: auto-capture payment
52
+ metadata: { orderId: order.id }, // Optional: additional data
53
+ });
54
+
55
+ console.log('Payment result:', result);
56
+ // result.status: AUTHORIZED or CAPTURED
57
+ // result.paymentId: unique payment identifier
58
+ // result.paymentType: CREDIT_CARD, CRYPTO, CDC, etc.
59
+
45
60
  setStatus('success');
46
61
  } catch (err) {
62
+ console.error('Payment failed:', err);
47
63
  setStatus('error');
48
64
  }
49
65
  }
@@ -56,6 +72,8 @@ function CheckoutContent() {
56
72
  transactionFeePercentage={0.04}
57
73
  className="w-full max-w-[540px]"
58
74
  isProcessing={status === 'processing'}
75
+ disabledPoints={false}
76
+ topUpLink="/top-up"
59
77
  />
60
78
  {status === 'success' && <p>Payment successful! Thank you for your order.</p>}
61
79
  {status === 'error' && <p>Payment failed. Please try again.</p>}
@@ -68,7 +86,7 @@ export default function ThreeDSRedirectPage() {
68
86
  // take payment intent from search params as payment_intent
69
87
  const searchParams = exampleGetSearchParams();
70
88
 
71
- // place that hook, it will take paymentIntent and close 3ds modal
89
+ // Pass the entire search params object to the hook
72
90
  useCapture3DS({ paymentIntent: searchParams['payment_intent'] });
73
91
 
74
92
  // Render null or any other UI/Loader
@@ -78,11 +96,140 @@ export default function ThreeDSRedirectPage() {
78
96
 
79
97
  ### SpreePay props
80
98
 
81
- - amount: number — USD amount to charge (e.g., 99 for $99). Used for display and fee calculation.
82
- - onProcess: () => Promise<void> — Called when the Checkout button is clicked. Implement your order flow here and call useSpreePay().process({ hash, ... }).
83
- - isProcessing: boolean Optional, shows a loading state and disables interactions when true (useful while your onProcess runs).
84
- - transactionFeePercentage: number Optional fee multiplier applied to the USD portion (e.g., 0.04 for 4%).
85
- - className: string Optional wrapper class for layout/styling.
99
+ ```typescript
100
+ type SpreePayProps = {
101
+ amount?: number; // USD amount to charge (e.g., 99 for $99). Used for display and fee calculation.
102
+ onProcess?: () => Promise<void>; // Called when the Checkout button is clicked. Implement your order flow here and call useSpreePay().process({ hash, ... }).
103
+ isProcessing?: boolean; // Shows a loading state and disables interactions when true (useful while your onProcess runs).
104
+ transactionFeePercentage?: number; // Fee multiplier applied to the USD portion (e.g., 0.04 for 4%).
105
+ disabledPoints?: boolean; // Disables points payment option if true.
106
+ topUpLink?: string; // Optional link to top-up page for points balance.
107
+ className?: string; // Optional wrapper class for layout/styling.
108
+ };
109
+ ```
110
+
111
+ ## API Reference
112
+
113
+ ### SpreePayProvider Props
114
+
115
+ ```typescript
116
+ type ENV = {
117
+ environment: 'dev' | 'stg' | 'prod'; // Environment for API endpoints and logging
118
+ tenantId: 'bookit' | 'moca' | 'qiibee' | 'umhp' | 'cdc'; // Tenant identifier
119
+ ssoPageURI: string; // Path to Keycloak SSO page (e.g., '/silent-check-sso.html')
120
+ redirect3dsURI: string; // Path to 3DS redirect handler (e.g., '/3ds')
121
+ accessToken?: string; // Optional: provide pre-authenticated token to skip Keycloak SSO
122
+ useWeb3Points?: boolean; // Optional: enable Web3-based points (default: true)
123
+ };
124
+ ```
125
+
126
+ ### useSpreePay Hook
127
+
128
+ ```typescript
129
+ const {
130
+ process, // Function to trigger payment processing
131
+ isProcessing, // Internal processing state (true while payment is being processed)
132
+ enabled, // true if a payment method is selected and ready
133
+ selectedPaymentMethod, // Currently selected payment method details
134
+ } = useSpreePay();
135
+
136
+ // process function signature:
137
+ async function process(params: ProcessFnParams): Promise<PaymentMethodResult>;
138
+
139
+ type ProcessFnParams = {
140
+ hash: string; // Order hash from your backend
141
+ capture?: boolean; // Optional: auto-capture payment (default: false)
142
+ metadata?: Record<string, unknown>; // Optional: additional metadata to pass through
143
+ };
144
+
145
+ type PaymentMethodResult = {
146
+ status: SlapiPaymentStatus; // Payment status (AUTHORIZED, CAPTURED, FAILED, etc.)
147
+ paymentId: string; // Unique payment identifier
148
+ txHash: string | null; // Transaction hash (for crypto payments)
149
+ txId: string | null; // Transaction ID
150
+ paymentType: PaymentType; // Type of payment used
151
+ };
152
+ ```
153
+
154
+ ### Payment Types & Statuses
155
+
156
+ ```typescript
157
+ enum PaymentType {
158
+ CREDIT_CARD = 'CREDIT_CARD',
159
+ CRYPTO = 'CRYPTO',
160
+ CDC = 'CDC', // Crypto.com Pay
161
+ CREDIT_CARD_SPLIT = 'SPLIT', // Split payment (card + points)
162
+ POINTS = 'POINTS',
163
+ }
164
+
165
+ enum SlapiPaymentStatus {
166
+ AUTHORIZED = 'AUTHORIZED', // Payment authorized (success)
167
+ CAPTURED = 'CAPTURED', // Payment captured (success)
168
+ FAILED = 'FAILED', // Payment failed
169
+ PENDING = 'PENDING', // Payment pending (backend only)
170
+ NOT_INITIALIZED = 'NOT_INITIALIZED', // Not yet started (backend only)
171
+ VOIDED = 'VOIDED', // Payment voided (backend only)
172
+ CAPTURE_FAILED = 'CAPTURE_FAILED', // Capture failed (backend only)
173
+ }
174
+ ```
175
+
176
+ ### useCapture3DS Hook
177
+
178
+ ```typescript
179
+ // Use in your 3DS redirect page to capture payment intent and close the modal
180
+ useCapture3DS(searchParams: Record<string, string | null>);
181
+ ```
182
+
183
+ ### Logger API
184
+
185
+ ```typescript
186
+ import { LogLevel, configureLogger, logger } from '@superlogic/spree-pay';
187
+
188
+ // Configure logging behavior
189
+ configureLogger({
190
+ environment: 'dev', // 'prod' = ERROR only, 'dev'/'stg' = all logs
191
+ minLevel: LogLevel.DEBUG, // Optional: override default log level
192
+ });
193
+
194
+ // Use the logger
195
+ logger.debug('Debug message', { context: 'data' });
196
+ logger.info('Info message');
197
+ logger.warn('Warning message');
198
+ logger.error('Error message', error);
199
+
200
+ // Create child logger with prefix
201
+ const componentLogger = logger.child('MyComponent');
202
+ componentLogger.info('Component initialized');
203
+
204
+ enum LogLevel {
205
+ DEBUG = 0,
206
+ INFO = 1,
207
+ WARN = 2,
208
+ ERROR = 3,
209
+ NONE = 4,
210
+ }
211
+ ```
212
+
213
+ ## Theme Customization
214
+
215
+ The widget uses CSS variables for theming. You can override the default theme by wrapping the `<SpreePay>` component in a container with custom CSS variables:
216
+
217
+ ```tsx
218
+ <div
219
+ style={
220
+ {
221
+ '--primary': '#your-color',
222
+ '--accent': '#your-accent',
223
+ '--s-default': '#your-surface-color',
224
+ // ... see packages/spree-pay/src/styles/globals.css for all 54 variables
225
+ } as React.CSSProperties
226
+ }
227
+ >
228
+ <SpreePay {...props} />
229
+ </div>
230
+ ```
231
+
232
+ All available CSS variables are documented in `packages/spree-pay/src/styles/globals.css:21-81`.
86
233
 
87
234
  ## Keycloak SSO page example (/silent-check-sso.html)
88
235