stripesync

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoSyncState = fmt.Errorf("no sync state found")

ErrNoSyncState is returned when no sync state is found in the database.

Functions

This section is empty.

Types

type Config

type Config struct {
	StripeAPIKey string

	// ExcludedFields is a list of fields that should be excluded from the sync.
	ExcludedFields []string

	Postgres PostgresConfig
}

Config is the configuration for the StripeSync handle.

type PostgresConfig

type PostgresConfig struct {
	Host     string
	Port     int
	User     string
	Password string
	DBName   string
	SSLMode  string
}

PostgresConfig is the configuration for the connection to the Postgres database.

func (PostgresConfig) StoreConfig

func (pc PostgresConfig) StoreConfig() postgres.Config

StoreConfig returns the PostgresConfig as the postgres package expects it.

type StripeSync

type StripeSync struct {
	// contains filtered or unexported fields
}

StripeSync is a struct that holds the common global state for all operations.

func New

func New(cfg Config) (*StripeSync, error)

New creates a new StripeSync handle.

func (*StripeSync) GetCurrentSyncState

func (o *StripeSync) GetCurrentSyncState(ctx context.Context) (SyncState, error)

GetCurrentSyncState returns the current sync state from the database.

func (*StripeSync) InitialLoad

func (o *StripeSync) InitialLoad(ctx context.Context, purge bool) error

InitialLoad loads all data from Stripe into the database. This is generally necessary if you have not synced in the last 30 days, as Stripe only keeps events for 30 days. If purge is true, it will delete all existing data from the database before loading.

func (StripeSync) MigrateDB

func (o StripeSync) MigrateDB(ctx context.Context) error

MigrateDB automatically migrates the database schema to the latest version. This is useful for setting up the database schema for the first time.

This only happens the happy path, if there are any errors, the user will need to fix them manually.

func (*StripeSync) SyncEvents

func (o *StripeSync) SyncEvents(ctx context.Context) error

SyncEvents syncs all events from stripe (which are up to 30 days old) to the database.

type SyncState

type SyncState struct {
	// LastEvent is the timestamp of the last event that was synced in unix time.
	LastEvent int64
	// contains filtered or unexported fields
}

SyncState contains information about previous sync operations.

func (SyncState) LastEventTime

func (s SyncState) LastEventTime() time.Time

LastEventTime returns the time of the last event that was synced.

func (SyncState) MayBeOutdated

func (s SyncState) MayBeOutdated() bool

MayBeOutdated returns true if the sync state is older than 30 days.

Jump to

Keyboard shortcuts

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