stk

package
v0.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 10, 2023 License: GPL-3.0, MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const StkTable = "stk_transactions"

StkTable is table for mpesa payments

Variables

This section is empty.

Functions

func GetMpesaRequestKey

func GetMpesaRequestKey(requestId string) string

GetMpesaRequestKey is key that initiates data

func GetMpesaSTKPushKey

func GetMpesaSTKPushKey(msisdn string) string

GetMpesaSTKPushKey retrives key storing initiator key

func NewStkAPI

func NewStkAPI(ctx context.Context, opt *Options) (_ stk.StkPushV1Server, err error)

NewStkAPI creates a singleton instance of mpesa stk API

func ToProto

func ToProto(db *STKTransaction) (*stk.StkTransaction, error)

ToProto returns the protobuf message of stk transaction

func ValidateOptionSTK

func ValidateOptionSTK(opt *OptionSTK) error

ValidateOptionSTK validates stk options

func ValidateOptions

func ValidateOptions(opt *Options) error

ValidateOptions validates options required by stk service

Types

type HTTPClient

type HTTPClient interface {
	Do(*http.Request) (*http.Response, error)
}

HTTPClient makes mocking test easier

type OptionSTK

type OptionSTK struct {
	AccessTokenURL    string
	PassKey           string
	ConsumerKey       string
	ConsumerSecret    string
	BusinessShortCode string
	AccountReference  string
	Timestamp         string
	CallBackURL       string
	PostURL           string
	QueryURL          string
	// contains filtered or unexported fields
}

OptionSTK contains options for sending push stk

type Options

type Options struct {
	SQLDB                     *gorm.DB
	RedisDB                   *redis.Client
	Logger                    grpclog.LoggerV2
	AuthAPI                   *auth.API
	OptionSTK                 *OptionSTK
	HTTPClient                HTTPClient
	UpdateAccessTokenDuration time.Duration
}

Options contain parameters passed for creating stk service

type STKRequestBody

type STKRequestBody struct {
	BusinessShortCode string `json:"BusinessShortCode,omitempty"`
	Password          string `json:"Password,omitempty"`
	Timestamp         string `json:"Timestamp,omitempty"`
	TransactionType   string `json:"TransactionType,omitempty"`
	Amount            string `json:"Amount,omitempty"`
	PartyA            string `json:"PartyA,omitempty"`
	PartyB            string `json:"PartyB,omitempty"`
	PhoneNumber       string `json:"PhoneNumber,omitempty"`
	CallBackURL       string `json:"CallBackURL,omitempty"`
	AccountReference  string `json:"AccountReference,omitempty"`
	TransactionDesc   string `json:"TransactionDesc,omitempty"`
}

STKRequestBody is STK push request payload

type STKTransaction

type STKTransaction struct {
	ID                         uint           `gorm:"primaryKey;autoIncrement"`
	InitiatorID                string         `gorm:"index;type:varchar(50)"`
	InitiatorCustomerReference string         `gorm:"index;type:varchar(50)"`
	InitiatorCustomerNames     string         `gorm:"type:varchar(50)"`
	PhoneNumber                string         `gorm:"index;type:varchar(15);not null"`
	Amount                     string         `gorm:"type:float(10);not null"`
	ShortCode                  string         `gorm:"index;type:varchar(15)"`
	AccountReference           string         `gorm:"index;type:varchar(50)"`
	TransactionDesc            sql.NullString `gorm:"type:varchar(300)"`
	MerchantRequestID          sql.NullString `gorm:"index;type:varchar(50);"`
	CheckoutRequestID          sql.NullString `gorm:"index;type:varchar(50);"`
	StkResponseDescription     sql.NullString `gorm:"type:varchar(300)"`
	StkResponseCustomerMessage sql.NullString `gorm:"type:varchar(300)"`
	StkResponseCode            sql.NullString `gorm:"index;type:varchar(10)"`
	ResultCode                 sql.NullString `gorm:"index;type:varchar(10)"`
	ResultDescription          sql.NullString `gorm:"type:varchar(300)"`
	MpesaReceiptId             sql.NullString `gorm:"index;type:varchar(50);unique"`
	StkStatus                  sql.NullString `gorm:"index;type:varchar(30)"`
	Source                     sql.NullString `gorm:"index;type:varchar(30)"`
	Tag                        sql.NullString `gorm:"index;type:varchar(30)"`
	// Succeeded                  bool         `gorm:"index;type:tinyint(1)"`
	// Processed                  bool         `gorm:"index;type:tinyint(1)"`
	Succeeded       string       `gorm:"index;type:enum('YES','NO');default:NO"`
	Processed       string       `gorm:"index;type:enum('YES','NO');default:NO"`
	TransactionTime sql.NullTime `gorm:"index;type:datetime(6)"`
	UpdatedAt       time.Time    `gorm:"autoUpdateTime;type:datetime(6)"`
	CreatedAt       time.Time    `gorm:"index;autoCreateTime;primaryKey;type:datetime(6);not null"`
}

STKTransaction contains mpesa stk transaction details

func (*STKTransaction) TableName

func (*STKTransaction) TableName() string

TableName returns the name of the table

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL