order

package
v0.0.0-...-53bd342 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2023 License: GPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Create

func Create(ctx context.Context, db sqlx.ExtContext, order Order) error

Create inserts a new order with the passed information.

func CreateItem

func CreateItem(ctx context.Context, db sqlx.ExtContext, item Item) error

CreateItem adds a new item in an order.

func HandlePaypalCapture

func HandlePaypalCapture(db *sqlx.DB, pp *paypal.Client) web.Handler

HandlePaypalCapture checks if the user's purchase has been successfully completed. After the capture, the money of the user will be transferred to our paypal account.

func HandlePaypalCheckout

func HandlePaypalCheckout(db *sqlx.DB, pp *paypal.Client) web.Handler

HandlePaypalCheckout starts the purchase flow with paypal.

func HandleStripeCapture

func HandleStripeCapture(db *sqlx.DB, cfg config.Stripe) web.Handler

HandleStripeCapture completes the user's purchase. Stripe webhooks must be configured to call this endpoint when a checkout is completed.

TODO: Remember to disable async payments. https://stripe.com/docs/payments/checkout/fulfill-orders#delayed-notification . TODO: rename in HandleStripeWebhooks.

func HandleStripeCheckout

func HandleStripeCheckout(db *sqlx.DB, strp *stripecl.API, cfg config.Stripe) web.Handler

HandleStripeCheckout starts the purchase flow with stripe.

func UpdateStatus

func UpdateStatus(ctx context.Context, db sqlx.ExtContext, up StatusUp) error

UpdateStatus updates only the status and the date of an order.

Types

type Item

type Item struct {
	OrderID   string    `json:"orderId" db:"order_id"`
	CourseID  string    `json:"courseId" db:"course_id"`
	Price     int       `json:"price" db:"price"`
	CreatedAt time.Time `json:"createdAt" db:"created_at"`
}

Item models the item of an order. An item can only belong to one order. An order can have many items.

type Order

type Order struct {
	ID         string    `json:"id" db:"order_id"`
	UserID     string    `json:"userId" db:"user_id"`
	ProviderID string    `json:"providerId" db:"provider_id"`
	Status     Status    `json:"status" db:"status"`
	CreatedAt  time.Time `json:"createdAt" db:"created_at"`
	UpdatedAt  time.Time `json:"updatedAt" db:"updated_at"`
}

Order models orders. Orders have a one-to-many relationship with items.

func FetchByProviderID

func FetchByProviderID(ctx context.Context, db sqlx.ExtContext, provID string) (Order, error)

FetchByProviderID retrieves the order with the specified provider id, if any.

type Status

type Status string

Status models the possible states of an order.

const (
	Pending Status = "pending"
	Success Status = "success"
	Expired Status = "expired"
)

type StatusUp

type StatusUp struct {
	ID        string    `db:"order_id"`
	Status    Status    `db:"status"`
	UpdatedAt time.Time `db:"updated_at"`
}

StatusUp contains the information needed to update an order.

Jump to

Keyboard shortcuts

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