database

package
v0.0.0-...-6a7e3ee Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// PaymentInitialized means process started. It's default state.
	PaymentInitialized paymentStatus

	// PaymentCompleted means process completed.
	PaymentCompleted
)

Variables

This section is empty.

Functions

This section is empty.

Types

type MockPaymentIntentRepository

type MockPaymentIntentRepository struct {
	Storage map[string]*PaymentIntent
}

MockPaymentIntentRepository is in-memory, database mimicking struct.

func (*MockPaymentIntentRepository) Create

func (p *MockPaymentIntentRepository) Create(referenceID, hookURL, successURL, failureURL string, amount float64) (*PaymentIntent, error)

Create inserts new intent to in-memory database with given parameters.

func (MockPaymentIntentRepository) FindOne

FindOne fetches record from in-memory database with given ID.

func (*MockPaymentIntentRepository) MarkAsCompleted

func (p *MockPaymentIntentRepository) MarkAsCompleted(ID string) error

MarkAsCompleted marks payment as complete for given ID.

type PaymentHookMessage

type PaymentHookMessage struct {
	ID          string    `json:"id"`
	Amount      float64   `json:"amount"`
	ReferenceID string    `json:"reference_id"`
	Status      int       `json:"status"`
	CreatedAt   time.Time `json:"created_at"`
}

PaymentHookMessage contains information that will send to hook.

type PaymentIntent

type PaymentIntent struct {
	ID          string        `bson:"_id,omitempty"`
	Amount      float64       `bson:"amount,omitempty"`
	ReferenceID string        `bson:"reference_id,omitempty"`
	Status      paymentStatus `bson:"status,omitempty"`

	CreatedAt time.Time `bson:"created_at,omitempty"`

	SuccessURL string `bson:"success_url,omitempty"`
	FailureURL string `bson:"failure_url,omitempty"`
	HookURL    string `bson:"hook_url,omitempty"`
}

PaymentIntent represents payments both completed and started.

func (PaymentIntent) AmountDisplay

func (i PaymentIntent) AmountDisplay() string

AmountDisplay displays float as two decimal string.

func (PaymentIntent) CreateHookMessage

func (i PaymentIntent) CreateHookMessage() PaymentHookMessage

CreateHookMessage creates PaymentHookMessage from intent.

type PaymentIntentRepository

type PaymentIntentRepository struct {
	Storage *mongo.Database
	Ctx     context.Context
}

PaymentIntentRepository Mongo integrated struct to handle create, find and update as defined in interface.

func (*PaymentIntentRepository) Create

func (p *PaymentIntentRepository) Create(referenceID, hookURL, successURL, failureURL string, amount float64) (*PaymentIntent, error)

Create creates document in mongo collection.

func (*PaymentIntentRepository) FindOne

FindOne retrieves one record.

func (*PaymentIntentRepository) MarkAsCompleted

func (p *PaymentIntentRepository) MarkAsCompleted(ID string) error

MarkAsCompleted updates given id record as completed.

type Repository

type Repository interface {
	Create(referenceID, hookURL, successURL, failureURL string, amount float64) (*PaymentIntent, error)
	FindOne(ID string) (*PaymentIntent, error)
	MarkAsCompleted(ID string) error
}

Repository is an interface for interacting between application and database.

Jump to

Keyboard shortcuts

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