Reorganized code + migration to go1.22
This commit is contained in:
1 parent
e3d77d55b9
commit
7369777098
25 files changed
+825
-605
No files matched your search
@@ -0,0 +1,44 @@
|
||||
package mock
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/google/uuid"
|
||||
"log/slog"
|
||||
database2 "payment-poc/domain/database"
|
||||
"payment-poc/domain/state"
|
||||
)
|
||||
|
||||
type Service struct {
|
||||
BackendUrl string
|
||||
}
|
||||
|
||||
func (s Service) UpdatePayment(entry database2.PaymentEntry) (updatedEntry database2.PaymentEntry, err error) {
|
||||
return entry, nil
|
||||
}
|
||||
|
||||
func (s Service) CreatePaymentUrl(entry database2.PaymentEntry) (updateEntry database2.PaymentEntry, url string, err error) {
|
||||
return entry, "/mock/gateway/" + entry.Id.String(), nil
|
||||
}
|
||||
|
||||
func (s Service) CompleteTransaction(entry database2.PaymentEntry, amount int64) (database2.PaymentEntry, error) {
|
||||
entry.Amount = &amount
|
||||
entry.State = state.StateCompleted
|
||||
return entry, nil
|
||||
}
|
||||
|
||||
func (s Service) CancelTransaction(entry database2.PaymentEntry) (database2.PaymentEntry, error) {
|
||||
entry.State = state.StateVoided
|
||||
return entry, nil
|
||||
}
|
||||
|
||||
func (s Service) HandleResponse(c *gin.Context, provider *database2.PaymentEntryProvider, paymentState state.PaymentState) (string, error) {
|
||||
id := uuid.MustParse(c.Query("id"))
|
||||
entry, err := provider.FetchById(id)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
entry.State = paymentState
|
||||
_, err = provider.UpdateEntry(entry)
|
||||
slog.Info("received authorization response", "entry_id", entry.Id.String(), "state", entry.State)
|
||||
return "/entries/" + id.String(), err
|
||||
}
|
||||
Reference in new issue
Block a user