@wix/headless-stores 0.0.5 → 0.0.7
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/astro/actions/package.json +4 -0
- package/cjs/dist/astro/actions/custom-checkout.d.ts +48 -0
- package/cjs/dist/astro/actions/custom-checkout.js +57 -0
- package/cjs/dist/astro/actions/index.d.ts +1 -0
- package/cjs/dist/astro/actions/index.js +17 -0
- package/cjs/dist/react/BuyNow.d.ts +57 -0
- package/cjs/dist/react/BuyNow.js +46 -0
- package/cjs/dist/react/PayNow.d.ts +43 -0
- package/cjs/dist/react/PayNow.js +37 -0
- package/cjs/dist/react/index.d.ts +2 -0
- package/cjs/dist/react/index.js +18 -0
- package/cjs/dist/server-actions/custom-checkout-action.d.ts +49 -0
- package/cjs/dist/server-actions/custom-checkout-action.js +63 -0
- package/cjs/dist/server-actions/index.d.ts +1 -0
- package/cjs/dist/server-actions/index.js +17 -0
- package/cjs/dist/services/buy-now-service.d.ts +89 -0
- package/cjs/dist/services/buy-now-service.js +68 -0
- package/cjs/dist/services/index.d.ts +2 -0
- package/cjs/dist/services/index.js +9 -0
- package/cjs/dist/services/pay-now-service.d.ts +72 -0
- package/cjs/dist/services/pay-now-service.js +50 -0
- package/cjs/dist/utils/index.d.ts +1 -0
- package/cjs/dist/utils/index.js +33 -0
- package/cjs/package.json +3 -0
- package/dist/astro/actions/custom-checkout.d.ts +1 -1
- package/dist/astro/actions/custom-checkout.js +4 -3
- package/dist/react/BuyNow.d.ts +7 -1
- package/dist/react/BuyNow.js +6 -2
- package/dist/react/CurrentCartServiceProvider.d.ts +5 -0
- package/dist/react/CurrentCartServiceProvider.js +12 -0
- package/dist/react/PayNow.d.ts +41 -8
- package/dist/react/PayNow.js +25 -2
- package/dist/react/VariantSelectorServiceProvider.d.ts +7 -0
- package/dist/react/VariantSelectorServiceProvider.js +22 -0
- package/dist/react/index.d.ts +1 -0
- package/dist/react/index.js +1 -0
- package/dist/server-actions/custom-checkout-action.d.ts +5 -1
- package/dist/server-actions/custom-checkout-action.js +5 -0
- package/dist/services/CurrentCartService.d.ts +18 -0
- package/dist/services/CurrentCartService.js +9 -0
- package/dist/services/VariantSelectorServices.d.ts +8 -0
- package/dist/services/VariantSelectorServices.js +20 -0
- package/dist/services/buy-now-service.d.ts +10 -14
- package/dist/services/buy-now-service.js +12 -20
- package/dist/services/index.d.ts +1 -0
- package/dist/services/index.js +1 -0
- package/dist/services/pay-now-service.d.ts +15 -39
- package/dist/services/pay-now-service.js +17 -13
- package/package.json +31 -7
- package/react/package.json +4 -0
- package/server-actions/package.json +4 -0
- package/services/package.json +4 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { ServiceFactoryConfig, Signal } from "@wix/services-definitions";
|
|
2
|
+
export declare const PayNowServiceDefinition: string & {
|
|
3
|
+
__api: {
|
|
4
|
+
redirectToCheckout: () => Promise<void>;
|
|
5
|
+
loadingSignal: Signal<boolean>;
|
|
6
|
+
errorSignal: Signal<string | null>;
|
|
7
|
+
};
|
|
8
|
+
__config: {};
|
|
9
|
+
isServiceDefinition?: boolean;
|
|
10
|
+
} & {
|
|
11
|
+
redirectToCheckout: () => Promise<void>;
|
|
12
|
+
loadingSignal: Signal<boolean>;
|
|
13
|
+
errorSignal: Signal<string | null>;
|
|
14
|
+
};
|
|
15
|
+
export declare const PayNowServiceImplementation: import("@wix/services-definitions").ServiceFactory<string & {
|
|
16
|
+
__api: {
|
|
17
|
+
redirectToCheckout: () => Promise<void>;
|
|
18
|
+
loadingSignal: Signal<boolean>;
|
|
19
|
+
errorSignal: Signal<string | null>;
|
|
20
|
+
};
|
|
21
|
+
__config: {};
|
|
22
|
+
isServiceDefinition?: boolean;
|
|
23
|
+
} & {
|
|
24
|
+
redirectToCheckout: () => Promise<void>;
|
|
25
|
+
loadingSignal: Signal<boolean>;
|
|
26
|
+
errorSignal: Signal<string | null>;
|
|
27
|
+
}, {
|
|
28
|
+
customCheckoutAction?: () => Promise<{
|
|
29
|
+
data: string | undefined;
|
|
30
|
+
error: unknown;
|
|
31
|
+
}>;
|
|
32
|
+
}, import("@wix/services-definitions").ThreadMode.MAIN>;
|
|
33
|
+
export declare const loadPayNowServiceInitialData: () => Promise<{
|
|
34
|
+
[PayNowServiceDefinition]: {};
|
|
35
|
+
}>;
|
|
36
|
+
export declare const payNowServiceBinding: <T extends {
|
|
37
|
+
[key: string]: Awaited<ReturnType<typeof loadPayNowServiceInitialData>>[typeof PayNowServiceDefinition];
|
|
38
|
+
}>(servicesConfigs: T, additionalConfig?: Partial<ServiceFactoryConfig<typeof PayNowServiceImplementation>>) => readonly [string & {
|
|
39
|
+
__api: {
|
|
40
|
+
redirectToCheckout: () => Promise<void>;
|
|
41
|
+
loadingSignal: Signal<boolean>;
|
|
42
|
+
errorSignal: Signal<string | null>;
|
|
43
|
+
};
|
|
44
|
+
__config: {};
|
|
45
|
+
isServiceDefinition?: boolean;
|
|
46
|
+
} & {
|
|
47
|
+
redirectToCheckout: () => Promise<void>;
|
|
48
|
+
loadingSignal: Signal<boolean>;
|
|
49
|
+
errorSignal: Signal<string | null>;
|
|
50
|
+
}, import("@wix/services-definitions").ServiceFactory<string & {
|
|
51
|
+
__api: {
|
|
52
|
+
redirectToCheckout: () => Promise<void>;
|
|
53
|
+
loadingSignal: Signal<boolean>;
|
|
54
|
+
errorSignal: Signal<string | null>;
|
|
55
|
+
};
|
|
56
|
+
__config: {};
|
|
57
|
+
isServiceDefinition?: boolean;
|
|
58
|
+
} & {
|
|
59
|
+
redirectToCheckout: () => Promise<void>;
|
|
60
|
+
loadingSignal: Signal<boolean>;
|
|
61
|
+
errorSignal: Signal<string | null>;
|
|
62
|
+
}, {
|
|
63
|
+
customCheckoutAction?: () => Promise<{
|
|
64
|
+
data: string | undefined;
|
|
65
|
+
error: unknown;
|
|
66
|
+
}>;
|
|
67
|
+
}, import("@wix/services-definitions").ThreadMode.MAIN>, {
|
|
68
|
+
customCheckoutAction?: () => Promise<{
|
|
69
|
+
data: string | undefined;
|
|
70
|
+
error: unknown;
|
|
71
|
+
}>;
|
|
72
|
+
}];
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.payNowServiceBinding = exports.loadPayNowServiceInitialData = exports.PayNowServiceImplementation = exports.PayNowServiceDefinition = void 0;
|
|
4
|
+
const services_definitions_1 = require("@wix/services-definitions");
|
|
5
|
+
const signals_1 = require("@wix/services-definitions/core-services/signals");
|
|
6
|
+
exports.PayNowServiceDefinition = (0, services_definitions_1.defineService)("PayNow");
|
|
7
|
+
exports.PayNowServiceImplementation = services_definitions_1.implementService.withConfig()(exports.PayNowServiceDefinition, ({ getService, config }) => {
|
|
8
|
+
const signalsService = getService(signals_1.SignalsServiceDefinition);
|
|
9
|
+
const loadingSignal = signalsService.signal(false);
|
|
10
|
+
const errorSignal = signalsService.signal(null);
|
|
11
|
+
return {
|
|
12
|
+
redirectToCheckout: async () => {
|
|
13
|
+
loadingSignal.set(true);
|
|
14
|
+
try {
|
|
15
|
+
if (config.customCheckoutAction) {
|
|
16
|
+
const result = await config.customCheckoutAction();
|
|
17
|
+
if (result && result.data) {
|
|
18
|
+
window.location.href = result.data;
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
throw new Error("Failed to create checkout" + result?.error);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
errorSignal.set(error.toString());
|
|
27
|
+
loadingSignal.set(false);
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
loadingSignal,
|
|
31
|
+
errorSignal,
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
const loadPayNowServiceInitialData = async () => {
|
|
35
|
+
return {
|
|
36
|
+
[exports.PayNowServiceDefinition]: {},
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
exports.loadPayNowServiceInitialData = loadPayNowServiceInitialData;
|
|
40
|
+
const payNowServiceBinding = (servicesConfigs, additionalConfig = {}) => {
|
|
41
|
+
return [
|
|
42
|
+
exports.PayNowServiceDefinition,
|
|
43
|
+
exports.PayNowServiceImplementation,
|
|
44
|
+
{
|
|
45
|
+
...servicesConfigs[exports.PayNowServiceDefinition],
|
|
46
|
+
...additionalConfig,
|
|
47
|
+
},
|
|
48
|
+
];
|
|
49
|
+
};
|
|
50
|
+
exports.payNowServiceBinding = payNowServiceBinding;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getCheckoutUrlForProduct(productId: string, variantId?: string): Promise<string>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCheckoutUrlForProduct = getCheckoutUrlForProduct;
|
|
4
|
+
const ecom_1 = require("@wix/ecom");
|
|
5
|
+
const redirects_1 = require("@wix/redirects");
|
|
6
|
+
const CATLOG_APP_ID_V3 = "215238eb-22a5-4c36-9e7b-e7c08025e04e";
|
|
7
|
+
async function getCheckoutUrlForProduct(productId, variantId) {
|
|
8
|
+
const checkoutResult = await ecom_1.checkout.createCheckout({
|
|
9
|
+
lineItems: [
|
|
10
|
+
{
|
|
11
|
+
catalogReference: {
|
|
12
|
+
catalogItemId: productId,
|
|
13
|
+
appId: CATLOG_APP_ID_V3,
|
|
14
|
+
options: {
|
|
15
|
+
variantId,
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
quantity: 1,
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
channelType: ecom_1.checkout.ChannelType.WEB,
|
|
22
|
+
});
|
|
23
|
+
if (!checkoutResult._id) {
|
|
24
|
+
throw new Error("Failed to create checkout");
|
|
25
|
+
}
|
|
26
|
+
const { redirectSession } = await redirects_1.redirects.createRedirectSession({
|
|
27
|
+
ecomCheckout: { checkoutId: checkoutResult._id },
|
|
28
|
+
callbacks: {
|
|
29
|
+
postFlowUrl: window.location.href,
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
return redirectSession?.fullUrl;
|
|
33
|
+
}
|
package/cjs/package.json
ADDED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type CustomLineItemCheckoutOptions } from
|
|
1
|
+
import { type CustomLineItemCheckoutOptions } from "@wix/headless-stores/server-actions";
|
|
2
2
|
/**
|
|
3
3
|
* Creates an Astro action factory for custom checkout functionality with line items.
|
|
4
4
|
*
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
/// <reference types="astro/
|
|
2
|
-
|
|
3
|
-
import {
|
|
1
|
+
/// <reference types="astro/env" />
|
|
2
|
+
// @ts-ignore
|
|
3
|
+
import { defineAction } from "astro:actions";
|
|
4
|
+
import { getCustomLineItemCheckoutURLFactory, } from "@wix/headless-stores/server-actions";
|
|
4
5
|
/**
|
|
5
6
|
* Creates an Astro action factory for custom checkout functionality with line items.
|
|
6
7
|
*
|
package/dist/react/BuyNow.d.ts
CHANGED
|
@@ -15,6 +15,10 @@ export interface BuyNowRenderProps {
|
|
|
15
15
|
price: string;
|
|
16
16
|
/** The currency of the product being purchased */
|
|
17
17
|
currency: string;
|
|
18
|
+
/** Whether the product is in stock */
|
|
19
|
+
inStock: boolean;
|
|
20
|
+
/** Whether the product is available for pre-order */
|
|
21
|
+
preOrderAvailable: boolean;
|
|
18
22
|
}
|
|
19
23
|
export type BuyNowChildren = (props: BuyNowRenderProps) => React.ReactNode;
|
|
20
24
|
/**
|
|
@@ -32,11 +36,13 @@ export interface BuyNowProps {
|
|
|
32
36
|
* @example
|
|
33
37
|
* ```tsx
|
|
34
38
|
* <BuyNow>
|
|
35
|
-
* {({ isLoading, productName, redirectToCheckout, error, price, currency }) => (
|
|
39
|
+
* {({ isLoading, productName, redirectToCheckout, error, price, currency, inStock, preOrderAvailable }) => (
|
|
36
40
|
* <div>
|
|
37
41
|
* <h2>{productName}</h2>
|
|
38
42
|
* <p>{price} {currency}</p>
|
|
39
43
|
* {error && <div className="error">{error}</div>}
|
|
44
|
+
* {inStock && <div>In stock</div>}
|
|
45
|
+
* {preOrderAvailable && <div>Pre-order available</div>}
|
|
40
46
|
* <button
|
|
41
47
|
* onClick={redirectToCheckout}
|
|
42
48
|
* disabled={isLoading}
|
package/dist/react/BuyNow.js
CHANGED
|
@@ -10,11 +10,13 @@ import { BuyNowServiceDefinition } from "../services/buy-now-service";
|
|
|
10
10
|
* @example
|
|
11
11
|
* ```tsx
|
|
12
12
|
* <BuyNow>
|
|
13
|
-
* {({ isLoading, productName, redirectToCheckout, error, price, currency }) => (
|
|
13
|
+
* {({ isLoading, productName, redirectToCheckout, error, price, currency, inStock, preOrderAvailable }) => (
|
|
14
14
|
* <div>
|
|
15
15
|
* <h2>{productName}</h2>
|
|
16
16
|
* <p>{price} {currency}</p>
|
|
17
17
|
* {error && <div className="error">{error}</div>}
|
|
18
|
+
* {inStock && <div>In stock</div>}
|
|
19
|
+
* {preOrderAvailable && <div>Pre-order available</div>}
|
|
18
20
|
* <button
|
|
19
21
|
* onClick={redirectToCheckout}
|
|
20
22
|
* disabled={isLoading}
|
|
@@ -27,7 +29,7 @@ import { BuyNowServiceDefinition } from "../services/buy-now-service";
|
|
|
27
29
|
* ```
|
|
28
30
|
*/
|
|
29
31
|
export function BuyNow(props) {
|
|
30
|
-
const { redirectToCheckout, loadingSignal, productName, errorSignal, price, currency, } = useService(BuyNowServiceDefinition);
|
|
32
|
+
const { redirectToCheckout, loadingSignal, productName, errorSignal, price, currency, inStock, preOrderAvailable, } = useService(BuyNowServiceDefinition);
|
|
31
33
|
return props.children({
|
|
32
34
|
isLoading: loadingSignal.get(),
|
|
33
35
|
error: errorSignal.get(),
|
|
@@ -35,5 +37,7 @@ export function BuyNow(props) {
|
|
|
35
37
|
redirectToCheckout,
|
|
36
38
|
price,
|
|
37
39
|
currency,
|
|
40
|
+
inStock,
|
|
41
|
+
preOrderAvailable,
|
|
38
42
|
});
|
|
39
43
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { CurrentCartService } from "../services/CurrentCartService";
|
|
4
|
+
export const CurrentCartServiceContext = React.createContext(null);
|
|
5
|
+
export function CurrentCartServiceProvider(props) {
|
|
6
|
+
const theService = CurrentCartService({
|
|
7
|
+
// @ts-expect-error
|
|
8
|
+
getService: () => { },
|
|
9
|
+
config: {},
|
|
10
|
+
});
|
|
11
|
+
return (_jsx(CurrentCartServiceContext.Provider, { value: theService, children: props.children }));
|
|
12
|
+
}
|
package/dist/react/PayNow.d.ts
CHANGED
|
@@ -1,10 +1,43 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
export type PayNowRedirectToCheckout = () => void;
|
|
2
|
+
/**
|
|
3
|
+
* Props passed to the render function of the PayNow component
|
|
4
|
+
*/
|
|
5
|
+
export interface PayNowRenderProps {
|
|
6
|
+
/** Whether the buy now operation is currently loading */
|
|
7
|
+
isLoading: boolean;
|
|
8
|
+
/** Function to redirect the user to the checkout page */
|
|
9
|
+
redirectToCheckout: PayNowRedirectToCheckout;
|
|
10
|
+
/** The error message if the buy now operation fails */
|
|
11
|
+
error: string | null;
|
|
8
12
|
}
|
|
13
|
+
export type PayNowChildren = (props: PayNowRenderProps) => React.ReactNode;
|
|
14
|
+
/**
|
|
15
|
+
* Props for the PayNow component
|
|
16
|
+
*/
|
|
17
|
+
export interface PayNowProps {
|
|
18
|
+
/** Render function that receives buy now state and actions */
|
|
19
|
+
children: PayNowChildren;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* A headless component that provides pay now functionality using the render props pattern.
|
|
23
|
+
*
|
|
24
|
+
* This component manages the state and actions for a "pay now" flow, allowing consumers
|
|
25
|
+
* to render their own UI while accessing the underlying payment functionality.
|
|
26
|
+
* @example
|
|
27
|
+
* ```tsx
|
|
28
|
+
* <PayNow>
|
|
29
|
+
* {({ isLoading, redirectToCheckout, error }) => (
|
|
30
|
+
* <div>
|
|
31
|
+
* {error && <div className="error">{error}</div>}
|
|
32
|
+
* <button
|
|
33
|
+
* onClick={redirectToCheckout}
|
|
34
|
+
* disabled={isLoading}
|
|
35
|
+
* >
|
|
36
|
+
* {isLoading ? 'Processing...' : 'Pay Now'}
|
|
37
|
+
* </button>
|
|
38
|
+
* </div>
|
|
39
|
+
* )}
|
|
40
|
+
* </PayNow>
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
9
43
|
export declare function PayNow(props: PayNowProps): import("react").ReactNode;
|
|
10
|
-
export {};
|
package/dist/react/PayNow.js
CHANGED
|
@@ -1,11 +1,34 @@
|
|
|
1
1
|
import { useService } from "@wix/services-manager-react";
|
|
2
2
|
import { PayNowServiceDefinition } from "../services/pay-now-service";
|
|
3
|
+
;
|
|
4
|
+
;
|
|
5
|
+
/**
|
|
6
|
+
* A headless component that provides pay now functionality using the render props pattern.
|
|
7
|
+
*
|
|
8
|
+
* This component manages the state and actions for a "pay now" flow, allowing consumers
|
|
9
|
+
* to render their own UI while accessing the underlying payment functionality.
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* <PayNow>
|
|
13
|
+
* {({ isLoading, redirectToCheckout, error }) => (
|
|
14
|
+
* <div>
|
|
15
|
+
* {error && <div className="error">{error}</div>}
|
|
16
|
+
* <button
|
|
17
|
+
* onClick={redirectToCheckout}
|
|
18
|
+
* disabled={isLoading}
|
|
19
|
+
* >
|
|
20
|
+
* {isLoading ? 'Processing...' : 'Pay Now'}
|
|
21
|
+
* </button>
|
|
22
|
+
* </div>
|
|
23
|
+
* )}
|
|
24
|
+
* </PayNow>
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
3
27
|
export function PayNow(props) {
|
|
4
|
-
const { redirectToCheckout, loadingSignal,
|
|
28
|
+
const { redirectToCheckout, loadingSignal, errorSignal, } = useService(PayNowServiceDefinition);
|
|
5
29
|
return props.children({
|
|
6
30
|
isLoading: loadingSignal.get(),
|
|
7
31
|
error: errorSignal.get(),
|
|
8
|
-
productName: productName,
|
|
9
32
|
redirectToCheckout,
|
|
10
33
|
});
|
|
11
34
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { productsV3 } from "@wix/stores";
|
|
3
|
+
export declare const VariantSelectorContext: React.Context<unknown>;
|
|
4
|
+
export declare function VariantSelectorServiceProvider(props: {
|
|
5
|
+
product: productsV3.V3Product;
|
|
6
|
+
children: React.ReactNode;
|
|
7
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import React, { useContext } from "react";
|
|
3
|
+
import { VariantSelectorService } from "../services/VariantSelectorServices";
|
|
4
|
+
import { CurrentCartServiceContext } from "./CurrentCartServiceProvider";
|
|
5
|
+
import { CurrentCartServiceDefinition } from "../services/CurrentCartService";
|
|
6
|
+
export const VariantSelectorContext = React.createContext(null);
|
|
7
|
+
export function VariantSelectorServiceProvider(props) {
|
|
8
|
+
const currentCartService = useContext(CurrentCartServiceContext);
|
|
9
|
+
const theService = VariantSelectorService({
|
|
10
|
+
// @ts-expect-error
|
|
11
|
+
getService: (id) => {
|
|
12
|
+
if (id === CurrentCartServiceDefinition) {
|
|
13
|
+
return currentCartService;
|
|
14
|
+
}
|
|
15
|
+
throw new Error(`Unknown service: ${id}`);
|
|
16
|
+
},
|
|
17
|
+
config: {
|
|
18
|
+
product: props.product,
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
return (_jsx(VariantSelectorContext.Provider, { value: theService, children: props.children }));
|
|
22
|
+
}
|
package/dist/react/index.d.ts
CHANGED
package/dist/react/index.js
CHANGED
|
@@ -11,7 +11,7 @@ export interface CustomLineItemCheckoutOptions {
|
|
|
11
11
|
* A description for the price, which will be displayed to the customer.
|
|
12
12
|
* @example "per month"
|
|
13
13
|
*/
|
|
14
|
-
priceDescription
|
|
14
|
+
priceDescription: string;
|
|
15
15
|
/**
|
|
16
16
|
* An array of policies related to this custom item.
|
|
17
17
|
* Each policy should have a title and content.
|
|
@@ -33,6 +33,10 @@ export interface CustomLineItemCheckoutOptions {
|
|
|
33
33
|
* The price of the product.
|
|
34
34
|
*/
|
|
35
35
|
price: string;
|
|
36
|
+
/**
|
|
37
|
+
* The currency of the product. It will only take effect after configuring the payment provider to accept this currency.
|
|
38
|
+
*/
|
|
39
|
+
currency: string;
|
|
36
40
|
}
|
|
37
41
|
/**
|
|
38
42
|
* Creates a factory function to generate checkout URLs for custom line items with a fixed price.
|
|
@@ -36,6 +36,11 @@ export function getCustomLineItemCheckoutURLFactory(factoryOpts) {
|
|
|
36
36
|
}
|
|
37
37
|
],
|
|
38
38
|
channelType: checkout.ChannelType.WEB,
|
|
39
|
+
...(factoryOpts.currency ? {
|
|
40
|
+
checkoutInfo: {
|
|
41
|
+
currency: factoryOpts.currency,
|
|
42
|
+
}
|
|
43
|
+
} : {})
|
|
39
44
|
});
|
|
40
45
|
if (!checkoutResult._id) {
|
|
41
46
|
throw new Error(`Failed to create checkout for custom line item ${factoryOpts.productName}`);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare const CurrentCartServiceDefinition: string & {
|
|
2
|
+
__api: {
|
|
3
|
+
addItem: () => void;
|
|
4
|
+
};
|
|
5
|
+
__config: {};
|
|
6
|
+
isServiceDefinition?: boolean;
|
|
7
|
+
} & {
|
|
8
|
+
addItem: () => void;
|
|
9
|
+
};
|
|
10
|
+
export declare const CurrentCartService: import("@wix/services-definitions").ServiceFactory<string & {
|
|
11
|
+
__api: {
|
|
12
|
+
addItem: () => void;
|
|
13
|
+
};
|
|
14
|
+
__config: {};
|
|
15
|
+
isServiceDefinition?: boolean;
|
|
16
|
+
} & {
|
|
17
|
+
addItem: () => void;
|
|
18
|
+
}, {}, import("@wix/services-definitions").ThreadMode.MAIN>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { defineService, implementService } from "@wix/services-definitions";
|
|
2
|
+
export const CurrentCartServiceDefinition = defineService("kaki2");
|
|
3
|
+
export const CurrentCartService = implementService.withConfig()(CurrentCartServiceDefinition, () => {
|
|
4
|
+
return {
|
|
5
|
+
addItem: () => {
|
|
6
|
+
alert("addItem");
|
|
7
|
+
},
|
|
8
|
+
};
|
|
9
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { productsV3 } from "@wix/stores";
|
|
2
|
+
export declare const VariantSelectorService: import("@wix/services-definitions").ServiceFactory<string & {
|
|
3
|
+
__api: {};
|
|
4
|
+
__config: {};
|
|
5
|
+
isServiceDefinition?: boolean;
|
|
6
|
+
}, {
|
|
7
|
+
product: productsV3.V3Product;
|
|
8
|
+
}, import("@wix/services-definitions").ThreadMode.MAIN>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { defineService, implementService, } from "@wix/services-definitions";
|
|
2
|
+
import { SignalsServiceDefinition } from "@wix/services-definitions/core-services/signals";
|
|
3
|
+
import { CurrentCartServiceDefinition } from "./CurrentCartService";
|
|
4
|
+
const VariantSelectorServiceDefinition = defineService("kaki");
|
|
5
|
+
export const VariantSelectorService = implementService.withConfig()(VariantSelectorServiceDefinition, ({ getService, config }) => {
|
|
6
|
+
const cartService = getService(CurrentCartServiceDefinition);
|
|
7
|
+
const signalsService = getService(SignalsServiceDefinition);
|
|
8
|
+
const selectedVariant = signalsService.signal((config.product.variantsInfo?.variants ?? []).length > 0
|
|
9
|
+
? config.product.variantsInfo.variants[0]._id
|
|
10
|
+
: null);
|
|
11
|
+
return {
|
|
12
|
+
selectedVariant,
|
|
13
|
+
setSelectedVariant: (variant) => {
|
|
14
|
+
selectedVariant.set(variant);
|
|
15
|
+
},
|
|
16
|
+
addToCart: async () => {
|
|
17
|
+
await cartService.addItem();
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
});
|
|
@@ -30,23 +30,23 @@ export declare const BuyNowServiceImplementation: import("@wix/services-definiti
|
|
|
30
30
|
productName: string;
|
|
31
31
|
price: string;
|
|
32
32
|
currency: string;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
error: unknown;
|
|
36
|
-
}>;
|
|
33
|
+
inStock: boolean;
|
|
34
|
+
preOrderAvailable: boolean;
|
|
37
35
|
}, import("@wix/services-definitions").ThreadMode.MAIN>;
|
|
38
36
|
export declare const loadBuyNowServiceInitialData: (productSlug: string, variantId?: string) => Promise<{
|
|
39
37
|
[BuyNowServiceDefinition]: {
|
|
40
|
-
variantId?: string | undefined;
|
|
41
38
|
productId: string;
|
|
42
39
|
productName: string;
|
|
43
40
|
price: string;
|
|
44
41
|
currency: string;
|
|
42
|
+
variantId: string | null | undefined;
|
|
43
|
+
inStock: boolean | undefined;
|
|
44
|
+
preOrderAvailable: boolean | undefined;
|
|
45
45
|
};
|
|
46
46
|
}>;
|
|
47
47
|
export declare const buyNowServiceBinding: <T extends {
|
|
48
48
|
[key: string]: Awaited<ReturnType<typeof loadBuyNowServiceInitialData>>[typeof BuyNowServiceDefinition];
|
|
49
|
-
}>(servicesConfigs: T, additionalConfig
|
|
49
|
+
}>(servicesConfigs: T, additionalConfig?: Partial<ServiceFactoryConfig<typeof BuyNowServiceImplementation>>) => readonly [string & {
|
|
50
50
|
__api: {
|
|
51
51
|
redirectToCheckout: () => Promise<void>;
|
|
52
52
|
loadingSignal: Signal<boolean>;
|
|
@@ -76,18 +76,14 @@ export declare const buyNowServiceBinding: <T extends {
|
|
|
76
76
|
productName: string;
|
|
77
77
|
price: string;
|
|
78
78
|
currency: string;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
error: unknown;
|
|
82
|
-
}>;
|
|
79
|
+
inStock: boolean;
|
|
80
|
+
preOrderAvailable: boolean;
|
|
83
81
|
}, import("@wix/services-definitions").ThreadMode.MAIN>, {
|
|
84
82
|
productId: string;
|
|
85
83
|
variantId?: string;
|
|
86
84
|
productName: string;
|
|
87
85
|
price: string;
|
|
88
86
|
currency: string;
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
error: unknown;
|
|
92
|
-
}>;
|
|
87
|
+
inStock: boolean;
|
|
88
|
+
preOrderAvailable: boolean;
|
|
93
89
|
}];
|
|
@@ -7,20 +7,12 @@ export const BuyNowServiceImplementation = implementService.withConfig()(BuyNowS
|
|
|
7
7
|
const signalsService = getService(SignalsServiceDefinition);
|
|
8
8
|
const loadingSignal = signalsService.signal(false);
|
|
9
9
|
const errorSignal = signalsService.signal(null);
|
|
10
|
+
const inStockSignal = signalsService.signal(config.inStock);
|
|
11
|
+
const preOrderAvailableSignal = signalsService.signal(config.preOrderAvailable);
|
|
10
12
|
return {
|
|
11
13
|
redirectToCheckout: async () => {
|
|
12
14
|
loadingSignal.set(true);
|
|
13
15
|
try {
|
|
14
|
-
if (config.customCheckoutAction) {
|
|
15
|
-
const result = await config.customCheckoutAction();
|
|
16
|
-
if (result && result.data) {
|
|
17
|
-
window.location.href = result.data;
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
throw new Error("Failed to create checkout" + result?.error);
|
|
21
|
-
}
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
16
|
const checkoutUrl = await getCheckoutUrlForProduct(config.productId, config.variantId);
|
|
25
17
|
window.location.href = checkoutUrl;
|
|
26
18
|
}
|
|
@@ -31,6 +23,8 @@ export const BuyNowServiceImplementation = implementService.withConfig()(BuyNowS
|
|
|
31
23
|
},
|
|
32
24
|
loadingSignal,
|
|
33
25
|
errorSignal,
|
|
26
|
+
inStockSignal,
|
|
27
|
+
preOrderAvailableSignal,
|
|
34
28
|
productName: config.productName,
|
|
35
29
|
price: config.price,
|
|
36
30
|
currency: config.currency,
|
|
@@ -41,25 +35,23 @@ export const loadBuyNowServiceInitialData = async (productSlug, variantId) => {
|
|
|
41
35
|
fields: ["CURRENCY"],
|
|
42
36
|
});
|
|
43
37
|
const product = res.product;
|
|
44
|
-
const
|
|
45
|
-
const price =
|
|
46
|
-
|
|
47
|
-
|
|
38
|
+
const selectedVariant = variantId ? product.variantsInfo?.variants?.find((v) => v._id === variantId) : product.variantsInfo?.variants?.[0];
|
|
39
|
+
const price = selectedVariant?.price?.actualPrice?.amount ?? product.actualPriceRange?.minValue?.amount;
|
|
40
|
+
const inStock = selectedVariant?.inventoryStatus?.inStock;
|
|
41
|
+
const preOrderAvailable = selectedVariant?.inventoryStatus?.preorderEnabled;
|
|
48
42
|
return {
|
|
49
43
|
[BuyNowServiceDefinition]: {
|
|
50
44
|
productId: product._id,
|
|
51
45
|
productName: product.name,
|
|
52
46
|
price: price,
|
|
53
47
|
currency: product.currency,
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
: {}),
|
|
48
|
+
variantId: selectedVariant?._id,
|
|
49
|
+
inStock,
|
|
50
|
+
preOrderAvailable,
|
|
59
51
|
},
|
|
60
52
|
};
|
|
61
53
|
};
|
|
62
|
-
export const buyNowServiceBinding = (servicesConfigs, additionalConfig) => {
|
|
54
|
+
export const buyNowServiceBinding = (servicesConfigs, additionalConfig = {}) => {
|
|
63
55
|
return [
|
|
64
56
|
BuyNowServiceDefinition,
|
|
65
57
|
BuyNowServiceImplementation,
|
package/dist/services/index.d.ts
CHANGED
package/dist/services/index.js
CHANGED