Golang library for the Swish Payment and Refund Request API.
Check out the API Documentation http://godoc.org/github.com/NicklasWallgren/swish
The library can be installed through go get
go get github.com/NicklasWallgren/swish
We support the two major Go versions, which are 1.14 and 1.15 at the moment.
- Create payment request
- Retrieve payment result
- Create refund request
- Retrieve refund result
import (
"context"
"fmt"
"io/ioutil"
"github.com/NicklasWallgren/swish"
)
certificate, err := ioutil.ReadFile("path/to/environment.p12")
if err != nil {
panic(err)
}
configuration := swish.NewConfiguration(
&swish.TestEnvironment,
&swish.Pkcs12{Content: certificate, Password: "p12 password"},
)
instance := swish.New(configuration)
payload := swish.PaymentPayload{PayeePaymentReference: "0123456789", CallbackUrl: "https://myfakehost.se/swishcallback.cfm", PayeeAlias: "9871065216", PayerAlias: "1231181189", Amount: "100", Currency: "SEK"}
paymentResponse, err := instance.Payment(context.Background(), &payload)
if err != nil {
fmt.Println(err)
return
}
paymentResult, err := instance.PaymentResult(context.Background(), paymentResponse.Id)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(paymentResult)
go test -v -race $(go list ./... | grep -v vendor)
We use GitHub Actions to make sure the codebase is consistent (golangci-lint run
) and continuously tested (go test -v -race $(go list ./... | grep -v vendor)
). We try to keep comments at a maximum of 120 characters of length and code at 120.
If you find any problems or have suggestions about this library, please submit an issue. Moreover, any pull request, code review and feedback are welcome.