vipps

package module
v0.7.4 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2021 License: MIT Imports: 3 Imported by: 0

README

Go Vipps

Community maintained Go client library for the Vipps E-commerce and Recurring payments APIs. Please see Vipps' own documentation on their Developer page.

GoDoc

Installation

Install go-vipps with:

go get -u github.com/torfjor/go-vipps

Then, import it using:

import (
    "github.com/torfjor/go-vipps"
)

Usage

package main

import (
	"context"
	"log"
	"os"
	"time"
	"github.com/torfjor/go-vipps"
	"github.com/torfjor/go-vipps/auth"
	"github.com/torfjor/go-vipps/ecom"
)

func main() {
	credentials := vipps.Credentials{
		ClientID:           os.Getenv("CLIENT_ID"),
		ClientSecret:       os.Getenv("CLIENT_SECRET"),
		APISubscriptionKey: os.Getenv("API_KEY"),
	}
	env := vipps.EnvironmentTesting
	authClient := auth.NewClient(env, credentials)
	client := ecom.NewClient(vipps.ClientConfig{
		HTTPClient: authClient,
		Environment: env,
	})
	
	mobileNumber := 97777776
	amount := 1000
	orderID := "8b84-0ad5258beb0f"
	transactionText := "A transaction"
	
	cmd := ecom.InitiatePaymentCommand{
		MerchantInfo: ecom.MerchantInfo{
			MerchantSerialNumber: "CHANGETHIS",
			CallbackURL:          "https://some.endpoint.no/callbacks",
			RedirectURL:          "https://some.endpoint.no/redirect",
			ConsentRemovalURL:    "https://some.endpoint.no/consentremoval",
			IsApp:                false,
			PaymentType:          ecom.PaymentTypeRegular,
		},
		CustomerInfo: ecom.CustomerInfo{
			MobileNumber: mobileNumber,
		},
		Transaction:  ecom.Transaction{
			Amount: amount,
			OrderID: orderID,
			TransactionText: transactionText,
		},
	}
	
	ctx, _ := context.WithTimeout(context.Background(), 5 * time.Second)
	p, err := client.InitiatePayment(ctx, cmd)
	if err != nil {
		log.Fatal(err)
	}
	// Do something with p
}

Documentation

Index

Constants

View Source
const (
	BaseURL        = "https://api.vipps.no"
	BaseURLTesting = "https://apitest.vipps.no"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientConfig

type ClientConfig struct {
	Environment Environment
	Logger      log.Logger
	HTTPClient  *http.Client
}

ClientConfig represents the configuration to use for a Client

type Credentials

type Credentials struct {
	APISubscriptionKey string
	ClientID           string
	ClientSecret       string
}

Credentials represents secrets used to authenticate and authorize a client to the Vipps APIs.

type Environment

type Environment string

Environment is the Vipps environment that a Client should use.

const (
	EnvironmentTesting Environment = "testing"
)

List of values that Environment can take.

type ErrUnexpectedResponse

type ErrUnexpectedResponse struct {
	Body   []byte
	Status int
}

ErrUnexpectedResponse represents an unexpected erroneous response from the Vipps APIs.

func (ErrUnexpectedResponse) Error

func (e ErrUnexpectedResponse) Error() string

Directories

Path Synopsis
_examples
Package auth provides a HTTP client suitable for consuming Vipps APIs.
Package auth provides a HTTP client suitable for consuming Vipps APIs.
Package ecom provides a Client and supporting types to consume and interact with the Vipps Ecom V2 API
Package ecom provides a Client and supporting types to consume and interact with the Vipps Ecom V2 API
Package recurring provides a Client and supporting types to consume and interact with the Vipps Recurring Payments API
Package recurring provides a Client and supporting types to consume and interact with the Vipps Recurring Payments API

Jump to

Keyboard shortcuts

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