Skip to content

Commit

Permalink
Merge pull request #29 from silaselisha/develop
Browse files Browse the repository at this point in the history
hotfix
  • Loading branch information
silaselisha committed May 23, 2024
2 parents e4b8d14 + ec155bd commit a2c7ad4
Show file tree
Hide file tree
Showing 15 changed files with 36 additions and 19 deletions.
2 changes: 2 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
// Organize this list alphabetically

[Elisha Silas] <elisilas87@outlook.com>
8 changes: 0 additions & 8 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,6 @@ How to get your contributions merged smoothly and quickly.
widely agreed-upon anti-patterns, then please do create a PR and explain the
benefits of the change.

- Unless your PR is trivial, you should expect there will be reviewer comments
that you'll need to address before merging. We'll mark it as `Status: Requires
Reporter Clarification` if we expect you to respond to these comments in a
timely manner. If the PR remains inactive for 6 days, it will be marked as
`stale` and automatically close 7 days after that if we don't hear back from
you.

- Maintain **clean commit history** and use **meaningful commit messages**. PRs
with messy commit history are difficult to review and won't be merged. Fork the project
and create a new branch to start woring on.
Expand All @@ -47,4 +40,3 @@ How to get your contributions merged smoothly and quickly.
early on.
- `go test --cover -v ./...` to run the tests

- Exceptions to the rules can be made if there's a compelling reason for doing so.
3 changes: 3 additions & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Organize this list alphabetically

[Elisha Silas] <elisilas87@outlook.com>
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Go-daraja is an open-source project facilitating seamless integration of Safaric
3. Install go-daraja package

```go
go get github.com/silaselisha/go-daraja
go "get github.com/silaselisha/go-daraja"
```

``` go
Expand Down
2 changes: 1 addition & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The versions currently being supported with security updates.

| Version | Supported |
| ------- | ------------------ |
| 0.5.x | :white_check_mark: |
| 0.7.x | :white_check_mark: |

## Reporting a Vulnerability

Expand Down
2 changes: 1 addition & 1 deletion internal/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func BaseUrlBuilder(environment string) string {
case "sandbox":
baseURL = "https://sandbox.safaricom.co.ke"
case "production":
baseURL = "https://sandbox.safaricom.co.ke"
baseURL = "https://api.safaricom.co.ke"
default:
baseURL = "https://sandbox.safaricom.co.ke"
}
Expand Down
2 changes: 1 addition & 1 deletion internal/builder/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func TestBaseURL(t *testing.T) {
environment: "production",
check: func(t *testing.T, URL string) {
require.NotEmpty(t, URL)
require.Equal(t, "https://sandbox.safaricom.co.ke", URL)
require.Equal(t, "https://api.safaricom.co.ke", URL)
},
},
{
Expand Down
2 changes: 2 additions & 0 deletions pkg/handler/business-buygoods_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package handler

import (
"fmt"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -34,6 +35,7 @@ func TestBusinessBuyGoods(t *testing.T) {
amount: 239,
accountRefrence: "353353",
check: func(t *testing.T, data *DarajaResParams, err error) {
fmt.Printf("Business Buy Goods: %+v\n", data)
require.NoError(t, err)

require.Equal(t, "0", data.ResponseCode)
Expand Down
2 changes: 2 additions & 0 deletions pkg/handler/business-consumer_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package handler

import (
"fmt"
"testing"

"github.com/stretchr/testify/require"
Expand All @@ -26,6 +27,7 @@ func TestBusinessConsumer(t *testing.T) {
qeueuTimeURL: "https://mydomain.com/b2c/queue",
resultURL: "https://mydomain.com/b2c/result",
check: func(t *testing.T, data *DarajaResParams, err error) {
fmt.Printf("Business Consumer: %+v\n", data)
require.NoError(t, err)

require.Equal(t, "0", data.ResponseCode)
Expand Down
10 changes: 5 additions & 5 deletions pkg/handler/business-express.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ import (

type BExpressCheckoutParams struct {
PrimaryShortCode string `json:"primaryShortCode"`
ReceiverShortCode string `json:"receiverShortCode"`
ReceiverShortCode string `json:"receiverShortCode"`
Amount float64 `json:"amount"`
PaymentRef string `json:"paymentRef"`
CallbackURL string `json:"callbackUrl"`
PartnerName string `json:"partnerName"`
RequestRefID string `json:"RequestRefID"`
RequestRefID string `json:"requestRefId"`
}

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")

id, err := uuid.NewRandom()
requestRedID, err := uuid.NewRandom()
if err != nil {
return nil, err
}
Expand All @@ -33,9 +33,9 @@ func (cl *DarajaClient) BusinessExpressCheckout(paymentRef, callbackURL, partner
PaymentRef: paymentRef,
CallbackURL: callbackURL,
PartnerName: partnerName,
RequestRefID: id.String(),
RequestRefID: requestRedID.String(),
}

fmt.Println(payload)
fmt.Printf("PAYLOAD: %+v\n", payload)
return handlerHelper(payload, URL, http.MethodPost, cl.accessToken)
}
2 changes: 2 additions & 0 deletions pkg/handler/business-express_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package handler

import (
"fmt"
"testing"

"github.com/stretchr/testify/require"
Expand All @@ -24,6 +25,7 @@ func TestBusinessExpress(t *testing.T) {
receiver: "174379",
amount: 10,
check: func(t *testing.T, data *DarajaResParams, err error) {
fmt.Printf("Business Express: %+v\n", data)
require.NoError(t, err)

require.Equal(t, "0", data.ResponseBody.Code)
Expand Down
10 changes: 8 additions & 2 deletions pkg/handler/customer-business_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package handler

import (
"fmt"
"testing"

"github.com/stretchr/testify/require"
Expand All @@ -20,10 +21,15 @@ func TestCustomerToBusiness(t *testing.T) {
validationURL: "https://mydomain.com/validation",
confirmationURL: "https://mydomain.com/confirmation",
check: func(t *testing.T, data *DarajaResParams, err error) {
fmt.Printf("Consumer Business: %+v\n", data)
require.NoError(t, err)

require.Equal(t, "0", data.ResponseCode)
require.Equal(t, "Success", data.ResponseDescription)
if data.ErrorCode == "500.003.1001" {
require.Equal(t, "Service is currently unreachable. Please try again later.", data.ErrorMessage)
} else {
require.Equal(t, "0", data.ResponseCode)
require.Equal(t, "Success", data.ResponseDescription)
}
},
},
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/handler/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package handler
import (
"bytes"
"encoding/json"
"fmt"
"io"
"log"
"net/http"
Expand Down Expand Up @@ -38,6 +39,8 @@ func handlerHelper[T B2BReqParams | B2CReqParams | C2BReqParams | ExpressReqPara
if err != nil {
return nil, err
}

fmt.Printf("Bytes From Helper: %+v\n", string(buff))
var result DarajaResParams
if err := json.Unmarshal(buff, &result); err != nil {
return nil, err
Expand Down
2 changes: 2 additions & 0 deletions pkg/handler/mpesa-express_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package handler

import (
"fmt"
"testing"

"github.com/stretchr/testify/require"
Expand All @@ -23,6 +24,7 @@ func TestMpesaExpress(t *testing.T) {
description: "test payment",
amount: 1,
check: func(t *testing.T, data *DarajaResParams, err error) {
fmt.Printf("Mpesa Express: %+v\n", data)
require.Equal(t, "0", data.ResponseCode)
require.Equal(t, "Success. Request accepted for processing", data.ResponseDescription)
require.Equal(t, "Success. Request accepted for processing", data.CustomerMessage)
Expand Down
3 changes: 3 additions & 0 deletions pkg/handler/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ type DarajaResParams struct {
Code string `json:"code"`
Status string `json:"status"`
}
RequestID string `json:"requestId"`
ErrorCode string `json:"errorCode"`
ErrorMessage string `json:"errorMessage"`
}

type DarajaErrorParams struct {
Expand Down

0 comments on commit a2c7ad4

Please sign in to comment.