-
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
10 changed files
with
703 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// 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 cin7 | ||
|
||
import ( | ||
sdk "github.com/wakflo/go-sdk/connector" | ||
) | ||
|
||
func NewConnector() (*sdk.ConnectorPlugin, error) { | ||
return sdk.CreateConnector(&sdk.CreateConnectorArgs{ | ||
Name: "Cin7", | ||
Description: "interacts with the cin7 api", | ||
Logo: "twemoji:passenger-ship", | ||
Version: "0.0.1", | ||
Category: sdk.Apps, | ||
Authors: []string{"Wakflo <integrations@wakflo.com>"}, | ||
Triggers: []sdk.ITrigger{ | ||
NewTriggerNewSales(), | ||
}, | ||
Operations: []sdk.IOperation{ | ||
NewGetProductsOperation(), | ||
NewGetCustomersOperation(), | ||
NewGetSalesOrderOperation(), | ||
NewGetSalesListOperation(), | ||
NewGetPurchaseInvoiceOperation(), | ||
}, | ||
}) | ||
} |
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 @@ | ||
// 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 cin7 | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/wakflo/go-sdk/autoform" | ||
sdk "github.com/wakflo/go-sdk/connector" | ||
sdkcore "github.com/wakflo/go-sdk/core" | ||
) | ||
|
||
type getPaymentOperationProps struct { | ||
PaymentID string `json:"id"` | ||
} | ||
|
||
type GetPaymentOperation struct { | ||
options *sdk.OperationInfo | ||
} | ||
|
||
func NewGetPaymentOperation() *GetPaymentOperation { | ||
return &GetPaymentOperation{ | ||
options: &sdk.OperationInfo{ | ||
Name: "Get a payment", | ||
Description: "Get payment information", | ||
RequireAuth: true, | ||
Auth: sharedAuth, | ||
Input: map[string]*sdkcore.AutoFormSchema{ | ||
"id": autoform.NewShortTextField(). | ||
SetDisplayName("Payment ID"). | ||
SetDescription("The paymentId of the payment"). | ||
SetRequired(true). | ||
Build(), | ||
}, | ||
ErrorSettings: sdkcore.StepErrorSettings{ | ||
ContinueOnError: false, | ||
RetryOnError: false, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func (c *GetPaymentOperation) Run(ctx *sdk.RunContext) (sdk.JSON, error) { | ||
input := sdk.InputToType[getPaymentOperationProps](ctx) | ||
|
||
endpoint := "/ExternalApi/" | ||
accountID := ctx.Auth.Extra["account_id"] | ||
applicationKey := ctx.Auth.Extra["key"] | ||
queryParams := map[string]interface{}{ | ||
"ID": input.PaymentID, | ||
} | ||
|
||
response, err := fetchData(endpoint, accountID, applicationKey, queryParams) | ||
if err != nil { | ||
log.Fatalf("Error fetching data: %v", err) | ||
} | ||
|
||
return sdk.JSON(map[string]interface{}{ | ||
"data": response, | ||
}), nil | ||
} | ||
|
||
func (c *GetPaymentOperation) Test(ctx *sdk.RunContext) (sdk.JSON, error) { | ||
return c.Run(ctx) | ||
} | ||
|
||
func (c *GetPaymentOperation) 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,83 @@ | ||
// 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 cin7 | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/wakflo/go-sdk/autoform" | ||
|
||
sdk "github.com/wakflo/go-sdk/connector" | ||
sdkcore "github.com/wakflo/go-sdk/core" | ||
) | ||
|
||
type getCustomerOperationProps struct { | ||
PageLimit int `json:"page-limit"` | ||
} | ||
|
||
type GetCustomersOperation struct { | ||
options *sdk.OperationInfo | ||
} | ||
|
||
func NewGetCustomersOperation() *GetCustomersOperation { | ||
return &GetCustomersOperation{ | ||
options: &sdk.OperationInfo{ | ||
Name: "Get Customers", | ||
Description: "Retrieves a list of customers from Cin7", | ||
RequireAuth: true, | ||
Auth: sharedAuth, | ||
Input: map[string]*sdkcore.AutoFormSchema{ | ||
"page-limit": autoform.NewNumberField(). | ||
SetDisplayName("Product limit"). | ||
SetDescription(" Specifies the page limit for getting products."). | ||
SetDefaultValue(100). | ||
Build(), | ||
}, | ||
ErrorSettings: sdkcore.StepErrorSettings{ | ||
ContinueOnError: false, | ||
RetryOnError: false, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func (c *GetCustomersOperation) Run(ctx *sdk.RunContext) (sdk.JSON, error) { | ||
input := sdk.InputToType[getProductsOperationProps](ctx) | ||
|
||
endpoint := "/ExternalApi/Customers" | ||
accountID := ctx.Auth.Extra["account_id"] | ||
applicationKey := ctx.Auth.Extra["key"] | ||
queryParams := map[string]interface{}{ | ||
"Page": "1", | ||
"Limit": input.PageLimit, | ||
} | ||
|
||
response, err := fetchData(endpoint, accountID, applicationKey, queryParams) | ||
if err != nil { | ||
log.Fatalf("Error fetching data: %v", err) | ||
} | ||
|
||
return sdk.JSON(map[string]interface{}{ | ||
"customers": response, | ||
}), nil | ||
} | ||
|
||
func (c *GetCustomersOperation) Test(ctx *sdk.RunContext) (sdk.JSON, error) { | ||
return c.Run(ctx) | ||
} | ||
|
||
func (c *GetCustomersOperation) 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,81 @@ | ||
// 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 cin7 | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/wakflo/go-sdk/autoform" | ||
sdk "github.com/wakflo/go-sdk/connector" | ||
sdkcore "github.com/wakflo/go-sdk/core" | ||
) | ||
|
||
type getProductsOperationProps struct { | ||
PageLimit int `json:"page-limit"` | ||
} | ||
|
||
type GetProductsOperation struct { | ||
options *sdk.OperationInfo | ||
} | ||
|
||
func NewGetProductsOperation() *GetProductsOperation { | ||
return &GetProductsOperation{ | ||
options: &sdk.OperationInfo{ | ||
Name: "Get Products", | ||
Description: "Retrieves a list of products from Cin7", | ||
RequireAuth: true, | ||
Auth: sharedAuth, | ||
Input: map[string]*sdkcore.AutoFormSchema{ | ||
"page-limit": autoform.NewNumberField(). | ||
SetDisplayName("Product limit"). | ||
SetDescription(" Specifies the page limit for getting products."). | ||
SetDefaultValue(100). | ||
Build(), | ||
}, | ||
ErrorSettings: sdkcore.StepErrorSettings{ | ||
ContinueOnError: false, | ||
RetryOnError: false, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func (c *GetProductsOperation) Run(ctx *sdk.RunContext) (sdk.JSON, error) { | ||
input := sdk.InputToType[getProductsOperationProps](ctx) | ||
|
||
endpoint := "/ExternalApi/Products" | ||
accountID := ctx.Auth.Extra["account_id"] | ||
applicationKey := ctx.Auth.Extra["key"] | ||
queryParams := map[string]interface{}{ | ||
"Limit": input.PageLimit, | ||
} | ||
|
||
response, err := fetchData(endpoint, accountID, applicationKey, queryParams) | ||
if err != nil { | ||
log.Fatalf("Error fetching data: %v", err) | ||
} | ||
|
||
return sdk.JSON(map[string]interface{}{ | ||
"products": response, | ||
}), nil | ||
} | ||
|
||
func (c *GetProductsOperation) Test(ctx *sdk.RunContext) (sdk.JSON, error) { | ||
return c.Run(ctx) | ||
} | ||
|
||
func (c *GetProductsOperation) GetInfo() *sdk.OperationInfo { | ||
return c.options | ||
} |
82 changes: 82 additions & 0 deletions
82
internal/connectors/cin7/operation_get_purchase_invoice.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,82 @@ | ||
// 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 cin7 | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/wakflo/go-sdk/autoform" | ||
sdk "github.com/wakflo/go-sdk/connector" | ||
sdkcore "github.com/wakflo/go-sdk/core" | ||
) | ||
|
||
type getPurchaseInvoiceOperationProps struct { | ||
TaskID string `json:"id"` | ||
} | ||
|
||
type GetPurchaseInvoiceOperation struct { | ||
options *sdk.OperationInfo | ||
} | ||
|
||
func NewGetPurchaseInvoiceOperation() *GetPurchaseInvoiceOperation { | ||
return &GetPurchaseInvoiceOperation{ | ||
options: &sdk.OperationInfo{ | ||
Name: "Get Purchase Invoice", | ||
Description: "Retrieves the purchase invoice", | ||
RequireAuth: true, | ||
Auth: sharedAuth, | ||
Input: map[string]*sdkcore.AutoFormSchema{ | ||
"id": autoform.NewShortTextField(). | ||
SetDisplayName("Task ID"). | ||
SetDescription("The ID of Task"). | ||
SetRequired(true). | ||
Build(), | ||
}, | ||
ErrorSettings: sdkcore.StepErrorSettings{ | ||
ContinueOnError: false, | ||
RetryOnError: false, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func (c *GetPurchaseInvoiceOperation) Run(ctx *sdk.RunContext) (sdk.JSON, error) { | ||
input := sdk.InputToType[getPurchaseInvoiceOperationProps](ctx) | ||
|
||
endpoint := "/ExternalApi/v2/purchase/invoice" | ||
accountID := ctx.Auth.Extra["account_id"] | ||
applicationKey := ctx.Auth.Extra["key"] | ||
queryParams := map[string]interface{}{ | ||
"TaskID": input.TaskID, | ||
"CombineAdditionalCharges": true, | ||
} | ||
|
||
response, err := fetchData(endpoint, accountID, applicationKey, queryParams) | ||
if err != nil { | ||
log.Fatalf("Error fetching data: %v", err) | ||
} | ||
|
||
return sdk.JSON(map[string]interface{}{ | ||
"data": response, | ||
}), nil | ||
} | ||
|
||
func (c *GetPurchaseInvoiceOperation) Test(ctx *sdk.RunContext) (sdk.JSON, error) { | ||
return c.Run(ctx) | ||
} | ||
|
||
func (c *GetPurchaseInvoiceOperation) GetInfo() *sdk.OperationInfo { | ||
return c.options | ||
} |
Oops, something went wrong.