lib/rules/developer-workflow.go

125 lines
3.0 KiB
Go
Raw Permalink Normal View History

2021-01-13 02:41:43 +00:00
package rules
import (
"time"
"code.tnxs.net/taxnexus/lib/app"
"go.temporal.io/sdk/workflow"
)
2021-01-19 20:11:18 +00:00
// NewDeveloperWorkflowWrapper wraps a contact, account, payment method with auth and saga info
type NewDeveloperWorkflowWrapper struct {
2021-01-19 17:45:58 +00:00
AccountName string
BillingStreet string
BillingCity string
BillingState string
BillingPostalCode string
Company string
Description string
Email string
FirstName string
LastName string
MobilePhone string
Name string
Phone string
Title string
Website string
APIKey string
SagaID string
SagaType string
2021-01-13 02:41:43 +00:00
}
2021-01-14 06:36:35 +00:00
// NewDeveloperWorkflow is a Temporal workflow
2021-01-19 21:20:11 +00:00
func NewDeveloperWorkflow(ctx workflow.Context, w NewDeveloperWorkflowWrapper) error { //nolint:gocritic // don't care
2021-01-13 02:41:43 +00:00
ctx = workflow.WithActivityOptions(ctx, workflow.ActivityOptions{
StartToCloseTimeout: time.Minute,
})
err := workflow.ExecuteActivity(ctx,
StoreContactActivity,
2021-01-19 20:23:02 +00:00
app.ContactActivityWrapper{
2021-01-19 21:18:59 +00:00
Description: w.Description,
Email: w.Email,
FirstName: w.FirstName,
LastName: w.LastName,
MobilePhone: w.MobilePhone,
Name: w.Name,
Phone: w.Phone,
Title: w.Title,
APIKey: w.APIKey,
SagaID: w.SagaID,
SagaType: w.SagaType,
2021-01-13 02:41:43 +00:00
}).Get(ctx, nil)
if err != nil {
return err
}
err = workflow.ExecuteActivity(ctx,
StoreAccountActivity,
2021-01-19 20:23:02 +00:00
&app.AccountActivityWrapper{
2021-01-19 02:48:56 +00:00
APIKey: w.APIKey,
SagaID: w.SagaID,
SagaType: w.SagaType,
2021-01-19 21:18:59 +00:00
//
Description: w.Description,
Email: w.Email,
Name: w.AccountName,
2021-01-13 02:41:43 +00:00
}).Get(ctx, nil)
if err != nil {
return err
}
err = workflow.ExecuteActivity(ctx,
StorePaymentMethodActivity,
2021-01-19 20:23:02 +00:00
&app.PaymentMethodActivityWrapper{
2021-01-19 02:48:56 +00:00
APIKey: w.APIKey,
SagaID: w.SagaID,
SagaType: w.SagaType,
2021-01-19 21:18:59 +00:00
//
AccountID: "todo fix this",
AchAccountType: "",
AchBankAccount: "",
AchRouting: "",
Active: false,
Autopay: false,
BankName: "",
BillingContactID: "",
CCnumber: "",
CCtype: "",
ContractID: "",
Default: false,
ExpirationMonth: "",
ExpirationYear: "",
Gateway: "",
GatewayKey: "",
Nickname: "",
RecordType: "",
Ref: "",
TenantID: "",
2021-01-13 02:41:43 +00:00
}).Get(ctx, nil)
if err != nil {
return err
}
err = workflow.ExecuteActivity(ctx,
NotifyContactActivity,
2021-01-19 20:23:02 +00:00
&app.ContactActivityWrapper{
2021-01-19 02:48:56 +00:00
APIKey: w.APIKey,
SagaID: w.SagaID,
SagaType: w.SagaType,
2021-01-19 21:18:59 +00:00
//
Description: w.Description,
Email: w.Email,
FirstName: w.FirstName,
LastName: w.LastName,
MobilePhone: w.MobilePhone,
Name: w.Name,
Phone: w.Phone,
Title: w.Title,
2021-01-13 02:41:43 +00:00
}).Get(ctx, nil)
if err != nil {
return err
}
2021-01-19 02:48:56 +00:00
err = workflow.ExecuteActivity(ctx, NotifyLeadActivity, w).Get(ctx, nil)
2021-01-13 02:41:43 +00:00
if err != nil {
return err
}
return nil
}