diff --git a/.gitignore b/.gitignore
index 4bd539d..3a6cce9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -11,3 +11,6 @@ yarn-error.log*
# Misc
.DS_Store
out
+
+.yarn
+.idea
diff --git a/.yarn/install-state.gz b/.yarn/install-state.gz
index e9adee3..6573d01 100644
Binary files a/.yarn/install-state.gz and b/.yarn/install-state.gz differ
diff --git a/README.md b/README.md
index d6cb0ae..af66d12 100644
--- a/README.md
+++ b/README.md
@@ -1,9 +1,25 @@
-# carbon-offset-app
+# Order custom actions template
This project was bootstrapped with [Create Wix App](https://www.npmjs.com/package/@wix/create-app).
Read more about it in the [Wix CLI for Apps
documentation](https://dev.wix.com/docs/build-apps/developer-tools/cli/get-started/about-the-wix-cli-for-apps).
+This template demonstrate the usage of the Ecom orderes SDK, the addition of a menu item to the Order page in the Business Manager and an integration with WhatsUp web.
+
+### Using the Ecom orders SDK
+The Ecom orders SDK is a powerful tool that allows you to interact with the orders in the store.
+ In this template we use the SDK to get the order details and the order items.
+//https://dev.wix.com/docs/sdk/backend-modules/ecom/orders/get-order
+
+### Adding a menu item to the Order page in the Business Manager
+The Business Manager is the place where the store owner can manage his store.
+In this template we add a menu item to the Order page in the Business Manager.
+ The file (/src/dashboard/menu-plugins/my-plugin/plugin.json) demionstrate how to add a menu item to the Order page in the Business Manager.
+
+### Integration with WhatsUp web
+WhatsUp web is a popular messaging app that allows you to send messages directly to your customers.
+In this template we integrate with WhatsUp web and send an up sale message to the customer.
+ the message includes the selected product details and a link to the store product with a coupon code.
## Setup 🔧
##### Install dependencies:
diff --git a/src/assets/checkout.png b/src/assets/checkout.png
deleted file mode 100644
index 39b5afc..0000000
Binary files a/src/assets/checkout.png and /dev/null differ
diff --git a/src/backend/api/checkout/api.ts b/src/backend/api/checkout/api.ts
deleted file mode 100644
index 9659921..0000000
--- a/src/backend/api/checkout/api.ts
+++ /dev/null
@@ -1,35 +0,0 @@
-import { upsertDataToCollection, safelyGetItemFromCollection } from '../../database';
-import { CHECKOUT_COLLECTION_ID } from '../../consts';
-
-export async function GET(req: Request) {
- const purchaseFlowId = new URL(req.url).searchParams.get('purchaseFlowId') as string;
- const checkoutData = await safelyGetItemFromCollection({
- itemId: purchaseFlowId,
- dataCollectionId: CHECKOUT_COLLECTION_ID,
- });
-
- return new Response(JSON.stringify(checkoutData ?? {}));
-};
-
-export async function POST(req: Request) {
- const { purchaseFlowId, checkoutId, shouldAdd } = await req.json();
-
- try {
- await upsertDataToCollection({
- dataCollectionId: CHECKOUT_COLLECTION_ID,
- item: {
- _id: purchaseFlowId,
- data: {
- checkoutId,
- shouldAdd,
- },
- },
- });
-
- //
- return new Response('Success');
- } catch (error) {
- console.log(error)
- return new Response('Error')
- };
-};
diff --git a/src/backend/api/order/api.ts b/src/backend/api/order/api.ts
new file mode 100644
index 0000000..0196fc5
--- /dev/null
+++ b/src/backend/api/order/api.ts
@@ -0,0 +1,10 @@
+import { orders } from '@wix/ecom';
+
+export async function GET(req: Request) {
+ const id = new URL(req.url).searchParams.get('orderId') as string;
+
+ // https://dev.wix.com/docs/sdk/backend-modules/ecom/orders/get-order
+ const order = await orders.getOrder(id);
+
+ return Response.json(order);
+};
\ No newline at end of file
diff --git a/src/backend/api/settings/api.ts b/src/backend/api/settings/api.ts
deleted file mode 100644
index 4cc8b3f..0000000
--- a/src/backend/api/settings/api.ts
+++ /dev/null
@@ -1,38 +0,0 @@
-import { getDataFromCollection, upsertDataToCollection } from '../../database';
-import { SETTINGS_COLLECTION_ID, DEFAULT_SETTING } from '../../consts';
-import type { Settings } from '../../../types';
-
-export async function GET(req: Request) {
- const settingsCollection = await getDataFromCollection({
- dataCollectionId: SETTINGS_COLLECTION_ID,
- });
-
- const settingsData = settingsCollection.items[0]?.data as Settings;
- const settings: Settings = {
- title: settingsData?.title || DEFAULT_SETTING.title,
- amount: settingsData?.amount || DEFAULT_SETTING.amount,
- color: settingsData?.color || DEFAULT_SETTING.color,
- iconColor: settingsData?.iconColor || DEFAULT_SETTING.iconColor,
- };
-
- return new Response(JSON.stringify(settings));
-};
-
-export async function POST(req: Request) {
- const settingsData = await req.json() as Settings;
-
- try {
- await upsertDataToCollection({
- dataCollectionId: SETTINGS_COLLECTION_ID,
- item: {
- // Wix data collection can be initialized as a "single item" that has the same ID
- _id: 'SETTINGS',
- data: settingsData,
- },
- });
-
- return new Response('Success');
- } catch (error) {
- return new Response('Error');
- };
-};
diff --git a/src/backend/consts.ts b/src/backend/consts.ts
deleted file mode 100644
index cc981d0..0000000
--- a/src/backend/consts.ts
+++ /dev/null
@@ -1,11 +0,0 @@
-import type { Settings } from "../types";
-
-// Update according to your app's needed collections
-export const SETTINGS_COLLECTION_ID = 'carbon-offset-settings';
-export const CHECKOUT_COLLECTION_ID = 'carbon-offset-checkout';
-export const DEFAULT_SETTING: Settings = {
- title: 'Make it carbon neutral',
- amount: 2,
- color: '#000000',
- iconColor: '#000000',
-};
diff --git a/src/backend/database.ts b/src/backend/database.ts
deleted file mode 100644
index 687c959..0000000
--- a/src/backend/database.ts
+++ /dev/null
@@ -1,66 +0,0 @@
-import { items } from '@wix/data';
-import { auth } from '@wix/essentials';
-
-// Exposing utility functions over Wix Data APIs for easier usage and replacement of database
-
-type DataItem = {
- _id?: string;
- data: Record;
-};
-
-export const getDataFromCollection = async ({
- dataCollectionId
-}: { dataCollectionId: string }) => {
- const data = await auth.elevate(items.queryDataItems)({
- dataCollectionId,
- }).find();
-
- return data;
-};
-
-export const safelyGetItemFromCollection = async ({
- dataCollectionId,
- itemId
-}: { dataCollectionId: string; itemId: string }) => {
- try {
- const { data } = await auth.elevate(items.getDataItem)(
- itemId,
- { dataCollectionId },
- );
-
- return data;
- } catch (error) {
- // Wix data's "getDataItem" API throws exception when item with id does not exist
- }
-};
-
-export const upsertDataToCollection = async ({
- dataCollectionId,
- item
-}: { dataCollectionId: string; item: DataItem }) => {
- const collection = await getDataFromCollection({ dataCollectionId });
- const existsInCollection = item._id && collection.items.find(existingItem => existingItem._id === item._id);
-
- if (item._id && existsInCollection) {
- await auth.elevate(items.updateDataItem)(item._id, {
- dataCollectionId,
- dataItem: {
- data: {
- _id: item._id,
- ...item.data
- },
- },
- });
- } else {
- await auth.elevate(items.insertDataItem)({
- dataCollectionId,
- dataItem: {
- _id: item._id ?? undefined,
- data: {
- _id: item._id ?? undefined,
- ...item.data
- },
- },
- });
- };
-};
diff --git a/src/backend/events/cleanup/event.ts b/src/backend/events/cleanup/event.ts
deleted file mode 100644
index 57644bb..0000000
--- a/src/backend/events/cleanup/event.ts
+++ /dev/null
@@ -1,11 +0,0 @@
-import { auth } from '@wix/essentials';
-import { items } from '@wix/data';
-import { checkout } from '@wix/ecom';
-import { CHECKOUT_COLLECTION_ID } from '../../consts';
-
-checkout.onCheckoutCompleted(({ data }) => {
- auth.elevate(items.removeDataItem)(
- data.checkout?.purchaseFlowId ?? '',
- { dataCollectionId: CHECKOUT_COLLECTION_ID },
- );
-});
diff --git a/src/backend/events/installation/event.ts b/src/backend/events/installation/event.ts
deleted file mode 100644
index 1d9142d..0000000
--- a/src/backend/events/installation/event.ts
+++ /dev/null
@@ -1,49 +0,0 @@
-import { auth } from '@wix/essentials';
-import { collections } from '@wix/data';
-import { appInstances } from '@wix/app-management';
-import { CHECKOUT_COLLECTION_ID, SETTINGS_COLLECTION_ID } from '../../consts';
-
-appInstances.onAppInstanceInstalled(() => {
- auth.elevate(collections.createDataCollection)({
- _id: SETTINGS_COLLECTION_ID,
- displayName: "Carbon Offset Settings",
- fields: [
- { key: 'title', type: collections.Type.TEXT },
- { key: 'amount', type: collections.Type.NUMBER },
- { key: 'color', type: collections.Type.TEXT },
- { key: 'iconColor', type: collections.Type.TEXT },
- ],
- permissions: {
- // Make sure to change the permissions according to the actual usage of your collection
- insert: collections.Role.ANYONE,
- read: collections.Role.ANYONE,
- remove: collections.Role.ANYONE,
- update: collections.Role.ANYONE,
- },
- // Plugin for single item collection
- plugins: [{
- type: collections.PluginType.SINGLE_ITEM,
- singleItemOptions: {
- singleItemId: "SETTINGS"
- },
- }],
- });
-
- auth.elevate(collections.createDataCollection)({
- _id: CHECKOUT_COLLECTION_ID,
- displayName: "Carbon Offset Checkout",
- fields: [
- // In this case, checkoutId is stored as an "added" field that is not neccessarry
- // the actual _id for each item of this collection will be purchaseFlowId for easy fetching
- { key: 'checkoutId', type: collections.Type.TEXT },
- { key: 'shouldAdd', type: collections.Type.BOOLEAN },
- ],
- permissions: {
- // Make sure to change the permissions according to the actual usage of your collection
- insert: collections.Role.ANYONE,
- read: collections.Role.ANYONE,
- remove: collections.Role.ANYONE,
- update: collections.Role.ANYONE,
- },
- });
-});
diff --git a/src/backend/service-plugins/ecom-additional-fees/carbon-offset/plugin.json b/src/backend/service-plugins/ecom-additional-fees/carbon-offset/plugin.json
deleted file mode 100644
index 99a8d01..0000000
--- a/src/backend/service-plugins/ecom-additional-fees/carbon-offset/plugin.json
+++ /dev/null
@@ -1,5 +0,0 @@
-{
- "$schema": "https://dev.wix.com/wix-cli/schemas/ecom-additional-fees.json",
- "id": "4b15f857-4e87-4cec-bdf3-0b501b063b30",
- "name": "carbon-offset"
-}
diff --git a/src/backend/service-plugins/ecom-additional-fees/carbon-offset/plugin.ts b/src/backend/service-plugins/ecom-additional-fees/carbon-offset/plugin.ts
deleted file mode 100644
index f771d58..0000000
--- a/src/backend/service-plugins/ecom-additional-fees/carbon-offset/plugin.ts
+++ /dev/null
@@ -1,51 +0,0 @@
-import { auth } from '@wix/essentials';
-import { items } from '@wix/data';
-import { additionalFees } from '@wix/ecom/service-plugins/context';
-import { CHECKOUT_COLLECTION_ID, SETTINGS_COLLECTION_ID, DEFAULT_SETTING } from '../../../consts';
-import type { Settings } from '../../../../types';
-
-const getCheckoutDataFromCollection = async (purchaseFlowId: string) => {
- try {
- const { data } = await auth.elevate(items.getDataItem)(
- purchaseFlowId,
- { dataCollectionId: CHECKOUT_COLLECTION_ID },
- );
-
- return data;
- } catch (error) {
- // Wix data's "getDataItem" API throws exception when item with id does not exist
- }
-};
-
-const getSettingsDataFromCollection = async () => {
- return auth.elevate(items.queryDataItems)({
- dataCollectionId: SETTINGS_COLLECTION_ID,
- }).find()
-};
-
-additionalFees.provideHandlers({
- calculateAdditionalFees: async ({ request, metadata }) => {
- const [checkoutData, settingsCollection] = await Promise.all([
- getCheckoutDataFromCollection(request.purchaseFlowId ?? ''),
- getSettingsDataFromCollection(),
- ]);
-
- if (checkoutData?.shouldAdd) {
- const settingsData = settingsCollection.items[0]?.data as Settings;
-
- return {
- additionalFees: [{
- name: 'Carbon Offset',
- code: 'carbon-offset-fee',
- price: `${settingsData.amount ?? DEFAULT_SETTING.amount}`,
- }],
- currency: metadata.currency!,
- };
- } else {
- return {
- additionalFees: [],
- currency: metadata.currency!,
- };
- };
- },
-});
diff --git a/src/components/carbon-offset.tsx b/src/components/carbon-offset.tsx
deleted file mode 100644
index 3dec0e1..0000000
--- a/src/components/carbon-offset.tsx
+++ /dev/null
@@ -1,94 +0,0 @@
-import React, { type FC } from 'react';
-import { httpClient } from '@wix/essentials';
-import { LeafIcon } from './leaf-icon';
-import type { Settings } from '../types'
-
-type Props = {
- settings: Settings;
- purchaseFlowId?: string;
- checkoutId?: string;
- checked?: boolean;
- refreshCheckout?: () => void;
-};
-
-export const CarbonOffset: FC = ({
- settings,
- purchaseFlowId,
- checkoutId,
- checked = false,
- refreshCheckout,
-}) => {
- return (
-
-
- {
- // We are using the same component both for rendering on site and for previewing in dashboard
- // so we make sure it does not do anything when changing / clicking things in preview
- if (purchaseFlowId) {
- await httpClient.fetchWithAuth(`${import.meta.env.BASE_API_URL}/checkout`, {
- method: 'POST',
- body: JSON.stringify({
- purchaseFlowId,
- checkoutId,
- shouldAdd: e.target.checked,
- }),
- });
-
- // Known Issue: Refresh Checkout is not yet implemented in Custom Element plugins (Wix CLI)
- // to workaround it after using the plugin in the site - go out of the checkout and back again
- // in order for it to reload and call the relevant SPIs with you updated configurations
- refreshCheckout?.();
- };
- }}
- />
-