paypal

package
v0.0.0-...-0746445 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// The API endpoint to call, provided in the config file
	EndpointKey = "ENDPOINT"

	// Fields needed to make a request
	MethodKey  = "METHOD"
	VersionKey = "VERSION"

	// These are security params, provided in the config file
	UserKey      = "USER"
	PasswordKey  = "PWD"
	SignatureKey = "SIGNATURE"
)
View Source
const PayPalDateFormat = "2006-01-02T15:04:05Z"

Variables

This section is empty.

Functions

func GetEndDate

func GetEndDate(year, month int) string

TODO: Maybe move...

func ParseNvpName

func ParseNvpName(name string) (string, int)

Types

type ByDate

type ByDate struct{ Transactions }

func (ByDate) Less

func (s ByDate) Less(i, j int) bool

type Client

type Client struct {
	Debug bool
	// contains filtered or unexported fields
}

func NewClient

func NewClient(config *Config) *Client

func (*Client) GetAndSaveMonth

func (c *Client) GetAndSaveMonth(year, month int, fm *FileManager) error

func (*Client) GetTransactions

func (c *Client) GetTransactions(startDate, endDate string) Transactions

func (*Client) GetTransactionsForMonth

func (c *Client) GetTransactionsForMonth(year, month int) Transactions

type Config

type Config struct {
	Endpoint  string `json:"endpoint"`
	User      string `json:"user"`
	Password  string `json:"password"`
	Signature string `json:"signature"`
}

Config has various config values for getting PayPal transations with their NVP API

type FileManager

type FileManager struct {
	Year   int
	Months map[int]Transactions
}

FileManager manages files containing PayPal transactions fetched from the PayPal API.

func NewEmptyFileManager

func NewEmptyFileManager(year int) *FileManager

func NewFileManager

func NewFileManager(year int) (*FileManager, error)

NewFileManager will load any PayPal files for the given year from the data directory, and can be used to save new transactions there.

func (*FileManager) GetExistingMonths

func (p *FileManager) GetExistingMonths() []int

GetExistingMonths will return all months which are currently stored in this file manager.

func (*FileManager) GetLatestMonth

func (p *FileManager) GetLatestMonth() int

GetLatestMonth returns the latest month with transactions loaded by this file manager. When managing the current year, this helps determine what new data needs to be fetched from the PayPal API.

func (*FileManager) GetLatestTransaction

func (p *FileManager) GetLatestTransaction() *Transaction

GetLatestTransaction will get the most recent transaction from the most recent month stored in this file manager.

func (*FileManager) GetMissingMonths

func (p *FileManager) GetMissingMonths() []int

GetMissingMonths will return all months which are not currently stored in this file manager.

func (*FileManager) SaveMonth

func (p *FileManager) SaveMonth(month int, txns Transactions) error

SaveMonth will save the given transactions to a file for that month, and add these transactions to the Months stored in this manager.

type NameValues

type NameValues map[string]string

type NvpResult

type NvpResult struct {
	Ack  string
	List map[int]NameValues
}

func ParseNvpData

func ParseNvpData(data string) *NvpResult

func (*NvpResult) Successful

func (n *NvpResult) Successful() bool

type Transaction

type Transaction struct {
	Timestamp     time.Time `json:"timestamp,omitempty"`
	Type          string    `json:"type,omitempty"`
	Email         string    `json:"email,omitempty"`
	Name          string    `json:"name,omitempty"`
	TransactionID string    `json:"transaction_id,omitempty"`
	Status        string    `json:"status,omitempty"`
	Amt           float32   `json:"amt,omitempty"`
	FeeAmt        float32   `json:"fee_amt,omitempty"`
	NetAmt        float32   `json:"net_amt,omitempty"`
	CurrencyCode  string    `json:"currency_code,omitempty"`
}

func NewTransaction

func NewTransaction(tran map[string]string) *Transaction

func (*Transaction) IsDonation

func (p *Transaction) IsDonation() bool

func (*Transaction) IsSubscription

func (p *Transaction) IsSubscription() bool

func (*Transaction) String

func (p *Transaction) String() string

type Transactions

type Transactions []*Transaction

func TransactionsFromNvp

func TransactionsFromNvp(nvp *NvpResult) Transactions

func (Transactions) FilterDonations

func (p Transactions) FilterDonations() (Transactions, Transactions)

func (Transactions) Len

func (p Transactions) Len() int

func (Transactions) Merge

func (p Transactions) Merge(other Transactions) Transactions

func (Transactions) Sort

func (p Transactions) Sort()

func (Transactions) Summarize

func (p Transactions) Summarize() util.MonthlySummaries

func (Transactions) Swap

func (p Transactions) Swap(i, j int)

func (Transactions) TotalByCurrency

func (p Transactions) TotalByCurrency() util.CurrencyAmounts

type TransactionsJSON

type TransactionsJSON struct {
	Transactions Transactions `json:"transactions"`
}

TransactionsJSON is the structure that will be saved to and loaded from files.

Jump to

Keyboard shortcuts

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