|
| 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