Série: Go
go
40 linhas
· Atualizado 2026-04-18
payment.go
Go/payment-gateway-challenge/internal/models/payment.go
// Package models contains GORM entities mapped to PostgreSQL.
//
// PCI DSS note: we never persist full Primary Account Number (PAN) or CVV.
// Only the last four digits and the original PAN length are stored so we can
// render a masked card number on retrieval without keeping sensitive data.
package models
import (
"time"
"github.com/google/uuid"
)
// Payment is a single card payment attempt that reached the acquiring bank
// (status Authorized or Declined). Rejected validation failures are not stored.
type Payment struct {
ID uuid.UUID `gorm:"type:uuid;primaryKey"`
Status string `gorm:"size:20;not null;index"` // Authorized | Declined
CardLast4 string `gorm:"column:card_last_four;size:4;not null"`
// CardNumberLength records how many digits the PAN had (14–19) so we can
// build a same-length mask (e.g. ************1111) without storing the PAN.
CardNumberLength int `gorm:"not null"`
ExpiryMonth int `gorm:"not null"`
ExpiryYear int `gorm:"not null"`
Currency string `gorm:"size:3;not null"`
Amount int64 `gorm:"not null"`
// AuthorizationCode is returned by the bank simulator when authorized;
// NULL / empty when the bank declines.
AuthorizationCode *string `gorm:"size:64"`
CreatedAt time.Time `gorm:"autoCreateTime"`
}
// TableName keeps the physical table name explicit.
func (Payment) TableName() string {
return "payments"
}
Artigos relacionados
Go
go
Atualizado 2026-04-18
main.go
main.go — go source code from the Go learning materials (Go/Baasid/cmd/hashpw/main.go).
Ler artigo →
Go
go
Atualizado 2026-04-18
main.go
main.go — go source code from the Go learning materials (Go/Baasid/cmd/server/main.go).
Ler artigo →
Go
go
Atualizado 2026-04-18
docs.go
docs.go — go source code from the Go learning materials (Go/Baasid/docs/docs.go).
Ler artigo →
Go
go
Atualizado 2026-04-18
jwt.go
jwt.go — go source code from the Go learning materials (Go/Baasid/internal/auth/jwt.go).
Ler artigo →
Go
go
Atualizado 2026-04-18
password.go
password.go — go source code from the Go learning materials (Go/Baasid/internal/auth/password.go).
Ler artigo →
Go
go
Atualizado 2026-04-18
password_test.go
password_test.go — go source code from the Go learning materials (Go/Baasid/internal/auth/password_test.go).
Ler artigo →