Skip to content

Commit

Permalink
setup mkdocs and refactor project structure
Browse files Browse the repository at this point in the history
  • Loading branch information
silaselisha committed May 24, 2024
1 parent ec155bd commit a60bdfb
Show file tree
Hide file tree
Showing 20 changed files with 46 additions and 28 deletions.
17 changes: 17 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Welcome to MkDocs

For full documentation visit [mkdocs.org](https://www.mkdocs.org).

## Commands

* `mkdocs new [dir-name]` - Create a new project.
* `mkdocs serve` - Start the live-reloading docs server.
* `mkdocs build` - Build the documentation site.
* `mkdocs -h` - Print help message and exit.

## Project layout

mkdocs.yml # The configuration file.
docs/
index.md # The documentation homepage.
... # Other markdown pages, images and other files.
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
site_name: My Docs
10 changes: 5 additions & 5 deletions pkg/handler/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"io"
"net/http"

"github.com/silaselisha/go-daraja/internal/auth"
"github.com/silaselisha/go-daraja/internal/config"
"github.com/silaselisha/go-daraja/internal/builder"
"github.com/silaselisha/go-daraja/pkg/internal/auth"
"github.com/silaselisha/go-daraja/pkg/internal/builder"
"github.com/silaselisha/go-daraja/pkg/internal/config"
)

type DarajaAuth struct {
Expand All @@ -22,9 +22,9 @@ type DarajaAuth struct {
func ClientAuth(cfgs *config.Configs) (*DarajaAuth, error) {
client := &http.Client{}

fmt.Println(cfgs.DarajaEnvironment)
fmt.Println(cfgs.MpesaEnvironment)

URL := fmt.Sprintf("%s/%s", builder.BaseUrlBuilder(cfgs.DarajaEnvironment), "oauth/v1/generate?grant_type=client_credentials")
URL := fmt.Sprintf("%s/%s", builder.BaseUrlBuilder(cfgs.MpesaEnvironment), "oauth/v1/generate?grant_type=client_credentials")

req, err := http.NewRequest(http.MethodGet, URL, nil)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/handler/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"testing"

"github.com/silaselisha/go-daraja/internal/config"
"github.com/silaselisha/go-daraja/pkg/internal/config"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -34,7 +34,7 @@ func TestAuth(t *testing.T) {

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
auth, err := ClientAuth(&config.Configs{DarajaEnvironment: "sandbox", DarajaConsumerKey: "JDG40OnpvvRgXhgoPZ9GhGCTm1WZ42geJ66pH1tHIwwo4MrR", DarajaConsumerSecret: "yQcMx6pBUMVjZ90ILmA3QGJzf0m0l2gwhY45l9S3EzcLkH8xOPdqIaE7DQiX5xyO"})
auth, err := ClientAuth(&config.Configs{MpesaEnvironment: "sandbox", DarajaConsumerKey: "JDG40OnpvvRgXhgoPZ9GhGCTm1WZ42geJ66pH1tHIwwo4MrR", DarajaConsumerSecret: "yQcMx6pBUMVjZ90ILmA3QGJzf0m0l2gwhY45l9S3EzcLkH8xOPdqIaE7DQiX5xyO"})
tc.check(t, auth, err)
})
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/handler/business-buygoods.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"fmt"
"net/http"

"github.com/silaselisha/go-daraja/internal/x509"
"github.com/silaselisha/go-daraja/internal/builder"
"github.com/silaselisha/go-daraja/pkg/internal/x509"
"github.com/silaselisha/go-daraja/pkg/internal/builder"
)

type B2BReqParams struct {
Expand All @@ -25,9 +25,9 @@ type B2BReqParams struct {
}

func (cl *DarajaClient) BusinessBuyGoods(amount float64, username, shortCode, commandID, remarks, resultURL, queueTimeOutURL, receiverID, senderID, accountReference string) (*DarajaResParams, error) {
URL := fmt.Sprintf("%s/%s", builder.BaseUrlBuilder(cl.configs.DarajaEnvironment), "mpesa/b2b/v1/paymentrequest")
URL := fmt.Sprintf("%s/%s", builder.BaseUrlBuilder(cl.configs.MpesaEnvironment), "mpesa/b2b/v1/paymentrequest")

securityCred, err := x509.GenSecurityCred(cl.configs, "./../../internal/x509")
securityCred, err := x509.GenSecurityCred(cl.configs, "./../internal/x509")
if err != nil {
return nil, err
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/handler/business-consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"net/http"

"github.com/google/uuid"
"github.com/silaselisha/go-daraja/internal/builder"
"github.com/silaselisha/go-daraja/internal/x509"
"github.com/silaselisha/go-daraja/pkg/internal/builder"
"github.com/silaselisha/go-daraja/pkg/internal/x509"
)

type txnType int
Expand All @@ -32,13 +32,13 @@ type B2CReqParams struct {
}

func (cl *DarajaClient) BusinessToConsumer(amount float64, txnType txnType, customerNo, remarks, qeueuTimeOutURL, resultURL string) (*DarajaResParams, error) {
URL := fmt.Sprintf("%s/%s", builder.BaseUrlBuilder(cl.configs.DarajaEnvironment), "mpesa/b2c/v3/paymentrequest")
URL := fmt.Sprintf("%s/%s", builder.BaseUrlBuilder(cl.configs.MpesaEnvironment), "mpesa/b2c/v3/paymentrequest")
ID, err := uuid.NewRandom()
if err != nil {
return nil, err
}

securityCred, err := x509.GenSecurityCred(cl.configs, "./../../internal/x509")
securityCred, err := x509.GenSecurityCred(cl.configs, "./../internal/x509")
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/handler/business-express.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"net/http"

"github.com/google/uuid"
"github.com/silaselisha/go-daraja/internal/builder"
"github.com/silaselisha/go-daraja/pkg/internal/builder"
)

type BExpressCheckoutParams struct {
Expand All @@ -19,7 +19,7 @@ type BExpressCheckoutParams struct {
}

func (cl *DarajaClient) BusinessExpressCheckout(paymentRef, callbackURL, partnerName, receiver string, amount float64) (*DarajaResParams, error) {
URL := fmt.Sprintf("%s%s", builder.BaseUrlBuilder(cl.configs.DarajaEnvironment), "/v1/ussdpush/get-msisdn")
URL := fmt.Sprintf("%s%s", builder.BaseUrlBuilder(cl.configs.MpesaEnvironment), "/v1/ussdpush/get-msisdn")

requestRedID, err := uuid.NewRandom()
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/handler/customer-business.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"net/http"

"github.com/silaselisha/go-daraja/internal/builder"
"github.com/silaselisha/go-daraja/pkg/internal/builder"
)

type b2cType int
Expand All @@ -22,7 +22,7 @@ type C2BReqParams struct {
}

func (cl *DarajaClient) CustomerToBusiness(confirmationURL, validationURL string, responseType b2cType) (*DarajaResParams, error) {
URL := fmt.Sprintf("%s/%s", builder.BaseUrlBuilder(cl.configs.DarajaEnvironment), "mpesa/c2b/v1/registerurl")
URL := fmt.Sprintf("%s/%s", builder.BaseUrlBuilder(cl.configs.MpesaEnvironment), "mpesa/c2b/v1/registerurl")

var command string
switch {
Expand Down
4 changes: 2 additions & 2 deletions pkg/handler/mpesa-express.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"net/http"

"github.com/silaselisha/go-daraja/internal/builder"
"github.com/silaselisha/go-daraja/pkg/internal/builder"
)

type NICallbackParams struct {
Expand Down Expand Up @@ -54,7 +54,7 @@ func (cl *DarajaClient) NIPush(description string, phoneNumber string, amount fl
TransactionDesc: description,
}

URL := fmt.Sprintf("%s/%s", builder.BaseUrlBuilder(cl.configs.DarajaEnvironment), "mpesa/stkpush/v1/processrequest")
URL := fmt.Sprintf("%s/%s", builder.BaseUrlBuilder(cl.configs.MpesaEnvironment), "mpesa/stkpush/v1/processrequest")

return handlerHelper[ExpressReqParams](payload, URL, http.MethodPost, cl.accessToken)
}
2 changes: 1 addition & 1 deletion pkg/handler/types.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package handler

import (
"github.com/silaselisha/go-daraja/internal/config"
"github.com/silaselisha/go-daraja/pkg/internal/config"
)

type Daraja interface {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

type Configs struct {
DarajaEnvironment string `mapstructure:"DARAJA_ENVIRONMENT"`
MpesaEnvironment string `mapstructure:"MPESA_ENVIRONMENT"`
DarajaConsumerKey string `mapstructure:"DARAJA_CONSUMER_KEY"`
DarajaConsumerSecret string `mapstructure:"DARAJA_CONSUMER_SECRET"`
DarajaBusinessShortCode string `mapstructure:"DARAJA_BUSINESS_SHORT_CODE"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestLoadConfigs(t *testing.T) {
},
{
name: "valid env path",
path: "./../../example",
path: "./../../../example",
check: func(t *testing.T, envs *Configs, err error) {
fmt.Println(envs)
require.NoError(t, err)
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import (
"os"
"path"

"github.com/silaselisha/go-daraja/internal/config"
"github.com/silaselisha/go-daraja/pkg/internal/config"
)

func GenSecurityCred(config *config.Configs, filePath string) (string, error) {
passwordBuff := []byte(config.DarajaInitiatorPassword)
fileName := "sandbox"
if config.DarajaEnvironment == "production" {
if config.MpesaEnvironment == "production" {
fileName = "production"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import (
"testing"

"github.com/stretchr/testify/require"
"github.com/silaselisha/go-daraja/internal/config"
"github.com/silaselisha/go-daraja/pkg/internal/config"
)

func TestGenSecurityCred(t *testing.T) {
cred, err := GenSecurityCred(&config.Configs{DarajaEnvironment: "sandbox"}, ".")
cred, err := GenSecurityCred(&config.Configs{MpesaEnvironment: "sandbox"}, ".")
require.NoError(t, err)
require.NotNil(t, cred)
fmt.Println(cred)
Expand Down

0 comments on commit a60bdfb

Please sign in to comment.