niki/adapter/sms_provider/kavenegar/otp/send_otp.go

51 lines
1.4 KiB
Go

package kavenegarotp
import (
"fmt"
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
"github.com/kavenegar/kavenegar-go"
)
func (a Adapter) SendForNewUser(phoneNumber, code string) {
const op = richerror.Op("kavenegarotp.Send")
params := &kavenegar.VerifyLookupParam{}
if _, err := a.adapter.Client().Verify.Lookup(phoneNumber, a.adapter.Config().OtpTemplateNewUser, code, params); err != nil {
//nolint
switch err := err.(type) {
case *kavenegar.APIError:
// log error
fmt.Println(fmt.Errorf("error(%s):%w", op, err))
case *kavenegar.HTTPError:
// log error
fmt.Println(fmt.Errorf("error(%s):%w", op, err))
default:
// log error
fmt.Println(fmt.Errorf("error(%s):%w", op, err))
}
}
// TODO - log res res.Status
}
func (a Adapter) SendForRegisteredUser(phoneNumber, code string) {
const op = richerror.Op("kavenegarotp.Send")
params := &kavenegar.VerifyLookupParam{}
if _, err := a.adapter.Client().Verify.Lookup(phoneNumber, a.adapter.Config().OtpTemplateRegisteredUser, code, params); err != nil {
//nolint
switch err := err.(type) {
case *kavenegar.APIError:
// log error
fmt.Println(fmt.Errorf("error(%s):%w", op, err))
case *kavenegar.HTTPError:
// log error
fmt.Println(fmt.Errorf("error(%s):%w", op, err))
default:
// log error
fmt.Println(fmt.Errorf("error(%s):%w", op, err))
}
}
// TODO - log res res.Status
}