ecom

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package ecom provides a client and supporting types to consume and interact with the Vipps Ecom V2 API

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandleConsentRemoval added in v0.1.1

func HandleConsentRemoval(cb func(uid string)) http.HandlerFunc

HandleConsentRemoval returns a convenience http.HandlerFunc for receiving requests for user consent removals from Vipps. `cb` is called with the uid of the user to that wishes to have its consents and data removed.

func HandleShippingDetails added in v0.1.1

func HandleShippingDetails(authToken string, cb func(orderId string, req ShippingCostRequest) (ShippingCostResponse, error)) http.HandlerFunc

HandleShippingDetails returns a convenience http.HandlerFunc for responding to requests from Vipps to calculate shipping costs for an order.

The provided authToken, if not empty, will be matched with the `Authorization` header of the incoming requests. If they don't match, the request will fail.

func HandleTransactionUpdate added in v0.1.1

func HandleTransactionUpdate(authToken string, cb func(t TransactionUpdate)) http.HandlerFunc

HandleTransactionUpdate returns a convenience http.HandlerFunc for getting notifications from Vipps about transaction updates.

The provided authToken, if not empty, will be matched with the `Authorization` header of the incoming requests. If they don't match, the request will fail.

`cb` will be called with the TransactionUpdate. Please be aware that for payments of PaymentTypeRegular, the fields `ShippingDetails` and `UserDetails` will be nil.

Types

type Address

type Address struct {
	AddressLine1 string `json:"addressLine1"`
	AddressLine2 string `json:"addressLine2"`
	City         string `json:"city"`
	Country      string `json:"country"`
	PostCode     string `json:"postCode"`
}

Address represents a Customer's shipping address

type AddressType added in v0.1.1

type AddressType string

AddressType represents an address type

const (
	AddressTypeHome     AddressType = "H"
	AddressTypeBusiness AddressType = "B"
)

List of values that AddressType can take

type CancelPaymentCommand

type CancelPaymentCommand struct {
	OrderID              string
	MerchantSerialNumber string
	TransactionText      string
}

CancelPaymentCommand represents the command used to cancel Vipps Ecom payments

type CancelledPayment

type CancelledPayment struct {
	OrderID            string             `json:"orderId"`
	TransactionInfo    TransactionInfo    `json:"transactionInfo"`
	TransactionSummary TransactionSummary `json:"transactionSummary"`
}

CancelledPayment represents a cancelled payment

type CapturePaymentCommand

type CapturePaymentCommand struct {
	IdempotencyKey       string
	OrderID              string
	MerchantSerialNumber string
	Amount               int
	TransactionText      string
}

CapturePaymentCommand represents the command used to capture Vipps Ecom payments

type CapturedPayment

type CapturedPayment struct {
	OrderID            string             `json:"orderId"`
	TransactionInfo    TransactionInfo    `json:"transactionInfo"`
	TransactionSummary TransactionSummary `json:"transactionSummary"`
}

CapturedPayment represents a captured Vipps Ecom payment

type Client

type Client interface {
	// InitiatePayment initiates a new Payment and returns a reference to a resource
	// hosted by Vipps where the payment flow can continue.
	InitiatePayment(ctx context.Context, cmd InitiatePaymentCommand) (*PaymentReference, error)
	// CapturePayment captures reserved amounts on a Payment
	CapturePayment(ctx context.Context, cmd CapturePaymentCommand) (*CapturedPayment, error)
	// CancelPayment cancels an initiated payment. Errors for payments that are not
	// in a cancellable state.
	CancelPayment(ctx context.Context, cmd CancelPaymentCommand) (*CancelledPayment, error)
	// RefundPayment refunds already captured amounts on a Payment.
	RefundPayment(ctx context.Context, cmd RefundPaymentCommand) (*RefundedPayment, error)
	// GetPayment gets a Payment.
	GetPayment(ctx context.Context, orderID string) (*Payment, error)
}

Client is the interface that wraps all the methods available for interacting with the Vipps Ecom V2 API.

func NewClient

func NewClient(config vipps.ClientConfig) Client

NewClient returns a configured client that implements the Client interface.

type CustomerInfo

type CustomerInfo struct {
	// MobileNumber is a Norwegian mobile phone number. 8 digits, no country
	// prefix
	MobileNumber int `json:"mobileNumber"`
}

CustomerInfo represents information about a Vipps customer

type EcomAPIError

type EcomAPIError struct {
	Group   string `json:"errorGroup"`
	Message string `json:"errorMessage"`
	Code    string `json:"errorCode"`
}

EcomAPIError represents a single error returned from the Vipps Ecom API.

type ErrEcom

type ErrEcom []EcomAPIError

ErrEcomm represents errors returned from the Vipps Ecom API.

func (ErrEcom) Error

func (e ErrEcom) Error() string

type InitiatePaymentCommand

type InitiatePaymentCommand struct {
	MerchantInfo MerchantInfo `json:"merchantInfo"`
	CustomerInfo CustomerInfo `json:"customerInfo"`
	Transaction  Transaction  `json:"transaction"`
}

InitiatePaymentCommand represents the command used to initiate Vipps Ecom payments

type MerchantInfo

type MerchantInfo struct {
	// AuthToken, if set, will be used as the `Authorization` header of the
	// callback request that Vipps does to `CallbackURL` for transaction
	// updates.
	AuthToken string `json:"authToken,omitempty"`
	// MerchantSerialNumber uniquely represents a sales unit in the Vipps
	// system.
	MerchantSerialNumber string `json:"merchantSerialNumber"`
	// CallbackURL is a publicly reachable HTTP endpoint that will receive
	// transaction updates from Vipps.
	CallbackURL string `json:"callbackPrefix,omitempty"`
	// ConsentRemovalURL is a publicly reachable HTTP endpoint that will receive
	// requests for removal of user consents, for GDPR compliance.
	ConsentRemovalURL string `json:"consentRemovalPrefix,omitempty"`
	// RedirectURL is the URL clients are redirected to after completing the
	// payment flow in the Vipps app.
	RedirectURL string `json:"fallBack,omitempty"`
	// PaymentType selects the type of payment flow to use. If not provided,
	// `PaymentTypeRegular` is assumed by Vipps.
	PaymentType PaymentType `json:"paymentType,omitempty"`
	// IsApp signals whether the payment flow is initiated from a mobile app or
	// website. Returns a deep link url of the form `vipps://` if set to `true`.
	IsApp bool `json:"isApp,omitempty"`
	// ShippingDetailsURL is a publicly reachable HTTP endpoint that will
	// receive requests from Vipps to calculate shipping costs.
	ShippingDetailsURL string `json:"shippingDetailsPrefix,omitempty"`
	// ShippingMethods is a static list of shipping methods to present to the
	// user in the Vipps app.
	ShippingMethods []StaticShippingMethod `json:"staticShippingDetails,omitempty"`
}

MerchantInfo represents a merchant configuration to use for Vipps Ecom payments

type Payment

type Payment struct {
	OrderID            string                `json:"orderId"`
	ShippingDetails    ShippingDetails       `json:"shippingDetails"`
	TransactionLog     []TransactionLogEntry `json:"transactionLogHistory"`
	TransactionSummary TransactionSummary    `json:"transactionSummary"`
	UserDetails        UserDetails           `json:"userDetails"`
}

Payment represents a Vipps payment.

type PaymentReference

type PaymentReference struct {
	URL     string `json:"url"`
	OrderID string `json:"orderId"`
}

PaymentReference represents a reference to a Vipps payment

type PaymentType

type PaymentType string

PaymentType is the type of payment flow to use for Vipps Ecom payments

const (
	PaymentTypeRegular PaymentType = "eComm Regular Payment"
	PaymentTypeExpress PaymentType = "eComm Express Payment"
)

List of values that PaymentType can take

type RefundPaymentCommand

type RefundPaymentCommand struct {
	IdempotencyKey       string
	OrderID              string
	MerchantSerialNumber string
	TransactionText      string
	Amount               int
}

RefundPaymentCommand represents the command used to refund Vipps Ecom payments

type RefundedPayment

type RefundedPayment struct {
	OrderID            string             `json:"orderId"`
	TransactionInfo    TransactionInfo    `json:"transactionInfo"`
	TransactionSummary TransactionSummary `json:"transactionSummary"`
}

RefundedPayment represents a refunded Vipps Ecom payment

type ShippingCostRequest added in v0.1.1

type ShippingCostRequest struct {
	AddressID    int         `json:"addressId"`
	AddressLine1 string      `json:"addressLine1"`
	AddressLine2 string      `json:"addressLine2"`
	City         string      `json:"city"`
	Country      string      `json:"country"`
	PostCode     string      `json:"postCode"`
	AddressType  AddressType `json:"addressType"`
}

ShippingCostRequest is the request sent from Vipps to calculate shipping costs for an order.

type ShippingCostResponse added in v0.1.1

type ShippingCostResponse struct {
	AddressID       int                    `json:"addressId"`
	OrderID         string                 `json:"orderId"`
	ShippingDetails []StaticShippingMethod `json:"shippingDetails"`
}

ShippingCostResponse is sent in response to a ShippingCostRequest

type ShippingDetails

type ShippingDetails struct {
	Address          Address `json:"address"`
	ShippingCost     int     `json:"shippingCost"`
	ShippingMethod   string  `json:"shippingMethod"`
	ShippingMethodID string  `json:"shippingMethodId"`
}

ShippingDetails represents details for a shipping method

type StaticShippingMethod

type StaticShippingMethod struct {
	IsDefault        YesNoEnum `json:"isDefault"`
	Priority         int       `json:"priority"`
	ShippingCost     float64   `json:"shippingCost"`
	ShippingMethod   string    `json:"shippingMethod"`
	ShippingMethodID string    `json:"shippingMethodId"`
}

StaticShippingMethod represents a static shipping method represented to the user in the Vipps app.

type Timestamp

type Timestamp time.Time

Timestamp is a time.Time with a custom JSON marshaller.

func (Timestamp) MarshalJSON

func (t Timestamp) MarshalJSON() ([]byte, error)

type Transaction

type Transaction struct {
	// OrderID represents the order that this payment refers to. Must be unique
	// for each sales unit.
	OrderID string `json:"orderId"`
	// Amount is the amount (in cents) to be paid for the order.
	Amount int `json:"amount"`
	// TransactionText is the short message displayed to the user about the
	// payment in the Vipps app.
	TransactionText string `json:"transactionText"`
}

Transaction represents details for a Vipps Ecom payment.

type TransactionInfo

type TransactionInfo struct {
	Amount          int        `json:"amount"`
	Status          string     `json:"status"`
	Timestamp       *time.Time `json:"timeStamp"`
	TransactionID   string     `json:"transactionId"`
	TransactionText string     `json:"transactionText"`
}

TransactionInfo represents details about a Transaction in the Vipps Ecom system.

type TransactionLogEntry

type TransactionLogEntry struct {
	Amount           int        `json:"amount"`
	Operation        string     `json:"operation"`
	OperationSuccess bool       `json:"operationSuccess"`
	RequestID        string     `json:"requestId"`
	Timestamp        *time.Time `json:"timeStamp"`
	TransactionID    string     `json:"transactionId"`
	TransactionText  string     `json:"transactionText"`
}

TransactionLogEntry represents the list of transactions associated with a payment

type TransactionSummary

type TransactionSummary struct {
	CapturedAmount           int `json:"capturedAmount"`
	RefundedAmount           int `json:"refundedAmount"`
	RemainingAmountToCapture int `json:"remainingAmountToCapture"`
	RemainingAmountToRefund  int `json:"remainingAmountToRefund"`
	BankIdentificationNumber int `json:"bankIdentificationNumber"`
}

TransactionSummary represents a summary of captured, refunded and available amounts on a Vipps Ecom payment.

type TransactionUpdate added in v0.1.1

type TransactionUpdate struct {
	MerchantSerialNumber string           `json:"merchantSerialNumber"`
	OrderID              string           `json:"orderId"`
	ShippingDetails      *ShippingDetails `json:"shippingDetails"`
	TransactionInfo      *TransactionInfo `json:"transactionInfo"`
	UserDetails          *UserDetails     `json:"userDetails"`
	ErrorInfo            *EcomAPIError    `json:"errorInfo"`
}

TransactionUpdate represents a transaction update from Vipps

type UserDetails

type UserDetails struct {
	BankIDVerified string `json:"bankIdVerified"`
	DateOfBirth    string `json:"dateOfBirth"`
	Email          string `json:"email"`
	FirstName      string `json:"firstName"`
	LastName       string `json:"lastName"`
	MobileNumber   string `json:"mobileNumber"`
	SSN            string `json:"ssn"`
	UserID         string `json:"userId"`
}

UserDetails represents customer details from Vipps

type YesNoEnum

type YesNoEnum string

YesNoEnum is a binary choice between `Yes` or `No`.

const (
	Yes YesNoEnum = "Y"
	No  YesNoEnum = "N"
)

List of values that YesNoEnum can take.

Jump to

Keyboard shortcuts

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