recurring

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package recurring provides a client and supporting types to consume and interact with the Vipps Recurring Payments API

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Agreement

type Agreement struct {
	Campaign           *Campaign       `json:"campaign"`
	Currency           Currency        `json:"currency"`
	ID                 string          `json:"id"`
	Interval           ChargeInterval  `json:"interval"`
	IntervalCount      int             `json:"intervalCount"`
	Price              int             `json:"price"`
	ProductName        string          `json:"productName"`
	ProductDescription string          `json:"productDescription"`
	Start              *time.Time      `json:"start"`
	End                *time.Time      `json:"end"`
	Status             AgreementStatus `json:"status"`
}

Agreement represents an agreement associated with a Vipps recurring payment.

type AgreementID

type AgreementID = string

type AgreementReference

type AgreementReference struct {
	AgreementResource string `json:"agreementResource"`
	AgreementID       string `json:"agreementId"`
	URL               string `json:"vippsConfirmationUrl"`
}

AgreementReference represents a reference to an agreement associated with a Vipps recurring payment.

type AgreementStatus

type AgreementStatus string

AgreementStatus is the current status of an Agreement.

const (
	AgreementStatusPending AgreementStatus = "PENDING"
	AgreementStatusActive  AgreementStatus = "ACTIVE"
	AgreementStatusStopped AgreementStatus = "STOPPED"
	AgreementStatusExpired AgreementStatus = "EXPIRED"
)

List of values that AgreementStatus can take.

type Campaign

type Campaign struct {
	Price int        `json:"campaignPrice"`
	End   *time.Time `json:"end"`
}

Campaign represents a Vipps Recurring Payments campaign.

type CaptureChargeCommand

type CaptureChargeCommand struct {
	ChargeIdentifier
	IdempotencyKey
}

CaptureChargeCommand represents the command used to capture a Charge.

type Charge

type Charge struct {
	Amount         int          `json:"amount"`
	AmountRefunded int          `json:"amountRefunded"`
	Description    string       `json:"description"`
	Due            time.Time    `json:"due"`
	ID             string       `json:"id"`
	Status         ChargeStatus `json:"status"`
	TransactionID  string       `json:"transactionId"`
	Type           ChargeType   `json:"type"`
}

Charge represents a charge associated with an Agreement.

type ChargeIdentifier

type ChargeIdentifier struct {
	AgreementID string `json:"-"`
	ChargeID    string `json:"-"`
}

ChargeIdentifier identifies a Charge.

type ChargeInterval

type ChargeInterval string

ChargeInterval represents the interval that recurring payments are charged.

const (
	ChargeIntervalMonth ChargeInterval = "MONTH"
	ChargeIntervalWeek  ChargeInterval = "WEEK"
	ChargeIntervalDay   ChargeInterval = "DAY"
)

List of values that ChargeInterval can take.

type ChargeReference

type ChargeReference struct {
	ChargeID string `json:"chargeId"`
}

ChargeReference is a reference to a Charge.

type ChargeStatus

type ChargeStatus string

ChargeStatus represents the current status for a Charge.

const (
	ChargeStatusPending           ChargeStatus = "PENDING"
	ChargeStatusDue               ChargeStatus = "DUE"
	ChargeStatusReserved          ChargeStatus = "RESERVED"
	ChargeStatusCharged           ChargeStatus = "CHARGED"
	ChargeStatusFailed            ChargeStatus = "FAILED"
	ChargeStatusCancelled         ChargeStatus = "CANCELLED"
	ChargeStatusPartiallyRefunded ChargeStatus = "PARTIALLY_REFUNDED"
	ChargeStatusRefunded          ChargeStatus = "REFUNDED"
	ChargeStatusProcessing        ChargeStatus = "PROCESSING"
)

List of values that ChargeStatus can take.

type ChargeType

type ChargeType string

ChargeType represents the type of charge used for a transaction.

const (
	ChargeTypeInitial   ChargeType = "INITIAL"
	ChargeTypeRecurring ChargeType = "RECURRING"
)

List of values that ChargeType can take.

type Client

type Client interface {
	// CreateCharge creates a Charge for an Agreement.
	CreateCharge(ctx context.Context, cmd CreateChargeCommand) (*ChargeReference, error)
	// CaptureCharge captures reserved amounts on a Charge.
	CaptureCharge(ctx context.Context, cmd CaptureChargeCommand) error
	// RefundCharge refunds already captured amounts on a Charge.
	RefundCharge(ctx context.Context, cmd RefundChargeCommand) error
	// CancelCharge deletes a Charge. Will error for Charges that are not in a
	// cancellable state.
	CancelCharge(ctx context.Context, cmd DeleteChargeCommand) (*Charge, error)
	// GetCharge gets a Charge associated with an Agreement.
	GetCharge(ctx context.Context, cmd GetChargeCommand) (*Charge, error)
	// ListCharges lists Charges associated with an Agreement.
	ListCharges(ctx context.Context, agreementID string, status ...ChargeStatus) ([]*Charge, error)
	// CreateAgreement creates an Agreement.
	CreateAgreement(ctx context.Context, cmd CreateAgreementCommand) (*AgreementReference, error)
	// UpdateAgreement updates an Agreement.
	UpdateAgreement(ctx context.Context, cmd UpdateAgreementCommand) (AgreementID, error)
	// ListAgreements lists Agreements for a sales unit.
	ListAgreements(ctx context.Context, status ...AgreementStatus) ([]*Agreement, error)
	// GetAgreement gets an Agreement.
	GetAgreement(ctx context.Context, agreementID string) (*Agreement, error)
}

Client is the interface that wraps all the methods available for interacting with the Vipps Recurring Payments API.

func NewClient

func NewClient(config vipps.ClientConfig) Client

NewClient returns a configured client that implements the Client interface.

type CreateAgreementCommand

type CreateAgreementCommand struct {
	Campaign            *Campaign      `json:"campaign,omitempty"`
	Currency            Currency       `json:"currency"`
	CustomerPhoneNumber string         `json:"customerPhoneNumber"`
	InitialCharge       InitialCharge  `json:"initialCharge"`
	Interval            ChargeInterval `json:"interval"`
	IntervalCount       int            `json:"intervalCount"`
	IsApp               bool           `json:"isApp"`
	AgreementURL        string         `json:"merchantAgreementUrl"`
	RedirectURL         string         `json:"merchantRedirectUrl"`
	Price               int            `json:"price"`
	ProductName         string         `json:"productName"`
	ProductDescription  string         `json:"productDescription"`
}

CreateAgreementCommand represents the command used to create an Agreement

type CreateChargeCommand

type CreateChargeCommand struct {
	IdempotencyKey
	AgreementID string   `json:"-"`
	Amount      int      `json:"amount"`
	Currency    Currency `json:"currency,omitempty"`
	Description string   `json:"description"`
	Due         DueDate  `json:"due"`
	RetryDays   int      `json:"retryDays,omitempty"`
	OrderID     string   `json:"orderId,omitempty"`
}

CreateChargeCommand represents the command used to created a Charge.

type Currency

type Currency string

Currency represents the currency to use for a Vipps Ecom payment.

const (
	CurrencyNOK Currency = "NOK"
)

List of values that Currency can take.

type DeleteChargeCommand

type DeleteChargeCommand struct {
	ChargeIdentifier
	IdempotencyKey
}

DeleteChargeCommand represents the command used to delete a Charge.

type DueDate

type DueDate struct {
	time.Time
}

DueDate is the date at which a charge is due to be paid

func (DueDate) MarshalJSON

func (d DueDate) MarshalJSON() ([]byte, error)

type ErrRecurring

type ErrRecurring []RecurringAPIError

ErrRecurring represents errors returned from the Vipps Recurring Payments API.

func (ErrRecurring) Error

func (e ErrRecurring) Error() string

type GetChargeCommand

type GetChargeCommand struct {
	ChargeIdentifier
}

GetChargeCommand represents the command used to get a Charge.

type IdempotencyKey

type IdempotencyKey = string

IdempotencyKey is used to make idempotent retries in mutating commands.

type InitialCharge

type InitialCharge struct {
	Amount          int             `json:"amount"`
	Currency        Currency        `json:"currency"`
	Description     string          `json:"description"`
	TransactionType TransactionType `json:"transactionType"`
	OrderID         string          `json:"orderId,omitempty"`
}

InitialCharge represents the initial charge used in a Vipps recurring payment.

type RecurringAPIError

type RecurringAPIError struct {
	Field     string `json:"field"`
	Code      string `json:"code"`
	Message   string `json:"message"`
	ContextID string `json:"contextId"`
}

RecurringAPIError represents a single error returned from the Vipps Recurring Payments API.

type RefundChargeCommand

type RefundChargeCommand struct {
	ChargeIdentifier `json:"-"`
	IdempotencyKey   `json:"-"`
	Amount           int    `json:"amount"`
	Description      string `json:"description"`
}

RefundChargeCommand represents the command used to refund a Charge.

type TransactionType

type TransactionType string

TransactionType represents the type of capture used for a payment.

const (
	TransactionTypeDirectCapture  TransactionType = "DIRECT_CAPTURE"
	TransactionTypeReserveCapture TransactionType = "RESERVE_CAPTURE"
)

List of values that TransactionType can take.

type UpdateAgreementCommand

type UpdateAgreementCommand struct {
	AgreementID        string          `json:"-"`
	Campaign           *Campaign       `json:"campaign,omitempty"`
	Price              int             `json:"price,omitempty"`
	ProductName        string          `json:"productName,omitempty"`
	ProductDescription string          `json:"productDescription,omitempty"`
	Status             AgreementStatus `json:"status,omitempty"`
}

UpdateAgreementCommand represents the command used to update an Agreement

Jump to

Keyboard shortcuts

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