diff --git a/internal/handlers/ussd/menuhandler.go b/internal/handlers/ussd/menuhandler.go index 4f010d6..93acc02 100644 --- a/internal/handlers/ussd/menuhandler.go +++ b/internal/handlers/ussd/menuhandler.go @@ -624,7 +624,7 @@ func (h *Handlers) ResetIncorrectYob(ctx context.Context, sym string, input []by return res, nil } -// CheckBalance retrieves the balance from the API using the "PublicKey" and sets +// CheckBalance retrieves the balance of the active voucher and sets // the balance as the result content func (h *Handlers) CheckBalance(ctx context.Context, sym string, input []byte) (resource.Result, error) { var res resource.Result @@ -640,12 +640,13 @@ func (h *Handlers) CheckBalance(ctx context.Context, sym string, input []byte) ( // get the active sym and active balance activeSym, err := store.ReadEntry(ctx, sessionId, utils.DATA_ACTIVE_SYM) if err != nil { - return res, err + res.Content = "0.00" + return res, nil } activeBal, err := store.ReadEntry(ctx, sessionId, utils.DATA_ACTIVE_BAL) if err != nil { - return res, err + return res, nil } res.Content = fmt.Sprintf("%s %s", activeBal, activeSym) @@ -991,6 +992,8 @@ func (h *Handlers) SetDefaultVoucher(ctx context.Context, sym string, input []by return res, fmt.Errorf("missing session") } + flag_no_active_voucher, _ := h.flagManager.GetFlag("flag_no_active_voucher") + // check if the user has an active sym _, err = store.ReadEntry(ctx, sessionId, utils.DATA_ACTIVE_SYM) @@ -1008,9 +1011,10 @@ func (h *Handlers) SetDefaultVoucher(ctx context.Context, sym string, input []by return res, nil } - // Ensure there is at least one voucher + // Return if there is no voucher if len(vouchersResp.Result.Holdings) == 0 { - return res, err + res.FlagSet = append(res.FlagSet, flag_no_active_voucher) + return res, nil } // Use only the first voucher @@ -1035,6 +1039,8 @@ func (h *Handlers) SetDefaultVoucher(ctx context.Context, sym string, input []by return res, err } + res.FlagReset = append(res.FlagReset, flag_no_active_voucher) + return res, nil } @@ -1160,7 +1166,7 @@ func (h *Handlers) ViewVoucher(ctx context.Context, sym string, input []byte) (r if err != nil { return res, err } - + res.FlagReset = append(res.FlagReset, flag_incorrect_voucher) res.Content = fmt.Sprintf("%s\n%s", matchedSymbol, matchedBalance) } else { diff --git a/services/registration/no_voucher b/services/registration/no_voucher new file mode 100644 index 0000000..332f00e --- /dev/null +++ b/services/registration/no_voucher @@ -0,0 +1 @@ +You need a voucher to send \ No newline at end of file diff --git a/services/registration/no_voucher.vis b/services/registration/no_voucher.vis new file mode 100644 index 0000000..832ef22 --- /dev/null +++ b/services/registration/no_voucher.vis @@ -0,0 +1,5 @@ +MOUT back 0 +MOUT quit 9 +HALT +INCMP ^ 0 +INCMP quit 9 diff --git a/services/registration/no_voucher_swa b/services/registration/no_voucher_swa new file mode 100644 index 0000000..66e8f26 --- /dev/null +++ b/services/registration/no_voucher_swa @@ -0,0 +1 @@ +Unahitaji sarafu kutuma \ No newline at end of file diff --git a/services/registration/pp.csv b/services/registration/pp.csv index 96d3e8a..ec0d8c1 100644 --- a/services/registration/pp.csv +++ b/services/registration/pp.csv @@ -15,4 +15,5 @@ flag,flag_allow_update,21,this is set to allow a user to update their profile da flag,flag_single_edit,22,this is set to allow a user to edit a single profile item such as year of birth flag,flag_incorrect_date_format,23,this is set when the given year of birth is invalid flag,flag_incorrect_voucher,24,this is set when the selected voucher is invalid -flag,flag_api_call_error,25,this is set when communication to an external service fails +flag,flag_api_call_error,25,this is set when communication to an external service fails +flag,flag_no_active_voucher,26,this is set when a user does not have an active voucher diff --git a/services/registration/send.vis b/services/registration/send.vis index e120302..0ff0927 100644 --- a/services/registration/send.vis +++ b/services/registration/send.vis @@ -1,4 +1,5 @@ LOAD transaction_reset 0 +CATCH no_voucher flag_no_active_voucher 1 MOUT back 0 HALT LOAD validate_recipient 20