diff --git a/cmd/main.go b/cmd/main.go index ad8699c..bd38a3f 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -101,6 +101,7 @@ func main() { rfs.AddLocalFunc("reset_transaction_amount", ussdHandlers.ResetTransactionAmount) rfs.AddLocalFunc("get_recipient", ussdHandlers.GetRecipient) rfs.AddLocalFunc("get_sender", ussdHandlers.GetSender) + rfs.AddLocalFunc("get_amount", ussdHandlers.GetAmount) rfs.AddLocalFunc("reset_incorrect", ussdHandlers.ResetIncorrectPin) rfs.AddLocalFunc("save_firstname", ussdHandlers.SaveFirstname) rfs.AddLocalFunc("save_familyname", ussdHandlers.SaveFamilyname) @@ -115,6 +116,7 @@ func main() { rfs.AddLocalFunc("verify_yob", ussdHandlers.VerifyYob) rfs.AddLocalFunc("reset_incorrect_date_format", ussdHandlers.ResetIncorrectYob) rfs.AddLocalFunc("set_reset_single_edit", ussdHandlers.SetResetSingleEdit) + rfs.AddLocalFunc("initiate_transaction", ussdHandlers.InitiateTransaction) cont, err := en.Init(ctx) en.SetDebugger(engine.NewSimpleDebug(nil)) diff --git a/internal/handlers/ussd/menuhandler.go b/internal/handlers/ussd/menuhandler.go index 7116df0..8d40c1f 100644 --- a/internal/handlers/ussd/menuhandler.go +++ b/internal/handlers/ussd/menuhandler.go @@ -494,8 +494,9 @@ func (h *Handlers) TransactionReset(ctx context.Context, sym string, input []byt return res, err } - // reset the recipient + // reset the transaction accountData["Recipient"] = "" + accountData["Amount"] = "" err = h.accountFileHandler.WriteAccountData(accountData) if err != nil { @@ -662,6 +663,21 @@ func (h *Handlers) GetSender(ctx context.Context, sym string, input []byte) (res return res, nil } +// GetAmount retrieves the amount from a JSON data file. +func (h *Handlers) GetAmount(ctx context.Context, sym string, input []byte) (resource.Result, error) { + res := resource.Result{} + + accountData, err := h.accountFileHandler.ReadAccountData() + if err != nil { + return res, err + } + + res.Content = accountData["Amount"] + + return res, nil +} + + func (h *Handlers) QuitWithBalance(ctx context.Context, sym string, input []byte) (resource.Result, error) { res := resource.Result{} @@ -677,3 +693,13 @@ func (h *Handlers) QuitWithBalance(ctx context.Context, sym string, input []byte res.FlagReset = append(res.FlagReset, models.USERFLAG_ACCOUNT_UNLOCKED) return res, nil } + +func (h *Handlers) InitiateTransaction(ctx context.Context, sym string, input []byte) (resource.Result, error) { + res := resource.Result{} + + // TODO + // Use the amount, recipient and sender to call the API and initialize the transaction + + res.FlagReset = append(res.FlagReset, models.USERFLAG_ACCOUNT_UNLOCKED) + return res, nil +} diff --git a/services/registration/transaction_initiated b/services/registration/transaction_initiated new file mode 100644 index 0000000..2909071 --- /dev/null +++ b/services/registration/transaction_initiated @@ -0,0 +1 @@ +Your request has been sent. {{.get_recipient}} will receive {{.get_amount}} from {{.get_sender}}. \ No newline at end of file diff --git a/services/registration/transaction_initiated.vis b/services/registration/transaction_initiated.vis new file mode 100644 index 0000000..c51a441 --- /dev/null +++ b/services/registration/transaction_initiated.vis @@ -0,0 +1,12 @@ +LOAD reset_incorrect 0 +LOAD get_amount 10 +MAP get_amount +RELOAD get_recipient +MAP get_recipient +RELOAD get_sender +MAP get_sender +LOAD initiate_transaction 0 +RELOAD transaction_reset +MOUT quit 9 +HALT +INCMP quit 9 diff --git a/services/registration/transaction_initiated_swa b/services/registration/transaction_initiated_swa new file mode 100644 index 0000000..fb6125a --- /dev/null +++ b/services/registration/transaction_initiated_swa @@ -0,0 +1 @@ +Ombi lako limetumwa. {{.get_recipient}} atapokea {{.get_amount}} kutoka kwa {{.get_sender}}. \ No newline at end of file diff --git a/services/registration/transaction_pin.vis b/services/registration/transaction_pin.vis index 38347ba..5c10b3f 100644 --- a/services/registration/transaction_pin.vis +++ b/services/registration/transaction_pin.vis @@ -6,5 +6,9 @@ MAP get_sender MOUT back 0 MOUT quit 9 HALT +LOAD unlock_account 1 +RELOAD unlock_account +CATCH incorrect_pin 15 1 INCMP _ 0 INCMP quit 9 +MOVE transaction_initiated