@cimplify/sdk 0.6.2 → 0.6.3

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/react.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { eB as AdSlot, eC as AdPosition, eG as AdContextValue, y as CimplifyElements, C as CimplifyClient, J as ElementsOptions, ev as AuthenticatedData, et as AddressInfo, eu as PaymentMethodInfo, ex as ElementsCheckoutResult } from './ads-CXOn6J7P.mjs';
2
- export { eE as AdConfig } from './ads-CXOn6J7P.mjs';
1
+ import { eJ as AdSlot, eK as AdPosition, eO as AdContextValue, C as CimplifyClient, a2 as ProcessCheckoutResult, a4 as CheckoutStatus, a5 as CheckoutStatusContext, y as CimplifyElements, J as ElementsOptions, eD as AuthenticatedData, ez as AddressInfo, eA as PaymentMethodInfo, eF as ElementsCheckoutResult, a1 as ProcessCheckoutOptions } from './ads-Cz14AMnc.mjs';
2
+ export { eM as AdConfig } from './ads-Cz14AMnc.mjs';
3
3
  import React, { ReactNode } from 'react';
4
4
 
5
5
  interface UserIdentity {
@@ -47,6 +47,32 @@ interface AdProps {
47
47
  }
48
48
  declare function Ad({ slot, position, className, style, fallback, onImpression, onClick, }: AdProps): React.ReactElement | null;
49
49
 
50
+ type CheckoutOrderType = "pickup" | "delivery" | "dine_in";
51
+ interface CimplifyCheckoutProps {
52
+ client: CimplifyClient;
53
+ businessId: string;
54
+ cartId: string;
55
+ locationId?: string;
56
+ orderTypes?: CheckoutOrderType[];
57
+ enrollInLink?: boolean;
58
+ onComplete: (result: ProcessCheckoutResult) => void;
59
+ onError?: (error: {
60
+ code: string;
61
+ message: string;
62
+ }) => void;
63
+ onStatusChange?: (status: CheckoutStatus, context: CheckoutStatusContext) => void;
64
+ appearance?: {
65
+ theme?: "light" | "dark";
66
+ variables?: {
67
+ primaryColor?: string;
68
+ fontFamily?: string;
69
+ borderRadius?: string;
70
+ };
71
+ };
72
+ className?: string;
73
+ }
74
+ declare function CimplifyCheckout({ client, businessId, cartId, locationId, orderTypes, enrollInLink, onComplete, onError, onStatusChange, appearance, className, }: CimplifyCheckoutProps): React.ReactElement;
75
+
50
76
  declare function useElements(): CimplifyElements | null;
51
77
  declare function useElementsReady(): boolean;
52
78
  interface ElementsProviderProps {
@@ -99,7 +125,8 @@ declare function useCheckout(): {
99
125
  tip_amount?: number;
100
126
  notes?: string;
101
127
  }) => Promise<ElementsCheckoutResult>;
128
+ process: (options: ProcessCheckoutOptions) => Promise<ProcessCheckoutResult>;
102
129
  isLoading: boolean;
103
130
  };
104
131
 
105
- export { Ad, AdPosition, type AdProps, AdProvider, AdSlot, AddressElement, AuthElement, ElementsProvider, PaymentElement, useAds, useCheckout, useElements, useElementsReady };
132
+ export { Ad, AdPosition, type AdProps, AdProvider, AdSlot, AddressElement, AuthElement, CimplifyCheckout, type CimplifyCheckoutProps, ElementsProvider, PaymentElement, useAds, useCheckout, useElements, useElementsReady };
package/dist/react.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { eB as AdSlot, eC as AdPosition, eG as AdContextValue, y as CimplifyElements, C as CimplifyClient, J as ElementsOptions, ev as AuthenticatedData, et as AddressInfo, eu as PaymentMethodInfo, ex as ElementsCheckoutResult } from './ads-CXOn6J7P.js';
2
- export { eE as AdConfig } from './ads-CXOn6J7P.js';
1
+ import { eJ as AdSlot, eK as AdPosition, eO as AdContextValue, C as CimplifyClient, a2 as ProcessCheckoutResult, a4 as CheckoutStatus, a5 as CheckoutStatusContext, y as CimplifyElements, J as ElementsOptions, eD as AuthenticatedData, ez as AddressInfo, eA as PaymentMethodInfo, eF as ElementsCheckoutResult, a1 as ProcessCheckoutOptions } from './ads-Cz14AMnc.js';
2
+ export { eM as AdConfig } from './ads-Cz14AMnc.js';
3
3
  import React, { ReactNode } from 'react';
4
4
 
5
5
  interface UserIdentity {
@@ -47,6 +47,32 @@ interface AdProps {
47
47
  }
48
48
  declare function Ad({ slot, position, className, style, fallback, onImpression, onClick, }: AdProps): React.ReactElement | null;
49
49
 
50
+ type CheckoutOrderType = "pickup" | "delivery" | "dine_in";
51
+ interface CimplifyCheckoutProps {
52
+ client: CimplifyClient;
53
+ businessId: string;
54
+ cartId: string;
55
+ locationId?: string;
56
+ orderTypes?: CheckoutOrderType[];
57
+ enrollInLink?: boolean;
58
+ onComplete: (result: ProcessCheckoutResult) => void;
59
+ onError?: (error: {
60
+ code: string;
61
+ message: string;
62
+ }) => void;
63
+ onStatusChange?: (status: CheckoutStatus, context: CheckoutStatusContext) => void;
64
+ appearance?: {
65
+ theme?: "light" | "dark";
66
+ variables?: {
67
+ primaryColor?: string;
68
+ fontFamily?: string;
69
+ borderRadius?: string;
70
+ };
71
+ };
72
+ className?: string;
73
+ }
74
+ declare function CimplifyCheckout({ client, businessId, cartId, locationId, orderTypes, enrollInLink, onComplete, onError, onStatusChange, appearance, className, }: CimplifyCheckoutProps): React.ReactElement;
75
+
50
76
  declare function useElements(): CimplifyElements | null;
51
77
  declare function useElementsReady(): boolean;
52
78
  interface ElementsProviderProps {
@@ -99,7 +125,8 @@ declare function useCheckout(): {
99
125
  tip_amount?: number;
100
126
  notes?: string;
101
127
  }) => Promise<ElementsCheckoutResult>;
128
+ process: (options: ProcessCheckoutOptions) => Promise<ProcessCheckoutResult>;
102
129
  isLoading: boolean;
103
130
  };
104
131
 
105
- export { Ad, AdPosition, type AdProps, AdProvider, AdSlot, AddressElement, AuthElement, ElementsProvider, PaymentElement, useAds, useCheckout, useElements, useElementsReady };
132
+ export { Ad, AdPosition, type AdProps, AdProvider, AdSlot, AddressElement, AuthElement, CimplifyCheckout, type CimplifyCheckoutProps, ElementsProvider, PaymentElement, useAds, useCheckout, useElements, useElementsReady };
package/dist/react.js CHANGED
@@ -317,6 +317,202 @@ function Ad({
317
317
  }
318
318
  );
319
319
  }
320
+ function labelForOrderType(orderType) {
321
+ if (orderType === "dine_in") {
322
+ return "Dine In";
323
+ }
324
+ if (orderType === "pickup") {
325
+ return "Pickup";
326
+ }
327
+ return "Delivery";
328
+ }
329
+ function statusToLabel(status) {
330
+ if (!status) {
331
+ return "";
332
+ }
333
+ if (status === "preparing") {
334
+ return "Preparing checkout";
335
+ }
336
+ if (status === "recovering") {
337
+ return "Resuming payment";
338
+ }
339
+ if (status === "processing") {
340
+ return "Processing payment";
341
+ }
342
+ if (status === "awaiting_authorization") {
343
+ return "Waiting for authorization";
344
+ }
345
+ if (status === "polling") {
346
+ return "Confirming payment";
347
+ }
348
+ if (status === "finalizing") {
349
+ return "Finalizing order";
350
+ }
351
+ if (status === "success") {
352
+ return "Payment complete";
353
+ }
354
+ return "Payment failed";
355
+ }
356
+ function CimplifyCheckout({
357
+ client,
358
+ businessId,
359
+ cartId,
360
+ locationId,
361
+ orderTypes,
362
+ enrollInLink = true,
363
+ onComplete,
364
+ onError,
365
+ onStatusChange,
366
+ appearance,
367
+ className
368
+ }) {
369
+ const resolvedOrderTypes = react.useMemo(
370
+ () => orderTypes && orderTypes.length > 0 ? orderTypes : ["pickup", "delivery"],
371
+ [orderTypes]
372
+ );
373
+ const [orderType, setOrderType] = react.useState(resolvedOrderTypes[0] || "pickup");
374
+ const [status, setStatus] = react.useState(null);
375
+ const [isSubmitting, setIsSubmitting] = react.useState(false);
376
+ const [errorMessage, setErrorMessage] = react.useState(null);
377
+ const authMountRef = react.useRef(null);
378
+ const addressMountRef = react.useRef(null);
379
+ const paymentMountRef = react.useRef(null);
380
+ const elementsRef = react.useRef(null);
381
+ const activeCheckoutRef = react.useRef(null);
382
+ react.useEffect(() => {
383
+ if (!resolvedOrderTypes.includes(orderType)) {
384
+ setOrderType(resolvedOrderTypes[0] || "pickup");
385
+ }
386
+ }, [resolvedOrderTypes, orderType]);
387
+ react.useEffect(() => {
388
+ const elements = client.elements(businessId, { appearance });
389
+ elementsRef.current = elements;
390
+ const auth = elements.create("auth");
391
+ const address = elements.create("address", { mode: "shipping" });
392
+ const payment = elements.create("payment");
393
+ if (authMountRef.current) {
394
+ auth.mount(authMountRef.current);
395
+ }
396
+ if (addressMountRef.current) {
397
+ address.mount(addressMountRef.current);
398
+ }
399
+ if (paymentMountRef.current) {
400
+ payment.mount(paymentMountRef.current);
401
+ }
402
+ return () => {
403
+ activeCheckoutRef.current?.abort();
404
+ activeCheckoutRef.current = null;
405
+ elements.destroy();
406
+ elementsRef.current = null;
407
+ };
408
+ }, [client, businessId, appearance]);
409
+ const handleStatusChange = react.useCallback(
410
+ (nextStatus, context) => {
411
+ setStatus(nextStatus);
412
+ onStatusChange?.(nextStatus, context);
413
+ },
414
+ [onStatusChange]
415
+ );
416
+ const handleSubmit = react.useCallback(async () => {
417
+ if (!elementsRef.current || isSubmitting) {
418
+ return;
419
+ }
420
+ setErrorMessage(null);
421
+ setIsSubmitting(true);
422
+ setStatus("preparing");
423
+ const checkout = elementsRef.current.processCheckout({
424
+ cart_id: cartId,
425
+ location_id: locationId,
426
+ order_type: orderType,
427
+ enroll_in_link: enrollInLink,
428
+ on_status_change: handleStatusChange
429
+ });
430
+ activeCheckoutRef.current = checkout;
431
+ try {
432
+ const result = await checkout;
433
+ if (result.success) {
434
+ onComplete(result);
435
+ return;
436
+ }
437
+ const code = result.error?.code || "CHECKOUT_FAILED";
438
+ const message = result.error?.message || "Payment failed.";
439
+ setErrorMessage(message);
440
+ onError?.({ code, message });
441
+ } finally {
442
+ activeCheckoutRef.current = null;
443
+ setIsSubmitting(false);
444
+ }
445
+ }, [
446
+ cartId,
447
+ enrollInLink,
448
+ handleStatusChange,
449
+ isSubmitting,
450
+ locationId,
451
+ onComplete,
452
+ onError,
453
+ orderType
454
+ ]);
455
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className, "data-cimplify-checkout": "", children: [
456
+ /* @__PURE__ */ jsxRuntime.jsx("div", { "data-cimplify-section": "auth", children: /* @__PURE__ */ jsxRuntime.jsx("div", { ref: authMountRef }) }),
457
+ /* @__PURE__ */ jsxRuntime.jsx("div", { "data-cimplify-section": "order-type", style: { marginTop: "12px" }, children: /* @__PURE__ */ jsxRuntime.jsx(
458
+ "div",
459
+ {
460
+ role: "group",
461
+ "aria-label": "Order type",
462
+ style: { display: "flex", gap: "8px", flexWrap: "wrap" },
463
+ children: resolvedOrderTypes.map((type) => /* @__PURE__ */ jsxRuntime.jsx(
464
+ "button",
465
+ {
466
+ type: "button",
467
+ onClick: () => setOrderType(type),
468
+ disabled: isSubmitting,
469
+ "data-selected": orderType === type ? "true" : "false",
470
+ style: {
471
+ padding: "8px 12px",
472
+ borderRadius: "8px",
473
+ border: "1px solid #d4d4d8",
474
+ background: orderType === type ? "#111827" : "#ffffff",
475
+ color: orderType === type ? "#ffffff" : "#111827",
476
+ cursor: isSubmitting ? "not-allowed" : "pointer",
477
+ opacity: isSubmitting ? 0.6 : 1
478
+ },
479
+ children: labelForOrderType(type)
480
+ },
481
+ type
482
+ ))
483
+ }
484
+ ) }),
485
+ /* @__PURE__ */ jsxRuntime.jsx(
486
+ "div",
487
+ {
488
+ "data-cimplify-section": "address",
489
+ style: { marginTop: "12px", display: orderType === "delivery" ? "block" : "none" },
490
+ children: /* @__PURE__ */ jsxRuntime.jsx("div", { ref: addressMountRef })
491
+ }
492
+ ),
493
+ /* @__PURE__ */ jsxRuntime.jsx("div", { "data-cimplify-section": "payment", style: { marginTop: "12px" }, children: /* @__PURE__ */ jsxRuntime.jsx("div", { ref: paymentMountRef }) }),
494
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: { marginTop: "12px" }, children: /* @__PURE__ */ jsxRuntime.jsx(
495
+ "button",
496
+ {
497
+ type: "button",
498
+ onClick: handleSubmit,
499
+ disabled: isSubmitting,
500
+ style: {
501
+ width: "100%",
502
+ padding: "10px 14px",
503
+ borderRadius: "8px",
504
+ border: "none",
505
+ background: isSubmitting ? "#a1a1aa" : "#111827",
506
+ color: "#ffffff",
507
+ cursor: isSubmitting ? "not-allowed" : "pointer"
508
+ },
509
+ children: isSubmitting ? "Processing..." : "Complete Order"
510
+ }
511
+ ) }),
512
+ status && /* @__PURE__ */ jsxRuntime.jsx("p", { "data-cimplify-status": "", style: { marginTop: "10px", fontSize: "14px", color: "#52525b" }, children: statusToLabel(status) }),
513
+ errorMessage && /* @__PURE__ */ jsxRuntime.jsx("p", { "data-cimplify-error": "", style: { marginTop: "8px", fontSize: "14px", color: "#b91c1c" }, children: errorMessage })
514
+ ] });
515
+ }
320
516
  var ElementsContext = react.createContext({
321
517
  elements: null,
322
518
  isReady: false
@@ -432,13 +628,31 @@ function useCheckout() {
432
628
  },
433
629
  [elements]
434
630
  );
435
- return { submit, isLoading };
631
+ const process = react.useCallback(
632
+ async (options) => {
633
+ if (!elements) {
634
+ return {
635
+ success: false,
636
+ error: { code: "NO_ELEMENTS", message: "Elements not initialized", recoverable: false }
637
+ };
638
+ }
639
+ setIsLoading(true);
640
+ try {
641
+ return await elements.processCheckout(options);
642
+ } finally {
643
+ setIsLoading(false);
644
+ }
645
+ },
646
+ [elements]
647
+ );
648
+ return { submit, process, isLoading };
436
649
  }
437
650
 
438
651
  exports.Ad = Ad;
439
652
  exports.AdProvider = AdProvider;
440
653
  exports.AddressElement = AddressElement;
441
654
  exports.AuthElement = AuthElement;
655
+ exports.CimplifyCheckout = CimplifyCheckout;
442
656
  exports.ElementsProvider = ElementsProvider;
443
657
  exports.PaymentElement = PaymentElement;
444
658
  exports.useAds = useAds;
package/dist/react.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { createContext, useContext, useState, useEffect, useRef, useCallback } from 'react';
2
- import { jsx, Fragment } from 'react/jsx-runtime';
1
+ import { createContext, useContext, useState, useEffect, useRef, useMemo, useCallback } from 'react';
2
+ import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
3
3
 
4
4
  // src/react/index.tsx
5
5
 
@@ -315,6 +315,202 @@ function Ad({
315
315
  }
316
316
  );
317
317
  }
318
+ function labelForOrderType(orderType) {
319
+ if (orderType === "dine_in") {
320
+ return "Dine In";
321
+ }
322
+ if (orderType === "pickup") {
323
+ return "Pickup";
324
+ }
325
+ return "Delivery";
326
+ }
327
+ function statusToLabel(status) {
328
+ if (!status) {
329
+ return "";
330
+ }
331
+ if (status === "preparing") {
332
+ return "Preparing checkout";
333
+ }
334
+ if (status === "recovering") {
335
+ return "Resuming payment";
336
+ }
337
+ if (status === "processing") {
338
+ return "Processing payment";
339
+ }
340
+ if (status === "awaiting_authorization") {
341
+ return "Waiting for authorization";
342
+ }
343
+ if (status === "polling") {
344
+ return "Confirming payment";
345
+ }
346
+ if (status === "finalizing") {
347
+ return "Finalizing order";
348
+ }
349
+ if (status === "success") {
350
+ return "Payment complete";
351
+ }
352
+ return "Payment failed";
353
+ }
354
+ function CimplifyCheckout({
355
+ client,
356
+ businessId,
357
+ cartId,
358
+ locationId,
359
+ orderTypes,
360
+ enrollInLink = true,
361
+ onComplete,
362
+ onError,
363
+ onStatusChange,
364
+ appearance,
365
+ className
366
+ }) {
367
+ const resolvedOrderTypes = useMemo(
368
+ () => orderTypes && orderTypes.length > 0 ? orderTypes : ["pickup", "delivery"],
369
+ [orderTypes]
370
+ );
371
+ const [orderType, setOrderType] = useState(resolvedOrderTypes[0] || "pickup");
372
+ const [status, setStatus] = useState(null);
373
+ const [isSubmitting, setIsSubmitting] = useState(false);
374
+ const [errorMessage, setErrorMessage] = useState(null);
375
+ const authMountRef = useRef(null);
376
+ const addressMountRef = useRef(null);
377
+ const paymentMountRef = useRef(null);
378
+ const elementsRef = useRef(null);
379
+ const activeCheckoutRef = useRef(null);
380
+ useEffect(() => {
381
+ if (!resolvedOrderTypes.includes(orderType)) {
382
+ setOrderType(resolvedOrderTypes[0] || "pickup");
383
+ }
384
+ }, [resolvedOrderTypes, orderType]);
385
+ useEffect(() => {
386
+ const elements = client.elements(businessId, { appearance });
387
+ elementsRef.current = elements;
388
+ const auth = elements.create("auth");
389
+ const address = elements.create("address", { mode: "shipping" });
390
+ const payment = elements.create("payment");
391
+ if (authMountRef.current) {
392
+ auth.mount(authMountRef.current);
393
+ }
394
+ if (addressMountRef.current) {
395
+ address.mount(addressMountRef.current);
396
+ }
397
+ if (paymentMountRef.current) {
398
+ payment.mount(paymentMountRef.current);
399
+ }
400
+ return () => {
401
+ activeCheckoutRef.current?.abort();
402
+ activeCheckoutRef.current = null;
403
+ elements.destroy();
404
+ elementsRef.current = null;
405
+ };
406
+ }, [client, businessId, appearance]);
407
+ const handleStatusChange = useCallback(
408
+ (nextStatus, context) => {
409
+ setStatus(nextStatus);
410
+ onStatusChange?.(nextStatus, context);
411
+ },
412
+ [onStatusChange]
413
+ );
414
+ const handleSubmit = useCallback(async () => {
415
+ if (!elementsRef.current || isSubmitting) {
416
+ return;
417
+ }
418
+ setErrorMessage(null);
419
+ setIsSubmitting(true);
420
+ setStatus("preparing");
421
+ const checkout = elementsRef.current.processCheckout({
422
+ cart_id: cartId,
423
+ location_id: locationId,
424
+ order_type: orderType,
425
+ enroll_in_link: enrollInLink,
426
+ on_status_change: handleStatusChange
427
+ });
428
+ activeCheckoutRef.current = checkout;
429
+ try {
430
+ const result = await checkout;
431
+ if (result.success) {
432
+ onComplete(result);
433
+ return;
434
+ }
435
+ const code = result.error?.code || "CHECKOUT_FAILED";
436
+ const message = result.error?.message || "Payment failed.";
437
+ setErrorMessage(message);
438
+ onError?.({ code, message });
439
+ } finally {
440
+ activeCheckoutRef.current = null;
441
+ setIsSubmitting(false);
442
+ }
443
+ }, [
444
+ cartId,
445
+ enrollInLink,
446
+ handleStatusChange,
447
+ isSubmitting,
448
+ locationId,
449
+ onComplete,
450
+ onError,
451
+ orderType
452
+ ]);
453
+ return /* @__PURE__ */ jsxs("div", { className, "data-cimplify-checkout": "", children: [
454
+ /* @__PURE__ */ jsx("div", { "data-cimplify-section": "auth", children: /* @__PURE__ */ jsx("div", { ref: authMountRef }) }),
455
+ /* @__PURE__ */ jsx("div", { "data-cimplify-section": "order-type", style: { marginTop: "12px" }, children: /* @__PURE__ */ jsx(
456
+ "div",
457
+ {
458
+ role: "group",
459
+ "aria-label": "Order type",
460
+ style: { display: "flex", gap: "8px", flexWrap: "wrap" },
461
+ children: resolvedOrderTypes.map((type) => /* @__PURE__ */ jsx(
462
+ "button",
463
+ {
464
+ type: "button",
465
+ onClick: () => setOrderType(type),
466
+ disabled: isSubmitting,
467
+ "data-selected": orderType === type ? "true" : "false",
468
+ style: {
469
+ padding: "8px 12px",
470
+ borderRadius: "8px",
471
+ border: "1px solid #d4d4d8",
472
+ background: orderType === type ? "#111827" : "#ffffff",
473
+ color: orderType === type ? "#ffffff" : "#111827",
474
+ cursor: isSubmitting ? "not-allowed" : "pointer",
475
+ opacity: isSubmitting ? 0.6 : 1
476
+ },
477
+ children: labelForOrderType(type)
478
+ },
479
+ type
480
+ ))
481
+ }
482
+ ) }),
483
+ /* @__PURE__ */ jsx(
484
+ "div",
485
+ {
486
+ "data-cimplify-section": "address",
487
+ style: { marginTop: "12px", display: orderType === "delivery" ? "block" : "none" },
488
+ children: /* @__PURE__ */ jsx("div", { ref: addressMountRef })
489
+ }
490
+ ),
491
+ /* @__PURE__ */ jsx("div", { "data-cimplify-section": "payment", style: { marginTop: "12px" }, children: /* @__PURE__ */ jsx("div", { ref: paymentMountRef }) }),
492
+ /* @__PURE__ */ jsx("div", { style: { marginTop: "12px" }, children: /* @__PURE__ */ jsx(
493
+ "button",
494
+ {
495
+ type: "button",
496
+ onClick: handleSubmit,
497
+ disabled: isSubmitting,
498
+ style: {
499
+ width: "100%",
500
+ padding: "10px 14px",
501
+ borderRadius: "8px",
502
+ border: "none",
503
+ background: isSubmitting ? "#a1a1aa" : "#111827",
504
+ color: "#ffffff",
505
+ cursor: isSubmitting ? "not-allowed" : "pointer"
506
+ },
507
+ children: isSubmitting ? "Processing..." : "Complete Order"
508
+ }
509
+ ) }),
510
+ status && /* @__PURE__ */ jsx("p", { "data-cimplify-status": "", style: { marginTop: "10px", fontSize: "14px", color: "#52525b" }, children: statusToLabel(status) }),
511
+ errorMessage && /* @__PURE__ */ jsx("p", { "data-cimplify-error": "", style: { marginTop: "8px", fontSize: "14px", color: "#b91c1c" }, children: errorMessage })
512
+ ] });
513
+ }
318
514
  var ElementsContext = createContext({
319
515
  elements: null,
320
516
  isReady: false
@@ -430,7 +626,24 @@ function useCheckout() {
430
626
  },
431
627
  [elements]
432
628
  );
433
- return { submit, isLoading };
629
+ const process = useCallback(
630
+ async (options) => {
631
+ if (!elements) {
632
+ return {
633
+ success: false,
634
+ error: { code: "NO_ELEMENTS", message: "Elements not initialized", recoverable: false }
635
+ };
636
+ }
637
+ setIsLoading(true);
638
+ try {
639
+ return await elements.processCheckout(options);
640
+ } finally {
641
+ setIsLoading(false);
642
+ }
643
+ },
644
+ [elements]
645
+ );
646
+ return { submit, process, isLoading };
434
647
  }
435
648
 
436
- export { Ad, AdProvider, AddressElement, AuthElement, ElementsProvider, PaymentElement, useAds, useCheckout, useElements, useElementsReady };
649
+ export { Ad, AdProvider, AddressElement, AuthElement, CimplifyCheckout, ElementsProvider, PaymentElement, useAds, useCheckout, useElements, useElementsReady };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cimplify/sdk",
3
- "version": "0.6.2",
3
+ "version": "0.6.3",
4
4
  "description": "Cimplify Commerce SDK for storefronts",
5
5
  "keywords": [
6
6
  "cimplify",
@@ -40,9 +40,13 @@
40
40
  "test:coverage": "vitest run --coverage"
41
41
  },
42
42
  "peerDependencies": {
43
+ "@paystack/inline-js": ">=2.0.0",
43
44
  "react": ">=17.0.0"
44
45
  },
45
46
  "peerDependenciesMeta": {
47
+ "@paystack/inline-js": {
48
+ "optional": true
49
+ },
46
50
  "react": {
47
51
  "optional": true
48
52
  }