Skip to content

Commit

Permalink
Fixed the documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
AchoArnold committed Aug 22, 2021
1 parent e1e3e6a commit a09c0af
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 5 deletions.
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import "github.com/NdoleStudio/campay-go-sdk"
- `POST /token` - Get access token
- [Collect](#collect)
- `POST /collect` - Request Payment
- [Transaction](#transaction)
- `POST /transaction/(reference)/` - Transaction Status

## Usage

Expand Down Expand Up @@ -88,7 +90,7 @@ log.Println(token.Token) // e.g eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsInVpZCI6Mn0.

This handles all API requests whose URL begins with `/collect/`

#### Get access token
#### Request Payment

`POST /collect/`: Request Payment

Expand All @@ -102,6 +104,21 @@ payload, httpResponse, err := campayClient.Collect(context.Background(), campay.
})
```

### Transaction

This handles all API requests whose URL begins with `/transaction/`

#### R

`POST /transaction/(reference)/`: Transaction Status

```go
transaction, httpResponse, err := campayClient.Transaction.Get(
context.Background(),
"bcedde9b-62a7-4421-96ac-2e6179552a1a"
)
```

## Testing

You can run the unit tests for this SDK from the root directory using the command below:
Expand Down
4 changes: 2 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type Client struct {
apiPassword string
token string
tokenExpirationTime int64
Transaction *TransactionService
Transaction *transactionService
}

// New creates and returns a new campay.Client from a slice of campay.ClientOption.
Expand All @@ -49,7 +49,7 @@ func New(options ...ClientOption) *Client {
}

client.common.client = client
client.Transaction = (*TransactionService)(&client.common)
client.Transaction = (*transactionService)(&client.common)
return client
}

Expand Down
12 changes: 12 additions & 0 deletions transaction.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package campay

// Transaction contains details of an initiated transaction
type Transaction struct {
Reference string `json:"reference"`
Status string `json:"status"`
Amount float64 `json:"amount"`
Currency string `json:"currency"`
Operator string `json:"operator"`
Code string `json:"code"`
OperatorReference string `json:"operator_reference"`
}
34 changes: 32 additions & 2 deletions transaction_service.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,34 @@
package campay

// TransactionService is the API client for the `/gateway` endpoint
type TransactionService service
import (
"context"
"encoding/json"
"net/http"
)

// transactionService is the API client for the `/gateway` endpoint
type transactionService service

func (service *transactionService) Get(ctx context.Context, reference string) (*Transaction, *Response, error) {
err := service.client.refreshToken(ctx)
if err != nil {
return nil, nil, err
}

request, err := service.client.newRequest(ctx, http.MethodGet, "/transaction/"+reference, nil)
if err != nil {
return nil, nil, err
}

response, err := service.client.do(request)
if err != nil {
return nil, response, err
}

var transaction Transaction
if err = json.Unmarshal(*response.Body, &transaction); err != nil {
return nil, response, err
}

return &transaction, response, nil
}

0 comments on commit a09c0af

Please sign in to comment.