project-tidyup - menuhandler and tests #90
@ -1318,41 +1318,6 @@ func (h *MenuHandlers) TransactionReset(ctx context.Context, sym string, input [
|
|||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// InviteValidRecipient sends an invitation to the valid phone number.
|
|
||||||
func (h *MenuHandlers) InviteValidRecipient(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
|
||||||
var res resource.Result
|
|
||||||
store := h.userdataStore
|
|
||||||
smsservice := h.smsService
|
|
||||||
|
|
||||||
sessionId, ok := ctx.Value("SessionId").(string)
|
|
||||||
if !ok {
|
|
||||||
return res, fmt.Errorf("missing session")
|
|
||||||
}
|
|
||||||
|
|
||||||
code := codeFromCtx(ctx)
|
|
||||||
l := gotext.NewLocale(translationDir, code)
|
|
||||||
l.AddDomain("default")
|
|
||||||
|
|
||||||
recipient, err := store.ReadEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE)
|
|
||||||
if err != nil {
|
|
||||||
logg.ErrorCtxf(ctx, "Failed to read invalid recipient info", "error", err)
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if !phone.IsValidPhoneNumber(string(recipient)) {
|
|
||||||
logg.InfoCtxf(ctx, "corrupted recipient", "key", storedb.DATA_TEMPORARY_VALUE, "recipient", recipient)
|
|
||||||
return res, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = smsservice.Accountservice.SendUpsellSMS(ctx, sessionId, string(recipient))
|
|
||||||
if err != nil {
|
|
||||||
res.Content = l.Get("Your invite request for %s to Sarafu Network failed. Please try again later.", string(recipient))
|
|
||||||
return res, nil
|
|
||||||
}
|
|
||||||
res.Content = l.Get("Your invitation to %s to join Sarafu Network has been sent.", string(recipient))
|
|
||||||
return res, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ResetTransactionAmount resets the transaction amount and invalid flag.
|
// ResetTransactionAmount resets the transaction amount and invalid flag.
|
||||||
func (h *MenuHandlers) ResetTransactionAmount(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
func (h *MenuHandlers) ResetTransactionAmount(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||||
var res resource.Result
|
var res resource.Result
|
||||||
|
46
handlers/application/upsell.go
Normal file
46
handlers/application/upsell.go
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
package application
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"git.defalsify.org/vise.git/resource"
|
||||||
|
"git.grassecon.net/grassrootseconomics/common/phone"
|
||||||
|
storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db"
|
||||||
|
"gopkg.in/leonelquinteros/gotext.v1"
|
||||||
|
)
|
||||||
|
|
||||||
|
// InviteValidRecipient sends an invitation to the valid phone number.
|
||||||
|
func (h *MenuHandlers) InviteValidRecipient(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||||
|
var res resource.Result
|
||||||
|
store := h.userdataStore
|
||||||
|
smsservice := h.smsService
|
||||||
|
|
||||||
|
sessionId, ok := ctx.Value("SessionId").(string)
|
||||||
|
if !ok {
|
||||||
|
return res, fmt.Errorf("missing session")
|
||||||
|
}
|
||||||
|
|
||||||
|
code := codeFromCtx(ctx)
|
||||||
|
l := gotext.NewLocale(translationDir, code)
|
||||||
|
l.AddDomain("default")
|
||||||
|
|
||||||
|
recipient, err := store.ReadEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE)
|
||||||
|
if err != nil {
|
||||||
|
logg.ErrorCtxf(ctx, "Failed to read invalid recipient info", "error", err)
|
||||||
|
return res, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !phone.IsValidPhoneNumber(string(recipient)) {
|
||||||
|
logg.InfoCtxf(ctx, "corrupted recipient", "key", storedb.DATA_TEMPORARY_VALUE, "recipient", recipient)
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = smsservice.Accountservice.SendUpsellSMS(ctx, sessionId, string(recipient))
|
||||||
|
if err != nil {
|
||||||
|
res.Content = l.Get("Your invite request for %s to Sarafu Network failed. Please try again later.", string(recipient))
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
res.Content = l.Get("Your invitation to %s to join Sarafu Network has been sent.", string(recipient))
|
||||||
|
return res, nil
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user