Skip to content

Commit

Permalink
Merge pull request #1 from Uchencho/skeleton
Browse files Browse the repository at this point in the history
Skeleton
  • Loading branch information
Uchencho authored Sep 24, 2023
2 parents d2d498d + 63c8e65 commit 68742ae
Show file tree
Hide file tree
Showing 30 changed files with 2,322 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/golang.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Go

on: [push, pull_request]

jobs:

build:
name: Build
runs-on: ubuntu-latest
steps:

- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.13
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Debug
run: |
printenv | sort
- name: Get dependencies
run: |
go get -t ./...
- name: Test
run: go test -v ./...
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/.vscode
.env
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Uchencho

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
OUTPUT = main

.PHONY: test
test:
go test -failfast -cover ./...

.PHONY: clean
clean:
rm -f $(OUTPUT)

build-local:
go build -o $(OUTPUT) ./client/main.go

run: build-local
@echo ">> Running application ..."
./$(OUTPUT)
85 changes: 85 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Pawapay

[Pawapay](https://pawapay.io/) client application written in Go

## Usage

### Install Package

```bash
go get github.com/Uchencho/pawapay
```

### Documentation

Please see [the docs](https://pawapay.io/) for the most up-to-date documentation of the Pawapay API.

#### Pawapay

- Sample Usage

```go
package main

import (
"log"
"time"

"github.com/Uchencho/pawapay"
)

func main() {
cfg := pawapay.GetConfigFromEnvVars()
cfg.AllowRequestLogging() // only for debugging, would not advise this for production. Also not necessary, read on for why

/*
You can also explicitly declare the config
cfg := pawapay.Config{
APIKey: "key",
BaseURL: "url",
LogRequest: os.Getenv("env") == "production",
LogResponse: strings.EqualFold(os.Getenv("env"), "production"),
}
*/

service := pawapay.NewService(cfg)

amt := pawapay.Amount{Currency: "GHS", Value: "500"}
description := "sending money to all my children" // this will be truncated to the first 22 characters
pn := pawapay.PhoneNumber{CountryCode: "233", Number: "704584739348"}

allCorrespondentMappings, err := pawapay.GetAllCorrespondents()
if err != nil {
log.Fatal(err)
}

// each mapping, think country, have a number of correspondents, pick the one you are trying to send money to
// ideally you will take this as an input and map to the correspondent of your choice
correspondent := allCorrespondentMappings[0].Correspondents[0]
req := pawapay.PayoutRequest{
Amount: amt,
PhoneNumber: pn,
Description: description,
PayoutId: "uniqueId",
Correspondent: correspondent.Correspondent,
}

resp, err := service.CreatePayout(time.Now, req)
if err != nil {
log.Printf("something went wrong, we will confirm through their webhook")

// even in error, depending on the error, you might have access to the annotation

log.Printf("request failed with status code %v, response payload %s, error=%s",
resp.Annotation.ResponseCode, resp.Annotation.ResponsePayload, err)
}

log.Printf("response: %+v", resp)
}


```

> **NOTE**
> You also have access to deposit and refund functionalities
> Check the `client` directory to see a sample implementation and pawapay_test.go file to see sample tests
57 changes: 57 additions & 0 deletions client/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package main

import (
"log"
"time"

"github.com/Uchencho/pawapay"
)

func main() {
cfg := pawapay.GetConfigFromEnvVars()
cfg.AllowRequestLogging() // only for debugging, would not advise this for production. Also not necessary, read on for why

/*
You can also explicitly declare the config
cfg := pawapay.Config{
APIKey: "key",
BaseURL: "url",
LogRequest: os.Getenv("env") == "production",
LogResponse: strings.EqualFold(os.Getenv("env"), "production"),
}
*/

service := pawapay.NewService(cfg)

amt := pawapay.Amount{Currency: "GHS", Value: "500"}
description := "sending money to all my children" // this will be truncated to the first 22 characters
pn := pawapay.PhoneNumber{CountryCode: "233", Number: "704584739348"}

allCorrespondentMappings, err := pawapay.GetAllCorrespondents()
if err != nil {
log.Fatal(err)
}

// each mapping, think country, have a number of correspondents, pick the one you are trying to send money to
// ideally you will take this as an input and map to the correspondent of your choice
correspondent := allCorrespondentMappings[0].Correspondents[0]
req := pawapay.PayoutRequest{
Amount: amt,
PhoneNumber: pn,
Description: description,
PayoutId: "uniqueId",
Correspondent: correspondent.Correspondent,
}

resp, err := service.CreatePayout(time.Now, req)
if err != nil {
log.Printf("something went wrong, we will confirm through their webhook")

// even in error, depending on the error, you might have access to the annotation

log.Printf("request failed with status code %v, response payload %s, error=%s",
resp.Annotation.ResponseCode, resp.Annotation.ResponsePayload, err)
}

log.Printf("response: %+v", resp)
}
Loading

0 comments on commit 68742ae

Please sign in to comment.