Skip to content

Commit 24bfd09

Browse files
2317 - add woocommerce component
1 parent 9855766 commit 24bfd09

25 files changed

+33523
-0
lines changed

server/apps/server-app/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ dependencies {
281281
implementation(project(":server:libs:modules:components:webflow"))
282282
implementation(project(":server:libs:modules:components:webhook"))
283283
implementation(project(":server:libs:modules:components:whatsapp"))
284+
implementation(project(":server:libs:modules:components:woocommerce"))
284285
implementation(project(":server:libs:modules:components:xero"))
285286
implementation(project(":server:libs:modules:components:xlsx-file"))
286287
implementation(project(":server:libs:modules:components:xml-file"))

server/ee/apps/worker-app/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ dependencies {
221221
implementation(project(":server:libs:modules:components:webflow"))
222222
implementation(project(":server:libs:modules:components:webhook"))
223223
implementation(project(":server:libs:modules:components:whatsapp"))
224+
implementation(project(":server:libs:modules:components:woocommerce"))
224225
implementation(project(":server:libs:modules:components:xero"))
225226
implementation(project(":server:libs:modules:components:xlsx-file"))
226227
implementation(project(":server:libs:modules:components:xml-file"))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright 2025 ByteChef
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.bytechef.component.woocommerce;
18+
19+
import static com.bytechef.component.definition.ComponentDsl.component;
20+
import static com.bytechef.component.definition.ComponentDsl.tool;
21+
22+
import com.bytechef.component.ComponentHandler;
23+
import com.bytechef.component.definition.ComponentCategory;
24+
import com.bytechef.component.definition.ComponentDefinition;
25+
import com.bytechef.component.woocommerce.action.WoocommerceCreateCouponAction;
26+
import com.bytechef.component.woocommerce.action.WoocommerceCreateCustomerAction;
27+
import com.bytechef.component.woocommerce.action.WoocommerceCreateOrderAction;
28+
import com.bytechef.component.woocommerce.action.WoocommerceCreateProductAction;
29+
import com.bytechef.component.woocommerce.connection.WoocommerceConnection;
30+
import com.bytechef.component.woocommerce.trigger.WoocommerceNewCouponTrigger;
31+
import com.bytechef.component.woocommerce.trigger.WoocommerceNewOrderTrigger;
32+
import com.google.auto.service.AutoService;
33+
34+
/**
35+
* @author Marija Horvat
36+
*/
37+
@AutoService(ComponentHandler.class)
38+
public class WoocommerceComponentHandler implements ComponentHandler {
39+
40+
private static final ComponentDefinition COMPONENT_DEFINITION = component("wooCommerce")
41+
.title("WooCommerce")
42+
.description(
43+
"WooCommerce is a e-commerce plugin for WordPress that allows you to turn a standard WordPress website into a fully functional online store.")
44+
.icon("path:assets/woocommerce.svg")
45+
.categories(ComponentCategory.E_COMMERCE)
46+
.customAction(true)
47+
.connection(WoocommerceConnection.CONNECTION_DEFINITION)
48+
.actions(
49+
WoocommerceCreateCouponAction.ACTION_DEFINITION,
50+
WoocommerceCreateCustomerAction.ACTION_DEFINITION,
51+
WoocommerceCreateOrderAction.ACTION_DEFINITION,
52+
WoocommerceCreateProductAction.ACTION_DEFINITION)
53+
.clusterElements(
54+
tool(WoocommerceCreateCouponAction.ACTION_DEFINITION),
55+
tool(WoocommerceCreateCustomerAction.ACTION_DEFINITION),
56+
tool(WoocommerceCreateOrderAction.ACTION_DEFINITION),
57+
tool(WoocommerceCreateProductAction.ACTION_DEFINITION))
58+
.triggers(
59+
WoocommerceNewOrderTrigger.TRIGGER_DEFINITION,
60+
WoocommerceNewCouponTrigger.TRIGGER_DEFINITION);
61+
62+
@Override
63+
public ComponentDefinition getDefinition() {
64+
return COMPONENT_DEFINITION;
65+
}
66+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/*
2+
* Copyright 2025 ByteChef
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.bytechef.component.woocommerce.action;
18+
19+
import static com.bytechef.component.definition.ComponentDsl.action;
20+
import static com.bytechef.component.definition.ComponentDsl.array;
21+
import static com.bytechef.component.definition.ComponentDsl.bool;
22+
import static com.bytechef.component.definition.ComponentDsl.dateTime;
23+
import static com.bytechef.component.definition.ComponentDsl.integer;
24+
import static com.bytechef.component.definition.ComponentDsl.option;
25+
import static com.bytechef.component.definition.ComponentDsl.outputSchema;
26+
import static com.bytechef.component.definition.ComponentDsl.string;
27+
import static com.bytechef.component.definition.Context.Http.ResponseType;
28+
import static com.bytechef.component.definition.Context.Http.responseType;
29+
import static com.bytechef.component.woocommerce.constants.WoocommerceConstants.AMOUNT;
30+
import static com.bytechef.component.woocommerce.constants.WoocommerceConstants.CODE;
31+
import static com.bytechef.component.woocommerce.constants.WoocommerceConstants.COUPON_OUTPUT_PROPERTY;
32+
import static com.bytechef.component.woocommerce.constants.WoocommerceConstants.DATE_EXPIRES;
33+
import static com.bytechef.component.woocommerce.constants.WoocommerceConstants.DESCRIPTION;
34+
import static com.bytechef.component.woocommerce.constants.WoocommerceConstants.DISCOUNT_TYPE;
35+
import static com.bytechef.component.woocommerce.constants.WoocommerceConstants.EXCLUDE_SALE_ITEMS;
36+
import static com.bytechef.component.woocommerce.constants.WoocommerceConstants.INDIVIDUAL_USE;
37+
import static com.bytechef.component.woocommerce.constants.WoocommerceConstants.MAXIMUM_AMOUNT;
38+
import static com.bytechef.component.woocommerce.constants.WoocommerceConstants.MINIMUM_AMOUNT;
39+
import static com.bytechef.component.woocommerce.constants.WoocommerceConstants.PRODUCT_IDS;
40+
41+
import com.bytechef.component.definition.ComponentDsl.ModifiableActionDefinition;
42+
import com.bytechef.component.definition.Context;
43+
import com.bytechef.component.definition.Context.Http.Body;
44+
import com.bytechef.component.definition.OptionsDataSource.ActionOptionsFunction;
45+
import com.bytechef.component.definition.Parameters;
46+
import com.bytechef.component.woocommerce.util.WoocommerceUtils;
47+
48+
/**
49+
* @author Marija Horvat
50+
*/
51+
public class WoocommerceCreateCouponAction {
52+
public static final ModifiableActionDefinition ACTION_DEFINITION = action("createCoupon")
53+
.title("Create Coupon")
54+
.description("Create a new coupon.")
55+
.properties(
56+
string(CODE)
57+
.label("Code")
58+
.description("Coupon code.")
59+
.required(true),
60+
string(AMOUNT)
61+
.label("Amount")
62+
.description("The amount of discount. Should always be numeric, even if setting a percentage.")
63+
.required(true),
64+
string(DISCOUNT_TYPE)
65+
.label("Discount Type")
66+
.description("Determines the type of discount that will be applied.")
67+
.options(
68+
option("Percent", "percent"),
69+
option("Fixed_cart", "fixed_cart"),
70+
option("Fixed_product", "fixed_product"))
71+
.required(true),
72+
string(DESCRIPTION)
73+
.label("Description")
74+
.description("Coupon description.")
75+
.required(false),
76+
dateTime(DATE_EXPIRES)
77+
.label("Date Expires")
78+
.description("The date the coupon expires, in the site's timezone.")
79+
.required(false),
80+
bool(INDIVIDUAL_USE)
81+
.label("Individual Use")
82+
.description(
83+
"If true, the coupon can only be used individually. Other applied coupons will be removed from the cart.")
84+
.required(false),
85+
array(PRODUCT_IDS)
86+
.label("Product Ids")
87+
.description("List of product IDs the coupon can be used on.")
88+
.required(false)
89+
.options((ActionOptionsFunction<String>) WoocommerceUtils::getProductIdOptions)
90+
.items(integer()),
91+
bool(EXCLUDE_SALE_ITEMS)
92+
.label("Exclude Sale Items")
93+
.description("If true, this coupon will not be applied to items that have sale prices.")
94+
.required(false),
95+
string(MINIMUM_AMOUNT)
96+
.label("Minimum Amount")
97+
.description("Minimum order amount that needs to be in the cart before coupon applies.")
98+
.required(false),
99+
string(MAXIMUM_AMOUNT)
100+
.label("Maximum Amount")
101+
.description("Maximum order amount allowed when using the coupon.")
102+
.required(false))
103+
.output(outputSchema(COUPON_OUTPUT_PROPERTY))
104+
.perform(WoocommerceCreateCouponAction::perform);
105+
106+
private WoocommerceCreateCouponAction() {
107+
}
108+
109+
public static Object perform(Parameters inputParameters, Parameters conectionParameters, Context context) {
110+
return context.http(http -> http.post("/coupons"))
111+
.body(
112+
Body.of(
113+
CODE, inputParameters.getRequiredString(CODE),
114+
AMOUNT, inputParameters.getRequiredString(AMOUNT),
115+
DISCOUNT_TYPE, inputParameters.getRequiredString(DISCOUNT_TYPE),
116+
DESCRIPTION, inputParameters.getString(DESCRIPTION),
117+
DATE_EXPIRES, inputParameters.getDate(DATE_EXPIRES),
118+
INDIVIDUAL_USE, inputParameters.getBoolean(INDIVIDUAL_USE),
119+
PRODUCT_IDS, inputParameters.getArray(PRODUCT_IDS),
120+
EXCLUDE_SALE_ITEMS, inputParameters.getBoolean(EXCLUDE_SALE_ITEMS),
121+
MINIMUM_AMOUNT, inputParameters.getString(MINIMUM_AMOUNT),
122+
MAXIMUM_AMOUNT, inputParameters.getString(MAXIMUM_AMOUNT)))
123+
.configuration(responseType(ResponseType.JSON))
124+
.execute()
125+
.getBody();
126+
}
127+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
/*
2+
* Copyright 2025 ByteChef
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.bytechef.component.woocommerce.action;
18+
19+
import static com.bytechef.component.definition.ComponentDsl.action;
20+
import static com.bytechef.component.definition.ComponentDsl.object;
21+
import static com.bytechef.component.definition.ComponentDsl.outputSchema;
22+
import static com.bytechef.component.definition.ComponentDsl.string;
23+
import static com.bytechef.component.definition.Context.Http.ResponseType;
24+
import static com.bytechef.component.definition.Context.Http.responseType;
25+
import static com.bytechef.component.woocommerce.constants.WoocommerceConstants.ADDRESS_1;
26+
import static com.bytechef.component.woocommerce.constants.WoocommerceConstants.ADDRESS_2;
27+
import static com.bytechef.component.woocommerce.constants.WoocommerceConstants.BILLING;
28+
import static com.bytechef.component.woocommerce.constants.WoocommerceConstants.CITY;
29+
import static com.bytechef.component.woocommerce.constants.WoocommerceConstants.COMPANY;
30+
import static com.bytechef.component.woocommerce.constants.WoocommerceConstants.COUNTRY;
31+
import static com.bytechef.component.woocommerce.constants.WoocommerceConstants.CUSTOMER_OUTPUT_PROPERTY;
32+
import static com.bytechef.component.woocommerce.constants.WoocommerceConstants.EMAIL;
33+
import static com.bytechef.component.woocommerce.constants.WoocommerceConstants.FIRST_NAME;
34+
import static com.bytechef.component.woocommerce.constants.WoocommerceConstants.LAST_NAME;
35+
import static com.bytechef.component.woocommerce.constants.WoocommerceConstants.PHONE;
36+
import static com.bytechef.component.woocommerce.constants.WoocommerceConstants.POSTCODE;
37+
import static com.bytechef.component.woocommerce.constants.WoocommerceConstants.SHIPPING;
38+
import static com.bytechef.component.woocommerce.constants.WoocommerceConstants.STATE;
39+
import static com.bytechef.component.woocommerce.constants.WoocommerceConstants.USERNAME;
40+
41+
import com.bytechef.component.definition.ComponentDsl.ModifiableActionDefinition;
42+
import com.bytechef.component.definition.Context;
43+
import com.bytechef.component.definition.Parameters;
44+
45+
/**
46+
* @author Marija Horvat
47+
*/
48+
public class WoocommerceCreateCustomerAction {
49+
public static final ModifiableActionDefinition ACTION_DEFINITION = action("createCustomer")
50+
.title("Create Customer")
51+
.description("Create a new customer.")
52+
.properties(
53+
string(EMAIL)
54+
.label("Email")
55+
.description("The email address for the customer.")
56+
.required(true),
57+
string(FIRST_NAME)
58+
.label("First Name")
59+
.description("Customer first name.")
60+
.required(true),
61+
string(LAST_NAME)
62+
.label("Last Name")
63+
.description("Customer last name.")
64+
.required(true),
65+
string(USERNAME)
66+
.label("Username")
67+
.description("Customer login name.")
68+
.required(true),
69+
object(BILLING)
70+
.label("Billing")
71+
.description("List of billing address data.")
72+
.required(false)
73+
.properties(
74+
string(FIRST_NAME)
75+
.label("First Name")
76+
.description("First name."),
77+
string(LAST_NAME)
78+
.label("Last Name")
79+
.description("Last name."),
80+
string(COMPANY)
81+
.label("Company")
82+
.description("Company name."),
83+
string(ADDRESS_1)
84+
.label("Address 1")
85+
.description("Address line 1."),
86+
string(ADDRESS_2)
87+
.label("Address 2")
88+
.description("Address line 2."),
89+
string(CITY)
90+
.label("City")
91+
.description("City name."),
92+
string(STATE)
93+
.label("State")
94+
.description("ISO code or name of the state, province or district."),
95+
string(POSTCODE)
96+
.label("Postcode")
97+
.description("Postal code."),
98+
string(COUNTRY)
99+
.label("Country")
100+
.description("ISO code of the country."),
101+
string(EMAIL)
102+
.label("Email")
103+
.description("Email address."),
104+
string(PHONE)
105+
.label("Phone")
106+
.description("Phone number.")),
107+
object(SHIPPING)
108+
.label("Shipping")
109+
.description("List of shipping address data.")
110+
.required(false)
111+
.properties(
112+
string(FIRST_NAME)
113+
.label("First Name")
114+
.description("First name."),
115+
string(LAST_NAME)
116+
.label("Last Name")
117+
.description("Last name."),
118+
string(COMPANY)
119+
.label("Company")
120+
.description("Company name."),
121+
string(ADDRESS_1)
122+
.label("Address 1")
123+
.description("Address line 1."),
124+
string(ADDRESS_2)
125+
.label("Address 2")
126+
.description("Address line 2."),
127+
string(CITY)
128+
.label("City")
129+
.description("City name."),
130+
string(STATE)
131+
.label("State")
132+
.description("ISO code or name of the state, province or district."),
133+
string(POSTCODE)
134+
.label("Postcode")
135+
.description("Postal code."),
136+
string(COUNTRY)
137+
.label("Country")
138+
.description("ISO code of the country."),
139+
string(PHONE)
140+
.label("Phone")
141+
.description("Phone number.")))
142+
.output(outputSchema(CUSTOMER_OUTPUT_PROPERTY))
143+
.perform(WoocommerceCreateCustomerAction::perform);
144+
145+
private WoocommerceCreateCustomerAction() {
146+
}
147+
148+
public static Object perform(Parameters inputParameters, Parameters conectionParameters, Context context) {
149+
return context.http(http -> http.post("/customers"))
150+
.body(
151+
Context.Http.Body.of(
152+
EMAIL, inputParameters.getRequiredString(EMAIL),
153+
FIRST_NAME, inputParameters.getRequiredString(FIRST_NAME),
154+
LAST_NAME, inputParameters.getRequiredString(LAST_NAME),
155+
USERNAME, inputParameters.getRequiredString(USERNAME),
156+
BILLING, inputParameters.getMap(BILLING),
157+
SHIPPING, inputParameters.getMap(SHIPPING)))
158+
.configuration(responseType(ResponseType.JSON))
159+
.execute()
160+
.getBody();
161+
}
162+
}

0 commit comments

Comments
 (0)