swish

package module
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 22, 2018 License: MIT Imports: 13 Imported by: 0

README

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoLocationHeader is the error when no location header exists in the response from Swish API.
	ErrNoLocationHeader = errors.New("Error: No location header from Swish API")
)

Functions

This section is empty.

Types

type Client

type Client struct {
	*Options
}

Client represents a Swish client.

func NewClient

func NewClient(opts *Options) (*Client, error)

NewClient creats a new Swish client.

func (*Client) CreatePaymentRequest

func (c *Client) CreatePaymentRequest(ctx context.Context, req *PaymentRequest) (*PaymentRequest, error)

CreatePaymentRequest will create a payment request to Swish and return a payment request containing the ID of the request and the data sent to Swish or a error.

func (*Client) CreateRefundRequest

func (c *Client) CreateRefundRequest(ctx context.Context, req *PaymentRequest) (*PaymentRequest, error)

CreateRefundRequest will create a refund request to Swish and return a refund request containing the ID of the request and the data sent to Swish or a error.

func (*Client) PaymentRequest

func (c *Client) PaymentRequest(ctx context.Context, id string) (*PaymentRequest, error)

PaymentRequest will return a payment request or a error for the given id.

func (*Client) RefundRequest

func (c *Client) RefundRequest(ctx context.Context, id string) (*PaymentRequest, error)

RefundRequest will return a payment request or a error for the given id.

func (*Client) URL

func (s *Client) URL() string

URL returns the BankID url.

type Error

type Error struct {
	AdditionalInformation string `json:"additionalInformation,omitempty"`
	ErrorCode             string `json:"errorCode,omitempty"`
	ErrorMessage          string `json:"errorMessage,omitempty"`
}

Error represents a error object from Swish API.

type Options

type Options struct {
	Env        string
	P12        string
	P12Data    []byte
	Passphrase string
	Root       string
	RootData   []byte
	Client     *http.Client
}

Options represents Swish client options.

type PaymentRequest

type PaymentRequest struct {
	AdditionalInformation    string `json:"additionalInformation,omitempty"`
	Amount                   string `json:"amount,omitempty"`
	CallbackURL              string `json:"callbackUrl,omitempty"`
	Currency                 string `json:"currency,omitempty"`
	DateCreated              string `json:"dateCreated,omitempty"`
	DatePaid                 string `json:"datePaid,omitempty"`
	ErrorCode                string `json:"errorCode,omitempty"`
	ErrorMessage             string `json:"errorMessage,omitempty"`
	ID                       string `json:"id,omitempty"`
	Message                  string `json:"message,omitempty"`
	PayeeAlias               string `json:"payeeAlias,omitempty"`
	PayeePaymentReference    string `json:"payeePaymentReference,omitempty"`
	PayerPaymentReference    string `json:"payerPaymentReference,omitempty"`
	PayerAlias               string `json:"payerAlias,omitempty"`
	PaymentReference         string `json:"paymentReference,omitempty"`
	OriginalPaymentReference string `json:"originalPaymentReference,omitempty"`
	Status                   string `json:"status,omitempty"`
}

PaymentRequest represents a payment request from Swish API.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL