2024-09-19 14:54:23 +02:00
|
|
|
package handlers
|
|
|
|
|
|
|
|
import (
|
2024-10-31 18:10:46 +01:00
|
|
|
"context"
|
|
|
|
|
2024-09-19 14:54:23 +02:00
|
|
|
"git.defalsify.org/vise.git/asm"
|
|
|
|
"git.defalsify.org/vise.git/db"
|
|
|
|
"git.defalsify.org/vise.git/engine"
|
|
|
|
"git.defalsify.org/vise.git/persist"
|
|
|
|
"git.defalsify.org/vise.git/resource"
|
2024-10-30 14:09:15 +01:00
|
|
|
|
2024-09-19 14:54:23 +02:00
|
|
|
"git.grassecon.net/urdt/ussd/internal/handlers/ussd"
|
2024-11-02 16:46:46 +01:00
|
|
|
"git.grassecon.net/urdt/ussd/internal/utils"
|
2024-10-30 14:09:15 +01:00
|
|
|
"git.grassecon.net/urdt/ussd/remote"
|
2024-09-19 14:54:23 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type HandlerService interface {
|
|
|
|
GetHandler() (*ussd.Handlers, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
func getParser(fp string, debug bool) (*asm.FlagParser, error) {
|
|
|
|
flagParser := asm.NewFlagParser().WithDebug()
|
|
|
|
_, err := flagParser.Load(fp)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return flagParser, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type LocalHandlerService struct {
|
|
|
|
Parser *asm.FlagParser
|
|
|
|
DbRs *resource.DbResource
|
|
|
|
Pe *persist.Persister
|
2024-09-19 20:04:09 +02:00
|
|
|
UserdataStore *db.Db
|
2024-10-30 12:32:01 +01:00
|
|
|
AdminStore *utils.AdminStore
|
2024-09-19 14:54:23 +02:00
|
|
|
Cfg engine.Config
|
|
|
|
Rs resource.Resource
|
|
|
|
}
|
|
|
|
|
2024-10-31 18:10:46 +01:00
|
|
|
func NewLocalHandlerService(ctx context.Context, fp string, debug bool, dbResource *resource.DbResource, cfg engine.Config, rs resource.Resource) (*LocalHandlerService, error) {
|
2024-09-19 14:54:23 +02:00
|
|
|
parser, err := getParser(fp, debug)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2024-10-31 18:10:46 +01:00
|
|
|
adminstore, err := utils.NewAdminStore(ctx, "admin_numbers")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2024-09-19 14:54:23 +02:00
|
|
|
return &LocalHandlerService{
|
2024-10-31 18:10:46 +01:00
|
|
|
Parser: parser,
|
|
|
|
DbRs: dbResource,
|
|
|
|
AdminStore: adminstore,
|
|
|
|
Cfg: cfg,
|
|
|
|
Rs: rs,
|
2024-09-19 14:54:23 +02:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2024-09-21 19:49:11 +02:00
|
|
|
func (ls *LocalHandlerService) SetPersister(Pe *persist.Persister) {
|
|
|
|
ls.Pe = Pe
|
2024-09-19 20:04:09 +02:00
|
|
|
}
|
|
|
|
|
2024-09-21 19:49:11 +02:00
|
|
|
func (ls *LocalHandlerService) SetDataStore(db *db.Db) {
|
|
|
|
ls.UserdataStore = db
|
2024-09-19 20:04:09 +02:00
|
|
|
}
|
|
|
|
|
2024-10-30 14:09:15 +01:00
|
|
|
func (ls *LocalHandlerService) GetHandler(accountService remote.AccountServiceInterface) (*ussd.Handlers, error) {
|
2024-10-30 12:32:01 +01:00
|
|
|
ussdHandlers, err := ussd.NewHandlers(ls.Parser, *ls.UserdataStore, ls.AdminStore, accountService)
|
2024-09-19 14:54:23 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2024-09-24 08:18:21 +02:00
|
|
|
ussdHandlers = ussdHandlers.WithPersister(ls.Pe)
|
|
|
|
ls.DbRs.AddLocalFunc("set_language", ussdHandlers.SetLanguage)
|
|
|
|
ls.DbRs.AddLocalFunc("create_account", ussdHandlers.CreateAccount)
|
2024-09-28 11:26:37 +02:00
|
|
|
ls.DbRs.AddLocalFunc("save_temporary_pin", ussdHandlers.SaveTemporaryPin)
|
|
|
|
ls.DbRs.AddLocalFunc("verify_create_pin", ussdHandlers.VerifyCreatePin)
|
2024-09-24 08:18:21 +02:00
|
|
|
ls.DbRs.AddLocalFunc("check_identifier", ussdHandlers.CheckIdentifier)
|
|
|
|
ls.DbRs.AddLocalFunc("check_account_status", ussdHandlers.CheckAccountStatus)
|
|
|
|
ls.DbRs.AddLocalFunc("authorize_account", ussdHandlers.Authorize)
|
|
|
|
ls.DbRs.AddLocalFunc("quit", ussdHandlers.Quit)
|
|
|
|
ls.DbRs.AddLocalFunc("check_balance", ussdHandlers.CheckBalance)
|
|
|
|
ls.DbRs.AddLocalFunc("validate_recipient", ussdHandlers.ValidateRecipient)
|
|
|
|
ls.DbRs.AddLocalFunc("transaction_reset", ussdHandlers.TransactionReset)
|
2024-11-14 12:59:39 +01:00
|
|
|
ls.DbRs.AddLocalFunc("invite_valid_recipient", ussdHandlers.InviteValidRecipient)
|
2024-09-24 08:18:21 +02:00
|
|
|
ls.DbRs.AddLocalFunc("max_amount", ussdHandlers.MaxAmount)
|
|
|
|
ls.DbRs.AddLocalFunc("validate_amount", ussdHandlers.ValidateAmount)
|
|
|
|
ls.DbRs.AddLocalFunc("reset_transaction_amount", ussdHandlers.ResetTransactionAmount)
|
|
|
|
ls.DbRs.AddLocalFunc("get_recipient", ussdHandlers.GetRecipient)
|
|
|
|
ls.DbRs.AddLocalFunc("get_sender", ussdHandlers.GetSender)
|
|
|
|
ls.DbRs.AddLocalFunc("get_amount", ussdHandlers.GetAmount)
|
|
|
|
ls.DbRs.AddLocalFunc("reset_incorrect", ussdHandlers.ResetIncorrectPin)
|
|
|
|
ls.DbRs.AddLocalFunc("save_firstname", ussdHandlers.SaveFirstname)
|
|
|
|
ls.DbRs.AddLocalFunc("save_familyname", ussdHandlers.SaveFamilyname)
|
|
|
|
ls.DbRs.AddLocalFunc("save_gender", ussdHandlers.SaveGender)
|
|
|
|
ls.DbRs.AddLocalFunc("save_location", ussdHandlers.SaveLocation)
|
|
|
|
ls.DbRs.AddLocalFunc("save_yob", ussdHandlers.SaveYob)
|
|
|
|
ls.DbRs.AddLocalFunc("save_offerings", ussdHandlers.SaveOfferings)
|
|
|
|
ls.DbRs.AddLocalFunc("reset_account_authorized", ussdHandlers.ResetAccountAuthorized)
|
|
|
|
ls.DbRs.AddLocalFunc("reset_allow_update", ussdHandlers.ResetAllowUpdate)
|
|
|
|
ls.DbRs.AddLocalFunc("get_profile_info", ussdHandlers.GetProfileInfo)
|
|
|
|
ls.DbRs.AddLocalFunc("verify_yob", ussdHandlers.VerifyYob)
|
|
|
|
ls.DbRs.AddLocalFunc("reset_incorrect_date_format", ussdHandlers.ResetIncorrectYob)
|
|
|
|
ls.DbRs.AddLocalFunc("initiate_transaction", ussdHandlers.InitiateTransaction)
|
|
|
|
ls.DbRs.AddLocalFunc("verify_new_pin", ussdHandlers.VerifyNewPin)
|
|
|
|
ls.DbRs.AddLocalFunc("confirm_pin_change", ussdHandlers.ConfirmPinChange)
|
|
|
|
ls.DbRs.AddLocalFunc("quit_with_help", ussdHandlers.QuitWithHelp)
|
2024-11-18 15:23:36 +01:00
|
|
|
ls.DbRs.AddLocalFunc("fetch_community_balance", ussdHandlers.FetchCommunityBalance)
|
2024-10-15 14:46:02 +02:00
|
|
|
ls.DbRs.AddLocalFunc("set_default_voucher", ussdHandlers.SetDefaultVoucher)
|
2024-10-05 15:56:49 +02:00
|
|
|
ls.DbRs.AddLocalFunc("check_vouchers", ussdHandlers.CheckVouchers)
|
2024-09-28 11:26:37 +02:00
|
|
|
ls.DbRs.AddLocalFunc("get_vouchers", ussdHandlers.GetVoucherList)
|
2024-10-07 15:16:57 +02:00
|
|
|
ls.DbRs.AddLocalFunc("view_voucher", ussdHandlers.ViewVoucher)
|
2024-10-09 14:39:06 +02:00
|
|
|
ls.DbRs.AddLocalFunc("set_voucher", ussdHandlers.SetVoucher)
|
2024-11-15 19:03:57 +01:00
|
|
|
ls.DbRs.AddLocalFunc("get_voucher_details", ussdHandlers.GetVoucherDetails)
|
2024-10-28 13:49:20 +01:00
|
|
|
ls.DbRs.AddLocalFunc("reset_valid_pin", ussdHandlers.ResetValidPin)
|
2024-12-17 16:32:10 +01:00
|
|
|
ls.DbRs.AddLocalFunc("check_pin_mismatch", ussdHandlers.CheckBlockedNumPinMisMatch)
|
2024-10-28 13:49:20 +01:00
|
|
|
ls.DbRs.AddLocalFunc("validate_blocked_number", ussdHandlers.ValidateBlockedNumber)
|
|
|
|
ls.DbRs.AddLocalFunc("retrieve_blocked_number", ussdHandlers.RetrieveBlockedNumber)
|
2024-10-29 15:34:34 +01:00
|
|
|
ls.DbRs.AddLocalFunc("reset_unregistered_number", ussdHandlers.ResetUnregisteredNumber)
|
2024-10-30 12:32:01 +01:00
|
|
|
ls.DbRs.AddLocalFunc("reset_others_pin", ussdHandlers.ResetOthersPin)
|
|
|
|
ls.DbRs.AddLocalFunc("save_others_temporary_pin", ussdHandlers.SaveOthersTemporaryPin)
|
2024-11-07 07:16:49 +01:00
|
|
|
ls.DbRs.AddLocalFunc("get_current_profile_info", ussdHandlers.GetCurrentProfileInfo)
|
2024-11-19 14:07:28 +01:00
|
|
|
ls.DbRs.AddLocalFunc("check_transactions", ussdHandlers.CheckTransactions)
|
|
|
|
ls.DbRs.AddLocalFunc("get_transactions", ussdHandlers.GetTransactionsList)
|
|
|
|
ls.DbRs.AddLocalFunc("view_statement", ussdHandlers.ViewTransactionStatement)
|
2024-12-02 18:35:56 +01:00
|
|
|
ls.DbRs.AddLocalFunc("update_all_profile_items", ussdHandlers.UpdateAllProfileItems)
|
2024-12-04 06:20:43 +01:00
|
|
|
ls.DbRs.AddLocalFunc("set_back", ussdHandlers.SetBack)
|
2024-09-19 14:54:23 +02:00
|
|
|
|
|
|
|
return ussdHandlers, nil
|
|
|
|
}
|
|
|
|
|
2024-09-21 19:49:11 +02:00
|
|
|
// TODO: enable setting of sessionId on engine init time
|
|
|
|
func (ls *LocalHandlerService) GetEngine() *engine.DefaultEngine {
|
|
|
|
en := engine.NewEngine(ls.Cfg, ls.Rs)
|
|
|
|
en = en.WithPersister(ls.Pe)
|
2024-09-19 14:54:23 +02:00
|
|
|
return en
|
|
|
|
}
|