-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
260 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// Copyright 2022-present Wakflo | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package shopify | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"time" | ||
|
||
goshopify "github.com/bold-commerce/go-shopify/v4" | ||
|
||
sdk "github.com/wakflo/go-sdk/connector" | ||
sdkcore "github.com/wakflo/go-sdk/core" | ||
) | ||
|
||
type TriggerNewOrder struct { | ||
options *sdk.TriggerInfo | ||
} | ||
|
||
func NewTriggerNewOrder() *TriggerNewCustomer { | ||
return &TriggerNewCustomer{ | ||
options: &sdk.TriggerInfo{ | ||
Name: "New Order", | ||
Description: "Triggers when a new order is created", | ||
RequireAuth: true, | ||
Auth: sharedAuth, | ||
Type: sdkcore.TriggerTypeCron, | ||
Input: map[string]*sdkcore.AutoFormSchema{}, | ||
Settings: &sdkcore.TriggerSettings{}, | ||
ErrorSettings: &sdkcore.StepErrorSettings{ | ||
ContinueOnError: false, | ||
RetryOnError: false, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func (t *TriggerNewOrder) Run(ctx *sdk.RunContext) (sdk.JSON, error) { | ||
if ctx.Auth.Extra["token"] == "" { | ||
return nil, errors.New("missing shopify auth token") | ||
} | ||
|
||
domain := ctx.Auth.Extra["domain"] | ||
shopName := domain + ".myshopify.com" | ||
client := getShopifyClient(shopName, ctx.Auth.Extra["token"]) | ||
|
||
// Get the last run time from metadata, or use a default if it's the first run | ||
var lastRunTime time.Time | ||
if ctx.Metadata.LastRun != nil { | ||
lastRunTime = *ctx.Metadata.LastRun | ||
} else { | ||
lastRunTime = time.Now().Add(-24 * time.Hour) | ||
} | ||
|
||
options := &goshopify.ListOptions{ | ||
CreatedAtMin: lastRunTime, | ||
} | ||
|
||
orders, err := client.Order.List(context.Background(), options) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return orders, nil | ||
} | ||
|
||
func (t *TriggerNewOrder) Test(ctx *sdk.RunContext) (sdk.JSON, error) { | ||
return t.Run(ctx) | ||
} | ||
|
||
func (t *TriggerNewOrder) OnEnabled(ctx *sdk.RunContext) error { | ||
return nil | ||
} | ||
|
||
func (t *TriggerNewOrder) OnDisabled(ctx *sdk.RunContext) error { | ||
return nil | ||
} | ||
|
||
func (t *TriggerNewOrder) GetInfo() *sdk.TriggerInfo { | ||
return t.options | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright 2022-present Wakflo | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package woocommerce | ||
|
||
import ( | ||
sdk "github.com/wakflo/go-sdk/connector" | ||
) | ||
|
||
func NewConnector() (*sdk.ConnectorPlugin, error) { | ||
return sdk.CreateConnector(&sdk.CreateConnectorArgs{ | ||
Name: "Woocommerce", | ||
Description: "E-commerce platform built on WordPress", | ||
Logo: "devicon:woocommerce", | ||
Version: "0.0.1", | ||
Category: sdk.Apps, | ||
Authors: []string{"Wakflo <integrations@wakflo.com>"}, | ||
Triggers: []sdk.ITrigger{}, | ||
Operations: []sdk.IOperation{ | ||
NewListProductsOperation(), | ||
}, | ||
}) | ||
} |
81 changes: 81 additions & 0 deletions
81
internal/connectors/woocommerce/operation_list_products.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package woocommerce | ||
|
||
import ( | ||
"errors" | ||
"github.com/hiscaler/woocommerce-go" | ||
"github.com/hiscaler/woocommerce-go/config" | ||
"github.com/wakflo/go-sdk/autoform" | ||
sdk "github.com/wakflo/go-sdk/connector" | ||
sdkcore "github.com/wakflo/go-sdk/core" | ||
) | ||
|
||
type ListProductsOperation struct { | ||
options *sdk.OperationInfo | ||
} | ||
|
||
func NewListProductsOperation() *ListProductsOperation { | ||
return &ListProductsOperation{ | ||
options: &sdk.OperationInfo{ | ||
Name: "List products", | ||
Description: "List products in store", | ||
RequireAuth: true, | ||
Auth: sharedAuth, | ||
Input: map[string]*sdkcore.AutoFormSchema{ | ||
"projectId": autoform.NewLongTextField(). | ||
SetDisplayName(""). | ||
SetDescription(""). | ||
Build(), | ||
}, | ||
ErrorSettings: sdkcore.StepErrorSettings{ | ||
ContinueOnError: false, | ||
RetryOnError: false, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func (c *ListProductsOperation) Run(ctx *sdk.RunContext) (sdk.JSON, error) { | ||
baseURL := ctx.Auth.Extra["shop-url"] | ||
consumerKey := ctx.Auth.Extra["consumer-key"] | ||
consumerSecret := ctx.Auth.Extra["consumer-secret"] | ||
|
||
if baseURL == "" || consumerKey == "" || consumerSecret == "" { | ||
return nil, errors.New("missing WooCommerce authentication credentials") | ||
} | ||
|
||
//URL := "https://shut-present.localsite.io/wp-json/wc/v3" | ||
|
||
con := config.Config{ | ||
Debug: true, | ||
URL: "https://shut-present.localsite.io/", | ||
Version: "v3", | ||
ConsumerKey: consumerKey, | ||
ConsumerSecret: consumerSecret, | ||
AddAuthenticationToURL: false, | ||
Timeout: 10, | ||
VerifySSL: true, | ||
} | ||
|
||
wooClient := woocommerce.NewClient(con) | ||
|
||
// Create a query parameters struct | ||
//params := woocommerce.ProductsQueryParams{} | ||
|
||
// Get all products | ||
product, _ := wooClient.Services.Product.One(1) | ||
|
||
// Process the products | ||
//for _, product := range products { | ||
// fmt.Printf("Product ID: %d, Name: %s, Price: %s\n", product.ID, product.Name, product.Price) | ||
//} | ||
|
||
return product, nil | ||
} | ||
|
||
func (c *ListProductsOperation) Test(ctx *sdk.RunContext) (sdk.JSON, error) { | ||
return c.Run(ctx) | ||
} | ||
|
||
func (c *ListProductsOperation) GetInfo() *sdk.OperationInfo { | ||
return c.options | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package woocommerce | ||
|
||
import ( | ||
//"encoding/json" | ||
//"fmt" | ||
//"io/ioutil" | ||
//"log" | ||
//"net/http" | ||
|
||
//"encoding/base64" | ||
//"fmt" | ||
//"strings" | ||
// | ||
//"github.com/go-resty/resty/v2" | ||
|
||
"github.com/wakflo/go-sdk/autoform" | ||
sdkcore "github.com/wakflo/go-sdk/core" | ||
) | ||
|
||
var sharedAuth = autoform.NewCustomAuthField(). | ||
SetFields(map[string]*sdkcore.AutoFormSchema{ | ||
"shop-url": autoform.NewShortTextField().SetDisplayName("ShopUrl"). | ||
SetDescription("The base URL of your app (e.g https://mystore.com) and it should start with HTTPS only"). | ||
SetRequired(true). | ||
Build(), | ||
"consumer-key": autoform.NewShortTextField().SetDisplayName("Consumer Key"). | ||
SetDescription("The consumer key generated from your app."). | ||
Build(), | ||
"consumer-secret": autoform.NewShortTextField().SetDisplayName("Consumer Secret"). | ||
SetDescription("The consumer secret generated from your app."). | ||
Build(), | ||
}). | ||
Build() |