[go: up one dir, main page]

Skip to content

frozzare/go-swish

Repository files navigation

Swish Build Status GoDoc Go Report Card

Go package for dealing with Swish merchant API.

Installation

go get -u github.com/frozzare/go-swish

Usage

Please read the Swish documentation first so you know what you need and what the different fields means.

Begin by obtaining the SSL certificates required by Swish. The Swish server itself uses a self-signed root certificated so a CA-bundle to verify its origin is needed. You will also need a client certificate and corresponding private key so the Swish server can identify you.

Certificates in certs directory is the test certificates from Swish and cannot be used in production.

package main

import (
	"context"
	"log"

	"github.com/frozzare/go-swish"
)

func main() {
	client, err := swish.NewClient(&swish.Options{
		Env:        "test",
		Passphrase: "swish",
		P12:        "./certs/test.p12",
		Root:       "./certs/root.pem",
	})

	if err != nil {
		log.Fatal(err)
	}

	res, err := client.CreatePayment(context.Background(), &swish.PaymentData{
		CallbackURL:           "https://example.com/api/swishcb/paymentrequests",
		PayeePaymentReference: "0123456789",
		PayeeAlias:            "1231181189",
		Amount:                "100.00",
		Currency:              "SEK",
		Message:               "Kingston USB Flash Drive 8 GB",
	})

	if err != nil {
		log.Fatal(err)
	}

	log.Println(res.ID)

	res, err = client.Payment(context.Background(), res.ID)

	if err != nil {
		log.Fatal(err)
	}

	log.Println(res.Status)
}

License

MIT © Fredrik Forsmo