Added support for stripe
This commit is contained in:
1 parent
3de5c8b0f1
commit
cefc5314f2
16 files changed
+365
-72
No files matched your search
@@ -0,0 +1,16 @@
|
||||
package stripe
|
||||
|
||||
import (
|
||||
"github.com/google/uuid"
|
||||
"payment-poc/state"
|
||||
)
|
||||
|
||||
type StripeDb struct {
|
||||
Id uuid.UUID `db:"id"`
|
||||
TotalAmount int64 `db:"total_amount"`
|
||||
Lang string `db:"lang"`
|
||||
|
||||
PaymentIntentId string `db:"payment_intent_id"`
|
||||
|
||||
State state.PaymentState `db:"payment_state"`
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package stripe
|
||||
|
||||
import (
|
||||
"github.com/google/uuid"
|
||||
"github.com/jmoiron/sqlx"
|
||||
"payment-poc/state"
|
||||
)
|
||||
|
||||
type Service struct {
|
||||
DB *sqlx.DB
|
||||
}
|
||||
|
||||
func (s *Service) CreateEntry(totalAmount int64) (StripeDb, error) {
|
||||
id := uuid.Must(uuid.NewRandom())
|
||||
entry := StripeDb{
|
||||
Id: id,
|
||||
TotalAmount: totalAmount,
|
||||
State: state.StateInitialized,
|
||||
}
|
||||
_, err := s.DB.Exec(`INSERT INTO "stripe" ("id", "total_amount", "payment_state") VALUES ($1, $2, $3)`,
|
||||
&entry.Id, &entry.TotalAmount, &entry.State,
|
||||
)
|
||||
if err != nil {
|
||||
return StripeDb{}, err
|
||||
}
|
||||
return s.FetchById(id)
|
||||
}
|
||||
|
||||
func (s *Service) FetchAll() ([]StripeDb, error) {
|
||||
var entries []StripeDb
|
||||
err := s.DB.Select(&entries, `SELECT * FROM "stripe"`)
|
||||
return entries, err
|
||||
}
|
||||
|
||||
func (s *Service) FetchById(id uuid.UUID) (StripeDb, error) {
|
||||
entry := StripeDb{}
|
||||
err := s.DB.Get(&entry, `SELECT * FROM "stripe" WHERE "id" = $1`, id)
|
||||
return entry, err
|
||||
}
|
||||
|
||||
func (s *Service) Update(entry StripeDb) error {
|
||||
_, err := s.DB.Exec(`UPDATE "stripe" set "payment_intent_id" = $2, "payment_state" = $3 WHERE "id" = $1`,
|
||||
&entry.Id, &entry.PaymentIntentId, &entry.State,
|
||||
)
|
||||
return err
|
||||
}
|
||||
Reference in new issue
Block a user